def runTest(self): nx, ny, nz, str_f, pt0, pt1 = self.args slidx = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, '') getf = GetFields(fields, str_f, pt0, pt1) # host allocations eh_dict = {} for sf in str_fs: eh_dict[sf] = np.random.rand(*fields.ns).astype(fields.dtype) cl.enqueue_copy(fields.queue, fields.get_buf(sf), eh_dict[sf]) # verify getf.get_event().wait() for str_f in str_fs: original = eh_dict[str_f][slidx] copy = getf.get_fields(str_f) self.assertEqual( np.abs(eh_dict[str_f][slidx] - getf.get_fields(str_f)).max(), 0, self.args)
def runTest(self): nx, ny, nz, str_f, pt0, pt1 = self.args slidx = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, '') getf = GetFields(fields, str_f, pt0, pt1) # host allocations eh_dict = {} for sf in str_fs: eh_dict[sf] = np.random.rand(*fields.ns).astype(fields.dtype) cl.enqueue_copy(fields.queue, fields.get_buf(sf), eh_dict[sf]) # verify getf.get_event().wait() for str_f in str_fs: original = eh_dict[str_f][slidx] copy = getf.get_fields(str_f) self.assertEqual(np.abs(eh_dict[str_f][slidx] - getf.get_fields(str_f)).max(), 0, self.args)
def runTest(self): if len(self.args) == 6: nx, ny, nz, str_f, pt0, pt1 = self.args src_is_array = False elif len(self.args) == 7: nx, ny, nz, str_f, pt0, pt1, src_is_array = self.args slidx = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, '') setf = SetFields(fields, str_f, pt0, pt1, src_is_array) # generate random source if src_is_array: shape = list(common.shape_two_points(pt0, pt1)) shape[0] *= 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 eh_dict = {} for sf in str_fs: eh_dict[sf] = np.zeros(fields.ns, dtype=fields.dtype) gpu_eh = np.zeros(fields.ns, dtype=fields.dtype) # verify for str_f in str_fs: if src_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: cl.enqueue_copy(fields.queue, gpu_eh, fields.get_buf(str_f)) self.assertEqual( np.abs(eh_dict[str_f] - gpu_eh).max(), 0, self.args)
def runTest(self): if len(self.args) == 6: nx, ny, nz, str_f, pt0, pt1 = self.args src_is_array = False elif len(self.args) == 7: nx, ny, nz, str_f, pt0, pt1, src_is_array = self.args slidx = common.slice_index_two_points(pt0, pt1) str_fs = common.convert_to_tuple(str_f) # instance gpu_devices = common_gpu.gpu_device_list(print_info=False) context = cl.Context(gpu_devices) device = gpu_devices[0] fields = Fields(context, device, nx, ny, nz, '') setf = SetFields(fields, str_f, pt0, pt1, src_is_array) # generate random source if src_is_array: shape = list( common.shape_two_points(pt0, pt1) ) shape[0] *= 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 eh_dict = {} for sf in str_fs: eh_dict[sf] = np.zeros(fields.ns, dtype=fields.dtype) gpu_eh = np.zeros(fields.ns, dtype=fields.dtype) # verify for str_f in str_fs: if src_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: cl.enqueue_copy(fields.queue, gpu_eh, fields.get_buf(str_f)) self.assertEqual(np.abs(eh_dict[str_f] - gpu_eh).max(), 0, self.args)