static void Main() { using var context = Context.Create(builder => builder.Cuda()); foreach (var device in context) { using var accelerator = device.CreateAccelerator(context) as CudaAccelerator; Console.WriteLine($"Performing operations on {accelerator}"); // Create NvmlDevice wrapper using var nvmlDevice = NvmlDevice.CreateFromAccelerator(accelerator); var temp = nvmlDevice.GetGpuTemperature(); // Calling low-level NvmlAPI directly NvmlException.ThrowIfFailed( nvmlDevice.API.DeviceGetTemperature( nvmlDevice.DeviceHandle, NvmlTemperatureSensors.NVML_TEMPERATURE_GPU, out temp)); // Create separate NvmlAPI instance var nvml = NvmlAPI.Create(NvmlAPIVersion.V6); NvmlException.ThrowIfFailed( nvml.UnitGetCount(out uint count)); } }
private static bool GetDeviceByPciBusID(string fullPciBusID, out NvmlDevice device, out string errorMessage) { device = new NvmlDevice(); var response = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? PInvokeWindows.NvmlDeviceGetHandleByPciBusId(fullPciBusID, ref device) : RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? PInvokeLinux.NvmlDeviceGetHandleByPciBusId(fullPciBusID, ref device) : 12; errorMessage = (response == SUCCESS) ? string.Empty : NvmlErrorString(response); return(response == SUCCESS); }
internal static uint?NvmlDeviceGetPcieThroughput(NvmlDevice nvmlDevice, NvmlPcieUtilCounter counter) { if (IsAvailable) { uint pcieThroughput; if (Software.OperatingSystem.IsUnix) { if (nvmlDeviceGetPcieThroughput(nvmlDevice, counter, out pcieThroughput) == NvmlReturn.Success) { return(pcieThroughput); } } else if (_windowsNvmlDeviceGetPcieThroughputDelegate(nvmlDevice, counter, out pcieThroughput) == NvmlReturn.Success) { return(pcieThroughput); } } return(null); }
internal static int?NvmlDeviceGetPowerUsage(NvmlDevice nvmlDevice) { if (IsAvailable) { int powerUsage; if (Software.OperatingSystem.IsUnix) { if (nvmlDeviceGetPowerUsage(nvmlDevice, out powerUsage) == NvmlReturn.Success) { return(powerUsage); } } else if (_windowsNvmlDeviceGetPowerUsage(nvmlDevice, out powerUsage) == NvmlReturn.Success) { return(powerUsage); } } return(null); }
public float?GetSensorValue(int deviceIndex, SensorType sensorType) { NvmlDevice device = nvmlDevices[deviceIndex]; switch (sensorType) { case SensorType.GFX_LOAD: throw new NotImplementedException(); case SensorType.GFX_TEMPERATURE: throw new NotImplementedException(); case SensorType.GFX_POWER: if (NvmlDeviceGetPowerUsage != null && NvmlDeviceGetPowerUsage(device, out int power) == 0) { return(power * 0.001f); } break; } return(null); }
private static extern NvmlReturn nvmlDeviceGetPcieThroughput(NvmlDevice device, NvmlPcieUtilCounter counter, out uint value);
private static extern NvmlReturn nvmlDeviceGetPowerUsage(NvmlDevice device, out int power);
private static extern NvmlReturn nvmlDeviceGetHandleByIndexLegacy(int index, out NvmlDevice device);
private static extern NvmlReturn nvmlDeviceGetHandleByPciBusId([MarshalAs(UnmanagedType.LPStr)] string pciBusId, out NvmlDevice device);
public static extern int NvmlDeviceGetUtilizationRates(NvmlDevice device, ref NvmlUtilization utilization);
public static extern int NvmlDeviceGetClockInfo(NvmlDevice device, NvmlClockType type, ref uint clock);
public static extern int NvmlDeviceGetPowerUsage(NvmlDevice device, ref uint power);
public static extern int NvmlDeviceGetFanSpeed(NvmlDevice device, ref uint speed);
public static extern int NvmlDeviceGetTemperature(NvmlDevice device, NvmlTemperatureSensors sensorType, ref uint temp);
public static extern int NvmlDeviceGetHandleByPciBusId([MarshalAs(UnmanagedType.LPStr)] string pciBusId, ref NvmlDevice device);