using System; using System.Runtime.InteropServices; public static class NvmlWrapper { [DllImport("nvml.dll", EntryPoint = "nvmlInit_v2")] public static extern int NvmlInit(); [DllImport("nvml.dll", EntryPoint = "nvmlShutdown")] public static extern int NvmlShutdown(); // Get device count [DllImport("nvml.dll", CallingConvention = CallingConvention.Cdecl)] private static extern int nvmlDeviceGetCount_v2(ref uint deviceCount); public static int NvmlDeviceGetCount(ref uint deviceCount) { return nvmlDeviceGetCount_v2(ref deviceCount); } [DllImport("nvml.dll", EntryPoint = "nvmlDeviceGetHandleByIndex_v2")] public static extern int NvmlDeviceGetHandleByIndex(int index, out IntPtr device); [DllImport("nvml.dll", EntryPoint = "nvmlDeviceGetUtilizationRates")] public static extern int NvmlDeviceGetUtilizationRates(IntPtr device, out NvmlUtilization utilization); [DllImport("nvml.dll", EntryPoint = "nvmlDeviceGetTemperature")] public static extern int NvmlDeviceGetTemperature(IntPtr device, uint sensorType, out uint temp); [DllImport("nvml.dll", EntryPoint = "nvmlDeviceGetFanSpeed")] public static extern int NvmlDeviceGetFanSpeed(IntPtr device, out uint speed); [StructLayout(LayoutKind.Sequential)] public struct NvmlUtilization { public uint Gpu; public uint Memory; } }