def setUp(self): #Set which CL device to use, and disable kernel caching self.cl_ctx = make_cl_ctx() # Make some host data which we can play with self.nx = 3 self.ny = 5 self.nx_halo = 1 self.ny_halo = 2 self.dataShape = (self.ny + 2 * self.ny_halo, self.nx + 2 * self.nx_halo) self.buf1 = np.zeros(self.dataShape, dtype=np.float32, order='C') self.buf2 = np.zeros(self.dataShape) self.buf3 = np.zeros(self.dataShape, dtype=np.float32, order='C') for j in range(self.dataShape[0]): for i in range(self.dataShape[1]): self.buf1[j, i] = i * 100 + j self.buf2[j, i] = self.buf1[j, i] self.buf3[j, i] = j * 1000 - i self.explicit_free = False self.device_name = self.cl_ctx.devices[0].name self.cl_queue = pyopencl.CommandQueue(self.cl_ctx) self.tests_failed = True self.clarray = Common.OpenCLArray2D(self.cl_ctx, \ self.nx, self.ny, self.nx_halo, self.ny_halo, \ self.buf1)
def test_copy_buffer(self): clarray2 = Common.OpenCLArray2D(self.cl_ctx, \ self.nx, self.ny, self.nx_halo, self.ny_halo, \ self.buf3) host_data_pre_copy = self.clarray.download(self.cl_queue) self.assertEqual(host_data_pre_copy.tolist(), self.buf1.tolist()) self.clarray.copyBuffer(self.cl_queue, clarray2) host_data_post_copy = self.clarray.download(self.cl_queue) self.assertEqual(host_data_post_copy.tolist(), self.buf3.tolist()) self.tests_failed = False