async def get(self, object_id: str, **kwargs) -> object: from cudf.core.buffer import Buffer as CPBuffer from rmm import DeviceBuffer headers, buffers = _id_to_buffers[object_id] new_buffers = [] for buf in buffers: if isinstance(buf, cupy.ndarray): new_buffers.append( DeviceBuffer(ptr=buf.data.ptr, size=buf.size)) elif isinstance(buf, CPBuffer): new_buffers.append( CPBuffer(buf.ptr, buf.size, DeviceBuffer(ptr=buf.ptr, size=buf.size))) else: new_buffers.append(buf) return deserialize(headers, new_buffers)
async def get(self, object_id: CudaObjectId, **kwargs) -> object: from cudf.core.buffer import Buffer from rmm import DeviceBuffer headers = object_id.headers ptrs = object_id.ptrs data_type = headers.pop('data_type') if data_type == 'cupy': ptr = ptrs[0] size = headers['lengths'][0] cuda_buf = DeviceBuffer(ptr=ptr, size=size) buffers = [cuda_buf] elif data_type == 'cudf': buffers = [Buffer(ptr, length, DeviceBuffer(ptr=ptr, size=length)) for ptr, length in zip(ptrs, headers['lengths'])] else: raise TypeError(f'Unknown data type {data_type}') return deserialize(headers, buffers)
def copy(self): """ Create a new Buffer containing a copy of the data contained in this Buffer. """ from rmm._lib.device_buffer import copy_device_to_ptr out = Buffer(DeviceBuffer(size=self.size)) copy_device_to_ptr(self.ptr, out.ptr, self.size) return out
def _init_from_array_like(self, data): if hasattr(data, "__cuda_array_interface__"): ptr, size = _buffer_data_from_array_interface( data.__cuda_array_interface__) self.ptr = ptr self.size = size self._owner = data elif hasattr(data, "__array_interface__"): ptr, size = _buffer_data_from_array_interface( data.__array_interface__) dbuf = DeviceBuffer(ptr=ptr, size=size) self._init_from_array_like(dbuf) else: raise TypeError( f"Cannot construct Buffer from {data.__class__.__name__}")
def empty(cls, shape, dtype, order='F'): """ Create an empty Array with an allocated but uninitialized DeviceBuffer Parameters ---------- dtype : data-type, optional Any object that can be interpreted as a numpy or cupy data type. shape : int or tuple of ints, optional Shape of created array. order: string, optional Whether to create a F-major or C-major array. """ size, _ = _get_size_from_shape(shape, dtype) dbuf = DeviceBuffer(size=size) return CumlArray(data=dbuf, shape=shape, dtype=dtype, order=order)
def empty(cls, size): dbuf = DeviceBuffer(size=size) return Buffer(dbuf)
def empty(cls, size: int) -> Buffer: dbuf = DeviceBuffer(size=size) return Buffer(dbuf)