Hi,
I am trying to build a C-code for NVML for A5000 GPU. I got a code from internet which is as below.
#include <stdio.h>
#include <nvml.h>
int main() {
nvmlReturn_t result;
nvmlDevice_t device;
nvmlMemory_t memory;
unsigned int device_count, i;
result = nvmlInit();
if (result != NVML_SUCCESS) {
printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
return 1;
}
result = nvmlDeviceGetCount(&device_count);
if (result != NVML_SUCCESS) {
printf("Failed to get device count: %s\n", nvmlErrorString(result));
nvmlShutdown();
return 1;
}
for (i = 0; i < device_count; i++) {
result = nvmlDeviceGetHandleByIndex(i, &device);
if (result != NVML_SUCCESS) {
printf("Failed to get device handle for device %d: %s\n", i, nvmlErrorString(result));
continue;
}
result = nvmlDeviceGetMemoryInfo(device, &memory);
if (result != NVML_SUCCESS) {
printf("Failed to get memory info for device %d: %s\n", i, nvmlErrorString(result));
continue;
}
printf("Device %d:\n", i);
printf(" Total memory: %lu\n", memory.total);
printf(" Free memory: %lu\n", memory.free);
printf(" Used memory: %lu\n", memory.used);
}
nvmlShutdown();
return 0;
}
However, when I am trying to compile this code in Ubuntu, I am getting error as : fatal_error: nvml.h: no such file or directory.
Then I found that, nvml.h file exists in : /usr/include/hwloc/
So, I included this for compile path using
gcc -o hw_nvml hw_nvml.c -I/usr/include/hwloc/ -lnvidia-ml
Now I am seeing error as “error: unknown type name 'nvmlDevice_t’”
Can someone please help?