pylibraft.common.handle#

4 min read time

Applies to Linux

Exceptions#

CudaRuntimeError

Unspecified run-time error.

Classes#

DeviceResources

DeviceResources is a lightweight python wrapper around the corresponding

Handle

Handle is a lightweight python wrapper around the corresponding

Functions#

auto_sync_handle(f)

auto_sync_handle(f)

Module Contents#

exception pylibraft.common.handle.CudaRuntimeError(extraMsg=None)#

Bases: RuntimeError

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

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

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