Skip to content

Commit 59d8742

Browse files
author
Saurav Muralidharan
committed
Adding NVML init and shutdown code
1 parent e8663ee commit 59d8742

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

examples/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
all: demo
22

33
INCLUDES = -I ../include/
4+
INCLUDES += -I $(GDK_PATH)
5+
LIBS = -lnvidia-ml
6+
CXXARGS = -std=c++11 -O3
47

58
demo: demo.cu
6-
nvcc -std=c++11 -O3 $(INCLUDES) demo.cu -o demo
9+
nvcc $(CXXARGS) $(INCLUDES) $(LIBS) demo.cu -o demo
710

811
clean:
912
rm -f *.o demo

examples/demo.cu

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
#include <gpu_freqlib/freqlib.h>
55

66
int main() {
7-
87
freqlib::instance knob;
98

10-
std::vector<double> clock_frequencies{knob.get_supported_clocks()};
11-
std::vector<double> mem_frequencies{knob.get_supported_mem_clocks()};
9+
//std::vector<double> clock_frequencies{knob.get_supported_clocks()};
10+
//std::vector<double> mem_frequencies{knob.get_supported_mem_clocks()};
1211

1312
return 0;
1413
}

include/gpu_freqlib/freqlib.h

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,78 @@
11
#pragma once
22

3+
#include <cstdio>
4+
#include <nvml.h>
5+
6+
#define NVML_CALL(call) \
7+
do { \
8+
nvmlReturn_t result = call; \
9+
if(NVML_SUCCESS != result) { \
10+
fprintf(stderr, "[Fatal] NVML call failed with error %s\n", \
11+
nvmlErrorString(result)); \
12+
result = nvmlShutdown(); \
13+
if(NVML_SUCCESS != result) { \
14+
fprintf(stderr, "[Fatal] Failed to shutdown NVML: %s\n", \
15+
nvmlErrorString(result)); \
16+
} \
17+
} \
18+
} while(0)
19+
320
namespace freqlib {
421
using freqlist_t = std::vector<double>;
22+
using error_t = void;
23+
using frequency_t = double;
524

625
struct instance {
7-
instance() {
26+
instance() :
27+
m_device(0) {
28+
nvmlReturn_t result = nvmlInit();
29+
if(NVML_SUCCESS != result) {
30+
fprintf(stderr, "[Fatal] Failed to initialize NVML: %s\n",
31+
nvmlErrorString(result));
32+
//exit(-1);
33+
}
34+
}
35+
36+
~instance() {
37+
nvmlReturn_t result = nvmlShutdown();
38+
if(NVML_SUCCESS != result) {
39+
fprintf(stderr, "[Fatal] Failed to shutdown NVML: %s\n",
40+
nvmlErrorString(result));
41+
}
842
}
943

1044
freqlist_t get_supported_clocks() {
1145
}
1246

1347
freqlist_t get_supported_mem_clocks() {
1448
}
49+
50+
error_t step_up_clock() {
51+
}
52+
53+
error_t step_down_clock() {
54+
}
55+
56+
error_t step_up_mem_clock() {
57+
}
58+
59+
error_t step_down_mem_clock() {
60+
}
61+
62+
error_t set_clock(frequency_t value) {
63+
}
64+
65+
error_t set_mem_clock(frequency_t value) {
66+
}
67+
68+
frequency_t get_current_clock() {
69+
}
70+
71+
frequency_t get_current_mem_clock() {
72+
}
73+
74+
private:
75+
int m_device;
1576
};
1677

1778
} // ns freqlib

0 commit comments

Comments
 (0)