def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slice_xyz = common.slices_two_points(pt0, pt1) # generate random source if is_array: shape = common.shape_two_points(pt0, pt1) value = np.random.rand(*shape).astype(np.float32) else: value = np.random.ranf() # instance fields = Fields(0, nx, ny, nz, '', 'single') tfunc = lambda tstep: np.sin(0.03 * tstep) incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) # host allocations eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1)) fields.update_e() fields.update_h() copy_eh_buf = fields.get_buf(str_f) copy_eh = np.zeros_like(eh) cuda.memcpy_dtoh(copy_eh, copy_eh_buf) original = eh[slice_xyz] copy = copy_eh[slice_xyz] norm = np.linalg.norm(original - copy) self.assertEqual(norm, 0, '%s, %g' % (self.args, norm)) fields.context_pop()
def runTest(self): nx, ny, nz, str_f, pt0, pt1 = self.args slidx = common.slices_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance fields = Fields(0, nx, ny, nz, '', 'single') getf = GetFields(fields, str_f, pt0, pt1) # host allocations ehs = common_random.generate_ehs(nx, ny, nz, fields.dtype) eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) ) fields.set_eh_bufs(*ehs) # verify getf.wait() for str_f in str_fs: original = eh_dict[str_f][slidx] copy = getf.get_fields(str_f) norm = np.linalg.norm(original - copy) self.assertEqual(norm, 0, '%s, %g' % (self.args, norm)) fields.context_pop()
def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slice_xyz = common.slices_two_points(pt0, pt1) # generate random source if is_array: shape = common.shape_two_points(pt0, pt1) value = np.random.rand(*shape).astype(np.float32) else: value = np.random.ranf() # instance fields = Fields(0, nx, ny, nz, '', 'single') tfunc = lambda tstep: np.sin(0.03*tstep) incident = IncidentDirect(fields, str_f, pt0, pt1, tfunc, value) # host allocations eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify eh[slice_xyz] = fields.dtype(value) * fields.dtype(tfunc(1)) fields.update_e() fields.update_h() copy_eh_buf = fields.get_buf(str_f) copy_eh = np.zeros_like(eh) cuda.memcpy_dtoh(copy_eh, copy_eh_buf) original = eh[slice_xyz] copy = copy_eh[slice_xyz] norm = np.linalg.norm(original - copy) self.assertEqual(norm, 0, '%s, %g' % (self.args, norm)) fields.context_pop()
def runTest(self): nx, ny, nz, str_f, pt0, pt1, is_array = self.args slidx = common.slices_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance fields = Fields(0, nx, ny, nz, '', 'single') setf = SetFields(fields, str_f, pt0, pt1, is_array) # generate random source if is_array: shape = common.shape_two_points(pt0, pt1, len(str_fs)) value = np.random.rand(*shape).astype(fields.dtype) split_value = np.split(value, len(str_fs)) split_value_dict = dict( zip(str_fs, split_value) ) else: value = np.random.ranf() # host allocations ehs = [np.zeros(fields.ns, dtype=fields.dtype) for i in range(6)] eh_dict = dict( zip(['ex', 'ey', 'ez', 'hx', 'hy', 'hz'], ehs) ) gpu_eh = np.zeros(fields.ns_pitch, dtype=fields.dtype) # verify for str_f in str_fs: if is_array: eh_dict[str_f][slidx] = split_value_dict[str_f] else: eh_dict[str_f][slidx] = value setf.set_fields(value) for str_f in str_fs: cuda.memcpy_dtoh(gpu_eh, fields.get_buf(str_f)) original = eh_dict[str_f] copy = gpu_eh[:,:,fields.slice_z] norm = np.linalg.norm(original - copy) self.assertEqual(norm, 0, '%s, %g' % (self.args, norm)) fields.context_pop()
''' # main loop from datetime import datetime from time import time t0 = datetime.now() t00 = time() for tstep in xrange(1, tmax+1): fields.update_e() fields.update_h() ''' if tstep % tgap == 0: print('[%s] %d/%d (%d %%)\r' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100)), sys.stdout.flush() getf.get_event().wait() imag.set_array( getf.get_fields().T ) #plt.savefig('./png/%.6d.png' % tstep) plt.draw() ''' #plt.show() fields.context.synchronize() dt = time() - t00 print dt print('[%s] %d/%d (%d %%) %f Mpoint/s' % (datetime.now() - t0, tstep, tmax, float(tstep)/tmax*100, nx*ny*nz*tmax/dt/1e6) ) fields.context_pop()