Add GPU detection and usage retrieval with error handling

This commit is contained in:
sothman01
2025-04-28 13:42:16 +08:00
parent 5eec358b68
commit caa7436d51
2 changed files with 85 additions and 19 deletions
+9
View File
@@ -9,6 +9,15 @@ public static class NvmlWrapper
[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);