示例#1
0
        private static bool InitialiseDelegates()
        {
            IntPtr nvmlInit = Kernel32.GetProcAddress(WindowsDll, "nvmlInit_v2");

            if (nvmlInit != IntPtr.Zero)
            {
                _windowsNvmlInit = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlInit, typeof(WindowsNvmlDelegate));
            }
            else
            {
                nvmlInit = Kernel32.GetProcAddress(WindowsDll, "nvmlInit");
                if (nvmlInit != IntPtr.Zero)
                {
                    _windowsNvmlInit = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlInit, typeof(WindowsNvmlDelegate));
                }
                else
                {
                    return(false);
                }
            }

            IntPtr nvmlShutdown = Kernel32.GetProcAddress(WindowsDll, "nvmlShutdown");

            if (nvmlShutdown != IntPtr.Zero)
            {
                _windowsNvmlShutdown = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlShutdown, typeof(WindowsNvmlDelegate));
            }
            else
            {
                return(false);
            }


            IntPtr nvmlGetHandle = Kernel32.GetProcAddress(WindowsDll, "nvmlDeviceGetHandleByIndex_v2");

            if (nvmlGetHandle != IntPtr.Zero)
            {
                _windowsNvmlDeviceGetHandleByIndex = (WindowsNvmlGetHandleDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandle, typeof(WindowsNvmlGetHandleDelegate));
            }
            else
            {
                nvmlGetHandle = Kernel32.GetProcAddress(WindowsDll, "nvmlDeviceGetHandleByIndex");
                if (nvmlGetHandle != IntPtr.Zero)
                {
                    _windowsNvmlDeviceGetHandleByIndex = (WindowsNvmlGetHandleDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandle, typeof(WindowsNvmlGetHandleDelegate));
                }
                else
                {
                    return(false);
                }
            }

            IntPtr nvmlGetPowerUsage = Kernel32.GetProcAddress(WindowsDll, "nvmlDeviceGetPowerUsage");

            if (nvmlGetPowerUsage != IntPtr.Zero)
            {
                _windowsNvmlDeviceGetPowerUsage = (WindowsNvmlGetPowerUsageDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetPowerUsage, typeof(WindowsNvmlGetPowerUsageDelegate));
            }
            else
            {
                return(false);
            }

            IntPtr nvmlGetPcieThroughput = Kernel32.GetProcAddress(WindowsDll, "nvmlDeviceGetPcieThroughput");

            if (nvmlGetPcieThroughput != IntPtr.Zero)
            {
                _windowsNvmlDeviceGetPcieThroughputDelegate = (WindowsNvmlDeviceGetPcieThroughputDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetPcieThroughput, typeof(WindowsNvmlDeviceGetPcieThroughputDelegate));
            }
            else
            {
                return(false);
            }

            IntPtr nvmlGetHandlePciBus = Kernel32.GetProcAddress(WindowsDll, "nvmlDeviceGetHandleByPciBusId_v2");

            if (nvmlGetHandlePciBus != IntPtr.Zero)
            {
                _windowsNvmlDeviceGetHandleByPciBusId = (WindowsNvmlGetHandleByPciBusIdDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandlePciBus, typeof(WindowsNvmlGetHandleByPciBusIdDelegate));
            }
            else
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        private bool InitialiseDelegates()
        {
            var nvmlInit = GetProcAddress(windowsDll, "nvmlInit_v2");

            if (nvmlInit != IntPtr.Zero)
            {
                WindowsNvmlInit = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlInit, typeof(WindowsNvmlDelegate));
            }
            else
            {
                nvmlInit = GetProcAddress(windowsDll, "nvmlInit");
                if (nvmlInit != IntPtr.Zero)
                {
                    WindowsNvmlInit = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlInit, typeof(WindowsNvmlDelegate));
                }
                else
                {
                    return(false);
                }
            }

            var nvmlShutdown = GetProcAddress(windowsDll, "nvmlShutdown");

            if (nvmlShutdown != IntPtr.Zero)
            {
                WindowsNvmlShutdown = (WindowsNvmlDelegate)Marshal.GetDelegateForFunctionPointer(nvmlShutdown, typeof(WindowsNvmlDelegate));
            }
            else
            {
                return(false);
            }

            var nvmlGetHandle = GetProcAddress(windowsDll, "nvmlDeviceGetHandleByIndex_v2");

            if (nvmlGetHandle != IntPtr.Zero)
            {
                WindowsNvmlDeviceGetHandleByIndex = (WindowsNvmlGetHandleDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandle, typeof(WindowsNvmlGetHandleDelegate));
            }
            else
            {
                nvmlGetHandle = GetProcAddress(windowsDll, "nvmlDeviceGetHandleByIndex");
                if (nvmlGetHandle != IntPtr.Zero)
                {
                    WindowsNvmlDeviceGetHandleByIndex = (WindowsNvmlGetHandleDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetHandle, typeof(WindowsNvmlGetHandleDelegate));
                }
                else
                {
                    return(false);
                }
            }

            var nvmlGetPowerUsage = GetProcAddress(windowsDll, "nvmlDeviceGetPowerUsage");

            if (nvmlGetPowerUsage != IntPtr.Zero)
            {
                WindowsNvmlDeviceGetPowerUsage = (WindowsNvmlGetPowerUsageDelegate)Marshal.GetDelegateForFunctionPointer(nvmlGetPowerUsage, typeof(WindowsNvmlGetPowerUsageDelegate));
            }
            else
            {
                return(false);
            }

            return(true);
        }