Difference between revisions of "GPU: NVML"

From Define Wiki
Jump to navigation Jump to search
 
Line 1: Line 1:
 +
NVML is a way of including nvidia GPU functions within your own code. There are bindings for C Python and Perl.
 +
 
== Installation ==
 
== Installation ==
  

Latest revision as of 13:52, 19 April 2013

NVML is a way of including nvidia GPU functions within your own code. There are bindings for C Python and Perl.

Installation

https://developer.nvidia.com/tesla-deployment-kit

Do Not overwrite libraries from Cuda

  1. Download and Untar
  2. Add the files from the include / libary folders or copy them to a folder already on the path.

Compilation

gcc -o nvml_test nvml_test.c -lnvidia-ml -I

Example NVML C program

#include <stdio.h>
#include "nvml.h"
int main() {
        nvmlReturn_t result;
        unsigned int device_count, i;
        char version[80];
        result = nvmlInit();
        result = nvmlSystemGetDriverVersion(version,80);
        printf("\n Driver version: %s \n\n", version);
        result = nvmlDeviceGetCount(&device_count);
        printf("Found %d device%s\n\n", device_count,
        device_count != 1 ? "s" : "");
        printf("Listing devices:\n");
        for (i = 0; i < device_count; i++) {
                nvmlDevice_t device;
                char name[64];
                nvmlComputeMode_t compute_mode;
                result = nvmlDeviceGetHandleByIndex(i, &device);
                result = nvmlDeviceGetName(device, name,
                sizeof(name)/sizeof(name[0]));
                printf("%d. %s \n", i, name);
        }
        result = nvmlShutdown();
}


Output

[root@compute022 ~]# ./nvml_test

 Driver version: 304.54

Found 3 devices

Listing devices:
0. Tesla K20m
1. Tesla K20m
2. Tesla K20m