Common

View as Markdown

Python module: cuvs.common

auto_sync_resources

1def 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

Resources

1cdef class Resources

Resources is a lightweight python wrapper around the corresponding C++ class of resources exposed by RAFT’s C++ interface. Refer to the header file raft/core/resources.hpp for interface level details of this struct.

Parameters

NameTypeDescription
streamOptional stream to use for ordering CUDA instructions

Examples

Basic usage:

1>>> from cuvs.common import Resources
2>>> handle = Resources()
3>>>
4>>> # call algos here
5>>>
6>>> # final sync of all work launched in the stream of this handle
7>>> handle.sync()

Using a cuPy stream with cuVS Resources:

1>>> import cupy
2>>> from cuvs.common import Resources
3>>>
4>>> cupy_stream = cupy.cuda.Stream()
5>>> handle = Resources(stream=cupy_stream.ptr)

Members

NameKind
syncmethod
get_c_objmethod

sync

1def sync(self)

get_c_obj

1def get_c_obj(self)

Return the pointer to the underlying c_obj as a size_t

MultiGpuResources

1cdef class MultiGpuResources

Multi-GPU Resources is a lightweight python wrapper around the corresponding C++ class of multi-GPU resources exposed by RAFT’s C++ interface. This class provides a handle for multi-GPU operations across all available GPUs.

Parameters

NameTypeDescription
streamint, optionalA CUDA stream pointer to use for this resource handle. If None, a default stream will be used.
device_idslist of int, optionalA list of device IDs to use for multi-GPU operations. If None, all available GPUs will be used.

Examples

Basic usage:

1>>> from cuvs.common import MultiGpuResources
2>>> handle = MultiGpuResources()
3>>>
4>>> # call multi-GPU algos here
5>>>
6>>> # final sync of all work launched in the stream of this handle
7>>> handle.sync()

Using a cuPy stream with cuVS Multi-GPU Resources:

1>>> import cupy
2>>> from cuvs.common import MultiGpuResources
3>>>
4>>> cupy_stream = cupy.cuda.Stream()
5>>> handle = MultiGpuResources(stream=cupy_stream.ptr)

Using specific device IDs:

1>>> from cuvs.common import MultiGpuResources
2>>> handle = MultiGpuResources(device_ids=[0])
3>>>
4>>> # call multi-GPU algos here
5>>>
6>>> handle.sync()

Members

NameKind
syncmethod
set_memory_poolmethod
get_c_objmethod

sync

1def sync(self)

set_memory_pool

1def set_memory_pool(self, percent_of_free_memory)

Set a memory pool on all devices managed by these resources.

Parameters

NameTypeDescription
percent_of_free_memoryintPercentage of free device memory to allocate for the pool.

Examples

1>>> from cuvs.common import MultiGpuResources
2>>> handle = MultiGpuResources()
3>>> handle.set_memory_pool(80) # Use 80% of free memory

get_c_obj

1def get_c_obj(self)

Return the pointer to the underlying c_obj as a size_t

auto_sync_multi_gpu_resources

1def auto_sync_multi_gpu_resources(f)

Decorator to automatically call sync on a cuVS Multi-GPU 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 multi-GPU 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