Core#

2026-09-01

5 min read time

Applies to Linux

The core C API provides the foundational types used throughout hipVS: error reporting, logging, the opaque resources handle used to carry CUDA/HIP stream and device state, and low-level memory allocation helpers.

#include <cuvs/core/c_api.h>

Error Messages#

enum cuvsError_t#

An enum denoting error statuses for function calls.

Values:

enumerator CUVS_ERROR#
enumerator CUVS_SUCCESS#
CUVS_EXPORT const char * cuvsGetLastErrorText ()

Returns a string describing the last seen error on this thread, or NULL if the last function succeeded.

void cuvsLogLastErrorText(
)#

Logs the last seen error on this thread to the standard error stream.

CUVS_EXPORT void cuvsSetLastErrorText (const char *error)

Sets a string describing an error seen on the thread. Passing NULL clears any previously seen error message.

Logging#

enum cuvsLogLevel_t#

An enum denoting log levels.

Values:

enumerator CUVS_LOG_LEVEL_TRACE#
enumerator CUVS_LOG_LEVEL_DEBUG#
enumerator CUVS_LOG_LEVEL_INFO#
enumerator CUVS_LOG_LEVEL_WARN#
enumerator CUVS_LOG_LEVEL_ERROR#
enumerator CUVS_LOG_LEVEL_CRITICAL#
enumerator CUVS_LOG_LEVEL_OFF#
CUVS_EXPORT cuvsLogLevel_t cuvsGetLogLevel ()

Returns the current log level.

CUVS_EXPORT void cuvsSetLogLevel (cuvsLogLevel_t)

Sets the log level.

Resources Handle#

typedef uintptr_t cuvsResources_t#

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

CUVS_EXPORT cuvsError_t cuvsResourcesCreate (cuvsResources_t *res)

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

Parameters:

res – [in] cuvsResources_t opaque C handle

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsResourcesDestroy (cuvsResources_t res)

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

Parameters:

res – [in] cuvsResources_t opaque C handle

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsStreamSet (cuvsResources_t res, cudaStream_t stream)

Set cudaStream_t on cuvsResources_t to queue CUDA kernels on APIs that accept a cuvsResources_t handle.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • stream – [in] cudaStream_t stream to queue CUDA kernels

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsStreamGet (cuvsResources_t res, cudaStream_t *stream)

Get the cudaStream_t from a cuvsResources_t.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • stream – [out] cudaStream_t stream to queue CUDA kernels

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsStreamSync (cuvsResources_t res)

Syncs the current CUDA stream on the resources object.

Parameters:

res – [in] cuvsResources_t opaque C handle

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsDeviceIdGet (cuvsResources_t res, int *device_id)

Get the id of the device associated with this cuvsResources_t.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • device_id – [out] int the id of the device associated with res

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesCreate (cuvsResources_t *res)

Create an Initialized opaque C handle for C++ type raft::device_resources_snmg for multi-GPU operations.

Parameters:

res – [in] cuvsResources_t opaque C handle

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesCreateWithDeviceIds (cuvsResources_t *res, DLManagedTensor *device_ids)

Create an Initialized opaque C handle for C++ type raft::device_resources_snmg for multi-GPU operations with specific device IDs.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • device_ids – [in] DLManagedTensor* containing device IDs to use

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesDestroy (cuvsResources_t res)

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

Parameters:

res – [in] cuvsResources_t opaque C handle

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsMultiGpuResourcesSetMemoryPool (cuvsResources_t res, int percent_of_free_memory)

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

Parameters:
  • res – [in] cuvsResources_t opaque C handle for multi-GPU resources

  • percent_of_free_memory – [in] Percent of free memory to allocate for the pool

Returns:

cuvsError_t

Memory Allocation#

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

Allocates device memory using RMM.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • ptr – [out] Pointer to allocated device memory

  • bytes – [in] Size in bytes to allocate

Returns:

cuvsError_t

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

Deallocates device memory using RMM.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • ptr – [in] Pointer to allocated device memory to free

  • bytes – [in] Size in bytes to allocate

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsRMMPoolMemoryResourceEnable (int initial_pool_size_percent, int max_pool_size_percent, bool managed)

Switches the working memory resource to use the RMM pool memory resource, which will 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.

Parameters:
  • initial_pool_size_percent – [in] The initial pool size as a percentage of the total available memory

  • max_pool_size_percent – [in] The maximum pool size as a percentage of the total available memory

  • managed – [in] Whether to use a managed memory resource as upstream resource or not

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsRMMMemoryResourceReset ()

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

Returns:

cuvsError_t

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

Allocates pinned memory on the host using RMM.

Parameters:
  • ptr – [out] Pointer to allocated host memory

  • bytes – [in] Size in bytes to allocate

Returns:

cuvsError_t

CUVS_EXPORT cuvsError_t cuvsRMMHostFree (void *ptr, size_t bytes)

Deallocates pinned memory on the host using RMM.

Parameters:
  • ptr – [in] Pointer to allocated host memory to free

  • bytes – [in] Size in bytes to deallocate

Returns:

cuvsError_t

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

Get the version of the cuVS library.

Parameters:
  • major – [out] Major version

  • minor – [out] Minor version

  • patch – [out] Patch version

Returns:

cuvsError_t

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

Copy a matrix.

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:
  • res – [in] cuvsResources_t opaque C handle

  • src – [in] Pointer to DLManagedTensor to copy

  • dst – [out] Pointer to DLManagedTensor to receive copy of data

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

Slices rows from a matrix.

Parameters:
  • res – [in] cuvsResources_t opaque C handle

  • src – [in] Pointer to DLManagedTensor to copy

  • start – [in] First row index to include in the output

  • end – [in] Last row index to include in the output

  • dst – [out] Pointer to DLManagedTensor to receive slice from matrix