pylibraft.common#

4 min read time

Applies to Linux

Submodules#

Classes#

Stream

Stream represents a thin-wrapper around cudaStream_t and its operations.

DeviceResources

DeviceResources is a lightweight python wrapper around the corresponding

Handle

Handle is a lightweight python wrapper around the corresponding

Package Contents#

class pylibraft.common.Stream#

Stream represents a thin-wrapper around cudaStream_t and its operations.

Examples#

>>> from pylibraft.common.cuda import Stream
>>> stream = Stream()
>>> stream.sync()
>>> del stream  # optional!
__pyx_vtable__: ClassVar[Any]#
static __reduce__(*args, **kwargs)#

Stream.__reduce_cython__(self)

static __setstate__(*args, **kwargs)#

Stream.__setstate_cython__(self, __pyx_state)

get_ptr()#

Stream.get_ptr(self)

Return the uintptr_t pointer of the underlying cudaStream_t handle

sync()#

Stream.sync(self)

Synchronize on the cudastream owned by this object. Note that this could raise exception due to issues with previous asynchronous launches

class pylibraft.common.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#

streamOptional 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#

Bases: DeviceResources

Handle 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#

streamOptional 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)