C API

View as Markdown

Source header: cuvs/core/c_api.h

cuVS Error Messages

cuvsError_t

An enum denoting error statuses for function calls

1typedef enum { ... } cuvsError_t;

Values

NameValue
CUVS_ERROR0
CUVS_SUCCESS1

cuvsGetLastErrorText

Returns a string describing the last seen error on this thread, or

1CUVS_EXPORT const char* cuvsGetLastErrorText();

NULL if the last function succeeded.

Returns

CUVS_EXPORT const char*

cuvsSetLastErrorText

Sets a string describing an error seen on the thread. Passing NULL

1CUVS_EXPORT void cuvsSetLastErrorText(const char* error);

clears any previously seen error message.

Parameters

NameDirectionTypeDescription
errorconst char*

Returns

CUVS_EXPORT void

cuVS Logging

cuvsLogLevel_t

An enum denoting log levels

1typedef enum { ... } cuvsLogLevel_t;

Values

NameValue
CUVS_LOG_LEVEL_TRACE0
CUVS_LOG_LEVEL_DEBUG1
CUVS_LOG_LEVEL_INFO2
CUVS_LOG_LEVEL_WARN3
CUVS_LOG_LEVEL_ERROR4
CUVS_LOG_LEVEL_CRITICAL5
CUVS_LOG_LEVEL_OFF6

cuvsGetLogLevel

Returns the current log level

1CUVS_EXPORT cuvsLogLevel_t cuvsGetLogLevel();

Returns

CUVS_EXPORT cuvsLogLevel_t

cuvsSetLogLevel

Sets the log level

1CUVS_EXPORT void cuvsSetLogLevel(cuvsLogLevel_t);

Parameters

NameDirectionTypeDescription
arg1cuvsLogLevel_t

Returns

CUVS_EXPORT void

cuVS Resources Handle

cuvsResources_t

An opaque C handle for C++ type raft::resources

1typedef uintptr_t cuvsResources_t;

cuvsResourcesCreate

Create an Initialized opaque C handle for C++ type raft::resources

1CUVS_EXPORT cuvsError_t cuvsResourcesCreate(cuvsResources_t* res);

Parameters

NameDirectionTypeDescription
resincuvsResources_t*cuvsResources_t opaque C handle

Returns

CUVS_EXPORT cuvsError_t

cuvsResourcesDestroy

Destroy and de-allocate opaque C handle for C++ type raft::resources

1CUVS_EXPORT cuvsError_t cuvsResourcesDestroy(cuvsResources_t res);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle

Returns

CUVS_EXPORT cuvsError_t

cuvsStreamSet

Set cudaStream_t on cuvsResources_t to queue CUDA kernels on APIs

1CUVS_EXPORT cuvsError_t cuvsStreamSet(cuvsResources_t res, cudaStream_t stream);

that accept a cuvsResources_t handle

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
streamincudaStream_tcudaStream_t stream to queue CUDA kernels

Returns

CUVS_EXPORT cuvsError_t

cuvsStreamGet

Get the cudaStream_t from a cuvsResources_t

1CUVS_EXPORT cuvsError_t cuvsStreamGet(cuvsResources_t res, cudaStream_t* stream);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
streamoutcudaStream_t*cudaStream_t stream to queue CUDA kernels

Returns

CUVS_EXPORT cuvsError_t

cuvsStreamSync

Syncs the current CUDA stream on the resources object

1CUVS_EXPORT cuvsError_t cuvsStreamSync(cuvsResources_t res);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle

Returns

CUVS_EXPORT cuvsError_t

cuvsDeviceIdGet

Get the id of the device associated with this cuvsResources_t

1CUVS_EXPORT cuvsError_t cuvsDeviceIdGet(cuvsResources_t res, int* device_id);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
device_idoutint*int the id of the device associated with res

Returns

CUVS_EXPORT cuvsError_t

cuvsMultiGpuResourcesCreate

Create an Initialized opaque C handle for C++ type raft::device_resources_snmg

1CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesCreate(cuvsResources_t* res);

for multi-GPU operations

Parameters

NameDirectionTypeDescription
resincuvsResources_t*cuvsResources_t opaque C handle

Returns

CUVS_EXPORT cuvsError_t

cuvsMultiGpuResourcesCreateWithDeviceIds

Create an Initialized opaque C handle for C++ type raft::device_resources_snmg

1CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesCreateWithDeviceIds(cuvsResources_t* res,
2DLManagedTensor* device_ids);

for multi-GPU operations with specific device IDs

Parameters

NameDirectionTypeDescription
resincuvsResources_t*cuvsResources_t opaque C handle
device_idsinDLManagedTensor*DLManagedTensor* containing device IDs to use

Returns

CUVS_EXPORT cuvsError_t

cuvsMultiGpuResourcesDestroy

Destroy and de-allocate opaque C handle for C++ type raft::device_resources_snmg

1CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesDestroy(cuvsResources_t res);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle

Returns

CUVS_EXPORT cuvsError_t

cuvsMultiGpuResourcesSetMemoryPool

Set a memory pool on all devices managed by the multi-GPU resources

1CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesSetMemoryPool(cuvsResources_t res, int percent_of_free_memory);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle for multi-GPU resources
percent_of_free_memoryinintPercent of free memory to allocate for the pool

Returns

CUVS_EXPORT cuvsError_t

cuVS Memory Allocation

cuvsRMMAlloc

Allocates device memory using RMM

1CUVS_EXPORT cuvsError_t cuvsRMMAlloc(cuvsResources_t res, void** ptr, size_t bytes);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
ptroutvoid**Pointer to allocated device memory
bytesinsize_tSize in bytes to allocate

Returns

CUVS_EXPORT cuvsError_t

cuvsRMMFree

Deallocates device memory using RMM

1CUVS_EXPORT cuvsError_t cuvsRMMFree(cuvsResources_t res, void* ptr, size_t bytes);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
ptrinvoid*Pointer to allocated device memory to free
bytesinsize_tSize in bytes to allocate

Returns

CUVS_EXPORT cuvsError_t

cuvsRMMPoolMemoryResourceEnable

Switches the working memory resource to use the RMM pool memory resource, which will

1CUVS_EXPORT cuvsError_t cuvsRMMPoolMemoryResourceEnable(int initial_pool_size_percent,
2int max_pool_size_percent,
3bool managed);

bypass unnecessary synchronizations by allocating a chunk of device memory up front and carving that up for temporary memory allocations within algorithms. Be aware that this function will change the memory resource for the whole process and the new memory resource will be used until explicitly changed.

available memory available memory

Parameters

NameDirectionTypeDescription
initial_pool_size_percentinintThe initial pool size as a percentage of the total
max_pool_size_percentinintThe maximum pool size as a percentage of the total
managedinboolWhether to use a managed memory resource as upstream resource or not

Returns

CUVS_EXPORT cuvsError_t

cuvsRMMMemoryResourceReset

Resets the memory resource to use the default memory resource (cuda_memory_resource)

1CUVS_EXPORT cuvsError_t cuvsRMMMemoryResourceReset();

Returns

CUVS_EXPORT cuvsError_t

cuvsRMMHostAlloc

Allocates pinned memory on the host using RMM

1CUVS_EXPORT cuvsError_t cuvsRMMHostAlloc(void** ptr, size_t bytes);

Parameters

NameDirectionTypeDescription
ptroutvoid**Pointer to allocated host memory
bytesinsize_tSize in bytes to allocate

Returns

CUVS_EXPORT cuvsError_t

cuvsRMMHostFree

Deallocates pinned memory on the host using RMM

1CUVS_EXPORT cuvsError_t cuvsRMMHostFree(void* ptr, size_t bytes);

Parameters

NameDirectionTypeDescription
ptrinvoid*Pointer to allocated host memory to free
bytesinsize_tSize in bytes to deallocate

Returns

CUVS_EXPORT cuvsError_t

cuvsVersionGet

Get the version of the cuVS library

1CUVS_EXPORT cuvsError_t cuvsVersionGet(uint16_t* major, uint16_t* minor, uint16_t* patch);

Parameters

NameDirectionTypeDescription
majoroutuint16_t*Major version
minoroutuint16_t*Minor version
patchoutuint16_t*Patch version

Returns

CUVS_EXPORT cuvsError_t

cuvsMatrixCopy

Copy a matrix

1CUVS_EXPORT cuvsError_t cuvsMatrixCopy(cuvsResources_t res, DLManagedTensor* src, DLManagedTensor* dst);

This function copies a matrix from dst to src. This lets you copy a matrix from device memory to host memory (or vice versa), while accounting for differences in strides.

Both src and dst must have the same shape and dtype, but can have different strides and device type. The memory for the output dst tensor must already be allocated and the tensor initialized.

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
srcinDLManagedTensor*Pointer to DLManagedTensor to copy
dstoutDLManagedTensor*Pointer to DLManagedTensor to receive copy of data

Returns

CUVS_EXPORT cuvsError_t

cuvsMatrixSliceRows

Slices rows from a matrix

1CUVS_EXPORT cuvsError_t cuvsMatrixSliceRows(
2cuvsResources_t res, DLManagedTensor* src, int64_t start, int64_t end, DLManagedTensor* dst);

Parameters

NameDirectionTypeDescription
resincuvsResources_tcuvsResources_t opaque C handle
srcinDLManagedTensor*Pointer to DLManagedTensor to copy
startinint64_tFirst row index to include in the output
endinint64_tLast row index to include in the output
dstoutDLManagedTensor*Pointer to DLManagedTensor to receive slice from matrix

Returns

CUVS_EXPORT cuvsError_t