node-gpuinfo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +336 -0
  3. package/binding.gyp +69 -0
  4. package/build/Release/gpu.exp +0 -0
  5. package/build/Release/gpu.lib +0 -0
  6. package/build/Release/gpu.node +0 -0
  7. package/build/Release/gpu.pdb +0 -0
  8. package/build/binding.sln +19 -0
  9. package/build/gpu.vcxproj +175 -0
  10. package/build/gpu.vcxproj.filters +169 -0
  11. package/example.js +69 -0
  12. package/index.js +33 -0
  13. package/package.json +68 -0
  14. package/src/binding.cpp +201 -0
  15. package/src/gpu_info.c +130 -0
  16. package/src/gpu_info.h +86 -0
  17. package/src/includes/adlx/ADLX.h +367 -0
  18. package/src/includes/adlx/ADLXDefines.h +1345 -0
  19. package/src/includes/adlx/ADLXHelper/ADLXHelper.c +175 -0
  20. package/src/includes/adlx/ADLXHelper/ADLXHelper.h +245 -0
  21. package/src/includes/adlx/ADLXHelper/WinAPIS.c +64 -0
  22. package/src/includes/adlx/ADLXStructures.h +206 -0
  23. package/src/includes/adlx/ADLXVersion.h +18 -0
  24. package/src/includes/adlx/I3DSettings.h +3476 -0
  25. package/src/includes/adlx/I3DSettings1.h +292 -0
  26. package/src/includes/adlx/I3DSettings2.h +317 -0
  27. package/src/includes/adlx/IApplications.h +397 -0
  28. package/src/includes/adlx/IChangedEvent.h +71 -0
  29. package/src/includes/adlx/ICollections.h +325 -0
  30. package/src/includes/adlx/IDesktops.h +918 -0
  31. package/src/includes/adlx/IDisplay3DLUT.h +663 -0
  32. package/src/includes/adlx/IDisplayGamma.h +683 -0
  33. package/src/includes/adlx/IDisplayGamut.h +760 -0
  34. package/src/includes/adlx/IDisplaySettings.h +3476 -0
  35. package/src/includes/adlx/IDisplays.h +2676 -0
  36. package/src/includes/adlx/IDisplays1.h +191 -0
  37. package/src/includes/adlx/IDisplays2.h +188 -0
  38. package/src/includes/adlx/IDisplays3.h +256 -0
  39. package/src/includes/adlx/IGPUAutoTuning.h +460 -0
  40. package/src/includes/adlx/IGPUManualFanTuning.h +1007 -0
  41. package/src/includes/adlx/IGPUManualGFXTuning.h +607 -0
  42. package/src/includes/adlx/IGPUManualPowerTuning.h +340 -0
  43. package/src/includes/adlx/IGPUManualVRAMTuning.h +576 -0
  44. package/src/includes/adlx/IGPUPresetTuning.h +469 -0
  45. package/src/includes/adlx/IGPUTuning.h +1239 -0
  46. package/src/includes/adlx/IGPUTuning1.h +197 -0
  47. package/src/includes/adlx/II2C.h +198 -0
  48. package/src/includes/adlx/ILog.h +72 -0
  49. package/src/includes/adlx/IMultiMedia.h +578 -0
  50. package/src/includes/adlx/IPerformanceMonitoring.h +2520 -0
  51. package/src/includes/adlx/IPerformanceMonitoring1.h +134 -0
  52. package/src/includes/adlx/IPerformanceMonitoring2.h +341 -0
  53. package/src/includes/adlx/IPerformanceMonitoring3.h +199 -0
  54. package/src/includes/adlx/IPowerTuning.h +473 -0
  55. package/src/includes/adlx/IPowerTuning1.h +515 -0
  56. package/src/includes/adlx/ISmartAccessMemory.h +114 -0
  57. package/src/includes/adlx/ISystem.h +1557 -0
  58. package/src/includes/adlx/ISystem1.h +237 -0
  59. package/src/includes/adlx/ISystem2.h +643 -0
  60. package/src/linux/amd_linux.c +269 -0
  61. package/src/linux/intel_linux.c +20 -0
  62. package/src/linux/nvidia_linux.c +257 -0
  63. package/src/macos/amd_mac.c +131 -0
  64. package/src/macos/intel_mac.c +131 -0
  65. package/src/macos/nvidia_mac.c +21 -0
  66. package/src/vendor/amd.c +37 -0
  67. package/src/vendor/intel.c +37 -0
  68. package/src/vendor/nvidia.c +37 -0
  69. package/src/windows/amd_windows.c +468 -0
  70. package/src/windows/intel_windows.c +157 -0
  71. package/src/windows/nvidia_windows.c +252 -0
