-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathvector_add.py
More file actions
43 lines (30 loc) · 1.06 KB
/
vector_add.py
File metadata and controls
43 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
"""This is the minimal example from the README"""
import numpy
from kernel_tuner import tune_kernel
from kernel_tuner.file_utils import store_output_file, store_metadata_file
def tune():
kernel_string = """
__global__ void vector_add(float *c, float *a, float *b, int n) {
int i = blockIdx.x * block_size_x + threadIdx.x;
if (i<n) {
c[i] = a[i] + b[i];
}
}
"""
size = 10000000
a = numpy.random.randn(size).astype(numpy.float32)
b = numpy.random.randn(size).astype(numpy.float32)
c = numpy.zeros_like(b)
n = numpy.int32(size)
args = [c, a, b, n]
tune_params = dict()
tune_params["block_size_x"] = [128+64*i for i in range(15)]
results, env = tune_kernel("vector_add", kernel_string, size, args, tune_params)
# Store the tuning results in an output file
store_output_file("vector_add.json", results, tune_params)
# Store the metadata of this run
store_metadata_file("vector_add-metadata.json")
return results
if __name__ == "__main__":
tune()