def check(self, device_id): size = 24 shape = (2, 3) dtype = cupy.float32 with device.Device(device_id): src_mem_ptr = self.allocator(size) src_ptr = src_mem_ptr.ptr args = (src_ptr, size, src_mem_ptr) kwargs = {} if self.specify_device_id: kwargs = {'device_id': device_id} unowned_mem = memory.UnownedMemory(*args, **kwargs) assert unowned_mem.size == size assert unowned_mem.ptr == src_ptr assert unowned_mem.device_id == device_id arr = cupy.ndarray(shape, dtype, memory.MemoryPointer(unowned_mem, 0)) # Delete the source object del src_mem_ptr with device.Device(device_id): arr[:] = 2 assert (arr == 2).all()
def check(self, device_id): if (cupy.cuda.runtime.is_hip and self.allocator is memory.malloc_managed): raise unittest.SkipTest('HIP does not support managed memory') size = 24 shape = (2, 3) dtype = cupy.float32 with device.Device(device_id): src_mem_ptr = self.allocator(size) src_ptr = src_mem_ptr.ptr args = (src_ptr, size, src_mem_ptr) kwargs = {} if self.specify_device_id: kwargs = {'device_id': device_id} unowned_mem = memory.UnownedMemory(*args, **kwargs) assert unowned_mem.size == size assert unowned_mem.ptr == src_ptr assert unowned_mem.device_id == device_id arr = cupy.ndarray(shape, dtype, memory.MemoryPointer(unowned_mem, 0)) # Delete the source object del src_mem_ptr with device.Device(device_id): arr[:] = 2 assert (arr == 2).all()
def check(self, device_id): if cupy.cuda.runtime.is_hip: if self.allocator is memory.malloc_managed: raise unittest.SkipTest('HIP does not support managed memory') if self.allocator is memory.malloc_async: raise unittest.SkipTest('HIP does not support async mempool') elif cupy.cuda.driver.get_build_version() < 11020: raise unittest.SkipTest('malloc_async is supported since ' 'CUDA 11.2') size = 24 shape = (2, 3) dtype = cupy.float32 with device.Device(device_id): src_mem_ptr = self.allocator(size) src_ptr = src_mem_ptr.ptr args = (src_ptr, size, src_mem_ptr) kwargs = {} if self.specify_device_id: kwargs = {'device_id': device_id} unowned_mem = memory.UnownedMemory(*args, **kwargs) assert unowned_mem.size == size assert unowned_mem.ptr == src_ptr assert unowned_mem.device_id == device_id arr = cupy.ndarray(shape, dtype, memory.MemoryPointer(unowned_mem, 0)) # Delete the source object del src_mem_ptr with device.Device(device_id): arr[:] = 2 assert (arr == 2).all()
def check(self, device_id): if cupy.cuda.runtime.is_hip: if self.allocator is memory.malloc_managed: if cupy.cuda.driver.get_build_version() < 40300000: raise unittest.SkipTest( 'Managed memory requires ROCm 4.3+') else: raise unittest.SkipTest( 'hipPointerGetAttributes does not support managed ' 'memory') if self.allocator is memory.malloc_async: raise unittest.SkipTest('HIP does not support async mempool') else: if self.allocator is memory.malloc_async: if cupy.cuda.driver._is_cuda_python(): version = cupy.cuda.runtime.runtimeGetVersion() else: version = cupy.cuda.driver.get_build_version() if version < 11020: raise unittest.SkipTest('malloc_async is supported since ' 'CUDA 11.2') elif runtime.deviceGetAttribute( runtime.cudaDevAttrMemoryPoolsSupported, 0) == 0: raise unittest.SkipTest( 'malloc_async is not supported on device 0') size = 24 shape = (2, 3) dtype = cupy.float32 with device.Device(device_id): src_mem_ptr = self.allocator(size) src_ptr = src_mem_ptr.ptr args = (src_ptr, size, src_mem_ptr) kwargs = {} if self.specify_device_id: kwargs = {'device_id': device_id} if cupy.cuda.runtime.is_hip and self.allocator is memory._malloc: # In ROCm, it seems that `hipPointerGetAttributes()`, which is # called in `UnownedMemory()`, requires an unmanaged device pointer # that the current device must be the one on which the memory # referred to by the pointer physically resides. with device.Device(device_id): unowned_mem = memory.UnownedMemory(*args, **kwargs) else: unowned_mem = memory.UnownedMemory(*args, **kwargs) assert unowned_mem.size == size assert unowned_mem.ptr == src_ptr assert unowned_mem.device_id == device_id arr = cupy.ndarray(shape, dtype, memory.MemoryPointer(unowned_mem, 0)) # Delete the source object del src_mem_ptr with device.Device(device_id): arr[:] = 2 assert (arr == 2).all()
def _convert_object_with_cuda_array_interface(a): desc = a.__cuda_array_interface__ shape = desc['shape'] dtype = numpy.dtype(desc['typestr']) if 'strides' in desc: strides = desc['strides'] nbytes = numpy.max(numpy.array(shape) * numpy.array(strides)) else: strides = None nbytes = numpy.prod(shape) * dtype.itemsize mem = memory.UnownedMemory(desc['data'][0], nbytes, a) memptr = memory.MemoryPointer(mem, 0) return ndarray(shape, dtype=dtype, memptr=memptr, strides=strides)
def mock_alloc(size): mem = MockMemory(size) return memory.MemoryPointer(mem, 0)