/// <summary> /// Returns information about each of the GPU devices in the system. /// </summary> /// <returns></returns> public static List <NVMLGPUInfo> GetGPUsInfo() { CheckInitialized(); List <NVMLGPUInfo> infos = new List <NVMLGPUInfo>(); for (uint i = 0; i < deviceCount; i++) { uint ret = NVMLMethods.nvmlDeviceGetHandleByIndex(i, out IntPtr device); StringBuilder name = new StringBuilder(50); NVMLMethods.nvmlDeviceGetName(device, name, 50); NVMLMethods.nvmlDeviceGetTemperature(device, 0, out uint temperatureCentigrade); NVMLMethods.nvmlDeviceGetUtilizationRates(device, out NVMLUtilization utilization); NVMLClocksThrottleReasons clocksThrottleReasons = 0; NVMLMethods.nvmlDeviceGetCurrentClocksThrottleReasons(device, ref clocksThrottleReasons); uint major = 0; uint minor = 0; NVMLMethods.nvmlDeviceGetCudaComputeCapability(device, ref major, ref minor); uint clocksSM = 0; NVMLMethods.nvmlDeviceGetClockInfo(device, nvmlClockType.Graphics, ref clocksSM); infos.Add(new NVMLGPUInfo((int)i, name.ToString(), (int)major, (int)minor, (int)clocksSM, (int)utilization.UtilizationGPUPct, (int)utilization.UtilizationMemoryPct, (int)temperatureCentigrade, clocksThrottleReasons)); } return(infos); }
static void CheckInitialized() { if (!haveInitialized) { NVMLMethods.nvmlInit(); haveInitialized = true; NVMLMethods.nvmlDeviceGetCount(out deviceCount); } }
public static void Shutdown() { NVMLMethods.nvmlShutdown(); haveInitialized = false; }