Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pycuda.autoinit
- import pycuda.driver as drv
- from pycuda import gpuarray
- from pycuda import cumath
- from pycuda.elementwise import ElementwiseKernel
- import numpy as np
- start = drv.Event()
- end = drv.Event()
- N = 10**6
- a = 2*np.ones(N,dtype=np.float64)
- start.record()
- np.exp(a)
- end.record()
- end.synchronize()
- secs = start.time_till(end)*1e-3
- print "Numpy",secs
- a_gpu = gpuarray.to_gpu(a)
- b_gpu = gpuarray.zeros_like(a_gpu)
- kernel = ElementwiseKernel(
- "double *a,double *b",
- "b[i] = exp(a[i]);",
- "kernel")
- start.record() # start timing
- kernel(a_gpu,b_gpu)
- end.record() # end timing
- end.synchronize()
- secs = start.time_till(end)*1e-3
- print "Kernel",secs
- start.record()
- cumath.exp(a_gpu)
- end.record()
- end.synchronize()
- secs = start.time_till(end)*1e-3
- print "Cumath", secs
- Numpy 0.0218774719238
- Kernel 0.143336898804
- Cumath 0.14694732666
- Numpy 0.0205841598511
- Kernel 0.138252410889
- Cumath 0.00203606390953
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement