示例#1
0
        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));
            }
        }
示例#2
0
        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);
        }
示例#3
0
        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);
        }
示例#4
0
        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);
        }
示例#5
0
        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);
        }
示例#6
0
 private static extern NvmlReturn nvmlDeviceGetPcieThroughput(NvmlDevice device, NvmlPcieUtilCounter counter, out uint value);
示例#7
0
 private static extern NvmlReturn nvmlDeviceGetPowerUsage(NvmlDevice device, out int power);
示例#8
0
 private static extern NvmlReturn nvmlDeviceGetHandleByIndexLegacy(int index, out NvmlDevice device);
示例#9
0
 private static extern NvmlReturn nvmlDeviceGetHandleByPciBusId([MarshalAs(UnmanagedType.LPStr)] string pciBusId, out NvmlDevice device);
示例#10
0
 public static extern int NvmlDeviceGetUtilizationRates(NvmlDevice device, ref NvmlUtilization utilization);
示例#11
0
 public static extern int NvmlDeviceGetClockInfo(NvmlDevice device, NvmlClockType type, ref uint clock);
示例#12
0
 public static extern int NvmlDeviceGetPowerUsage(NvmlDevice device, ref uint power);
示例#13
0
 public static extern int NvmlDeviceGetFanSpeed(NvmlDevice device, ref uint speed);
示例#14
0
 public static extern int NvmlDeviceGetTemperature(NvmlDevice device, NvmlTemperatureSensors sensorType, ref uint temp);
示例#15
0
 public static extern int NvmlDeviceGetHandleByPciBusId([MarshalAs(UnmanagedType.LPStr)] string pciBusId, ref NvmlDevice device);