def __init__(self, shape, strides, dtype, dgpu_data=None): """ Args ---- shape array shape. strides array strides. dtype data type as numpy.dtype. dgpu_data user provided device memory for the ndarray data buffer """ if isinstance(shape, (int, long)): shape = (shape,) if isinstance(strides, (int, long)): strides = (strides,) self.ndim = len(shape) if len(strides) != self.ndim: raise ValueError("strides not match ndim") self._dummy = dummyarray.Array.from_desc(0, shape, strides, dtype.itemsize) self.shape = tuple(shape) self.strides = tuple(strides) self.dtype = np.dtype(dtype) self.size = int(np.prod(self.shape)) # prepare dgpu memory if self.size > 0: if dgpu_data is None: from numba.roc.api import _memory_size_from_info self.alloc_size = _memory_size_from_info( self.shape, self.strides, self.dtype.itemsize ) # find a coarse region on the dGPU dgpu_data = devices.get_context().mempoolalloc(self.alloc_size) else: # we have some preallocated dgpu_memory sz = getattr(dgpu_data, "_hsa_memsize_", None) if sz is None: raise ValueError("dgpu_data as no _hsa_memsize_ attribute") assert sz >= 0 self.alloc_size = sz else: dgpu_data = None self.alloc_size = 0 self.dgpu_data = dgpu_data
def __init__(self, shape, strides, dtype, dgpu_data=None): """ Args ---- shape array shape. strides array strides. dtype data type as numpy.dtype. dgpu_data user provided device memory for the ndarray data buffer """ if isinstance(shape, (int, long)): shape = (shape,) if isinstance(strides, (int, long)): strides = (strides,) self.ndim = len(shape) if len(strides) != self.ndim: raise ValueError('strides not match ndim') self._dummy = dummyarray.Array.from_desc(0, shape, strides, dtype.itemsize) self.shape = tuple(shape) self.strides = tuple(strides) self.dtype = np.dtype(dtype) self.size = int(np.prod(self.shape)) # prepare dgpu memory if self.size > 0: if dgpu_data is None: from numba.roc.api import _memory_size_from_info self.alloc_size = _memory_size_from_info(self.shape, self.strides, self.dtype.itemsize) # find a coarse region on the dGPU dgpu_data = devices.get_context().mempoolalloc(self.alloc_size) else: # we have some preallocated dgpu_memory sz = getattr(dgpu_data, '_hsa_memsize_', None) if sz is None: raise ValueError('dgpu_data as no _hsa_memsize_ attribute') assert sz >= 0 self.alloc_size = sz else: dgpu_data = None self.alloc_size = 0 self.dgpu_data = dgpu_data