pylibraft.common.handle#
5 min read time
Exceptions#
Unspecified run-time error. |
Classes#
DeviceResources is a lightweight python wrapper around the corresponding |
|
DeviceResourcesSNMG manages multi-GPU resources |
|
Handle is a lightweight python wrapper around the corresponding |
Functions#
auto_sync_handle(f) |
Module Contents#
- exception pylibraft.common.handle.CudaRuntimeError(extraMsg=None)#
Bases:
RuntimeErrorUnspecified run-time error.
- class pylibraft.common.handle.DeviceResources#
DeviceResources is a lightweight python wrapper around the corresponding C++ class of device_resources exposed by RAFT’s C++ interface. Refer to the header file raft/core/device_resources.hpp for interface level details of this struct
- Parameters:
stream (Optional stream to use for ordering CUDA instructions) – Accepts pylibraft.common.Stream() or uintptr_t (cudaStream_t)
Examples
Basic usage:
>>> from pylibraft.common import Stream, DeviceResources >>> stream = Stream() >>> handle = DeviceResources(stream) >>> >>> # call algos here >>> >>> # final sync of all work launched in the stream of this handle >>> # this is same as `raft.cuda.Stream.sync()` call, but safer in case >>> # the default stream inside the `device_resources` is being used >>> handle.sync() >>> del handle # optional!
Using a cuPy stream with RAFT device_resources:
>>> import cupy >>> from pylibraft.common import Stream, DeviceResources >>> >>> cupy_stream = cupy.cuda.Stream() >>> handle = DeviceResources(stream=cupy_stream.ptr)
Using a RAFT stream with CuPy ExternalStream:
>>> import cupy >>> from pylibraft.common import Stream >>> >>> raft_stream = Stream() >>> cupy_stream = cupy.cuda.ExternalStream(raft_stream.get_ptr())
- static __reduce_cython__(*args, **kwargs)#
DeviceResources.__reduce_cython__(self)
- static __setstate_cython__(*args, **kwargs)#
DeviceResources.__setstate_cython__(self, __pyx_state)
- __getstate__()#
DeviceResources.__getstate__(self)
- __setstate__(state)#
DeviceResources.__setstate__(self, state)
- getHandle()#
DeviceResources.getHandle(self)
Return the pointer to the underlying raft::device_resources instance as a size_t
- sync()#
DeviceResources.sync(self)
Issues a sync on the stream set for this instance.
- class pylibraft.common.handle.DeviceResourcesSNMG#
DeviceResourcesSNMG manages multi-GPU resources in a single-node setup using RAFT’s device_resources_snmg. Refer to the header file raft/core/device_resources_snmg.hpp for interface level details of this struct :param device_ids: :type device_ids: Optional list to specify which devices will be used
Examples
Basic usage: >>> from pylibraft.common import DeviceResourcesSNMG >>> >>> # to use GPU IDs 0,1,2,3 on machine >>> # handle = DeviceResourcesSNMG([0,1,2,3]) >>> >>> # to use all GPUs on machine >>> handle = DeviceResourcesSNMG()
- static __reduce_cython__(*args, **kwargs)#
DeviceResourcesSNMG.__reduce_cython__(self)
- static __setstate_cython__(*args, **kwargs)#
DeviceResourcesSNMG.__setstate_cython__(self, __pyx_state)
- __getstate__()#
DeviceResourcesSNMG.__getstate__(self)
- __setstate__(state)#
DeviceResourcesSNMG.__setstate__(self, state)
- getHandle()#
DeviceResourcesSNMG.getHandle(self)
Return the pointer to the underlying raft::device_resources_snmg instance as a size_t
- sync()#
DeviceResourcesSNMG.sync(self)
Issues a sync on the stream set for this instance.
- class pylibraft.common.handle.Handle#
Bases:
DeviceResourcesHandle is a lightweight python wrapper around the corresponding C++ class of handle_t exposed by RAFT’s C++ interface. Refer to the header file raft/core/handle.hpp for interface level details of this struct
Note: This API is officially deprecated in favor of DeviceResources and will be removed in a future release.
- Parameters:
stream (Optional stream to use for ordering CUDA instructions) – Accepts pylibraft.common.Stream() or uintptr_t (cudaStream_t)
Examples
Basic usage:
>>> from pylibraft.common import Stream, Handle >>> stream = Stream() >>> handle = Handle(stream) >>> >>> # call algos here >>> >>> # final sync of all work launched in the stream of this handle >>> # this is same as `raft.cuda.Stream.sync()` call, but safer in case >>> # the default stream inside the `handle_t` is being used >>> handle.sync() >>> del handle # optional!
Using a cuPy stream with RAFT device_resources:
>>> import cupy >>> from pylibraft.common import Stream, Handle >>> >>> cupy_stream = cupy.cuda.Stream() >>> handle = Handle(stream=cupy_stream.ptr)
Using a RAFT stream with CuPy ExternalStream:
>>> import cupy >>> from pylibraft.common import Stream >>> >>> raft_stream = Stream() >>> cupy_stream = cupy.cuda.ExternalStream(raft_stream.get_ptr())
- static __reduce_cython__(*args, **kwargs)#
Handle.__reduce_cython__(self)
- static __setstate_cython__(*args, **kwargs)#
Handle.__setstate_cython__(self, __pyx_state)
- __getstate__()#
Handle.__getstate__(self)
- __setstate__(state)#
Handle.__setstate__(self, state)
- pylibraft.common.handle.auto_sync_handle(f)#
auto_sync_handle(f) Decorator to automatically call sync on a raft handle when
it isn’t passed to a function.
When a handle=None is passed to the wrapped function, this decorator will automatically create a default handle for the function, and call sync on that handle when the function exits.
This will also insert the appropriate docstring for the handle parameter