/// <summary> /// Helper function to create and initialize a new instance of NvmlAPI. /// </summary> private static NvmlAPI CreateInitAPI(NvmlAPIVersion?apiVersion) { var api = NvmlAPI.Create(apiVersion); NvmlException.ThrowIfFailed(api.Init()); return(api); }
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)); } }