I have two graphics cards on my PC: GPU 0 is Intel UHD Graphics 770, and GPU 1 is GeForce RTX 3060. The CUDA version installed is 11.5, and the driver version is 531.79, which is compatible with CUDA 11.5.
I’m developing an application that uses NVML (NVIDIA Management Library) to interact with NVIDIA GPUs. To ensure NVML works correctly, I tested it using a sample code from the NVIDIA GPU Deployment Kit:
#include <stdio.h>
#include <nvml.h>
const char* convertToComputeModeString(nvmlComputeMode_t mode) {
switch (mode) {
case NVML_COMPUTEMODE_DEFAULT:
return "Default";
case NVML_COMPUTEMODE_EXCLUSIVE_THREAD:
return "Exclusive_Thread";
case NVML_COMPUTEMODE_PROHIBITED:
return "Prohibited";
case NVML_COMPUTEMODE_EXCLUSIVE_PROCESS:
return "Exclusive Process";
default:
return "Unknown";
}
}
int main() {
nvmlReturn_t result;
unsigned int device_count, i;
// Initialize NVML library
result = nvmlInit();
if (NVML_SUCCESS != result) {
printf("Failed to initialize NVML: %s\n", nvmlErrorString(result));
return 1;
}
// Query the number of NVIDIA devices
result = nvmlDeviceGetCount(&device_count);
if (NVML_SUCCESS != result) {
printf("Failed to query device count: %s\n", nvmlErrorString(result));
nvmlShutdown();
return 1;
}
printf("Found %d device%s\n\n", device_count, device_count != 1 ? "s" : "");
// List and query details of each device
printf("Listing devices:\n");
for (i = 0; i < device_count; i++) {
nvmlDevice_t device;
char name[NVML_DEVICE_NAME_BUFFER_SIZE];
nvmlPciInfo_t pci;
nvmlComputeMode_t compute_mode;
// Get handle for the device
result = nvmlDeviceGetHandleByIndex(i, &device);
if (NVML_SUCCESS != result) {
printf("Failed to get handle for device %i: %s\n", i, nvmlErrorString(result));
nvmlShutdown();
return 1;
}
}
// Shutdown NVML library
nvmlShutdown();
return 0;
}
Upon running this program, I receive the following output:
Found 1 device
Listing devices:
Failed to get handle for device 0: Not Supported
It appears that all functionalities work except for nvmlDeviceGetHandleByIndex(). Any suggestions on resolving this issue would be greatly appreciated. Thank you!