Skip to content

Commit 3f89fc3

Browse files
committed
added vector add in simulation mode to examples
1 parent c8b9198 commit 3f89fc3

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
"""This is the minimal example from the README"""
3+
4+
import numpy
5+
from kernel_tuner import tune_kernel
6+
from kernel_tuner.file_utils import store_output_file, store_metadata_file
7+
import logging
8+
from collections import OrderedDict
9+
import os
10+
11+
def tune():
12+
13+
kernel_string = """
14+
__global__ void vector_add(float *c, float *a, float *b, int n) {
15+
int i = blockIdx.x * block_size_x + threadIdx.x;
16+
if (i<n) {
17+
c[i] = a[i] + b[i];
18+
}
19+
}
20+
"""
21+
22+
size = 10000000
23+
24+
a = numpy.random.randn(size).astype(numpy.float32)
25+
b = numpy.random.randn(size).astype(numpy.float32)
26+
c = numpy.zeros_like(b)
27+
n = numpy.int32(size)
28+
29+
args = [c, a, b, n]
30+
31+
tune_params = OrderedDict()
32+
tune_params["block_size_x"] = [128+64*i for i in range(15)]
33+
34+
filename = "vector_add.json"
35+
if os.path.isfile(filename):
36+
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params,
37+
strategy="simulated_annealing",
38+
lang="HIP", simulation_mode=True, cache="vector_add.json")
39+
40+
# Store the tuning results in an output file
41+
store_output_file("vector_add_simulated_annealing.json", results, tune_params)
42+
43+
return results
44+
else:
45+
print(f"{filename} does not exist in the directory, run vector_add.py first.")
46+
47+
48+
if __name__ == "__main__":
49+
tune()

0 commit comments

Comments
 (0)