Skip to content

Commit 7f7e01e

Browse files
example use of tegra observer
1 parent 75b74a2 commit 7f7e01e

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env python
2+
"""This is the minimal example from the README"""
3+
4+
import json
5+
6+
import numpy
7+
from kernel_tuner import tune_kernel
8+
from kernel_tuner.observers.tegra import TegraObserver
9+
10+
def tune():
11+
12+
kernel_string = """
13+
__global__ void vector_add(float *c, float *a, float *b, int n) {
14+
int i = blockIdx.x * block_size_x + threadIdx.x;
15+
if (i<n) {
16+
c[i] = a[i] + b[i];
17+
}
18+
}
19+
"""
20+
21+
size = 800000
22+
23+
a = numpy.random.randn(size).astype(numpy.float32)
24+
b = numpy.random.randn(size).astype(numpy.float32)
25+
c = numpy.zeros_like(b)
26+
n = numpy.int32(size)
27+
28+
args = [c, a, b, n]
29+
30+
tune_params = dict()
31+
tune_params["block_size_x"] = [128+64*i for i in range(15)]
32+
33+
tegraobserver = TegraObserver(["core_freq"])
34+
35+
metrics = dict()
36+
metrics["f"] = lambda p: p["core_freq"]
37+
38+
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params, observers=[tegraobserver], metrics=metrics)
39+
40+
print(results)
41+
42+
return results
43+
44+
45+
if __name__ == "__main__":
46+
tune()

0 commit comments

Comments
 (0)