From df0241e261372ba476fce165157cbbe370624cf1 Mon Sep 17 00:00:00 2001 From: sasha0552 Date: Tue, 27 Aug 2024 19:33:06 +0000 Subject: [PATCH] Print managed GPU names --- src/main.c | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 383c9cb..bf49211 100644 --- a/src/main.c +++ b/src/main.c @@ -286,8 +286,8 @@ int main(int argc, char *argv[]) { } } - // Flag to check if any GPUs are managed - bool hasManagedGpus = false; + // Initialize the counter for managed GPUs + unsigned int managedGPUs = 0; // Iterate through each GPU for (unsigned int i = 0; i < deviceCount; i++) { @@ -296,26 +296,31 @@ int main(int argc, char *argv[]) { // If GPU is managed if (state->managed) { - // Update flag - hasManagedGpus = true; + // Buffer to store the GPU name + char gpuName[256]; + + // Retrieve the GPU name + NVML_CALL(nvmlDeviceGetName(nvmlDevices[i], gpuName, sizeof(gpuName)), errored); + + // Print the managed GPU details + printf("%u. %s (GPU id = %u)\n", managedGPUs, gpuName, i); + + // Increment the managed GPU counter + managedGPUs++; } } // If no GPUs are managed, report an error - if (!hasManagedGpus) { + if (managedGPUs == 0) { // Print error message - printf("Can't find GPUs to manage!"); + printf("Can't find GPUs to manage!\n"); // Jump to error handling section goto errored; } // Print the number of GPUs being managed - if (idsCount == 0) { - printf("Managing %u GPUs...\n", deviceCount); - } else { - printf("Managing %zu GPUs...\n", idsCount); - } + printf("Managing %u GPUs...\n", managedGPUs); // Iterate through each GPU for (unsigned int i = 0; i < deviceCount; i++) {