Skip to content

Commit edd5eeb

Browse files
examples use store output file functions
1 parent 57bffb1 commit edd5eeb

File tree

2 files changed

+34
-15
lines changed

2 files changed

+34
-15
lines changed

examples/cuda/vector_add.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
22
"""This is the minimal example from the README"""
33

4-
import json
54
import numpy
65
from kernel_tuner import tune_kernel
6+
from kernel_tuner.file_utils import store_output_file, store_metadata_file
77

88
def tune():
99

@@ -28,12 +28,15 @@ def tune():
2828
tune_params = dict()
2929
tune_params["block_size_x"] = [128+64*i for i in range(15)]
3030

31-
result = tune_kernel("vector_add", kernel_string, size, args, tune_params)
31+
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params)
3232

33-
with open("vector_add.json", 'w') as fp:
34-
json.dump(result, fp)
33+
# Store the tuning results in an output file
34+
store_output_file("vector_add.json", results, tune_params)
3535

36-
return result
36+
# Store the metadata of this run
37+
store_metadata_file("vector_add-metadata.json")
38+
39+
return results
3740

3841

3942
if __name__ == "__main__":

examples/opencl/vector_add.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#!/usr/bin/env python
2+
"""This is the minimal example from the README"""
3+
24
import numpy
35
from kernel_tuner import tune_kernel
6+
from kernel_tuner.file_utils import store_output_file, store_metadata_file
7+
8+
def tune():
49

5-
kernel_string = """
10+
kernel_string = """
611
__kernel void vector_add(__global float *c, __global const float *a, __global const float *b, int n) {
712
int i = get_global_id(0);
813
if (i<n) {
@@ -11,17 +16,28 @@
1116
}
1217
"""
1318

14-
size = 10000000
19+
size = 10000000
20+
21+
a = numpy.random.rand(size).astype(numpy.float32)
22+
b = numpy.random.rand(size).astype(numpy.float32)
23+
c = numpy.zeros_like(a)
24+
n = numpy.int32(size)
25+
26+
args = [c, a, b, n]
27+
28+
tune_params = dict()
29+
tune_params["block_size_x"] = [128+64*i for i in range(15)]
30+
31+
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params)
1532

16-
a = numpy.random.rand(size).astype(numpy.float32)
17-
b = numpy.random.rand(size).astype(numpy.float32)
18-
c = numpy.zeros_like(a)
19-
n = numpy.int32(size)
33+
# Store the tuning results in an output file
34+
store_output_file("vector_add.json", results, tune_params)
2035

21-
args = [c, a, b, n]
36+
# Store the metadata of this run
37+
store_metadata_file("vector_add-metadata.json")
2238

23-
tune_params = dict()
24-
tune_params["block_size_x"] = [128+64*i for i in range(15)]
39+
return results
2540

26-
tune_kernel("vector_add", kernel_string, size, args, tune_params)
2741

42+
if __name__ == "__main__":
43+
tune()

0 commit comments

Comments
 (0)