cuvs.common.device_tensor_view#
2 min read time
Classes#
DeviceTensorView(array_like=None) |
Functions#
|
dl_data_type_to_numpy(DLDataType dtype) |
|
check_cuvs(cuvsError_t status: cuvsError_t) |
auto_sync_resources(f) |
Module Contents#
- cuvs.common.device_tensor_view.dl_data_type_to_numpy(dtype)#
dl_data_type_to_numpy(DLDataType dtype)
Converts a DLDataType dtype to a numpy dtype
- cuvs.common.device_tensor_view.check_cuvs(status: cuvsError_t)#
check_cuvs(cuvsError_t status: cuvsError_t)
Converts a status code into an exception
- cuvs.common.device_tensor_view.auto_sync_resources(f)#
auto_sync_resources(f)
Decorator to automatically call sync on a cuVS Resources object when it isn’t passed to a function.
When a resources=None is passed to the wrapped function, this decorator will automatically create a default resources for the function, and call sync on that resources when the function exits.
This will also insert the appropriate docstring for the resources parameter
- class cuvs.common.device_tensor_view.DeviceTensorView#
DeviceTensorView(array_like=None)
A __cuda_array_interface__ compatible tensor on device memory
This aims to be a lightweight wrapper around device_matrix_view and device_vector_view objects in the C++ layer of cuvs - and lets us access memory internals of cuvs without copying into temporary storage.
Since this support the __cuda_array_interface__ protocol, this object gives us easy interopability with other libraries such as cupy, pytorch, and cudf - without adding any dependencies on these libraries inside cuvs.
Since cuvs also understands CAI, DeviceTensorView objects can also be passed directly to cuvs python functions.
- static __reduce__(*args, **kwargs)#
DeviceTensorView.__reduce_cython__(self)
- static __setstate__(*args, **kwargs)#
DeviceTensorView.__setstate_cython__(self, __pyx_state)
- static copy_to_host(*args, resources=None, **kwargs)#
DeviceTensorView.copy_to_host(self, resources=None)
copies a device matrix to a numpy array
Parameters#
- resourcesOptional cuVS Resource handle for reusing CUDA resources.
If Resources aren’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If resources are supplied, you will need to explicitly synchronize yourself by calling resources.sync() before accessing the output.
Returns#
- tensor: np.array
This tensor copied into host memory
- static slice_rows(*args, resources=None, **kwargs)#
DeviceTensorView.slice_rows(self, start, end, resources=None)
Slices rows from this tensor
Slices a subset, and returns in a new DeviceTensorView without copying data.
Parameters#
- start: int
the index of the first row to slice
- end: int
the index of the last row to slice
- resourcesOptional cuVS Resource handle for reusing CUDA resources.
If Resources aren’t supplied, CUDA resources will be allocated inside this function and synchronized before the function exits. If resources are supplied, you will need to explicitly synchronize yourself by calling resources.sync() before accessing the output.
Returns#
- tensor: DeviceTensorView
A non-owning view of the rows sliced from this tensor
- get_handle()#
DeviceTensorView.get_handle(self)