#include #include #include #define CHECK(X) { nvmlReturn_t myresult = X; if(myresult != NVML_SUCCESS) { printf("%s\n",nvmlErrorString(myresult)); nvmlShutdown(); return 1; } } int main() { // Initialize NVML CHECK(nvmlInit()); // Get device handle. nvmlDevice_t device; CHECK(nvmlDeviceGetHandleByIndex(0, &device)); // GPU name. char gpu_name[NVML_DEVICE_NAME_BUFFER_SIZE]; int version; CHECK(nvmlDeviceGetName(device, gpu_name, NVML_DEVICE_NAME_BUFFER_SIZE)); CHECK(nvmlSystemGetCudaDriverVersion(&version)); printf("\n%s, driver version %d\n",gpu_name,version); printf("\n"); // Clocks. unsigned int clock, clockmax; // The second parameter specifies the type of clock to query. CHECK(nvmlDeviceGetClockInfo(device, NVML_CLOCK_GRAPHICS, &clock)); CHECK(nvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_GRAPHICS, &clockmax)); printf("graphics clock frequency %dMHz current, %dMHz max\n",clock,clockmax); CHECK(nvmlDeviceGetClockInfo(device, NVML_CLOCK_SM, &clock)); CHECK(nvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_SM, &clockmax)); printf("SM clock frequency %dMHz current, %dMHz max\n",clock,clockmax); CHECK(nvmlDeviceGetClockInfo(device, NVML_CLOCK_MEM, &clock)); CHECK(nvmlDeviceGetMaxClockInfo(device, NVML_CLOCK_MEM, &clockmax)); printf("memory clock frequency %dMHz current, %dMHz max\n",clock,clockmax); printf("\n"); // Cores unsigned int ncores; CHECK(nvmlDeviceGetNumGpuCores (device, &ncores)); printf("%d cores\n",ncores); printf("\n"); // Memory unsigned int e; int busspeed; CHECK(nvmlDeviceGetPcieLinkMaxSpeed(device, &e)); switch(e) { case 1: { busspeed = 2.5; break; } case 2: { busspeed = 5; break; } case 3: { busspeed = 8; break; } case 4: { busspeed = 16; break; } case 5: { busspeed = 32; break; } default: { busspeed = -1.0; } } printf("max PCIE bus speed in GT/s %d\n",busspeed); CHECK(nvmlDeviceGetPcieSpeed (device, &e)); printf("max PCIE bus speed in Mbit/s %d\n",e); printf("\n"); // Power unsigned int power; CHECK(nvmlDeviceGetPowerUsage(device, &power)); printf("current power usage %.0f Watt\n",(double)power/1000.0); printf("\n"); // Temperature; unsigned int temp; CHECK(nvmlDeviceGetTemperature(device, NVML_TEMPERATURE_GPU ,&temp)); printf("current temperature %d\n",temp); CHECK(nvmlDeviceGetTemperatureThreshold (device, NVML_TEMPERATURE_THRESHOLD_SHUTDOWN ,&temp)); printf("threshold for shutrown %d\n",temp); CHECK(nvmlDeviceGetTemperatureThreshold (device, NVML_TEMPERATURE_THRESHOLD_SLOWDOWN ,&temp)); printf("threshold for slowdown %d\n",temp); printf("\n"); // Fan. unsigned int speed,nfans; CHECK(nvmlDeviceGetFanSpeed(device, &speed)); CHECK(nvmlDeviceGetNumFans (device, &nfans)); printf("%d fans, speed of fan %d\n",nfans,speed); printf("\n"); unsigned int buswidth; CHECK(nvmlDeviceGetMemoryBusWidth(device, &buswidth)); printf("bus width %d\n",buswidth); CHECK(nvmlShutdown()); return 0; }