def allocate(self, nd): arraytype = make_array_ctype(nd) sizeof = ctypes.sizeof(arraytype) # Oversized or insufficient space if sizeof > self.elemsize or not self.queue: return _allocate_head(nd) mem = self.queue.popleft() self.allocated.add(mem) return mem
def ndarray_populate_head(gpu_mem, gpu_data, shape, strides, stream=0): """ Populate the array header """ nd = len(shape) assert nd > 0, "0 or negative dimension" arraytype = make_array_ctype(nd) struct = arraytype(parent=None, data=driver.device_pointer(gpu_data), shape=shape, strides=strides) gpu_head = gpu_mem.allocate(nd) databytes = np.ndarray(shape=ctypes.sizeof(struct), dtype=np.byte, buffer=struct) gpu_mem.write(databytes, gpu_head, stream=stream) driver.device_memory_depends(gpu_head, gpu_data) return gpu_head
def _test_array(self, ndim): c_array = make_array_ctype(ndim) self.assertEqual(ctypes.sizeof(c_array), self._cpu_array_sizeof(ndim))
def _allocate_head(nd): """Allocate the metadata structure """ arraytype = make_array_ctype(nd) gpu_head = devices.get_context().memalloc(ctypes.sizeof(arraytype)) return gpu_head
def _test_array(self, ndim): c_array = make_array_ctype(ndim) self.assertEqual(ctypes.sizeof(c_array), self._cpu_array_sizeof(ndim))