python - Is it right way to launch kernel when using numba guvectorize -


this code addition. after completion of compute_norm how measure et(end time) compute_norm.

import sys  import time import numpy np numba import guvectorize, cuda  @guvectorize(['void(float32[:], float32[:])'], '(n)->()', target='cuda') def compute_norm(a,v_mag):      tmp = 0.0     in xrange(len(a)):         tmp += a[i]     out[0] = tmp  def main(num):      device = cuda.get_current_device()      v_matrix  = np.full((num,300), 2.0, dtype = np.float32)     v_mag = np.full(num, 0.0,dtype = np.float32)      d_matrix = cuda.to_device(v_matrix)      d_mag = cuda.to_device(v_mag, copy = false)      st = time.time()      compute_norm(d_matrix, v_mag = d_mag)      et = time.time()      print "time taken" et-st,"seconds"      d_mag.copy_to_host(v_mag)   if __name__=='__main__':     main(int(sys.argv[1])) 

run:python numba_norm_over_gpu.py 6800000

output:time taken 0.00115299224854 seconds


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -