-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgpu.py
More file actions
44 lines (35 loc) · 1.03 KB
/
gpu.py
File metadata and controls
44 lines (35 loc) · 1.03 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
44
import csv
import numpy
# import time
from numba import cuda
# @cuda.reduce
# def sum_reduce(a, b):
# return a + b
# start_time = time.time()
# while(True):
# got = sum_reduce(A) # cuda sum reduction
# print("GPU", time.time() - start_time)
# print(got)
@cuda.reduce
def sum_reduce(a, b):
return a + b
num = 0
class GPU:
def run_task(self, task):
ans = 0
global num
for i in range(task.level):
# print("GPU running task at level", i)
workload_arr = self.workload_to_arr("tasks/" + str(task.name) + "/stage" + str(i))
ans += self.do_work(workload_arr)
ans = ans / task.level
num = num + 1
# reward_sum = task.reward
print(num)
# print("Final answer to task: ", ans)
def workload_to_arr(self, stagedir):
return numpy.genfromtxt(stagedir, delimiter=',', dtype = numpy.float64)
def do_work(self, workload):
work_sum = 0
work_sum = work_sum + sum_reduce(workload)
return work_sum / len(workload)