-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtestcl.py
109 lines (73 loc) · 2.2 KB
/
testcl.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import os
import numpy as np
os.environ['PYOPENCL_NO_CACHE'] = '1'
import pyopencl as cl
class Tensor4D:
def __init__(self):
pass
class Layer:
def __init__(self):
pass
class Input2D(Layer):
def __init__(self, ch, h, w):
super().__init__()
self.ch = ch
self.h = h
self.w = w
class Conv2D(Layer):
def __init__(self, kernel_size, strides, padding):
super().__init__()
def forward(self, inp_t):
pass
def backward(self):
pass
def compile_program(self):
#\#define K_SIZE {self.kernel_size}
prg_s = \
"""
__kernel void sum(__global const float* inp, __global const float* K, __global float* outp)
{
int idx = get_global_id(0);
}
"""
self.cl_prg = cl.Program(ctx, prg_s).build()
def main():
#.get_devices()[1].get_info( cl.device_info.MAX_MEM_ALLOC_SIZE)
device = cl.get_platforms()[0].get_devices()[1]
ctx = cl.Context(devices=[device])
ctx_q = cl.CommandQueue(ctx)
buf = cl.Buffer(ctx, cl.mem_flags.READ_WRITE, size=512*1024*1024)
#ev = cl.enqueue_fill_buffer(ctx_q, buf, np.array([1], dtype=np.float32), 0, 4*1024)
buf_np = np.zeros( (1024,), dtype=np.float32 )
cl.enqueue_copy(ctx_q, buf_np, buf )
prg_s = \
"""
__kernel void conv2d(__global const float* inp, __global const float* K, __global float* outp)
{
int gid = get_global_id(0);
}
"""
cl_prg = cl.Program(ctx, prg_s).build()
"""
3,16,3,3
1,3,64,64
"""
prg_test_s = \
"""
__kernel void test(__global float* outp)
{
int v = 4;
outp[0] = (float) (v >= 5);
}
"""
cl_prg_test = cl.Program(ctx, prg_test_s).build()
buf_test = cl.Buffer(ctx, cl.mem_flags.READ_WRITE, size=4)
buf_test_np = np.zeros( (1,), dtype=np.float32 )
cl_prg_test.test(ctx_q, (1,), None, buf_test)
cl.enqueue_copy(ctx_q, buf_test_np, buf_test )
print(buf_test_np)
import code
code.interact(local=dict(globals(), **locals()))
#===================================================
if __name__ == "__main__":
main()