-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_StreamCompact.py
85 lines (60 loc) · 2.12 KB
/
test_StreamCompact.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
import os
import numpy as np
import pyopencl as cl
from StreamCompact import StreamCompact
szFloat = 4
szInt = 4
szChar = 1
cm = cl.mem_flags
platforms = cl.get_platforms()
devices = platforms[0].get_devices()
devices = [devices[1]]
context = cl.Context(devices)
queue = cl.CommandQueue(context)
nSamples = 65536
capcity = nSamples
streamCompact = StreamCompact(context, devices, capcity)
hList = np.empty((nSamples,), np.int32)
dList = streamCompact.listFactory(nSamples)
hFlags = np.random.randint(0, 2, nSamples).astype(np.int32)
dFlags = streamCompact.flagFactory(nSamples)
cl.enqueue_copy(queue, dFlags, hFlags).wait()
hLength = np.empty((1, ), np.int32)
dLength = cl.Buffer(context, cl.mem_flags.READ_WRITE, 1*szInt)
streamCompact.compact(dFlags, dList, dLength, nSamples)
cl.enqueue_copy(queue, hList, dList).wait()
cl.enqueue_copy(queue, hLength, dLength).wait()
print 'flags', hFlags
#test correctness
compact_cpu = np.where(hFlags == 1)[0]
assert(np.all(compact_cpu == hList[0:hLength]))
#evaluate performance
import time
import csv
from evaluate import global_dims, iterations, tile_dim, columns
res_file = open('results/streamcompact.csv', 'w')
resWriter = csv.writer(res_file)
resWriter.writerow(columns)
for global_dim in global_dims:
n_tiles = (global_dim[0]/tile_dim[0])*(global_dim[1]/tile_dim[1])
streamCompact = StreamCompact(context, devices, n_tiles)
dList = streamCompact.listFactory()
dFlags = streamCompact.flagFactory()
dLength = cl.Buffer(context, cl.mem_flags.READ_WRITE, 1*szInt)
mp = float(global_dim[0]*global_dim[1])/(1024*1024)
t = elapsed = 0
for i in xrange(iterations):
cl.enqueue_copy(queue, dFlags, dFlags).wait()
t = time.time()
streamCompact.compact(dFlags, dList, dLength, n_tiles)
elapsed += time.time()-t
row = [
"({0} {1})".format(global_dim[0], global_dim[1]),
mp,
"({0} {1})".format(tile_dim[0], tile_dim[1]),
n_tiles,
(elapsed/iterations * 1000)
]
resWriter.writerow(row)
print "{0:.2f}mp: {1:.2f} milliseconds per iteration (mean)".format(mp, (elapsed/iterations * 1000))
True