-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhello_gpu.py
More file actions
31 lines (25 loc) · 733 Bytes
/
Copy pathhello_gpu.py
File metadata and controls
31 lines (25 loc) · 733 Bytes
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
import numpy as np
from timeit import default_timer as timer
from numba import vectorize
@vectorize(["float32(float32, float32)"], target='cuda')
def vectorAdd(a, b):
return (a + b)*(a+b)
def main():
N = 3200000
A = np.ones(N, dtype=np.float32 )
B = np.ones(N, dtype=np.float32)
C = np.zeros(N, dtype=np.float32 )
start = timer()
C = vectorAdd(A, B)
C = vectorAdd(A, B)
vectorAdd_time = timer() - start
#print("c[:5] = " + str(C[:5]))
#print("c[-5:] = " + str(C[-5:]))
print("vectorAdd took %f seconds " % vectorAdd_time)
import time
import random
while True:
start = timer()
time.sleep(random.random())
print("sleep for %f seconds " % (timer() - start))
main()