@@ -0,0 +1,252 @@
1
+ #include "../gpu_info.h"
2
+ #include <windows.h>
3
+ #include <stdio.h>
4
+ #include <string.h>
5
+
6
+ static HMODULE nvml_library = NULL;
7
+ static int nvml_initialized = 0;
8
+
9
+ // NVML structures
10
+ typedef struct {
11
+ unsigned long long total;
12
+ unsigned long long free;
13
+ unsigned long long used;
14
+ } nvmlMemory_t;
15
+
16
+ typedef struct {
17
+ unsigned int gpu;
18
+ unsigned int memory;
19
+ } nvmlUtilization_t;
20
+
21
+ // PCI info structure
22
+ typedef struct {
23
+ char busId[16]; // PCI bus ID in format: "0000:00:00.0"
24
+ unsigned int domain;
25
+ unsigned int bus;
26
+ unsigned int device;
27
+ unsigned int pciDeviceId;
28
+ unsigned int pciSubSystemId;
29
+ } nvmlPciInfo_t;
30
+
31
+ // Function pointers
32
+ static int (*nvmlInit_v2)(void) = NULL;
33
+ static int (*nvmlShutdown)(void) = NULL;
34
+ static int (*nvmlDeviceGetCount_v2)(unsigned int*) = NULL;
35
+ static int (*nvmlDeviceGetHandleByIndex)(unsigned int, void**) = NULL;
36
+ static int (*nvmlDeviceGetName)(void*, char*, unsigned int) = NULL;
37
+ static int (*nvmlDeviceGetUUID)(void*, char*, unsigned int) = NULL;
38
+ static int (*nvmlDeviceGetMemoryInfo)(void*, nvmlMemory_t*) = NULL;
39
+ static int (*nvmlDeviceGetUtilizationRates)(void*, nvmlUtilization_t*) = NULL;
40
+ static int (*nvmlDeviceGetTemperature)(void*, int, unsigned int*) = NULL;
41
+ static int (*nvmlDeviceGetPowerUsage)(void*, unsigned int*) = NULL;
42
+ static int (*nvmlDeviceGetClockInfo)(void*, int, unsigned int*) = NULL;
43
+ static int (*nvmlDeviceGetFanSpeed)(void*, unsigned int*) = NULL;
44
+ static int (*nvmlDeviceGetPciInfo)(void*, nvmlPciInfo_t*) = NULL;
45
+
46
+ static gpu_error_t load_nvml_windows(void) {
47
+ if (nvml_initialized) return GPU_SUCCESS;
48
+
49
+ nvml_library = LoadLibraryA("nvml.dll");
50
+ if (!nvml_library) {
51
+ return GPU_ERROR_NOT_SUPPORTED;
52
+ }
53
+
54
+ // Load all NVML functions
55
+ nvmlInit_v2 = (int(*)(void))GetProcAddress(nvml_library, "nvmlInit_v2");
56
+ nvmlShutdown = (int(*)(void))GetProcAddress(nvml_library, "nvmlShutdown");
57
+ nvmlDeviceGetCount_v2 = (int(*)(unsigned int*))GetProcAddress(nvml_library, "nvmlDeviceGetCount_v2");
58
+ nvmlDeviceGetHandleByIndex = (int(*)(unsigned int, void**))GetProcAddress(nvml_library, "nvmlDeviceGetHandleByIndex");
59
+ nvmlDeviceGetName = (int(*)(void*, char*, unsigned int))GetProcAddress(nvml_library, "nvmlDeviceGetName");
60
+ nvmlDeviceGetUUID = (int(*)(void*, char*, unsigned int))GetProcAddress(nvml_library, "nvmlDeviceGetUUID");
61
+ nvmlDeviceGetMemoryInfo = (int(*)(void*, nvmlMemory_t*))GetProcAddress(nvml_library, "nvmlDeviceGetMemoryInfo");
62
+ nvmlDeviceGetUtilizationRates = (int(*)(void*, nvmlUtilization_t*))GetProcAddress(nvml_library, "nvmlDeviceGetUtilizationRates");
63
+ nvmlDeviceGetTemperature = (int(*)(void*, int, unsigned int*))GetProcAddress(nvml_library, "nvmlDeviceGetTemperature");
64
+ nvmlDeviceGetPowerUsage = (int(*)(void*, unsigned int*))GetProcAddress(nvml_library, "nvmlDeviceGetPowerUsage");
65
+ nvmlDeviceGetClockInfo = (int(*)(void*, int, unsigned int*))GetProcAddress(nvml_library, "nvmlDeviceGetClockInfo");
66
+ nvmlDeviceGetFanSpeed = (int(*)(void*, unsigned int*))GetProcAddress(nvml_library, "nvmlDeviceGetFanSpeed");
67
+ nvmlDeviceGetPciInfo = (int(*)(void*, nvmlPciInfo_t*))GetProcAddress(nvml_library, "nvmlDeviceGetPciInfo");
68
+
69
+ // Check for essential functions
70
+ if (!nvmlInit_v2 || !nvmlDeviceGetCount_v2 || !nvmlDeviceGetHandleByIndex) {
71
+ FreeLibrary(nvml_library);
72
+ nvml_library = NULL;
73
+ return GPU_ERROR_NOT_SUPPORTED;
74
+ }
75
+
76
+ if (nvmlInit_v2() != 0) {
77
+ FreeLibrary(nvml_library);
78
+ nvml_library = NULL;
79
+ return GPU_ERROR_NOT_SUPPORTED;
80
+ }
81
+
82
+ nvml_initialized = 1;
83
+ return GPU_SUCCESS;
84
+ }
85
+
86
+ gpu_error_t nvidia_windows_get_gpu_count(int32_t* count) {
87
+ if (!count) return GPU_ERROR_INVALID_PARAM;
88
+
89
+ gpu_error_t result = load_nvml_windows();
90
+ if (result != GPU_SUCCESS) {
91
+ *count = 0;
92
+ return GPU_SUCCESS;
93
+ }
94
+
95
+ unsigned int nv_count = 0;
96
+ if (nvmlDeviceGetCount_v2(&nv_count) != 0) {
97
+ *count = 0;
98
+ return GPU_ERROR_API_FAILED;
99
+ }
100
+
101
+ *count = (int32_t)nv_count;
102
+ return GPU_SUCCESS;
103
+ }
104
+
105
+ gpu_error_t nvidia_windows_get_gpu_info(int32_t index, gpu_info_t* info) {
106
+ if (!info) return GPU_ERROR_INVALID_PARAM;
107
+
108
+ gpu_error_t result = load_nvml_windows();
109
+ if (result != GPU_SUCCESS) {
110
+ return result;
111
+ }
112
+
113
+ void* device;
114
+ if (nvmlDeviceGetHandleByIndex((unsigned int)index, &device) != 0) {
115
+ return GPU_ERROR_API_FAILED;
116
+ }
117
+
118
+ memset(info, 0, sizeof(gpu_info_t));
119
+ info->index = index;
120
+ info->vendor = GPU_VENDOR_NVIDIA;
121
+
122
+ // Get GPU name
123
+ char name[256];
124
+ if (nvmlDeviceGetName && nvmlDeviceGetName(device, name, sizeof(name)) == 0) {
125
+ strncpy(info->name, name, sizeof(info->name) - 1);
126
+ } else {
127
+ strncpy(info->name, "NVIDIA GPU", sizeof(info->name) - 1);
128
+ }
129
+
130
+ // Get UUID
131
+ char uuid[64];
132
+ if (nvmlDeviceGetUUID && nvmlDeviceGetUUID(device, uuid, sizeof(uuid)) == 0) {
133
+ strncpy(info->uuid, uuid, sizeof(info->uuid) - 1);
134
+ } else {
135
+ snprintf(info->uuid, sizeof(info->uuid), "%d", index);
136
+ }
137
+
138
+ // Get PCI bus information
139
+ if (nvmlDeviceGetPciInfo) {
140
+ nvmlPciInfo_t pciInfo;
141
+ if (nvmlDeviceGetPciInfo(device, &pciInfo) == 0) {
142
+ // Use the actual PCI bus ID from NVML
143
+ strncpy(info->pci_bus_id, pciInfo.busId, sizeof(info->pci_bus_id) - 1);
144
+
145
+ // Debug output to see all PCI information (optional)
146
+ /*printf("GPU %d PCI Info:\n", index);
147
+ printf(" Bus ID: %s\n", pciInfo.busId);
148
+ printf(" Domain: 0x%04X\n", pciInfo.domain);
149
+ printf(" Bus: 0x%02X\n", pciInfo.bus);
150
+ printf(" Device: 0x%02X\n", pciInfo.device);
151
+ printf(" Device ID: 0x%04X\n", pciInfo.pciDeviceId);
152
+ printf(" Subsystem ID: 0x%04X\n", pciInfo.pciSubSystemId);*/
153
+ } else {
154
+ // Fallback: generate from index
155
+ snprintf(info->pci_bus_id, sizeof(info->pci_bus_id), "PCI:%d", index);
156
+ }
157
+ } else {
158
+ // Fallback: generate from index
159
+ snprintf(info->pci_bus_id, sizeof(info->pci_bus_id), "PCI:%d", index);
160
+ }
161
+
162
+ // Get memory info
163
+ nvmlMemory_t memory;
164
+ if (nvmlDeviceGetMemoryInfo && nvmlDeviceGetMemoryInfo(device, &memory) == 0) {
165
+ info->memory_total = memory.total / (1024 * 1024); // Convert to MB
166
+ info->memory_used = memory.used / (1024 * 1024);
167
+ info->memory_free = memory.free / (1024 * 1024);
168
+
169
+ // Calculate memory capacity utilization (for reference)
170
+ float capacity_utilization = 0.0f;
171
+ if (memory.total > 0) {
172
+ capacity_utilization = (float)memory.used / memory.total * 100.0f;
173
+ }
174
+
175
+ // Debug output (optional)
176
+ /*printf("GPU %d Memory: %llu/%llu MB (%.1f%% capacity)\n",
177
+ index, memory.used / (1024 * 1024), memory.total / (1024 * 1024),
178
+ capacity_utilization);*/
179
+ } else {
180
+ // Fallback values
181
+ info->memory_total = 8 * 1024;
182
+ info->memory_used = 0;
183
+ info->memory_free = 8 * 1024;
184
+ }
185
+
186
+ // Get utilization rates
187
+ nvmlUtilization_t utilization;
188
+ if (nvmlDeviceGetUtilizationRates && nvmlDeviceGetUtilizationRates(device, &utilization) == 0) {
189
+ info->gpu_utilization = (float)utilization.gpu;
190
+ info->memory_utilization = (float)utilization.memory; // Memory bandwidth utilization
191
+
192
+ // Debug output (optional)
193
+ /*printf("GPU %d Utilization: GPU=%u%%, Memory=%u%%\n",
194
+ index, utilization.gpu, utilization.memory);*/
195
+ } else {
196
+ info->gpu_utilization = 0.0f;
197
+ info->memory_utilization = 0.0f;
198
+ }
199
+
200
+ // Get temperature (GPU core)
201
+ unsigned int temperature;
202
+ if (nvmlDeviceGetTemperature && nvmlDeviceGetTemperature(device, 0, &temperature) == 0) {
203
+ info->temperature = (float)temperature;
204
+ } else {
205
+ info->temperature = 0.0f;
206
+ }
207
+
208
+ // Get power usage (in milliwatts)
209
+ unsigned int power;
210
+ if (nvmlDeviceGetPowerUsage && nvmlDeviceGetPowerUsage(device, &power) == 0) {
211
+ info->power_usage = (float)power / 1000.0f; // Convert to watts
212
+ } else {
213
+ info->power_usage = 0.0f;
214
+ }
215
+
216
+ // Get core clock (graphics clock)
217
+ unsigned int clock;
218
+ if (nvmlDeviceGetClockInfo && nvmlDeviceGetClockInfo(device, 0, &clock) == 0) {
219
+ info->core_clock = clock;
220
+ } else {
221
+ info->core_clock = 0;
222
+ }
223
+
224
+ // Get memory clock
225
+ if (nvmlDeviceGetClockInfo && nvmlDeviceGetClockInfo(device, 1, &clock) == 0) {
226
+ info->memory_clock = clock;
227
+ } else {
228
+ info->memory_clock = 0;
229
+ }
230
+
231
+ // Get fan speed
232
+ unsigned int fan_speed;
233
+ if (nvmlDeviceGetFanSpeed && nvmlDeviceGetFanSpeed(device, &fan_speed) == 0) {
234
+ info->fan_speed = (float)fan_speed;
235
+ } else {
236
+ info->fan_speed = 0.0f;
237
+ }
238
+
239
+ return GPU_SUCCESS;
240
+ }
241
+
242
+ // Cleanup function
243
+ void nvidia_windows_cleanup(void) {
244
+ if (nvml_initialized && nvmlShutdown) {
245
+ nvmlShutdown();
246
+ }
247
+ if (nvml_library) {
248
+ FreeLibrary(nvml_library);
249
+ nvml_library = NULL;
250
+ }
251
+ nvml_initialized = 0;
252
+ }