0

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>
///usr/include/hwloc/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 tried to compile this code in Ubuntu, I got compile 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?

  • Do you have `/usr/include/nvml.h`? Try compiling using that include path, `/usr/include/`. – Zois Tasoulas Feb 25 '23 at 01:15
  • I tried this. Didn't solve my issue. Am I missing any library to include? Getting below error. In file included from hw_nvml.c:2: /usr/include/nvml.h:57:9: error: unknown type name ‘nvmlDevice_t’ 57 | nvmlDevice_t device, hwloc_cpuset_t set) | ^~~~~~~~~~~~ /usr/include/nvml.h:129:56: error: unknown type name ‘nvmlDevice_t’ 129 | hwloc_nvml_get_device_osdev(hwloc_topology_t topology, nvmlDevice_t device) | ^~~~~~~~~~~~ hw_nvml.c: In function ‘main’: hw_nvml.c:8:5: error: unknown type name ‘nvmlReturn_t’ – Aravind D. Chakravarti Feb 27 '23 at 06:44

0 Answers0