1use crate::{cudaDataType_t, cudaStream_t};
4
5#[repr(u32)]
6#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
7pub enum DLDeviceType {
8 #[doc = " \\brief CPU device"]
9 kDLCPU = 1,
10 #[doc = " \\brief CUDA GPU device"]
11 kDLCUDA = 2,
12 #[doc = " \\brief Pinned CUDA CPU memory by cudaMallocHost"]
13 kDLCUDAHost = 3,
14 #[doc = " \\brief OpenCL devices."]
15 kDLOpenCL = 4,
16 #[doc = " \\brief Vulkan buffer for next generation graphics."]
17 kDLVulkan = 7,
18 #[doc = " \\brief Metal for Apple GPU."]
19 kDLMetal = 8,
20 #[doc = " \\brief Verilog simulator buffer"]
21 kDLVPI = 9,
22 #[doc = " \\brief ROCm GPUs for AMD GPUs"]
23 kDLROCM = 10,
24 #[doc = " \\brief Pinned ROCm CPU memory allocated by hipMallocHost"]
25 kDLROCMHost = 11,
26 #[doc = " \\brief Reserved extension device type,\n used for quickly test extension device\n The semantics can differ depending on the implementation."]
27 kDLExtDev = 12,
28 #[doc = " \\brief CUDA managed/unified memory allocated by cudaMallocManaged"]
29 kDLCUDAManaged = 13,
30 #[doc = " \\brief Unified shared memory allocated on a oneAPI non-partititioned\n device. Call to oneAPI runtime is required to determine the device\n type, the USM allocation type and the sycl context it is bound to.\n"]
31 kDLOneAPI = 14,
32 #[doc = " \\brief GPU support for next generation WebGPU standard."]
33 kDLWebGPU = 15,
34 #[doc = " \\brief Qualcomm Hexagon DSP"]
35 kDLHexagon = 16,
36}
37#[doc = " \\brief A Device for Tensor and operator."]
38#[repr(C)]
39#[derive(Debug, Copy, Clone)]
40pub struct DLDevice {
41 #[doc = " \\brief The device type used in the device."]
42 pub device_type: DLDeviceType,
43 #[doc = " \\brief The device index.\n For vanilla CPU memory, pinned memory, or managed memory, this is set to 0."]
44 pub device_id: i32,
45}
46#[allow(clippy::unnecessary_operation, clippy::identity_op)]
47const _: () = {
48 ["Size of DLDevice"][::std::mem::size_of::<DLDevice>() - 8usize];
49 ["Alignment of DLDevice"][::std::mem::align_of::<DLDevice>() - 4usize];
50 ["Offset of field: DLDevice::device_type"]
51 [::std::mem::offset_of!(DLDevice, device_type) - 0usize];
52 ["Offset of field: DLDevice::device_id"][::std::mem::offset_of!(DLDevice, device_id) - 4usize];
53};
54#[repr(u32)]
55#[doc = " \\brief The type code options DLDataType."]
56#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
57pub enum DLDataTypeCode {
58 #[doc = " \\brief signed integer"]
59 kDLInt = 0,
60 #[doc = " \\brief unsigned integer"]
61 kDLUInt = 1,
62 #[doc = " \\brief IEEE floating point"]
63 kDLFloat = 2,
64 #[doc = " \\brief Opaque handle type, reserved for testing purposes.\n Frameworks need to agree on the handle data type for the exchange to be well-defined."]
65 kDLOpaqueHandle = 3,
66 #[doc = " \\brief bfloat16"]
67 kDLBfloat = 4,
68 #[doc = " \\brief complex number\n (C/C++/Python layout: compact struct per complex number)"]
69 kDLComplex = 5,
70 #[doc = " \\brief boolean"]
71 kDLBool = 6,
72}
73#[doc = " \\brief The data type the tensor can hold. The data type is assumed to follow the\n native endian-ness. An explicit error message should be raised when attempting to\n export an array with non-native endianness\n\n Examples\n - float: type_code = 2, bits = 32, lanes = 1\n - float4(vectorized 4 float): type_code = 2, bits = 32, lanes = 4\n - int8: type_code = 0, bits = 8, lanes = 1\n - std::complex<float>: type_code = 5, bits = 64, lanes = 1\n - bool: type_code = 6, bits = 8, lanes = 1 (as per common array library convention, the underlying storage size of bool is 8 bits)"]
74#[repr(C)]
75#[derive(Debug, Copy, Clone)]
76pub struct DLDataType {
77 #[doc = " \\brief Type code of base types.\n We keep it uint8_t instead of DLDataTypeCode for minimal memory\n footprint, but the value should be one of DLDataTypeCode enum values."]
78 pub code: u8,
79 #[doc = " \\brief Number of bits, common choices are 8, 16, 32."]
80 pub bits: u8,
81 #[doc = " \\brief Number of lanes in the type, used for vector types."]
82 pub lanes: u16,
83}
84#[allow(clippy::unnecessary_operation, clippy::identity_op)]
85const _: () = {
86 ["Size of DLDataType"][::std::mem::size_of::<DLDataType>() - 4usize];
87 ["Alignment of DLDataType"][::std::mem::align_of::<DLDataType>() - 2usize];
88 ["Offset of field: DLDataType::code"][::std::mem::offset_of!(DLDataType, code) - 0usize];
89 ["Offset of field: DLDataType::bits"][::std::mem::offset_of!(DLDataType, bits) - 1usize];
90 ["Offset of field: DLDataType::lanes"][::std::mem::offset_of!(DLDataType, lanes) - 2usize];
91};
92#[doc = " \\brief Plain C Tensor object, does not manage memory."]
93#[repr(C)]
94#[derive(Debug, Copy, Clone)]
95pub struct DLTensor {
96 #[doc = " \\brief The data pointer points to the allocated data. This will be CUDA\n device pointer or cl_mem handle in OpenCL. It may be opaque on some device\n types. This pointer is always aligned to 256 bytes as in CUDA. The\n `byte_offset` field should be used to point to the beginning of the data.\n\n Note that as of Nov 2021, multiply libraries (CuPy, PyTorch, TensorFlow,\n TVM, perhaps others) do not adhere to this 256 byte aligment requirement\n on CPU/CUDA/ROCm, and always use `byte_offset=0`. This must be fixed\n (after which this note will be updated); at the moment it is recommended\n to not rely on the data pointer being correctly aligned.\n\n For given DLTensor, the size of memory required to store the contents of\n data is calculated as follows:\n\n \\code{.c}\n static inline size_t GetDataSize(const DLTensor* t) {\n size_t size = 1;\n for (tvm_index_t i = 0; i < t->ndim; ++i) {\n size *= t->shape[i];\n }\n size *= (t->dtype.bits * t->dtype.lanes + 7) / 8;\n return size;\n }\n \\endcode"]
97 pub data: *mut ::std::os::raw::c_void,
98 #[doc = " \\brief The device of the tensor"]
99 pub device: DLDevice,
100 #[doc = " \\brief Number of dimensions"]
101 pub ndim: i32,
102 #[doc = " \\brief The data type of the pointer"]
103 pub dtype: DLDataType,
104 #[doc = " \\brief The shape of the tensor"]
105 pub shape: *mut i64,
106 #[doc = " \\brief strides of the tensor (in number of elements, not bytes)\n can be NULL, indicating tensor is compact and row-majored."]
107 pub strides: *mut i64,
108 #[doc = " \\brief The offset in bytes to the beginning pointer to data"]
109 pub byte_offset: u64,
110}
111#[allow(clippy::unnecessary_operation, clippy::identity_op)]
112const _: () = {
113 ["Size of DLTensor"][::std::mem::size_of::<DLTensor>() - 48usize];
114 ["Alignment of DLTensor"][::std::mem::align_of::<DLTensor>() - 8usize];
115 ["Offset of field: DLTensor::data"][::std::mem::offset_of!(DLTensor, data) - 0usize];
116 ["Offset of field: DLTensor::device"][::std::mem::offset_of!(DLTensor, device) - 8usize];
117 ["Offset of field: DLTensor::ndim"][::std::mem::offset_of!(DLTensor, ndim) - 16usize];
118 ["Offset of field: DLTensor::dtype"][::std::mem::offset_of!(DLTensor, dtype) - 20usize];
119 ["Offset of field: DLTensor::shape"][::std::mem::offset_of!(DLTensor, shape) - 24usize];
120 ["Offset of field: DLTensor::strides"][::std::mem::offset_of!(DLTensor, strides) - 32usize];
121 ["Offset of field: DLTensor::byte_offset"]
122 [::std::mem::offset_of!(DLTensor, byte_offset) - 40usize];
123};
124#[doc = " \\brief C Tensor object, manage memory of DLTensor. This data structure is\n intended to facilitate the borrowing of DLTensor by another framework. It is\n not meant to transfer the tensor. When the borrowing framework doesn't need\n the tensor, it should call the deleter to notify the host that the resource\n is no longer needed."]
125#[repr(C)]
126#[derive(Debug, Copy, Clone)]
127pub struct DLManagedTensor {
128 #[doc = " \\brief DLTensor which is being memory managed"]
129 pub dl_tensor: DLTensor,
130 #[doc = " \\brief the context of the original host framework of DLManagedTensor in\n which DLManagedTensor is used in the framework. It can also be NULL."]
131 pub manager_ctx: *mut ::std::os::raw::c_void,
132 #[doc = " \\brief Destructor signature void (*)(void*) - this should be called\n to destruct manager_ctx which holds the DLManagedTensor. It can be NULL\n if there is no way for the caller to provide a reasonable destructor.\n The destructors deletes the argument self as well."]
133 pub deleter: ::std::option::Option<unsafe extern "C" fn(self_: *mut DLManagedTensor)>,
134}
135#[allow(clippy::unnecessary_operation, clippy::identity_op)]
136const _: () = {
137 ["Size of DLManagedTensor"][::std::mem::size_of::<DLManagedTensor>() - 64usize];
138 ["Alignment of DLManagedTensor"][::std::mem::align_of::<DLManagedTensor>() - 8usize];
139 ["Offset of field: DLManagedTensor::dl_tensor"]
140 [::std::mem::offset_of!(DLManagedTensor, dl_tensor) - 0usize];
141 ["Offset of field: DLManagedTensor::manager_ctx"]
142 [::std::mem::offset_of!(DLManagedTensor, manager_ctx) - 48usize];
143 ["Offset of field: DLManagedTensor::deleter"]
144 [::std::mem::offset_of!(DLManagedTensor, deleter) - 56usize];
145};
146#[repr(u32)]
147#[doc = " @defgroup error_c cuVS Error Messages\n @{\n/\n/**\n @brief An enum denoting error statuses for function calls\n"]
148#[must_use]
149#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
150pub enum cuvsError_t {
151 CUVS_ERROR = 0,
152 CUVS_SUCCESS = 1,
153}
154unsafe extern "C" {
155 #[doc = " @brief Returns a string describing the last seen error on this thread, or\n NULL if the last function succeeded."]
156 pub fn cuvsGetLastErrorText() -> *const ::std::os::raw::c_char;
157}
158unsafe extern "C" {
159 #[doc = " @brief Sets a string describing an error seen on the thread. Passing NULL\n clears any previously seen error message."]
160 pub fn cuvsSetLastErrorText(error: *const ::std::os::raw::c_char);
161}
162#[repr(u32)]
163#[doc = " @brief An enum denoting log levels\n"]
164#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
165pub enum cuvsLogLevel_t {
166 CUVS_LOG_LEVEL_TRACE = 0,
167 CUVS_LOG_LEVEL_DEBUG = 1,
168 CUVS_LOG_LEVEL_INFO = 2,
169 CUVS_LOG_LEVEL_WARN = 3,
170 CUVS_LOG_LEVEL_ERROR = 4,
171 CUVS_LOG_LEVEL_CRITICAL = 5,
172 CUVS_LOG_LEVEL_OFF = 6,
173}
174unsafe extern "C" {
175 #[doc = " @brief Returns the current log level"]
176 pub fn cuvsGetLogLevel() -> cuvsLogLevel_t;
177}
178unsafe extern "C" {
179 #[doc = " @brief Sets the log level"]
180 pub fn cuvsSetLogLevel(arg1: cuvsLogLevel_t);
181}
182#[doc = " @brief An opaque C handle for C++ type `raft::resources`\n"]
183pub type cuvsResources_t = usize;
184unsafe extern "C" {
185 #[must_use]
186 #[doc = " @brief Create an Initialized opaque C handle for C++ type `raft::resources`\n\n @param[in] res cuvsResources_t opaque C handle\n @return cuvsError_t"]
187 pub fn cuvsResourcesCreate(res: *mut cuvsResources_t) -> cuvsError_t;
188}
189unsafe extern "C" {
190 #[must_use]
191 #[doc = " @brief Destroy and de-allocate opaque C handle for C++ type `raft::resources`\n\n @param[in] res cuvsResources_t opaque C handle\n @return cuvsError_t"]
192 pub fn cuvsResourcesDestroy(res: cuvsResources_t) -> cuvsError_t;
193}
194unsafe extern "C" {
195 #[must_use]
196 #[doc = " @brief Set cudaStream_t on cuvsResources_t to queue CUDA kernels on APIs\n that accept a cuvsResources_t handle\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] stream cudaStream_t stream to queue CUDA kernels\n @return cuvsError_t"]
197 pub fn cuvsStreamSet(res: cuvsResources_t, stream: cudaStream_t) -> cuvsError_t;
198}
199unsafe extern "C" {
200 #[must_use]
201 #[doc = " @brief Get the cudaStream_t from a cuvsResources_t\n\n @param[in] res cuvsResources_t opaque C handle\n @param[out] stream cudaStream_t stream to queue CUDA kernels\n @return cuvsError_t"]
202 pub fn cuvsStreamGet(res: cuvsResources_t, stream: *mut cudaStream_t) -> cuvsError_t;
203}
204unsafe extern "C" {
205 #[must_use]
206 #[doc = " @brief Syncs the current CUDA stream on the resources object\n\n @param[in] res cuvsResources_t opaque C handle\n @return cuvsError_t"]
207 pub fn cuvsStreamSync(res: cuvsResources_t) -> cuvsError_t;
208}
209unsafe extern "C" {
210 #[must_use]
211 #[doc = " @brief Get the id of the device associated with this cuvsResources_t\n\n @param[in] res cuvsResources_t opaque C handle\n @param[out] device_id int the id of the device associated with res\n @return cuvsError_t"]
212 pub fn cuvsDeviceIdGet(
213 res: cuvsResources_t,
214 device_id: *mut ::std::os::raw::c_int,
215 ) -> cuvsError_t;
216}
217unsafe extern "C" {
218 #[must_use]
219 #[doc = " @brief Create an Initialized opaque C handle for C++ type `raft::device_resources_snmg`\n for multi-GPU operations\n\n @param[in] res cuvsResources_t opaque C handle\n @return cuvsError_t"]
220 pub fn cuvsMultiGpuResourcesCreate(res: *mut cuvsResources_t) -> cuvsError_t;
221}
222unsafe extern "C" {
223 #[must_use]
224 #[doc = " @brief Create an Initialized opaque C handle for C++ type `raft::device_resources_snmg`\n for multi-GPU operations with specific device IDs\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] device_ids DLManagedTensor* containing device IDs to use\n @return cuvsError_t"]
225 pub fn cuvsMultiGpuResourcesCreateWithDeviceIds(
226 res: *mut cuvsResources_t,
227 device_ids: *mut DLManagedTensor,
228 ) -> cuvsError_t;
229}
230unsafe extern "C" {
231 #[must_use]
232 #[doc = " @brief Destroy and de-allocate opaque C handle for C++ type `raft::device_resources_snmg`\n\n @param[in] res cuvsResources_t opaque C handle\n @return cuvsError_t"]
233 pub fn cuvsMultiGpuResourcesDestroy(res: cuvsResources_t) -> cuvsError_t;
234}
235unsafe extern "C" {
236 #[must_use]
237 #[doc = " @brief Set a memory pool on all devices managed by the multi-GPU resources\n\n @param[in] res cuvsResources_t opaque C handle for multi-GPU resources\n @param[in] percent_of_free_memory Percent of free memory to allocate for the pool\n @return cuvsError_t"]
238 pub fn cuvsMultiGpuResourcesSetMemoryPool(
239 res: cuvsResources_t,
240 percent_of_free_memory: ::std::os::raw::c_int,
241 ) -> cuvsError_t;
242}
243unsafe extern "C" {
244 #[must_use]
245 #[doc = " @brief Allocates device memory using RMM\n\n\n @param[in] res cuvsResources_t opaque C handle\n @param[out] ptr Pointer to allocated device memory\n @param[in] bytes Size in bytes to allocate\n @return cuvsError_t"]
246 pub fn cuvsRMMAlloc(
247 res: cuvsResources_t,
248 ptr: *mut *mut ::std::os::raw::c_void,
249 bytes: usize,
250 ) -> cuvsError_t;
251}
252unsafe extern "C" {
253 #[must_use]
254 #[doc = " @brief Deallocates device memory using RMM\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] ptr Pointer to allocated device memory to free\n @param[in] bytes Size in bytes to allocate\n @return cuvsError_t"]
255 pub fn cuvsRMMFree(
256 res: cuvsResources_t,
257 ptr: *mut ::std::os::raw::c_void,
258 bytes: usize,
259 ) -> cuvsError_t;
260}
261unsafe extern "C" {
262 #[must_use]
263 #[doc = " @brief Switches the working memory resource to use the RMM pool memory resource, which will\n bypass unnecessary synchronizations by allocating a chunk of device memory up front and carving\n that up for temporary memory allocations within algorithms. Be aware that this function will\n change the memory resource for the whole process and the new memory resource will be used until\n explicitly changed.\n\n @param[in] initial_pool_size_percent The initial pool size as a percentage of the total\n available memory\n @param[in] max_pool_size_percent The maximum pool size as a percentage of the total\n available memory\n @param[in] managed Whether to use a managed memory resource as upstream resource or not\n @return cuvsError_t"]
264 pub fn cuvsRMMPoolMemoryResourceEnable(
265 initial_pool_size_percent: ::std::os::raw::c_int,
266 max_pool_size_percent: ::std::os::raw::c_int,
267 managed: bool,
268 ) -> cuvsError_t;
269}
270unsafe extern "C" {
271 #[must_use]
272 #[doc = " @brief Resets the memory resource to use the default memory resource (cuda_memory_resource)\n @return cuvsError_t"]
273 pub fn cuvsRMMMemoryResourceReset() -> cuvsError_t;
274}
275unsafe extern "C" {
276 #[must_use]
277 #[doc = " @brief Allocates pinned memory on the host using RMM\n @param[out] ptr Pointer to allocated host memory\n @param[in] bytes Size in bytes to allocate\n @return cuvsError_t"]
278 pub fn cuvsRMMHostAlloc(ptr: *mut *mut ::std::os::raw::c_void, bytes: usize) -> cuvsError_t;
279}
280unsafe extern "C" {
281 #[must_use]
282 #[doc = " @brief Deallocates pinned memory on the host using RMM\n @param[in] ptr Pointer to allocated host memory to free\n @param[in] bytes Size in bytes to deallocate\n @return cuvsError_t"]
283 pub fn cuvsRMMHostFree(ptr: *mut ::std::os::raw::c_void, bytes: usize) -> cuvsError_t;
284}
285unsafe extern "C" {
286 #[must_use]
287 #[doc = " @brief Get the version of the cuVS library\n @param[out] major Major version\n @param[out] minor Minor version\n @param[out] patch Patch version\n @return cuvsError_t"]
288 pub fn cuvsVersionGet(major: *mut u16, minor: *mut u16, patch: *mut u16) -> cuvsError_t;
289}
290unsafe extern "C" {
291 #[must_use]
292 #[doc = " @brief Copy a matrix\n\n This function copies a matrix from dst to src. This lets you copy a matrix\n from device memory to host memory (or vice versa), while accounting for\n differences in strides.\n\n Both src and dst must have the same shape and dtype, but can have different\n strides and device type. The memory for the output dst tensor must already be\n allocated and the tensor initialized.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] src Pointer to DLManagedTensor to copy\n @param[out] dst Pointer to DLManagedTensor to receive copy of data"]
293 pub fn cuvsMatrixCopy(
294 res: cuvsResources_t,
295 src: *mut DLManagedTensor,
296 dst: *mut DLManagedTensor,
297 ) -> cuvsError_t;
298}
299unsafe extern "C" {
300 #[must_use]
301 #[doc = " @brief Slices rows from a matrix\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] src Pointer to DLManagedTensor to copy\n @param[in] start First row index to include in the output\n @param[in] end Last row index to include in the output\n @param[out] dst Pointer to DLManagedTensor to receive slice from matrix"]
302 pub fn cuvsMatrixSliceRows(
303 res: cuvsResources_t,
304 src: *mut DLManagedTensor,
305 start: i64,
306 end: i64,
307 dst: *mut DLManagedTensor,
308 ) -> cuvsError_t;
309}
310#[repr(u32)]
311#[doc = " enum to tell how to compute distance"]
312#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
313pub enum cuvsDistanceType {
314 #[doc = " evaluate as dist_ij = sum(x_ik^2) + sum(y_ij)^2 - 2*sum(x_ik * y_jk)"]
315 L2Expanded = 0,
316 #[doc = " same as above, but inside the epilogue, perform square root operation"]
317 L2SqrtExpanded = 1,
318 #[doc = " cosine distance"]
319 CosineExpanded = 2,
320 #[doc = " L1 distance"]
321 L1 = 3,
322 #[doc = " evaluate as dist_ij += (x_ik - y-jk)^2"]
323 L2Unexpanded = 4,
324 #[doc = " same as above, but inside the epilogue, perform square root operation"]
325 L2SqrtUnexpanded = 5,
326 #[doc = " basic inner product"]
327 InnerProduct = 6,
328 #[doc = " Chebyshev (Linf) distance"]
329 Linf = 7,
330 #[doc = " Canberra distance"]
331 Canberra = 8,
332 #[doc = " Generalized Minkowski distance"]
333 LpUnexpanded = 9,
334 #[doc = " Correlation distance"]
335 CorrelationExpanded = 10,
336 #[doc = " Jaccard distance"]
337 JaccardExpanded = 11,
338 #[doc = " Hellinger distance"]
339 HellingerExpanded = 12,
340 #[doc = " Haversine distance"]
341 Haversine = 13,
342 #[doc = " Bray-Curtis distance"]
343 BrayCurtis = 14,
344 #[doc = " Jensen-Shannon distance"]
345 JensenShannon = 15,
346 #[doc = " Hamming distance"]
347 HammingUnexpanded = 16,
348 #[doc = " KLDivergence"]
349 KLDivergence = 17,
350 #[doc = " RusselRao"]
351 RusselRaoExpanded = 18,
352 #[doc = " Dice-Sorensen distance"]
353 DiceExpanded = 19,
354 #[doc = " Bitstring Hamming distance"]
355 BitwiseHamming = 20,
356 #[doc = " Precomputed (special value)"]
357 Precomputed = 100,
358}
359#[repr(u32)]
360#[doc = " @defgroup kmeans_c_params k-means hyperparameters\n @{"]
361#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
362pub enum cuvsKMeansInitMethod {
363 #[doc = " Sample the centroids using the kmeans++ strategy"]
364 KMeansPlusPlus = 0,
365 #[doc = " Sample the centroids uniformly at random"]
366 Random = 1,
367 #[doc = " User provides the array of initial centroids"]
368 Array = 2,
369}
370#[doc = " @brief Hyper-parameters for the kmeans algorithm"]
371#[repr(C)]
372#[derive(Debug, Copy, Clone)]
373pub struct cuvsKMeansParams {
374 pub metric: cuvsDistanceType,
375 #[doc = " The number of clusters to form as well as the number of centroids to generate (default:8)."]
376 pub n_clusters: ::std::os::raw::c_int,
377 #[doc = " Method for initialization, defaults to k-means++:\n - cuvsKMeansInitMethod::KMeansPlusPlus (k-means++): Use scalable k-means++ algorithm\n to select the initial cluster centers.\n - cuvsKMeansInitMethod::Random (random): Choose 'n_clusters' observations (rows) at\n random from the input data for the initial centroids.\n - cuvsKMeansInitMethod::Array (ndarray): Use 'centroids' as initial cluster centers."]
378 pub init: cuvsKMeansInitMethod,
379 #[doc = " Maximum number of iterations of the k-means algorithm for a single run."]
380 pub max_iter: ::std::os::raw::c_int,
381 #[doc = " Relative tolerance with regards to inertia to declare convergence."]
382 pub tol: f64,
383 #[doc = " Number of instance k-means algorithm will be run with different seeds."]
384 pub n_init: ::std::os::raw::c_int,
385 #[doc = " Oversampling factor for use in the k-means|| algorithm"]
386 pub oversampling_factor: f64,
387 #[doc = " batch_samples and batch_centroids are used to tile 1NN computation which is\n useful to optimize/control the memory footprint\n Default tile is [batch_samples x n_clusters] i.e. when batch_centroids is 0\n then don't tile the centroids"]
388 pub batch_samples: ::std::os::raw::c_int,
389 #[doc = " if 0 then batch_centroids = n_clusters"]
390 pub batch_centroids: ::std::os::raw::c_int,
391 #[doc = " Check inertia during iterations for early convergence."]
392 pub inertia_check: bool,
393 #[doc = " Whether to use hierarchical (balanced) kmeans or not"]
394 pub hierarchical: bool,
395 #[doc = " For hierarchical k-means , defines the number of training iterations"]
396 pub hierarchical_n_iters: ::std::os::raw::c_int,
397 #[doc = " Number of samples to process per GPU batch for the batched (host-data) API.\n When set to 0, defaults to n_samples (process all at once)."]
398 pub streaming_batch_size: i64,
399}
400#[allow(clippy::unnecessary_operation, clippy::identity_op)]
401const _: () = {
402 ["Size of cuvsKMeansParams"][::std::mem::size_of::<cuvsKMeansParams>() - 64usize];
403 ["Alignment of cuvsKMeansParams"][::std::mem::align_of::<cuvsKMeansParams>() - 8usize];
404 ["Offset of field: cuvsKMeansParams::metric"]
405 [::std::mem::offset_of!(cuvsKMeansParams, metric) - 0usize];
406 ["Offset of field: cuvsKMeansParams::n_clusters"]
407 [::std::mem::offset_of!(cuvsKMeansParams, n_clusters) - 4usize];
408 ["Offset of field: cuvsKMeansParams::init"]
409 [::std::mem::offset_of!(cuvsKMeansParams, init) - 8usize];
410 ["Offset of field: cuvsKMeansParams::max_iter"]
411 [::std::mem::offset_of!(cuvsKMeansParams, max_iter) - 12usize];
412 ["Offset of field: cuvsKMeansParams::tol"]
413 [::std::mem::offset_of!(cuvsKMeansParams, tol) - 16usize];
414 ["Offset of field: cuvsKMeansParams::n_init"]
415 [::std::mem::offset_of!(cuvsKMeansParams, n_init) - 24usize];
416 ["Offset of field: cuvsKMeansParams::oversampling_factor"]
417 [::std::mem::offset_of!(cuvsKMeansParams, oversampling_factor) - 32usize];
418 ["Offset of field: cuvsKMeansParams::batch_samples"]
419 [::std::mem::offset_of!(cuvsKMeansParams, batch_samples) - 40usize];
420 ["Offset of field: cuvsKMeansParams::batch_centroids"]
421 [::std::mem::offset_of!(cuvsKMeansParams, batch_centroids) - 44usize];
422 ["Offset of field: cuvsKMeansParams::inertia_check"]
423 [::std::mem::offset_of!(cuvsKMeansParams, inertia_check) - 48usize];
424 ["Offset of field: cuvsKMeansParams::hierarchical"]
425 [::std::mem::offset_of!(cuvsKMeansParams, hierarchical) - 49usize];
426 ["Offset of field: cuvsKMeansParams::hierarchical_n_iters"]
427 [::std::mem::offset_of!(cuvsKMeansParams, hierarchical_n_iters) - 52usize];
428 ["Offset of field: cuvsKMeansParams::streaming_batch_size"]
429 [::std::mem::offset_of!(cuvsKMeansParams, streaming_batch_size) - 56usize];
430};
431pub type cuvsKMeansParams_t = *mut cuvsKMeansParams;
432unsafe extern "C" {
433 #[must_use]
434 #[doc = " @brief Allocate KMeans params, and populate with default values\n\n @param[in] params cuvsKMeansParams_t to allocate\n @return cuvsError_t"]
435 pub fn cuvsKMeansParamsCreate(params: *mut cuvsKMeansParams_t) -> cuvsError_t;
436}
437unsafe extern "C" {
438 #[must_use]
439 #[doc = " @brief De-allocate KMeans params\n\n @param[in] params\n @return cuvsError_t"]
440 pub fn cuvsKMeansParamsDestroy(params: cuvsKMeansParams_t) -> cuvsError_t;
441}
442#[repr(u32)]
443#[doc = " @brief Type of k-means algorithm."]
444#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
445pub enum cuvsKMeansType {
446 CUVS_KMEANS_TYPE_KMEANS = 0,
447 CUVS_KMEANS_TYPE_KMEANS_BALANCED = 1,
448}
449unsafe extern "C" {
450 #[must_use]
451 #[doc = " @brief Find clusters with k-means algorithm.\n\n Initial centroids are chosen with k-means++ algorithm. Empty\n clusters are reinitialized by choosing new centroids with\n k-means++ algorithm.\n\n X may reside on either host (CPU) or device (GPU) memory.\n When X is on the host the data is streamed to the GPU in\n batches controlled by params->streaming_batch_size.\n\n @param[in] res opaque C handle\n @param[in] params Parameters for KMeans model.\n @param[in] X Training instances to cluster. The data must\n be in row-major format. May be on host or\n device memory.\n [dim = n_samples x n_features]\n @param[in] sample_weight Optional weights for each observation in X.\n Must be on the same memory space as X.\n [len = n_samples]\n @param[inout] centroids [in] When init is InitMethod::Array, use\n centroids as the initial cluster centers.\n [out] The generated centroids from the\n kmeans algorithm are stored at the address\n pointed by 'centroids'. Must be on device.\n [dim = n_clusters x n_features]\n @param[out] inertia Sum of squared distances of samples to their\n closest cluster center.\n @param[out] n_iter Number of iterations run."]
452 pub fn cuvsKMeansFit(
453 res: cuvsResources_t,
454 params: cuvsKMeansParams_t,
455 X: *mut DLManagedTensor,
456 sample_weight: *mut DLManagedTensor,
457 centroids: *mut DLManagedTensor,
458 inertia: *mut f64,
459 n_iter: *mut ::std::os::raw::c_int,
460 ) -> cuvsError_t;
461}
462unsafe extern "C" {
463 #[must_use]
464 #[doc = " @brief Predict the closest cluster each sample in X belongs to.\n\n @param[in] res opaque C handle\n @param[in] params Parameters for KMeans model.\n @param[in] X New data to predict.\n [dim = n_samples x n_features]\n @param[in] sample_weight Optional weights for each observation in X.\n [len = n_samples]\n @param[in] centroids Cluster centroids. The data must be in\n row-major format.\n [dim = n_clusters x n_features]\n @param[in] normalize_weight True if the weights should be normalized\n @param[out] labels Index of the cluster each sample in X\n belongs to.\n [len = n_samples]\n @param[out] inertia Sum of squared distances of samples to\n their closest cluster center."]
465 pub fn cuvsKMeansPredict(
466 res: cuvsResources_t,
467 params: cuvsKMeansParams_t,
468 X: *mut DLManagedTensor,
469 sample_weight: *mut DLManagedTensor,
470 centroids: *mut DLManagedTensor,
471 labels: *mut DLManagedTensor,
472 normalize_weight: bool,
473 inertia: *mut f64,
474 ) -> cuvsError_t;
475}
476unsafe extern "C" {
477 #[must_use]
478 #[doc = " @brief Compute cluster cost\n\n @param[in] res opaque C handle\n @param[in] X Training instances to cluster. The data must\n be in row-major format.\n [dim = n_samples x n_features]\n @param[in] centroids Cluster centroids. The data must be in\n row-major format.\n [dim = n_clusters x n_features]\n @param[out] cost Resulting cluster cost\n"]
479 pub fn cuvsKMeansClusterCost(
480 res: cuvsResources_t,
481 X: *mut DLManagedTensor,
482 centroids: *mut DLManagedTensor,
483 cost: *mut f64,
484 ) -> cuvsError_t;
485}
486unsafe extern "C" {
487 #[must_use]
488 #[doc = " @brief Compute pairwise distances for two matrices\n\n\n Usage example:\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/distance/pairwise_distance.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor x;\n DLManagedTensor y;\n DLManagedTensor dist;\n\n cuvsPairwiseDistance(res, &x, &y, &dist, L2SqrtUnexpanded, 2.0);\n @endcode\n\n @param[in] res cuvs resources object for managing expensive resources\n @param[in] x first set of points (size n*k)\n @param[in] y second set of points (size m*k)\n @param[out] dist output distance matrix (size n*m)\n @param[in] metric distance to evaluate\n @param[in] metric_arg metric argument (used for Minkowski distance)"]
489 pub fn cuvsPairwiseDistance(
490 res: cuvsResources_t,
491 x: *mut DLManagedTensor,
492 y: *mut DLManagedTensor,
493 dist: *mut DLManagedTensor,
494 metric: cuvsDistanceType,
495 metric_arg: f32,
496 ) -> cuvsError_t;
497}
498#[repr(u32)]
499#[doc = " @defgroup ivf_pq_c_index_params IVF-PQ index build parameters\n @{\n/\n/**\n @brief A type for specifying how PQ codebooks are created\n"]
500#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
501pub enum cuvsIvfPqCodebookGen {
502 CUVS_IVF_PQ_CODEBOOK_GEN_PER_SUBSPACE = 0,
503 CUVS_IVF_PQ_CODEBOOK_GEN_PER_CLUSTER = 1,
504}
505#[repr(u32)]
506#[doc = " @brief A type for specifying the memory layout of IVF-PQ list data\n"]
507#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
508pub enum cuvsIvfPqListLayout {
509 CUVS_IVF_PQ_LIST_LAYOUT_FLAT = 0,
510 CUVS_IVF_PQ_LIST_LAYOUT_INTERLEAVED = 1,
511}
512#[doc = " @brief Supplemental parameters to build IVF-PQ Index\n"]
513#[repr(C)]
514#[derive(Debug, Copy, Clone)]
515pub struct cuvsIvfPqIndexParams {
516 #[doc = " Distance type."]
517 pub metric: cuvsDistanceType,
518 #[doc = " The argument used by some distance metrics."]
519 pub metric_arg: f32,
520 #[doc = " Whether to add the dataset content to the index, i.e.:\n\n - `true` means the index is filled with the dataset vectors and ready to search after calling\n `build`.\n - `false` means `build` only trains the underlying model (e.g. quantizer or clustering), but\n the index is left empty; you'd need to call `extend` on the index afterwards to populate it."]
521 pub add_data_on_build: bool,
522 #[doc = " The number of inverted lists (clusters)\n\n Hint: the number of vectors per cluster (`n_rows/n_lists`) should be approximately 1,000 to\n 10,000."]
523 pub n_lists: u32,
524 #[doc = " The number of iterations searching for kmeans centers (index building)."]
525 pub kmeans_n_iters: u32,
526 #[doc = " The fraction of data to use during iterative kmeans building."]
527 pub kmeans_trainset_fraction: f64,
528 #[doc = " The bit length of the vector element after compression by PQ.\n\n Possible values: [4, 5, 6, 7, 8].\n\n Hint: the smaller the 'pq_bits', the smaller the index size and the better the search\n performance, but the lower the recall."]
529 pub pq_bits: u32,
530 #[doc = " The dimensionality of the vector after compression by PQ. When zero, an optimal value is\n selected using a heuristic.\n\n NB: `pq_dim * pq_bits` must be a multiple of 8.\n\n Hint: a smaller 'pq_dim' results in a smaller index size and better search performance, but\n lower recall. If 'pq_bits' is 8, 'pq_dim' can be set to any number, but multiple of 8 are\n desirable for good performance. If 'pq_bits' is not 8, 'pq_dim' should be a multiple of 8.\n For good performance, it is desirable that 'pq_dim' is a multiple of 32. Ideally, 'pq_dim'\n should be also a divisor of the dataset dim."]
531 pub pq_dim: u32,
532 #[doc = " How PQ codebooks are created."]
533 pub codebook_kind: cuvsIvfPqCodebookGen,
534 #[doc = " Apply a random rotation matrix on the input data and queries even if `dim % pq_dim == 0`.\n\n Note: if `dim` is not multiple of `pq_dim`, a random rotation is always applied to the input\n data and queries to transform the working space from `dim` to `rot_dim`, which may be slightly\n larger than the original space and and is a multiple of `pq_dim` (`rot_dim % pq_dim == 0`).\n However, this transform is not necessary when `dim` is multiple of `pq_dim`\n (`dim == rot_dim`, hence no need in adding \"extra\" data columns / features).\n\n By default, if `dim == rot_dim`, the rotation transform is initialized with the identity\n matrix. When `force_random_rotation == true`, a random orthogonal transform matrix is generated\n regardless of the values of `dim` and `pq_dim`."]
535 pub force_random_rotation: bool,
536 #[doc = " By default, the algorithm allocates more space than necessary for individual clusters\n (`list_data`). This allows to amortize the cost of memory allocation and reduce the number of\n data copies during repeated calls to `extend` (extending the database).\n\n The alternative is the conservative allocation behavior; when enabled, the algorithm always\n allocates the minimum amount of memory required to store the given number of records. Set this\n flag to `true` if you prefer to use as little GPU memory for the database as possible."]
537 pub conservative_memory_allocation: bool,
538 #[doc = " The max number of data points to use per PQ code during PQ codebook training. Using more data\n points per PQ code may increase the quality of PQ codebook but may also increase the build\n time. The parameter is applied to both PQ codebook generation methods, i.e., PER_SUBSPACE and\n PER_CLUSTER. In both cases, we will use `pq_book_size * max_train_points_per_pq_code` training\n points to train each codebook."]
539 pub max_train_points_per_pq_code: u32,
540 #[doc = " Memory layout of the IVF-PQ list data.\n\n - CUVS_IVF_PQ_LIST_LAYOUT_FLAT: Codes are stored contiguously, one vector's codes after another.\n - CUVS_IVF_PQ_LIST_LAYOUT_INTERLEAVED: Codes are interleaved for optimized search performance.\n This is the default and recommended for search workloads."]
541 pub codes_layout: cuvsIvfPqListLayout,
542}
543#[allow(clippy::unnecessary_operation, clippy::identity_op)]
544const _: () = {
545 ["Size of cuvsIvfPqIndexParams"][::std::mem::size_of::<cuvsIvfPqIndexParams>() - 56usize];
546 ["Alignment of cuvsIvfPqIndexParams"][::std::mem::align_of::<cuvsIvfPqIndexParams>() - 8usize];
547 ["Offset of field: cuvsIvfPqIndexParams::metric"]
548 [::std::mem::offset_of!(cuvsIvfPqIndexParams, metric) - 0usize];
549 ["Offset of field: cuvsIvfPqIndexParams::metric_arg"]
550 [::std::mem::offset_of!(cuvsIvfPqIndexParams, metric_arg) - 4usize];
551 ["Offset of field: cuvsIvfPqIndexParams::add_data_on_build"]
552 [::std::mem::offset_of!(cuvsIvfPqIndexParams, add_data_on_build) - 8usize];
553 ["Offset of field: cuvsIvfPqIndexParams::n_lists"]
554 [::std::mem::offset_of!(cuvsIvfPqIndexParams, n_lists) - 12usize];
555 ["Offset of field: cuvsIvfPqIndexParams::kmeans_n_iters"]
556 [::std::mem::offset_of!(cuvsIvfPqIndexParams, kmeans_n_iters) - 16usize];
557 ["Offset of field: cuvsIvfPqIndexParams::kmeans_trainset_fraction"]
558 [::std::mem::offset_of!(cuvsIvfPqIndexParams, kmeans_trainset_fraction) - 24usize];
559 ["Offset of field: cuvsIvfPqIndexParams::pq_bits"]
560 [::std::mem::offset_of!(cuvsIvfPqIndexParams, pq_bits) - 32usize];
561 ["Offset of field: cuvsIvfPqIndexParams::pq_dim"]
562 [::std::mem::offset_of!(cuvsIvfPqIndexParams, pq_dim) - 36usize];
563 ["Offset of field: cuvsIvfPqIndexParams::codebook_kind"]
564 [::std::mem::offset_of!(cuvsIvfPqIndexParams, codebook_kind) - 40usize];
565 ["Offset of field: cuvsIvfPqIndexParams::force_random_rotation"]
566 [::std::mem::offset_of!(cuvsIvfPqIndexParams, force_random_rotation) - 44usize];
567 ["Offset of field: cuvsIvfPqIndexParams::conservative_memory_allocation"]
568 [::std::mem::offset_of!(cuvsIvfPqIndexParams, conservative_memory_allocation) - 45usize];
569 ["Offset of field: cuvsIvfPqIndexParams::max_train_points_per_pq_code"]
570 [::std::mem::offset_of!(cuvsIvfPqIndexParams, max_train_points_per_pq_code) - 48usize];
571 ["Offset of field: cuvsIvfPqIndexParams::codes_layout"]
572 [::std::mem::offset_of!(cuvsIvfPqIndexParams, codes_layout) - 52usize];
573};
574pub type cuvsIvfPqIndexParams_t = *mut cuvsIvfPqIndexParams;
575unsafe extern "C" {
576 #[must_use]
577 #[doc = " @brief Allocate IVF-PQ Index params, and populate with default values\n\n @param[in] index_params cuvsIvfPqIndexParams_t to allocate\n @return cuvsError_t"]
578 pub fn cuvsIvfPqIndexParamsCreate(index_params: *mut cuvsIvfPqIndexParams_t) -> cuvsError_t;
579}
580unsafe extern "C" {
581 #[must_use]
582 #[doc = " @brief De-allocate IVF-PQ Index params\n\n @param[in] index_params\n @return cuvsError_t"]
583 pub fn cuvsIvfPqIndexParamsDestroy(index_params: cuvsIvfPqIndexParams_t) -> cuvsError_t;
584}
585#[doc = " @defgroup ivf_pq_c_search_params IVF-PQ index search parameters\n @{\n/\n/**\n @brief Supplemental parameters to search IVF-PQ index\n"]
586#[repr(C)]
587pub struct cuvsIvfPqSearchParams {
588 #[doc = " The number of clusters to search."]
589 pub n_probes: u32,
590 #[doc = " Data type of look up table to be created dynamically at search time.\n\n Possible values: [CUDA_R_32F, CUDA_R_16F, CUDA_R_8U]\n\n The use of low-precision types reduces the amount of shared memory required at search time, so\n fast shared memory kernels can be used even for datasets with large dimansionality. Note that\n the recall is slightly degraded when low-precision type is selected."]
591 pub lut_dtype: cudaDataType_t,
592 #[doc = " Storage data type for distance/similarity computed at search time.\n\n Possible values: [CUDA_R_16F, CUDA_R_32F]\n\n If the performance limiter at search time is device memory access, selecting FP16 will improve\n performance slightly."]
593 pub internal_distance_dtype: cudaDataType_t,
594 #[doc = " The data type to use as the GEMM element type when searching the clusters to probe.\n\n Possible values: [CUDA_R_8I, CUDA_R_16F, CUDA_R_32F].\n\n - Legacy default: CUDA_R_32F (float)\n - Recommended for performance: CUDA_R_16F (half)\n - Experimental/low-precision: CUDA_R_8I (int8_t)\n (WARNING: int8_t variant degrades recall unless data is normalized and low-dimensional)"]
595 pub coarse_search_dtype: cudaDataType_t,
596 #[doc = " Set the internal batch size to improve GPU utilization at the cost of larger memory footprint."]
597 pub max_internal_batch_size: u32,
598 #[doc = " Preferred fraction of SM's unified memory / L1 cache to be used as shared memory.\n\n Possible values: [0.0 - 1.0] as a fraction of the `sharedMemPerMultiprocessor`.\n\n One wants to increase the carveout to make sure a good GPU occupancy for the main search\n kernel, but not to keep it too high to leave some memory to be used as L1 cache. Note, this\n value is interpreted only as a hint. Moreover, a GPU usually allows only a fixed set of cache\n configurations, so the provided value is rounded up to the nearest configuration. Refer to the\n NVIDIA tuning guide for the target GPU architecture.\n\n Note, this is a low-level tuning parameter that can have drastic negative effects on the search\n performance if tweaked incorrectly."]
599 pub preferred_shmem_carveout: f64,
600}
601#[allow(clippy::unnecessary_operation, clippy::identity_op)]
602const _: () = {
603 ["Size of cuvsIvfPqSearchParams"][::std::mem::size_of::<cuvsIvfPqSearchParams>() - 32usize];
604 ["Alignment of cuvsIvfPqSearchParams"]
605 [::std::mem::align_of::<cuvsIvfPqSearchParams>() - 8usize];
606 ["Offset of field: cuvsIvfPqSearchParams::n_probes"]
607 [::std::mem::offset_of!(cuvsIvfPqSearchParams, n_probes) - 0usize];
608 ["Offset of field: cuvsIvfPqSearchParams::lut_dtype"]
609 [::std::mem::offset_of!(cuvsIvfPqSearchParams, lut_dtype) - 4usize];
610 ["Offset of field: cuvsIvfPqSearchParams::internal_distance_dtype"]
611 [::std::mem::offset_of!(cuvsIvfPqSearchParams, internal_distance_dtype) - 8usize];
612 ["Offset of field: cuvsIvfPqSearchParams::coarse_search_dtype"]
613 [::std::mem::offset_of!(cuvsIvfPqSearchParams, coarse_search_dtype) - 12usize];
614 ["Offset of field: cuvsIvfPqSearchParams::max_internal_batch_size"]
615 [::std::mem::offset_of!(cuvsIvfPqSearchParams, max_internal_batch_size) - 16usize];
616 ["Offset of field: cuvsIvfPqSearchParams::preferred_shmem_carveout"]
617 [::std::mem::offset_of!(cuvsIvfPqSearchParams, preferred_shmem_carveout) - 24usize];
618};
619pub type cuvsIvfPqSearchParams_t = *mut cuvsIvfPqSearchParams;
620unsafe extern "C" {
621 #[must_use]
622 #[doc = " @brief Allocate IVF-PQ search params, and populate with default values\n\n @param[in] params cuvsIvfPqSearchParams_t to allocate\n @return cuvsError_t"]
623 pub fn cuvsIvfPqSearchParamsCreate(params: *mut cuvsIvfPqSearchParams_t) -> cuvsError_t;
624}
625unsafe extern "C" {
626 #[must_use]
627 #[doc = " @brief De-allocate IVF-PQ search params\n\n @param[in] params\n @return cuvsError_t"]
628 pub fn cuvsIvfPqSearchParamsDestroy(params: cuvsIvfPqSearchParams_t) -> cuvsError_t;
629}
630#[doc = " @defgroup ivf_pq_c_index IVF-PQ index\n @{\n/\n/**\n @brief Struct to hold address of cuvs::neighbors::ivf_pq::index and its active trained dtype\n"]
631#[repr(C)]
632#[derive(Debug, Copy, Clone)]
633pub struct cuvsIvfPqIndex {
634 pub addr: usize,
635 pub dtype: DLDataType,
636}
637#[allow(clippy::unnecessary_operation, clippy::identity_op)]
638const _: () = {
639 ["Size of cuvsIvfPqIndex"][::std::mem::size_of::<cuvsIvfPqIndex>() - 16usize];
640 ["Alignment of cuvsIvfPqIndex"][::std::mem::align_of::<cuvsIvfPqIndex>() - 8usize];
641 ["Offset of field: cuvsIvfPqIndex::addr"]
642 [::std::mem::offset_of!(cuvsIvfPqIndex, addr) - 0usize];
643 ["Offset of field: cuvsIvfPqIndex::dtype"]
644 [::std::mem::offset_of!(cuvsIvfPqIndex, dtype) - 8usize];
645};
646pub type cuvsIvfPqIndex_t = *mut cuvsIvfPqIndex;
647unsafe extern "C" {
648 #[must_use]
649 #[doc = " @brief Allocate IVF-PQ index\n\n @param[in] index cuvsIvfPqIndex_t to allocate\n @return cuvsError_t"]
650 pub fn cuvsIvfPqIndexCreate(index: *mut cuvsIvfPqIndex_t) -> cuvsError_t;
651}
652unsafe extern "C" {
653 #[must_use]
654 #[doc = " @brief De-allocate IVF-PQ index\n\n @param[in] index cuvsIvfPqIndex_t to de-allocate"]
655 pub fn cuvsIvfPqIndexDestroy(index: cuvsIvfPqIndex_t) -> cuvsError_t;
656}
657unsafe extern "C" {
658 #[must_use]
659 #[doc = " Get the number of clusters/inverted lists"]
660 pub fn cuvsIvfPqIndexGetNLists(index: cuvsIvfPqIndex_t, n_lists: *mut i64) -> cuvsError_t;
661}
662unsafe extern "C" {
663 #[must_use]
664 #[doc = " Get the dimensionality"]
665 pub fn cuvsIvfPqIndexGetDim(index: cuvsIvfPqIndex_t, dim: *mut i64) -> cuvsError_t;
666}
667unsafe extern "C" {
668 #[must_use]
669 #[doc = " Get the size of the index"]
670 pub fn cuvsIvfPqIndexGetSize(index: cuvsIvfPqIndex_t, size: *mut i64) -> cuvsError_t;
671}
672unsafe extern "C" {
673 #[must_use]
674 #[doc = " Get the dimensionality of an encoded vector after compression by PQ."]
675 pub fn cuvsIvfPqIndexGetPqDim(index: cuvsIvfPqIndex_t, pq_dim: *mut i64) -> cuvsError_t;
676}
677unsafe extern "C" {
678 #[must_use]
679 #[doc = " Get the bit length of an encoded vector element after compression by PQ."]
680 pub fn cuvsIvfPqIndexGetPqBits(index: cuvsIvfPqIndex_t, pq_bits: *mut i64) -> cuvsError_t;
681}
682unsafe extern "C" {
683 #[must_use]
684 #[doc = " Get the Dimensionality of a subspace, i.e. the number of vector\n components mapped to a subspace"]
685 pub fn cuvsIvfPqIndexGetPqLen(index: cuvsIvfPqIndex_t, pq_len: *mut i64) -> cuvsError_t;
686}
687unsafe extern "C" {
688 #[must_use]
689 #[doc = " @brief Get the cluster centers corresponding to the lists in the original space\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] centers Output tensor that will be populated with a non-owning view of the data\n @return cuvsError_t"]
690 pub fn cuvsIvfPqIndexGetCenters(
691 index: cuvsIvfPqIndex_t,
692 centers: *mut DLManagedTensor,
693 ) -> cuvsError_t;
694}
695unsafe extern "C" {
696 #[must_use]
697 #[doc = " @brief Get the padded cluster centers [n_lists, dim_ext]\n where dim_ext = round_up(dim + 1, 8)\n\n This returns the full padded centers as a contiguous array, suitable for\n use with cuvsIvfPqBuildPrecomputed.\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] centers Output tensor that will be populated with a non-owning view of the data\n @return cuvsError_t"]
698 pub fn cuvsIvfPqIndexGetCentersPadded(
699 index: cuvsIvfPqIndex_t,
700 centers: *mut DLManagedTensor,
701 ) -> cuvsError_t;
702}
703unsafe extern "C" {
704 #[must_use]
705 #[doc = " @brief Get the PQ cluster centers\n\n - CUVS_IVF_PQ_CODEBOOK_GEN_PER_SUBSPACE: [pq_dim , pq_len, pq_book_size]\n - CUVS_IVF_PQ_CODEBOOK_GEN_PER_CLUSTER: [n_lists, pq_len, pq_book_size]\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] pq_centers Output tensor that will be populated with a non-owning view of the data\n @return cuvsError_t"]
706 pub fn cuvsIvfPqIndexGetPqCenters(
707 index: cuvsIvfPqIndex_t,
708 pq_centers: *mut DLManagedTensor,
709 ) -> cuvsError_t;
710}
711unsafe extern "C" {
712 #[must_use]
713 #[doc = " @brief Get the rotated cluster centers [n_lists, rot_dim]\n where rot_dim = pq_len * pq_dim\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] centers_rot Output tensor that will be populated with a non-owning view of the data\n @return cuvsError_t"]
714 pub fn cuvsIvfPqIndexGetCentersRot(
715 index: cuvsIvfPqIndex_t,
716 centers_rot: *mut DLManagedTensor,
717 ) -> cuvsError_t;
718}
719unsafe extern "C" {
720 #[must_use]
721 #[doc = " @brief Get the rotation matrix [rot_dim, dim]\n Transform matrix (original space -> rotated padded space)\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] rotation_matrix Output tensor that will be populated with a non-owning view of the\n data\n @return cuvsError_t"]
722 pub fn cuvsIvfPqIndexGetRotationMatrix(
723 index: cuvsIvfPqIndex_t,
724 rotation_matrix: *mut DLManagedTensor,
725 ) -> cuvsError_t;
726}
727unsafe extern "C" {
728 #[must_use]
729 #[doc = " @brief Get the sizes of each list\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] list_sizes Output tensor that will be populated with a non-owning view of the data\n @return cuvsError_t"]
730 pub fn cuvsIvfPqIndexGetListSizes(
731 index: cuvsIvfPqIndex_t,
732 list_sizes: *mut DLManagedTensor,
733 ) -> cuvsError_t;
734}
735unsafe extern "C" {
736 #[must_use]
737 #[doc = " @brief Unpack `n_rows` consecutive PQ encoded vectors of a single list (cluster) in the\n compressed index starting at given `offset`, not expanded to one code per byte. Each code in the\n output buffer occupies ceildiv(index.pq_dim() * index.pq_bits(), 8) bytes.\n\n @param[in] res raft resource\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[out] out_codes\n the destination buffer [n_rows, ceildiv(index.pq_dim() * index.pq_bits(), 8)].\n The length `n_rows` defines how many records to unpack,\n offset + n_rows must be smaller than or equal to the list size.\n This DLManagedTensor must already point to allocated device memory\n @param[in] label\n The id of the list (cluster) to decode.\n @param[in] offset\n How many records in the list to skip."]
738 pub fn cuvsIvfPqIndexUnpackContiguousListData(
739 res: cuvsResources_t,
740 index: cuvsIvfPqIndex_t,
741 out_codes: *mut DLManagedTensor,
742 label: u32,
743 offset: u32,
744 ) -> cuvsError_t;
745}
746unsafe extern "C" {
747 #[must_use]
748 #[doc = " @brief Get the indices of each vector in a ivf-pq list\n\n @param[in] index cuvsIvfPqIndex_t Built Ivf-Pq index\n @param[in] label\n The id of the list (cluster) to decode.\n @param[out] out_labels\n output tensor that will be populated with a non-owning view of the data\n @return cuvsError_t"]
749 pub fn cuvsIvfPqIndexGetListIndices(
750 index: cuvsIvfPqIndex_t,
751 label: u32,
752 out_labels: *mut DLManagedTensor,
753 ) -> cuvsError_t;
754}
755unsafe extern "C" {
756 #[must_use]
757 #[doc = " @defgroup ivf_pq_c_index_build IVF-PQ index build\n @{\n/\n/**\n @brief Build a IVF-PQ index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n 3. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n 4. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/ivf_pq.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create default index params\n cuvsIvfPqIndexParams_t index_params;\n cuvsError_t params_create_status = cuvsIvfPqIndexParamsCreate(&index_params);\n\n // Create IVF-PQ index\n cuvsIvfPqIndex_t index;\n cuvsError_t index_create_status = cuvsIvfPqIndexCreate(&index);\n\n // Build the IVF-PQ Index\n cuvsError_t build_status = cuvsIvfPqBuild(res, index_params, &dataset, index);\n\n // de-allocate `index_params`, `index` and `res`\n cuvsError_t params_destroy_status = cuvsIvfPqIndexParamsDestroy(index_params);\n cuvsError_t index_destroy_status = cuvsIvfPqIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsIvfPqIndexParams_t used to build IVF-PQ index\n @param[in] dataset DLManagedTensor* training dataset\n @param[out] index cuvsIvfPqIndex_t Newly built IVF-PQ index\n @return cuvsError_t"]
758 pub fn cuvsIvfPqBuild(
759 res: cuvsResources_t,
760 params: cuvsIvfPqIndexParams_t,
761 dataset: *mut DLManagedTensor,
762 index: cuvsIvfPqIndex_t,
763 ) -> cuvsError_t;
764}
765unsafe extern "C" {
766 #[must_use]
767 #[doc = " @brief Build a view-type IVF-PQ index from device memory precomputed centroids and codebook.\n\n This function creates a non-owning index that stores a reference to the provided device data.\n All parameters must be provided with correct extents. The caller is responsible for ensuring\n the lifetime of the input data exceeds the lifetime of the returned index.\n\n The index_params must be consistent with the provided matrices. Specifically:\n - index_params.codebook_kind determines the expected shape of pq_centers\n - index_params.metric will be stored in the index\n - index_params.conservative_memory_allocation will be stored in the index\n The function will verify consistency between index_params, dim, and the matrix extents.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsIvfPqIndexParams_t used to configure the index (must be consistent with\n matrices)\n @param[in] dim dimensionality of the input data\n @param[in] pq_centers PQ codebook on device memory with required shape:\n - codebook_kind CUVS_IVF_PQ_CODEBOOK_GEN_PER_SUBSPACE: [pq_dim, pq_len, pq_book_size]\n - codebook_kind CUVS_IVF_PQ_CODEBOOK_GEN_PER_CLUSTER: [n_lists, pq_len, pq_book_size]\n @param[in] centers Cluster centers in the original space [n_lists, dim_ext]\n where dim_ext = round_up(dim + 1, 8)\n @param[in] centers_rot Rotated cluster centers [n_lists, rot_dim]\n where rot_dim = pq_len * pq_dim\n @param[in] rotation_matrix Transform matrix (original space -> rotated padded space) [rot_dim,\n dim]\n @param[out] index cuvsIvfPqIndex_t Newly built view-type IVF-PQ index\n @return cuvsError_t"]
768 pub fn cuvsIvfPqBuildPrecomputed(
769 res: cuvsResources_t,
770 params: cuvsIvfPqIndexParams_t,
771 dim: u32,
772 pq_centers: *mut DLManagedTensor,
773 centers: *mut DLManagedTensor,
774 centers_rot: *mut DLManagedTensor,
775 rotation_matrix: *mut DLManagedTensor,
776 index: cuvsIvfPqIndex_t,
777 ) -> cuvsError_t;
778}
779unsafe extern "C" {
780 #[must_use]
781 #[doc = " @defgroup ivf_pq_c_index_search IVF-PQ index search\n @{\n/\n/**\n @brief Search a IVF-PQ index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`.\n It is also important to note that the IVF-PQ Index must have been built\n with the same type of `queries`, such that `index.dtype.code ==\n queries.dl_tensor.dtype.code` Types for input are:\n 1. `queries`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n or `kDLDataType.bits = 16`\n 2. `neighbors`: `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 32`\n 3. `distances`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/ivf_pq.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n\n // Create default search params\n cuvsIvfPqSearchParams_t search_params;\n cuvsError_t params_create_status = cuvsIvfPqSearchParamsCreate(&search_params);\n\n // Search the `index` built using `cuvsIvfPqBuild`\n cuvsError_t search_status = cuvsIvfPqSearch(res, search_params, index, &queries, &neighbors,\n &distances);\n\n // de-allocate `search_params` and `res`\n cuvsError_t params_destroy_status = cuvsIvfPqSearchParamsDestroy(search_params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] search_params cuvsIvfPqSearchParams_t used to search IVF-PQ index\n @param[in] index cuvsIvfPqIndex which has been returned by `cuvsIvfPqBuild`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries"]
782 pub fn cuvsIvfPqSearch(
783 res: cuvsResources_t,
784 search_params: cuvsIvfPqSearchParams_t,
785 index: cuvsIvfPqIndex_t,
786 queries: *mut DLManagedTensor,
787 neighbors: *mut DLManagedTensor,
788 distances: *mut DLManagedTensor,
789 ) -> cuvsError_t;
790}
791unsafe extern "C" {
792 #[must_use]
793 #[doc = " @defgroup ivf_pq_c_index_serialize IVF-PQ C-API serialize functions\n @{\n/\n/**\n Save the index to file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @code{.cpp}\n #include <cuvs/neighbors/ivf_pq.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsIvfPqBuild`\n cuvsIvfPqSerialize(res, \"/path/to/index\", index, true);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file name for saving the index\n @param[in] index IVF-PQ index"]
794 pub fn cuvsIvfPqSerialize(
795 res: cuvsResources_t,
796 filename: *const ::std::os::raw::c_char,
797 index: cuvsIvfPqIndex_t,
798 ) -> cuvsError_t;
799}
800unsafe extern "C" {
801 #[must_use]
802 #[doc = " Load index from file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the name of the file that stores the index\n @param[out] index IVF-PQ index loaded disk"]
803 pub fn cuvsIvfPqDeserialize(
804 res: cuvsResources_t,
805 filename: *const ::std::os::raw::c_char,
806 index: cuvsIvfPqIndex_t,
807 ) -> cuvsError_t;
808}
809unsafe extern "C" {
810 #[must_use]
811 #[doc = " @defgroup ivf_pq_c_index_extend IVF-PQ index extend\n @{\n/\n/**\n @brief Extend the index with the new data.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] new_vectors DLManagedTensor* the new vectors to add to the index\n @param[in] new_indices DLManagedTensor* vector of new indices for the new vectors\n @param[inout] index IVF-PQ index to be extended\n @return cuvsError_t"]
812 pub fn cuvsIvfPqExtend(
813 res: cuvsResources_t,
814 new_vectors: *mut DLManagedTensor,
815 new_indices: *mut DLManagedTensor,
816 index: cuvsIvfPqIndex_t,
817 ) -> cuvsError_t;
818}
819unsafe extern "C" {
820 #[must_use]
821 #[doc = " @defgroup ivf_pq_c_index_transform IVF-PQ index transform\n @{\n/\n/**\n @brief Transform the input data by applying pq-encoding\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index IVF-PQ index\n @param[in] input_dataset DLManagedTensor* vectors to transform\n @param[out] output_labels DLManagedTensor* Vector of cluster labels for each vector in the input\n @param[out] output_dataset DLManagedTensor* input vectors after pq-encoding\n @return cuvsError_t"]
822 pub fn cuvsIvfPqTransform(
823 res: cuvsResources_t,
824 index: cuvsIvfPqIndex_t,
825 input_dataset: *mut DLManagedTensor,
826 output_labels: *mut DLManagedTensor,
827 output_dataset: *mut DLManagedTensor,
828 ) -> cuvsError_t;
829}
830#[repr(u32)]
831#[doc = " @brief Dtype to use for distance computation\n - `NND_DIST_COMP_AUTO`: Automatically determine the best dtype for distance computation based on the dataset dimensions.\n - `NND_DIST_COMP_FP32`: Use fp32 distance computation for better precision at the cost of performance and memory usage.\n - `NND_DIST_COMP_FP16`: Use fp16 distance computation."]
832#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
833pub enum cuvsNNDescentDistCompDtype {
834 NND_DIST_COMP_AUTO = 0,
835 NND_DIST_COMP_FP32 = 1,
836 NND_DIST_COMP_FP16 = 2,
837}
838#[doc = " @defgroup nn_descent_c_index_params The nn-descent algorithm parameters.\n @{\n/\n/**\n @brief Parameters used to build an nn-descent index\n\n `metric`: The distance metric to use\n `metric_arg`: The argument used by distance metrics like Minkowskidistance\n `graph_degree`: For an input dataset of dimensions (N, D),\n determines the final dimensions of the all-neighbors knn graph\n which turns out to be of dimensions (N, graph_degree)\n `intermediate_graph_degree`: Internally, nn-descent builds an\n all-neighbors knn graph of dimensions (N, intermediate_graph_degree)\n before selecting the final `graph_degree` neighbors. It's recommended\n that `intermediate_graph_degree` >= 1.5 * graph_degree\n `max_iterations`: The number of iterations that nn-descent will refine\n the graph for. More iterations produce a better quality graph at cost of performance\n `termination_threshold`: The delta at which nn-descent will terminate its iterations\n `return_distances`: Boolean to decide whether to return distances array\n `dist_comp_dtype`: dtype to use for distance computation. Defaults to `NND_DIST_COMP_AUTO` which automatically determines the best dtype for distance computation based on the dataset dimensions. Use `NND_DIST_COMP_FP32` for better precision at the cost of performance and memory usage. This option is only valid when data type is fp32. Use `NND_DIST_COMP_FP16` for better performance and memory usage at the cost of precision."]
839#[repr(C)]
840#[derive(Debug, Copy, Clone)]
841pub struct cuvsNNDescentIndexParams {
842 pub metric: cuvsDistanceType,
843 pub metric_arg: f32,
844 pub graph_degree: usize,
845 pub intermediate_graph_degree: usize,
846 pub max_iterations: usize,
847 pub termination_threshold: f32,
848 pub return_distances: bool,
849 pub dist_comp_dtype: cuvsNNDescentDistCompDtype,
850}
851#[allow(clippy::unnecessary_operation, clippy::identity_op)]
852const _: () = {
853 ["Size of cuvsNNDescentIndexParams"]
854 [::std::mem::size_of::<cuvsNNDescentIndexParams>() - 48usize];
855 ["Alignment of cuvsNNDescentIndexParams"]
856 [::std::mem::align_of::<cuvsNNDescentIndexParams>() - 8usize];
857 ["Offset of field: cuvsNNDescentIndexParams::metric"]
858 [::std::mem::offset_of!(cuvsNNDescentIndexParams, metric) - 0usize];
859 ["Offset of field: cuvsNNDescentIndexParams::metric_arg"]
860 [::std::mem::offset_of!(cuvsNNDescentIndexParams, metric_arg) - 4usize];
861 ["Offset of field: cuvsNNDescentIndexParams::graph_degree"]
862 [::std::mem::offset_of!(cuvsNNDescentIndexParams, graph_degree) - 8usize];
863 ["Offset of field: cuvsNNDescentIndexParams::intermediate_graph_degree"]
864 [::std::mem::offset_of!(cuvsNNDescentIndexParams, intermediate_graph_degree) - 16usize];
865 ["Offset of field: cuvsNNDescentIndexParams::max_iterations"]
866 [::std::mem::offset_of!(cuvsNNDescentIndexParams, max_iterations) - 24usize];
867 ["Offset of field: cuvsNNDescentIndexParams::termination_threshold"]
868 [::std::mem::offset_of!(cuvsNNDescentIndexParams, termination_threshold) - 32usize];
869 ["Offset of field: cuvsNNDescentIndexParams::return_distances"]
870 [::std::mem::offset_of!(cuvsNNDescentIndexParams, return_distances) - 36usize];
871 ["Offset of field: cuvsNNDescentIndexParams::dist_comp_dtype"]
872 [::std::mem::offset_of!(cuvsNNDescentIndexParams, dist_comp_dtype) - 40usize];
873};
874pub type cuvsNNDescentIndexParams_t = *mut cuvsNNDescentIndexParams;
875unsafe extern "C" {
876 #[must_use]
877 #[doc = " @brief Allocate NN-Descent Index params, and populate with default values\n\n @param[in] index_params cuvsNNDescentIndexParams_t to allocate\n @return cuvsError_t"]
878 pub fn cuvsNNDescentIndexParamsCreate(
879 index_params: *mut cuvsNNDescentIndexParams_t,
880 ) -> cuvsError_t;
881}
882unsafe extern "C" {
883 #[must_use]
884 #[doc = " @brief De-allocate NN-Descent Index params\n\n @param[in] index_params\n @return cuvsError_t"]
885 pub fn cuvsNNDescentIndexParamsDestroy(index_params: cuvsNNDescentIndexParams_t)
886 -> cuvsError_t;
887}
888#[doc = " @defgroup nn_descent_c_index NN-Descent index\n @{\n/\n/**\n @brief Struct to hold address of cuvs::neighbors::nn_descent::index and its active trained dtype\n"]
889#[repr(C)]
890#[derive(Debug, Copy, Clone)]
891pub struct cuvsNNDescentIndex {
892 pub addr: usize,
893 pub dtype: DLDataType,
894}
895#[allow(clippy::unnecessary_operation, clippy::identity_op)]
896const _: () = {
897 ["Size of cuvsNNDescentIndex"][::std::mem::size_of::<cuvsNNDescentIndex>() - 16usize];
898 ["Alignment of cuvsNNDescentIndex"][::std::mem::align_of::<cuvsNNDescentIndex>() - 8usize];
899 ["Offset of field: cuvsNNDescentIndex::addr"]
900 [::std::mem::offset_of!(cuvsNNDescentIndex, addr) - 0usize];
901 ["Offset of field: cuvsNNDescentIndex::dtype"]
902 [::std::mem::offset_of!(cuvsNNDescentIndex, dtype) - 8usize];
903};
904pub type cuvsNNDescentIndex_t = *mut cuvsNNDescentIndex;
905unsafe extern "C" {
906 #[must_use]
907 #[doc = " @brief Allocate NN-Descent index\n\n @param[in] index cuvsNNDescentIndex_t to allocate\n @return cuvsError_t"]
908 pub fn cuvsNNDescentIndexCreate(index: *mut cuvsNNDescentIndex_t) -> cuvsError_t;
909}
910unsafe extern "C" {
911 #[must_use]
912 #[doc = " @brief De-allocate NN-Descent index\n\n @param[in] index cuvsNNDescentIndex_t to de-allocate"]
913 pub fn cuvsNNDescentIndexDestroy(index: cuvsNNDescentIndex_t) -> cuvsError_t;
914}
915unsafe extern "C" {
916 #[must_use]
917 #[doc = " @defgroup nn_descent_c_index_build NN-Descent index build\n @{\n/\n/**\n @brief Build a NN-Descent index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n 3. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n 4. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/nn_descent.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create default index params\n cuvsNNDescentIndexParams_t index_params;\n cuvsError_t params_create_status = cuvsNNDescentIndexParamsCreate(&index_params);\n\n // Create NN-Descent index\n cuvsNNDescentIndex_t index;\n cuvsError_t index_create_status = cuvsNNDescentIndexCreate(&index);\n\n // Build the NN-Descent Index\n cuvsError_t build_status = cuvsNNDescentBuild(res, index_params, &dataset, index);\n\n // de-allocate `index_params`, `index` and `res`\n cuvsError_t params_destroy_status = cuvsNNDescentIndexParamsDestroy(index_params);\n cuvsError_t index_destroy_status = cuvsNNDescentIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index_params cuvsNNDescentIndexParams_t used to build NN-Descent index\n @param[in] dataset DLManagedTensor* training dataset on host or device memory\n @param[inout] graph Optional preallocated graph on host memory to store output\n @param[out] index cuvsNNDescentIndex_t Newly built NN-Descent index\n @return cuvsError_t"]
918 pub fn cuvsNNDescentBuild(
919 res: cuvsResources_t,
920 index_params: cuvsNNDescentIndexParams_t,
921 dataset: *mut DLManagedTensor,
922 graph: *mut DLManagedTensor,
923 index: cuvsNNDescentIndex_t,
924 ) -> cuvsError_t;
925}
926unsafe extern "C" {
927 #[must_use]
928 #[doc = " @brief Get the KNN graph from a built NN-Descent index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index cuvsNNDescentIndex_t Built NN-Descent index\n @param[out] graph Preallocated graph on host memory to store output\n @return cuvsError_t"]
929 pub fn cuvsNNDescentIndexGetGraph(
930 res: cuvsResources_t,
931 index: cuvsNNDescentIndex_t,
932 graph: *mut DLManagedTensor,
933 ) -> cuvsError_t;
934}
935unsafe extern "C" {
936 #[must_use]
937 #[doc = " @brief Get the distances from a build NN_Descent index\n\n This requires that the `return_distances` parameter was set when building the\n graph\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index cuvsNNDescentIndex_t Built NN-Descent index\n @param[out] distances Preallocated memory to store the output distances tensor\n @return cuvsError_t"]
938 pub fn cuvsNNDescentIndexGetDistances(
939 res: cuvsResources_t,
940 index: cuvsNNDescentIndex_t,
941 distances: *mut DLManagedTensor,
942 ) -> cuvsError_t;
943}
944#[repr(u32)]
945#[doc = " @brief Graph build algorithm selection."]
946#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
947pub enum cuvsAllNeighborsAlgo {
948 #[doc = "< Use Brute Force for local kNN subgraphs"]
949 CUVS_ALL_NEIGHBORS_ALGO_BRUTE_FORCE = 0,
950 #[doc = "< Use IVF-PQ for local kNN subgraphs (host dataset only)"]
951 CUVS_ALL_NEIGHBORS_ALGO_IVF_PQ = 1,
952 #[doc = "< Use NN-Descent for local kNN subgraphs"]
953 CUVS_ALL_NEIGHBORS_ALGO_NN_DESCENT = 2,
954}
955#[doc = " @brief Parameters controlling SNMG all-neighbors build."]
956#[repr(C)]
957#[derive(Debug, Copy, Clone)]
958pub struct cuvsAllNeighborsIndexParams {
959 #[doc = "< Local kNN graph build algorithm"]
960 pub algo: cuvsAllNeighborsAlgo,
961 #[doc = "< Number of clusters each point is assigned to (must be < n_clusters)"]
962 pub overlap_factor: usize,
963 #[doc = "< Number of clusters/batches to partition the dataset into (> overlap_factor)"]
964 pub n_clusters: usize,
965 #[doc = "< Distance metric used for graph construction"]
966 pub metric: cuvsDistanceType,
967 #[doc = "< Parameters for IVF-PQ algorithm (when algo ==\n< CUVS_ALL_NEIGHBORS_ALGO_IVF_PQ)"]
968 pub ivf_pq_params: cuvsIvfPqIndexParams_t,
969 #[doc = "< Parameters for NN-Descent algorithm (when algo\n< == CUVS_ALL_NEIGHBORS_ALGO_NN_DESCENT)"]
970 pub nn_descent_params: cuvsNNDescentIndexParams_t,
971}
972#[allow(clippy::unnecessary_operation, clippy::identity_op)]
973const _: () = {
974 ["Size of cuvsAllNeighborsIndexParams"]
975 [::std::mem::size_of::<cuvsAllNeighborsIndexParams>() - 48usize];
976 ["Alignment of cuvsAllNeighborsIndexParams"]
977 [::std::mem::align_of::<cuvsAllNeighborsIndexParams>() - 8usize];
978 ["Offset of field: cuvsAllNeighborsIndexParams::algo"]
979 [::std::mem::offset_of!(cuvsAllNeighborsIndexParams, algo) - 0usize];
980 ["Offset of field: cuvsAllNeighborsIndexParams::overlap_factor"]
981 [::std::mem::offset_of!(cuvsAllNeighborsIndexParams, overlap_factor) - 8usize];
982 ["Offset of field: cuvsAllNeighborsIndexParams::n_clusters"]
983 [::std::mem::offset_of!(cuvsAllNeighborsIndexParams, n_clusters) - 16usize];
984 ["Offset of field: cuvsAllNeighborsIndexParams::metric"]
985 [::std::mem::offset_of!(cuvsAllNeighborsIndexParams, metric) - 24usize];
986 ["Offset of field: cuvsAllNeighborsIndexParams::ivf_pq_params"]
987 [::std::mem::offset_of!(cuvsAllNeighborsIndexParams, ivf_pq_params) - 32usize];
988 ["Offset of field: cuvsAllNeighborsIndexParams::nn_descent_params"]
989 [::std::mem::offset_of!(cuvsAllNeighborsIndexParams, nn_descent_params) - 40usize];
990};
991pub type cuvsAllNeighborsIndexParams_t = *mut cuvsAllNeighborsIndexParams;
992unsafe extern "C" {
993 #[must_use]
994 #[doc = " @brief Create a default all-neighbors index parameters struct.\n\n @param[out] index_params Pointer to allocated index_params struct\n\n @return cuvsError_t"]
995 pub fn cuvsAllNeighborsIndexParamsCreate(
996 index_params: *mut cuvsAllNeighborsIndexParams_t,
997 ) -> cuvsError_t;
998}
999unsafe extern "C" {
1000 #[must_use]
1001 #[doc = " @brief Destroy an all-neighbors index parameters struct.\n\n @param[in] index_params Index parameters struct to destroy\n\n @return cuvsError_t"]
1002 pub fn cuvsAllNeighborsIndexParamsDestroy(
1003 index_params: cuvsAllNeighborsIndexParams_t,
1004 ) -> cuvsError_t;
1005}
1006unsafe extern "C" {
1007 #[must_use]
1008 #[doc = " @brief Build an all-neighbors k-NN graph automatically detecting host vs device dataset.\n\n @param[in] res Can be a SNMG multi-GPU resources (`cuvsResources_t`) or single-GPU\n resources\n @param[in] params Build parameters (see cuvsAllNeighborsIndexParams)\n @param[in] dataset 2D tensor [num_rows x dim] on host or device (auto-detected)\n @param[out] indices 2D tensor [num_rows x k] on device (int64)\n @param[out] distances Optional 2D tensor [num_rows x k] on device (float32); can be NULL\n @param[out] core_distances Optional 1D tensor [num_rows] on device (float32); can be NULL\n @param[in] alpha Mutual-reachability scaling; used only when core_distances is provided\n\n The function automatically detects whether the dataset is host-resident or device-resident\n and calls the appropriate implementation. For host datasets, it partitions data into\n `n_clusters` clusters and assigns each row to `overlap_factor` nearest clusters. For device\n datasets, `n_clusters` must be 1 (no batching); `overlap_factor` is ignored.\n Outputs always reside in device memory."]
1009 pub fn cuvsAllNeighborsBuild(
1010 res: cuvsResources_t,
1011 params: cuvsAllNeighborsIndexParams_t,
1012 dataset: *mut DLManagedTensor,
1013 indices: *mut DLManagedTensor,
1014 distances: *mut DLManagedTensor,
1015 core_distances: *mut DLManagedTensor,
1016 alpha: f32,
1017 ) -> cuvsError_t;
1018}
1019#[repr(u32)]
1020#[doc = " @brief Enum to denote filter type."]
1021#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1022pub enum cuvsFilterType {
1023 NO_FILTER = 0,
1024 BITSET = 1,
1025 BITMAP = 2,
1026}
1027#[doc = " @brief Struct to hold address of cuvs::neighbors::prefilter and its type\n"]
1028#[repr(C)]
1029#[derive(Debug, Copy, Clone)]
1030pub struct cuvsFilter {
1031 pub addr: usize,
1032 pub type_: cuvsFilterType,
1033}
1034#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1035const _: () = {
1036 ["Size of cuvsFilter"][::std::mem::size_of::<cuvsFilter>() - 16usize];
1037 ["Alignment of cuvsFilter"][::std::mem::align_of::<cuvsFilter>() - 8usize];
1038 ["Offset of field: cuvsFilter::addr"][::std::mem::offset_of!(cuvsFilter, addr) - 0usize];
1039 ["Offset of field: cuvsFilter::type_"][::std::mem::offset_of!(cuvsFilter, type_) - 8usize];
1040};
1041#[repr(u32)]
1042#[doc = " @brief Strategy for merging indices."]
1043#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1044pub enum cuvsMergeStrategy {
1045 #[doc = "< Merge indices physically"]
1046 MERGE_STRATEGY_PHYSICAL = 0,
1047 #[doc = "< Merge indices logically"]
1048 MERGE_STRATEGY_LOGICAL = 1,
1049}
1050#[doc = " @defgroup bruteforce_c_index Bruteforce index\n @{\n/\n/**\n @brief Struct to hold address of cuvs::neighbors::brute_force::index and its active trained dtype\n"]
1051#[repr(C)]
1052#[derive(Debug, Copy, Clone)]
1053pub struct cuvsBruteForceIndex {
1054 pub addr: usize,
1055 pub dtype: DLDataType,
1056}
1057#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1058const _: () = {
1059 ["Size of cuvsBruteForceIndex"][::std::mem::size_of::<cuvsBruteForceIndex>() - 16usize];
1060 ["Alignment of cuvsBruteForceIndex"][::std::mem::align_of::<cuvsBruteForceIndex>() - 8usize];
1061 ["Offset of field: cuvsBruteForceIndex::addr"]
1062 [::std::mem::offset_of!(cuvsBruteForceIndex, addr) - 0usize];
1063 ["Offset of field: cuvsBruteForceIndex::dtype"]
1064 [::std::mem::offset_of!(cuvsBruteForceIndex, dtype) - 8usize];
1065};
1066pub type cuvsBruteForceIndex_t = *mut cuvsBruteForceIndex;
1067unsafe extern "C" {
1068 #[must_use]
1069 #[doc = " @brief Allocate BRUTEFORCE index\n\n @param[in] index cuvsBruteForceIndex_t to allocate\n @return cuvsError_t"]
1070 pub fn cuvsBruteForceIndexCreate(index: *mut cuvsBruteForceIndex_t) -> cuvsError_t;
1071}
1072unsafe extern "C" {
1073 #[must_use]
1074 #[doc = " @brief De-allocate BRUTEFORCE index\n\n @param[in] index cuvsBruteForceIndex_t to de-allocate"]
1075 pub fn cuvsBruteForceIndexDestroy(index: cuvsBruteForceIndex_t) -> cuvsError_t;
1076}
1077unsafe extern "C" {
1078 #[must_use]
1079 #[doc = " @defgroup bruteforce_c_index_build Bruteforce index build\n @{\n/\n/**\n @brief Build a BRUTEFORCE index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/brute_force.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create BRUTEFORCE index\n cuvsBruteForceIndex_t index;\n cuvsError_t index_create_status = cuvsBruteForceIndexCreate(&index);\n\n // Build the BRUTEFORCE Index\n cuvsError_t build_status = cuvsBruteForceBuild(res, &dataset_tensor, L2Expanded, 0.f, index);\n\n // de-allocate `index` and `res`\n cuvsError_t index_destroy_status = cuvsBruteForceIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] dataset DLManagedTensor* training dataset\n @param[in] metric metric\n @param[in] metric_arg metric_arg\n @param[out] index cuvsBruteForceIndex_t Newly built BRUTEFORCE index\n @return cuvsError_t"]
1080 pub fn cuvsBruteForceBuild(
1081 res: cuvsResources_t,
1082 dataset: *mut DLManagedTensor,
1083 metric: cuvsDistanceType,
1084 metric_arg: f32,
1085 index: cuvsBruteForceIndex_t,
1086 ) -> cuvsError_t;
1087}
1088unsafe extern "C" {
1089 #[must_use]
1090 #[doc = " @defgroup bruteforce_c_index_search Bruteforce index search\n @{\n/\n/**\n @brief Search a BRUTEFORCE index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`.\n It is also important to note that the BRUTEFORCE index must have been built\n with the same type of `queries`, such that `index.dtype.code ==\n queries.dl_tensor.dtype.code` Types for input are:\n 1. `queries`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32` or\n `kDLDataType.bits = 16`\n 2. `neighbors`: `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 32`\n 3. `distances`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/brute_force.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n DLManagedTensor bitmap;\n\n cuvsFilter prefilter{(uintptr_t)&bitmap, BITMAP};\n\n // Search the `index` built using `cuvsBruteForceBuild`\n cuvsError_t search_status = cuvsBruteForceSearch(res, index, &queries, &neighbors, &distances,\n prefilter);\n\n // de-allocate `res`\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index cuvsBruteForceIndex which has been returned by `cuvsBruteForceBuild`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries\n @param[in] prefilter cuvsFilter input prefilter that can be used\nto filter queries and neighbors based on the given bitmap."]
1091 pub fn cuvsBruteForceSearch(
1092 res: cuvsResources_t,
1093 index: cuvsBruteForceIndex_t,
1094 queries: *mut DLManagedTensor,
1095 neighbors: *mut DLManagedTensor,
1096 distances: *mut DLManagedTensor,
1097 prefilter: cuvsFilter,
1098 ) -> cuvsError_t;
1099}
1100unsafe extern "C" {
1101 #[must_use]
1102 #[doc = " @defgroup bruteforce_c_index_serialize BRUTEFORCE C-API serialize functions\n @{\n/\n/**\n Save the index to file.\n The serialization format can be subject to changes, therefore loading\n an index saved with a previous version of cuvs is not guaranteed\n to work.\n\n @code{.c}\n #include <cuvs/neighbors/brute_force.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsBruteforceBuild`\n cuvsBruteForceSerialize(res, \"/path/to/index\", index);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file name for saving the index\n @param[in] index BRUTEFORCE index\n"]
1103 pub fn cuvsBruteForceSerialize(
1104 res: cuvsResources_t,
1105 filename: *const ::std::os::raw::c_char,
1106 index: cuvsBruteForceIndex_t,
1107 ) -> cuvsError_t;
1108}
1109unsafe extern "C" {
1110 #[must_use]
1111 #[doc = " Load index from file.\n The serialization format can be subject to changes, therefore loading\n an index saved with a previous version of cuvs is not guaranteed\n to work.\n\n @code{.c}\n #include <cuvs/neighbors/brute_force.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Deserialize an index previously built with `cuvsBruteforceBuild`\n cuvsBruteForceIndex_t index;\n cuvsBruteForceIndexCreate(&index);\n cuvsBruteForceDeserialize(res, \"/path/to/index\", index);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the name of the file that stores the index\n @param[out] index BRUTEFORCE index loaded disk"]
1112 pub fn cuvsBruteForceDeserialize(
1113 res: cuvsResources_t,
1114 filename: *const ::std::os::raw::c_char,
1115 index: cuvsBruteForceIndex_t,
1116 ) -> cuvsError_t;
1117}
1118#[repr(u32)]
1119#[doc = " @brief Enum to denote which ANN algorithm is used to build CAGRA graph\n"]
1120#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1121pub enum cuvsCagraGraphBuildAlgo {
1122 AUTO_SELECT = 0,
1123 IVF_PQ = 1,
1124 NN_DESCENT = 2,
1125 ITERATIVE_CAGRA_SEARCH = 3,
1126 #[doc = " Experimental, use ACE (Augmented Core Extraction) to build the graph. ACE partitions the\n dataset into core and augmented partitions and builds a sub-index for each partition. This\n enables building indices for datasets too large to fit in GPU or host memory.\n See cuvsAceParams for more details about the ACE algorithm and its parameters."]
1127 ACE = 4,
1128}
1129#[repr(u32)]
1130#[doc = " @brief A strategy for selecting the graph build parameters based on similar HNSW index\n parameters.\n\n Define how cuvsCagraIndexParamsFromHnswParams should construct a graph to construct a graph\n that is to be converted to (used by) a CPU HNSW index."]
1131#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1132pub enum cuvsCagraHnswHeuristicType {
1133 #[doc = " Create a graph that is very similar to an HNSW graph in\n terms of the number of nodes and search performance. Since HNSW produces a variable-degree\n graph (2M being the max graph degree) and CAGRA produces a fixed-degree graph, there's always a\n difference in the performance of the two.\n\n This function attempts to produce such a graph that the QPS and recall of the two graphs being\n searched by HNSW are close for any search parameter combination. The CAGRA-produced graph tends\n to have a \"longer tail\" on the low recall side (that is being slightly faster and less\n precise).\n"]
1134 CUVS_CAGRA_HEURISTIC_SIMILAR_SEARCH_PERFORMANCE = 0,
1135 #[doc = " Create a graph that has the same binary size as an HNSW graph with the given parameters\n (graph_degree = 2 * M) while trying to match the search performance as closely as possible.\n\n The reference HNSW index and the corresponding from-CAGRA generated HNSW index will NOT produce\n the same recalls and QPS for the same parameter ef. The graphs are different internally. For\n the same ef, the from-CAGRA index likely has a slightly higher recall and slightly lower QPS.\n However, the Recall-QPS curves should be similar (i.e. the points are just shifted along the\n curve)."]
1136 CUVS_CAGRA_HEURISTIC_SAME_GRAPH_FOOTPRINT = 1,
1137}
1138#[doc = " Parameters for VPQ compression."]
1139#[repr(C)]
1140#[derive(Debug, Copy, Clone)]
1141pub struct cuvsCagraCompressionParams {
1142 #[doc = " The bit length of the vector element after compression by PQ.\n\n Possible values: [4, 5, 6, 7, 8].\n\n Hint: the smaller the 'pq_bits', the smaller the index size and the better the search\n performance, but the lower the recall."]
1143 pub pq_bits: u32,
1144 #[doc = " The dimensionality of the vector after compression by PQ.\n When zero, an optimal value is selected using a heuristic.\n\n TODO: at the moment `dim` must be a multiple `pq_dim`."]
1145 pub pq_dim: u32,
1146 #[doc = " Vector Quantization (VQ) codebook size - number of \"coarse cluster centers\".\n When zero, an optimal value is selected using a heuristic."]
1147 pub vq_n_centers: u32,
1148 #[doc = " The number of iterations searching for kmeans centers (both VQ & PQ phases)."]
1149 pub kmeans_n_iters: u32,
1150 #[doc = " The fraction of data to use during iterative kmeans building (VQ phase).\n When zero, an optimal value is selected using a heuristic."]
1151 pub vq_kmeans_trainset_fraction: f64,
1152 #[doc = " The fraction of data to use during iterative kmeans building (PQ phase).\n When zero, an optimal value is selected using a heuristic."]
1153 pub pq_kmeans_trainset_fraction: f64,
1154}
1155#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1156const _: () = {
1157 ["Size of cuvsCagraCompressionParams"]
1158 [::std::mem::size_of::<cuvsCagraCompressionParams>() - 32usize];
1159 ["Alignment of cuvsCagraCompressionParams"]
1160 [::std::mem::align_of::<cuvsCagraCompressionParams>() - 8usize];
1161 ["Offset of field: cuvsCagraCompressionParams::pq_bits"]
1162 [::std::mem::offset_of!(cuvsCagraCompressionParams, pq_bits) - 0usize];
1163 ["Offset of field: cuvsCagraCompressionParams::pq_dim"]
1164 [::std::mem::offset_of!(cuvsCagraCompressionParams, pq_dim) - 4usize];
1165 ["Offset of field: cuvsCagraCompressionParams::vq_n_centers"]
1166 [::std::mem::offset_of!(cuvsCagraCompressionParams, vq_n_centers) - 8usize];
1167 ["Offset of field: cuvsCagraCompressionParams::kmeans_n_iters"]
1168 [::std::mem::offset_of!(cuvsCagraCompressionParams, kmeans_n_iters) - 12usize];
1169 ["Offset of field: cuvsCagraCompressionParams::vq_kmeans_trainset_fraction"]
1170 [::std::mem::offset_of!(cuvsCagraCompressionParams, vq_kmeans_trainset_fraction) - 16usize];
1171 ["Offset of field: cuvsCagraCompressionParams::pq_kmeans_trainset_fraction"]
1172 [::std::mem::offset_of!(cuvsCagraCompressionParams, pq_kmeans_trainset_fraction) - 24usize];
1173};
1174pub type cuvsCagraCompressionParams_t = *mut cuvsCagraCompressionParams;
1175#[repr(C)]
1176#[derive(Debug, Copy, Clone)]
1177pub struct cuvsIvfPqParams {
1178 pub ivf_pq_build_params: cuvsIvfPqIndexParams_t,
1179 pub ivf_pq_search_params: cuvsIvfPqSearchParams_t,
1180 pub refinement_rate: f32,
1181}
1182#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1183const _: () = {
1184 ["Size of cuvsIvfPqParams"][::std::mem::size_of::<cuvsIvfPqParams>() - 24usize];
1185 ["Alignment of cuvsIvfPqParams"][::std::mem::align_of::<cuvsIvfPqParams>() - 8usize];
1186 ["Offset of field: cuvsIvfPqParams::ivf_pq_build_params"]
1187 [::std::mem::offset_of!(cuvsIvfPqParams, ivf_pq_build_params) - 0usize];
1188 ["Offset of field: cuvsIvfPqParams::ivf_pq_search_params"]
1189 [::std::mem::offset_of!(cuvsIvfPqParams, ivf_pq_search_params) - 8usize];
1190 ["Offset of field: cuvsIvfPqParams::refinement_rate"]
1191 [::std::mem::offset_of!(cuvsIvfPqParams, refinement_rate) - 16usize];
1192};
1193pub type cuvsIvfPqParams_t = *mut cuvsIvfPqParams;
1194#[doc = " Parameters for ACE (Augmented Core Extraction) graph build.\n ACE enables building indexes for datasets too large to fit in GPU memory by:\n 1. Partitioning the dataset in core (closest) and augmented (second-closest)\n partitions using balanced k-means.\n 2. Building sub-indexes for each partition independently\n 3. Concatenating sub-graphs into a final unified index"]
1195#[repr(C)]
1196#[derive(Debug, Copy, Clone)]
1197pub struct cuvsAceParams {
1198 #[doc = " Number of partitions for ACE (Augmented Core Extraction) partitioned build.\n\n When set to 0 (default), the number of partitions is automatically derived\n based on available host and GPU memory to maximize partition size while\n ensuring the build fits in memory.\n\n Small values might improve recall but potentially degrade performance and\n increase memory usage. Partitions should not be too small to prevent issues\n in KNN graph construction. The partition size is on average 2 * (n_rows /\n npartitions) * dim * sizeof(T). 2 is because of the core and augmented\n vectors. Please account for imbalance in the partition sizes (up to 3x in\n our tests).\n\n If the specified number of partitions results in partitions that exceed\n available memory, the value will be automatically increased to fit memory\n constraints and a warning will be issued."]
1199 pub npartitions: usize,
1200 #[doc = " The index quality for the ACE build.\n\n Bigger values increase the index quality. At some point, increasing this will no longer\n improve the quality."]
1201 pub ef_construction: usize,
1202 #[doc = " Directory to store ACE build artifacts (e.g., KNN graph, optimized graph).\n\n Used when `use_disk` is true or when the graph does not fit in host and GPU\n memory. This should be the fastest disk in the system and hold enough space\n for twice the dataset, final graph, and label mapping."]
1203 pub build_dir: *const ::std::os::raw::c_char,
1204 #[doc = " Whether to use disk-based storage for ACE build.\n\n When true, enables disk-based operations for memory-efficient graph construction."]
1205 pub use_disk: bool,
1206 #[doc = " Maximum host memory to use for ACE build in GiB.\n\n When set to 0 (default), uses available host memory.\n When set to a positive value, limits host memory usage to the specified amount.\n Useful for testing or when running alongside other memory-intensive processes."]
1207 pub max_host_memory_gb: f64,
1208 #[doc = " Maximum GPU memory to use for ACE build in GiB.\n\n When set to 0 (default), uses available GPU memory.\n When set to a positive value, limits GPU memory usage to the specified amount.\n Useful for testing or when running alongside other memory-intensive processes."]
1209 pub max_gpu_memory_gb: f64,
1210}
1211#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1212const _: () = {
1213 ["Size of cuvsAceParams"][::std::mem::size_of::<cuvsAceParams>() - 48usize];
1214 ["Alignment of cuvsAceParams"][::std::mem::align_of::<cuvsAceParams>() - 8usize];
1215 ["Offset of field: cuvsAceParams::npartitions"]
1216 [::std::mem::offset_of!(cuvsAceParams, npartitions) - 0usize];
1217 ["Offset of field: cuvsAceParams::ef_construction"]
1218 [::std::mem::offset_of!(cuvsAceParams, ef_construction) - 8usize];
1219 ["Offset of field: cuvsAceParams::build_dir"]
1220 [::std::mem::offset_of!(cuvsAceParams, build_dir) - 16usize];
1221 ["Offset of field: cuvsAceParams::use_disk"]
1222 [::std::mem::offset_of!(cuvsAceParams, use_disk) - 24usize];
1223 ["Offset of field: cuvsAceParams::max_host_memory_gb"]
1224 [::std::mem::offset_of!(cuvsAceParams, max_host_memory_gb) - 32usize];
1225 ["Offset of field: cuvsAceParams::max_gpu_memory_gb"]
1226 [::std::mem::offset_of!(cuvsAceParams, max_gpu_memory_gb) - 40usize];
1227};
1228pub type cuvsAceParams_t = *mut cuvsAceParams;
1229#[doc = " @brief Supplemental parameters to build CAGRA Index\n"]
1230#[repr(C)]
1231#[derive(Debug, Copy, Clone)]
1232pub struct cuvsCagraIndexParams {
1233 #[doc = " Distance type."]
1234 pub metric: cuvsDistanceType,
1235 #[doc = " Degree of input graph for pruning."]
1236 pub intermediate_graph_degree: usize,
1237 #[doc = " Degree of output graph."]
1238 pub graph_degree: usize,
1239 #[doc = " ANN algorithm to build knn graph."]
1240 pub build_algo: cuvsCagraGraphBuildAlgo,
1241 #[doc = " Number of Iterations to run if building with NN_DESCENT"]
1242 pub nn_descent_niter: usize,
1243 #[doc = " Optional: specify compression parameters if compression is desired.\n\n NOTE: this is experimental new API, consider it unsafe."]
1244 pub compression: cuvsCagraCompressionParams_t,
1245 #[doc = " Optional: specify graph build params based on build_algo\n - IVF_PQ: cuvsIvfPqParams_t\n - ACE: cuvsAceParams_t\n - Others: nullptr"]
1246 pub graph_build_params: *mut ::std::os::raw::c_void,
1247}
1248#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1249const _: () = {
1250 ["Size of cuvsCagraIndexParams"][::std::mem::size_of::<cuvsCagraIndexParams>() - 56usize];
1251 ["Alignment of cuvsCagraIndexParams"][::std::mem::align_of::<cuvsCagraIndexParams>() - 8usize];
1252 ["Offset of field: cuvsCagraIndexParams::metric"]
1253 [::std::mem::offset_of!(cuvsCagraIndexParams, metric) - 0usize];
1254 ["Offset of field: cuvsCagraIndexParams::intermediate_graph_degree"]
1255 [::std::mem::offset_of!(cuvsCagraIndexParams, intermediate_graph_degree) - 8usize];
1256 ["Offset of field: cuvsCagraIndexParams::graph_degree"]
1257 [::std::mem::offset_of!(cuvsCagraIndexParams, graph_degree) - 16usize];
1258 ["Offset of field: cuvsCagraIndexParams::build_algo"]
1259 [::std::mem::offset_of!(cuvsCagraIndexParams, build_algo) - 24usize];
1260 ["Offset of field: cuvsCagraIndexParams::nn_descent_niter"]
1261 [::std::mem::offset_of!(cuvsCagraIndexParams, nn_descent_niter) - 32usize];
1262 ["Offset of field: cuvsCagraIndexParams::compression"]
1263 [::std::mem::offset_of!(cuvsCagraIndexParams, compression) - 40usize];
1264 ["Offset of field: cuvsCagraIndexParams::graph_build_params"]
1265 [::std::mem::offset_of!(cuvsCagraIndexParams, graph_build_params) - 48usize];
1266};
1267pub type cuvsCagraIndexParams_t = *mut cuvsCagraIndexParams;
1268unsafe extern "C" {
1269 #[must_use]
1270 #[doc = " @brief Allocate CAGRA Index params, and populate with default values\n\n @param[in] params cuvsCagraIndexParams_t to allocate\n @return cuvsError_t"]
1271 pub fn cuvsCagraIndexParamsCreate(params: *mut cuvsCagraIndexParams_t) -> cuvsError_t;
1272}
1273unsafe extern "C" {
1274 #[must_use]
1275 #[doc = " @brief De-allocate CAGRA Index params\n\n @param[in] params\n @return cuvsError_t"]
1276 pub fn cuvsCagraIndexParamsDestroy(params: cuvsCagraIndexParams_t) -> cuvsError_t;
1277}
1278unsafe extern "C" {
1279 #[must_use]
1280 #[doc = " @brief Allocate CAGRA Compression params, and populate with default values\n\n @param[in] params cuvsCagraCompressionParams_t to allocate\n @return cuvsError_t"]
1281 pub fn cuvsCagraCompressionParamsCreate(
1282 params: *mut cuvsCagraCompressionParams_t,
1283 ) -> cuvsError_t;
1284}
1285unsafe extern "C" {
1286 #[must_use]
1287 #[doc = " @brief De-allocate CAGRA Compression params\n\n @param[in] params\n @return cuvsError_t"]
1288 pub fn cuvsCagraCompressionParamsDestroy(params: cuvsCagraCompressionParams_t) -> cuvsError_t;
1289}
1290unsafe extern "C" {
1291 #[must_use]
1292 #[doc = " @brief Allocate ACE params, and populate with default values\n\n @param[in] params cuvsAceParams_t to allocate\n @return cuvsError_t"]
1293 pub fn cuvsAceParamsCreate(params: *mut cuvsAceParams_t) -> cuvsError_t;
1294}
1295unsafe extern "C" {
1296 #[must_use]
1297 #[doc = " @brief De-allocate ACE params\n\n @param[in] params\n @return cuvsError_t"]
1298 pub fn cuvsAceParamsDestroy(params: cuvsAceParams_t) -> cuvsError_t;
1299}
1300unsafe extern "C" {
1301 #[must_use]
1302 #[doc = " @brief Create CAGRA index parameters similar to an HNSW index\n\n This factory function creates CAGRA parameters that yield a graph compatible with\n an HNSW graph with the given parameters.\n\n @param[out] params The CAGRA index params to populate\n @param[in] n_rows Number of rows in the dataset\n @param[in] dim Number of dimensions in the dataset\n @param[in] M HNSW index parameter M\n @param[in] ef_construction HNSW index parameter ef_construction\n @param[in] heuristic Strategy for parameter selection\n @param[in] metric Distance metric to use\n @return cuvsError_t"]
1303 pub fn cuvsCagraIndexParamsFromHnswParams(
1304 params: cuvsCagraIndexParams_t,
1305 n_rows: i64,
1306 dim: i64,
1307 M: ::std::os::raw::c_int,
1308 ef_construction: ::std::os::raw::c_int,
1309 heuristic: cuvsCagraHnswHeuristicType,
1310 metric: cuvsDistanceType,
1311 ) -> cuvsError_t;
1312}
1313#[doc = " @defgroup cagra_c_extend_params C API for CUDA ANN Graph-based nearest neighbor search\n @{\n/\n/**\n @brief Supplemental parameters to extend CAGRA Index\n"]
1314#[repr(C)]
1315#[derive(Debug, Copy, Clone)]
1316pub struct cuvsCagraExtendParams {
1317 #[doc = " The additional dataset is divided into chunks and added to the graph. This is the knob to\n adjust the tradeoff between the recall and operation throughput. Large chunk sizes can result\n in high throughput, but use more working memory (O(max_chunk_size*degree^2)). This can also\n degrade recall because no edges are added between the nodes in the same chunk. Auto select when\n 0."]
1318 pub max_chunk_size: u32,
1319}
1320#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1321const _: () = {
1322 ["Size of cuvsCagraExtendParams"][::std::mem::size_of::<cuvsCagraExtendParams>() - 4usize];
1323 ["Alignment of cuvsCagraExtendParams"]
1324 [::std::mem::align_of::<cuvsCagraExtendParams>() - 4usize];
1325 ["Offset of field: cuvsCagraExtendParams::max_chunk_size"]
1326 [::std::mem::offset_of!(cuvsCagraExtendParams, max_chunk_size) - 0usize];
1327};
1328pub type cuvsCagraExtendParams_t = *mut cuvsCagraExtendParams;
1329unsafe extern "C" {
1330 #[must_use]
1331 #[doc = " @brief Allocate CAGRA Extend params, and populate with default values\n\n @param[in] params cuvsCagraExtendParams_t to allocate\n @return cuvsError_t"]
1332 pub fn cuvsCagraExtendParamsCreate(params: *mut cuvsCagraExtendParams_t) -> cuvsError_t;
1333}
1334unsafe extern "C" {
1335 #[must_use]
1336 #[doc = " @brief De-allocate CAGRA Extend params\n\n @param[in] params\n @return cuvsError_t"]
1337 pub fn cuvsCagraExtendParamsDestroy(params: cuvsCagraExtendParams_t) -> cuvsError_t;
1338}
1339#[repr(u32)]
1340#[doc = " @brief Enum to denote algorithm used to search CAGRA Index\n"]
1341#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1342pub enum cuvsCagraSearchAlgo {
1343 #[doc = " For large batch sizes."]
1344 SINGLE_CTA = 0,
1345 #[doc = " For small batch sizes."]
1346 MULTI_CTA = 1,
1347 #[doc = " For small batch sizes."]
1348 MULTI_KERNEL = 2,
1349 #[doc = " For small batch sizes."]
1350 AUTO = 100,
1351}
1352#[repr(u32)]
1353#[doc = " @brief Enum to denote Hash Mode used while searching CAGRA index\n"]
1354#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1355pub enum cuvsCagraHashMode {
1356 HASH = 0,
1357 SMALL = 1,
1358 AUTO_HASH = 100,
1359}
1360#[doc = " @brief Supplemental parameters to search CAGRA index\n"]
1361#[repr(C)]
1362#[derive(Debug, Copy, Clone)]
1363pub struct cuvsCagraSearchParams {
1364 #[doc = " Maximum number of queries to search at the same time (batch size). Auto select when 0."]
1365 pub max_queries: usize,
1366 #[doc = " Number of intermediate search results retained during the search.\n\n This is the main knob to adjust trade off between accuracy and search speed.\n Higher values improve the search accuracy."]
1367 pub itopk_size: usize,
1368 #[doc = " Upper limit of search iterations. Auto select when 0."]
1369 pub max_iterations: usize,
1370 #[doc = " Which search implementation to use."]
1371 pub algo: cuvsCagraSearchAlgo,
1372 #[doc = " Number of threads used to calculate a single distance. 4, 8, 16, or 32."]
1373 pub team_size: usize,
1374 #[doc = " Number of graph nodes to select as the starting point for the search in each iteration. aka\n search width?"]
1375 pub search_width: usize,
1376 #[doc = " Lower limit of search iterations."]
1377 pub min_iterations: usize,
1378 #[doc = " Thread block size. 0, 64, 128, 256, 512, 1024. Auto selection when 0."]
1379 pub thread_block_size: usize,
1380 #[doc = " Hashmap type. Auto selection when AUTO."]
1381 pub hashmap_mode: cuvsCagraHashMode,
1382 #[doc = " Lower limit of hashmap bit length. More than 8."]
1383 pub hashmap_min_bitlen: usize,
1384 #[doc = " Upper limit of hashmap fill rate. More than 0.1, less than 0.9."]
1385 pub hashmap_max_fill_rate: f32,
1386 #[doc = " Number of iterations of initial random seed node selection. 1 or more."]
1387 pub num_random_samplings: u32,
1388 #[doc = " Bit mask used for initial random seed node selection."]
1389 pub rand_xor_mask: u64,
1390 #[doc = " Whether to use the persistent version of the kernel (only SINGLE_CTA is supported a.t.m.)"]
1391 pub persistent: bool,
1392 #[doc = " Persistent kernel: time in seconds before the kernel stops if no requests received."]
1393 pub persistent_lifetime: f32,
1394 #[doc = " Set the fraction of maximum grid size used by persistent kernel.\n Value 1.0 means the kernel grid size is maximum possible for the selected device.\n The value must be greater than 0.0 and not greater than 1.0.\n\n One may need to run other kernels alongside this persistent kernel. This parameter can\n be used to reduce the grid size of the persistent kernel to leave a few SMs idle.\n Note: running any other work on GPU alongside with the persistent kernel makes the setup\n fragile.\n - Running another kernel in another thread usually works, but no progress guaranteed\n - Any CUDA allocations block the context (this issue may be obscured by using pools)\n - Memory copies to not-pinned host memory may block the context\n\n Even when we know there are no other kernels working at the same time, setting\n kDeviceUsage to 1.0 surprisingly sometimes hurts performance. Proceed with care.\n If you suspect this is an issue, you can reduce this number to ~0.9 without a significant\n impact on the throughput."]
1395 pub persistent_device_usage: f32,
1396}
1397#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1398const _: () = {
1399 ["Size of cuvsCagraSearchParams"][::std::mem::size_of::<cuvsCagraSearchParams>() - 112usize];
1400 ["Alignment of cuvsCagraSearchParams"]
1401 [::std::mem::align_of::<cuvsCagraSearchParams>() - 8usize];
1402 ["Offset of field: cuvsCagraSearchParams::max_queries"]
1403 [::std::mem::offset_of!(cuvsCagraSearchParams, max_queries) - 0usize];
1404 ["Offset of field: cuvsCagraSearchParams::itopk_size"]
1405 [::std::mem::offset_of!(cuvsCagraSearchParams, itopk_size) - 8usize];
1406 ["Offset of field: cuvsCagraSearchParams::max_iterations"]
1407 [::std::mem::offset_of!(cuvsCagraSearchParams, max_iterations) - 16usize];
1408 ["Offset of field: cuvsCagraSearchParams::algo"]
1409 [::std::mem::offset_of!(cuvsCagraSearchParams, algo) - 24usize];
1410 ["Offset of field: cuvsCagraSearchParams::team_size"]
1411 [::std::mem::offset_of!(cuvsCagraSearchParams, team_size) - 32usize];
1412 ["Offset of field: cuvsCagraSearchParams::search_width"]
1413 [::std::mem::offset_of!(cuvsCagraSearchParams, search_width) - 40usize];
1414 ["Offset of field: cuvsCagraSearchParams::min_iterations"]
1415 [::std::mem::offset_of!(cuvsCagraSearchParams, min_iterations) - 48usize];
1416 ["Offset of field: cuvsCagraSearchParams::thread_block_size"]
1417 [::std::mem::offset_of!(cuvsCagraSearchParams, thread_block_size) - 56usize];
1418 ["Offset of field: cuvsCagraSearchParams::hashmap_mode"]
1419 [::std::mem::offset_of!(cuvsCagraSearchParams, hashmap_mode) - 64usize];
1420 ["Offset of field: cuvsCagraSearchParams::hashmap_min_bitlen"]
1421 [::std::mem::offset_of!(cuvsCagraSearchParams, hashmap_min_bitlen) - 72usize];
1422 ["Offset of field: cuvsCagraSearchParams::hashmap_max_fill_rate"]
1423 [::std::mem::offset_of!(cuvsCagraSearchParams, hashmap_max_fill_rate) - 80usize];
1424 ["Offset of field: cuvsCagraSearchParams::num_random_samplings"]
1425 [::std::mem::offset_of!(cuvsCagraSearchParams, num_random_samplings) - 84usize];
1426 ["Offset of field: cuvsCagraSearchParams::rand_xor_mask"]
1427 [::std::mem::offset_of!(cuvsCagraSearchParams, rand_xor_mask) - 88usize];
1428 ["Offset of field: cuvsCagraSearchParams::persistent"]
1429 [::std::mem::offset_of!(cuvsCagraSearchParams, persistent) - 96usize];
1430 ["Offset of field: cuvsCagraSearchParams::persistent_lifetime"]
1431 [::std::mem::offset_of!(cuvsCagraSearchParams, persistent_lifetime) - 100usize];
1432 ["Offset of field: cuvsCagraSearchParams::persistent_device_usage"]
1433 [::std::mem::offset_of!(cuvsCagraSearchParams, persistent_device_usage) - 104usize];
1434};
1435pub type cuvsCagraSearchParams_t = *mut cuvsCagraSearchParams;
1436unsafe extern "C" {
1437 #[must_use]
1438 #[doc = " @brief Allocate CAGRA search params, and populate with default values\n\n @param[in] params cuvsCagraSearchParams_t to allocate\n @return cuvsError_t"]
1439 pub fn cuvsCagraSearchParamsCreate(params: *mut cuvsCagraSearchParams_t) -> cuvsError_t;
1440}
1441unsafe extern "C" {
1442 #[must_use]
1443 #[doc = " @brief De-allocate CAGRA search params\n\n @param[in] params\n @return cuvsError_t"]
1444 pub fn cuvsCagraSearchParamsDestroy(params: cuvsCagraSearchParams_t) -> cuvsError_t;
1445}
1446#[doc = " @brief Struct to hold address of cuvs::neighbors::cagra::index and its active trained dtype\n"]
1447#[repr(C)]
1448#[derive(Debug, Copy, Clone)]
1449pub struct cuvsCagraIndex {
1450 pub addr: usize,
1451 pub dtype: DLDataType,
1452}
1453#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1454const _: () = {
1455 ["Size of cuvsCagraIndex"][::std::mem::size_of::<cuvsCagraIndex>() - 16usize];
1456 ["Alignment of cuvsCagraIndex"][::std::mem::align_of::<cuvsCagraIndex>() - 8usize];
1457 ["Offset of field: cuvsCagraIndex::addr"]
1458 [::std::mem::offset_of!(cuvsCagraIndex, addr) - 0usize];
1459 ["Offset of field: cuvsCagraIndex::dtype"]
1460 [::std::mem::offset_of!(cuvsCagraIndex, dtype) - 8usize];
1461};
1462pub type cuvsCagraIndex_t = *mut cuvsCagraIndex;
1463unsafe extern "C" {
1464 #[must_use]
1465 #[doc = " @brief Allocate CAGRA index\n\n @param[in] index cuvsCagraIndex_t to allocate\n @return cagraError_t"]
1466 pub fn cuvsCagraIndexCreate(index: *mut cuvsCagraIndex_t) -> cuvsError_t;
1467}
1468unsafe extern "C" {
1469 #[must_use]
1470 #[doc = " @brief De-allocate CAGRA index\n\n @param[in] index cuvsCagraIndex_t to de-allocate"]
1471 pub fn cuvsCagraIndexDestroy(index: cuvsCagraIndex_t) -> cuvsError_t;
1472}
1473unsafe extern "C" {
1474 #[must_use]
1475 #[doc = " @brief Get dimension of the CAGRA index\n\n @param[in] index CAGRA index\n @param[out] dim return dimension of the index\n @return cuvsError_t"]
1476 pub fn cuvsCagraIndexGetDims(index: cuvsCagraIndex_t, dim: *mut i64) -> cuvsError_t;
1477}
1478unsafe extern "C" {
1479 #[must_use]
1480 #[doc = " @brief Get size of the CAGRA index\n\n @param[in] index CAGRA index\n @param[out] size return number of vectors in the index\n @return cuvsError_t"]
1481 pub fn cuvsCagraIndexGetSize(index: cuvsCagraIndex_t, size: *mut i64) -> cuvsError_t;
1482}
1483unsafe extern "C" {
1484 #[must_use]
1485 #[doc = " @brief Get graph degree of the CAGRA index\n\n @param[in] index CAGRA index\n @param[out] graph_degree return graph degree\n @return cuvsError_t"]
1486 pub fn cuvsCagraIndexGetGraphDegree(
1487 index: cuvsCagraIndex_t,
1488 graph_degree: *mut i64,
1489 ) -> cuvsError_t;
1490}
1491unsafe extern "C" {
1492 #[must_use]
1493 #[doc = " @brief Returns a view of the CAGRA dataset\n\n This function returns a non-owning view of the CAGRA dataset.\n The output will be referencing device memory that is directly used\n in CAGRA, without copying the dataset at all. This means that the\n output is only valid as long as the CAGRA index is alive, and once\n cuvsCagraIndexDestroy is called on the cagra index - the returned\n dataset view will be invalid.\n\n Note that the DLManagedTensor dataset returned will have an associated\n 'deleter' function that must be called when the dataset is no longer\n needed. This will free up host memory that stores the shape of the\n dataset view.\n\n @param[in] index CAGRA index\n @param[out] dataset the dataset used in cagra\n @return cuvsError_t"]
1494 pub fn cuvsCagraIndexGetDataset(
1495 index: cuvsCagraIndex_t,
1496 dataset: *mut DLManagedTensor,
1497 ) -> cuvsError_t;
1498}
1499unsafe extern "C" {
1500 #[must_use]
1501 #[doc = " @brief Returns a view of the CAGRA graph\n\n This function returns a non-owning view of the CAGRA graph.\n The output will be referencing device memory that is directly used\n in CAGRA, without copying the graph at all. This means that the\n output is only valid as long as the CAGRA index is alive, and once\n cuvsCagraIndexDestroy is called on the cagra index - the returned\n graph view will be invalid.\n\n Note that the DLManagedTensor graph returned will have an associated\n 'deleter' function that must be called when the graph is no longer\n needed. This will free up host memory that stores the metadata for the\n graph view.\n\n @param[in] index CAGRA index\n @param[out] graph the output knn graph.\n @return cuvsError_t"]
1502 pub fn cuvsCagraIndexGetGraph(
1503 index: cuvsCagraIndex_t,
1504 graph: *mut DLManagedTensor,
1505 ) -> cuvsError_t;
1506}
1507unsafe extern "C" {
1508 #[must_use]
1509 #[doc = " @brief Build a CAGRA index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n 3. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n 4. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create default index params\n cuvsCagraIndexParams_t params;\n cuvsError_t params_create_status = cuvsCagraIndexParamsCreate(¶ms);\n\n // Create CAGRA index\n cuvsCagraIndex_t index;\n cuvsError_t index_create_status = cuvsCagraIndexCreate(&index);\n\n // Build the CAGRA Index\n cuvsError_t build_status = cuvsCagraBuild(res, params, &dataset, index);\n\n // de-allocate `params`, `index` and `res`\n cuvsError_t params_destroy_status = cuvsCagraIndexParamsDestroy(params);\n cuvsError_t index_destroy_status = cuvsCagraIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsCagraIndexParams_t used to build CAGRA index\n @param[in] dataset DLManagedTensor* training dataset\n @param[inout] index cuvsCagraIndex_t Newly built CAGRA index. This index needs to be already\n created with cuvsCagraIndexCreate.\n @return cuvsError_t"]
1510 pub fn cuvsCagraBuild(
1511 res: cuvsResources_t,
1512 params: cuvsCagraIndexParams_t,
1513 dataset: *mut DLManagedTensor,
1514 index: cuvsCagraIndex_t,
1515 ) -> cuvsError_t;
1516}
1517unsafe extern "C" {
1518 #[must_use]
1519 #[doc = " @brief Extend a CAGRA index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n 3. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n 4. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsCagraExtendParams_t used to extend CAGRA index\n @param[in] additional_dataset DLManagedTensor* additional dataset\n @param[in,out] index cuvsCagraIndex_t CAGRA index\n @return cuvsError_t"]
1520 pub fn cuvsCagraExtend(
1521 res: cuvsResources_t,
1522 params: cuvsCagraExtendParams_t,
1523 additional_dataset: *mut DLManagedTensor,
1524 index: cuvsCagraIndex_t,
1525 ) -> cuvsError_t;
1526}
1527unsafe extern "C" {
1528 #[must_use]
1529 #[doc = " @defgroup cagra_c_index_search C API for CUDA ANN Graph-based nearest neighbor search\n @{\n/\n/**\n @brief Search a CAGRA index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`.\n It is also important to note that the CAGRA Index must have been built\n with the same type of `queries`, such that `index.dtype.code ==\n queries.dl_tensor.dtype.code` Types for input are:\n 1. `queries`:\n a. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n b. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n c. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n d. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n 2. `neighbors`: `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 32`\n or `kDLDataType.code == kDLInt` and `kDLDataType.bits = 64`\n 3. `distances`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n\n // Create default search params\n cuvsCagraSearchParams_t params;\n cuvsError_t params_create_status = cuvsCagraSearchParamsCreate(¶ms);\n\n // Search the `index` built using `cuvsCagraBuild`\n cuvsError_t search_status = cuvsCagraSearch(res, params, index, &queries, &neighbors,\n &distances);\n\n // de-allocate `params` and `res`\n cuvsError_t params_destroy_status = cuvsCagraSearchParamsDestroy(params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsCagraSearchParams_t used to search CAGRA index\n @param[in] index cuvsCagraIndex which has been returned by `cuvsCagraBuild`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries\n @param[in] filter cuvsFilter input filter that can be used\nto filter queries and neighbors based on the given bitset."]
1530 pub fn cuvsCagraSearch(
1531 res: cuvsResources_t,
1532 params: cuvsCagraSearchParams_t,
1533 index: cuvsCagraIndex_t,
1534 queries: *mut DLManagedTensor,
1535 neighbors: *mut DLManagedTensor,
1536 distances: *mut DLManagedTensor,
1537 filter: cuvsFilter,
1538 ) -> cuvsError_t;
1539}
1540unsafe extern "C" {
1541 #[must_use]
1542 #[doc = " @defgroup cagra_c_index_serialize CAGRA C-API serialize functions\n @{\n/\n/**\n Save the index to file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @code{.c}\n #include <cuvs/neighbors/cagra.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsCagraBuild`\n cuvsCagraSerialize(res, \"/path/to/index\", index, true);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file name for saving the index\n @param[in] index CAGRA index\n @param[in] include_dataset Whether or not to write out the dataset to the file.\n"]
1543 pub fn cuvsCagraSerialize(
1544 res: cuvsResources_t,
1545 filename: *const ::std::os::raw::c_char,
1546 index: cuvsCagraIndex_t,
1547 include_dataset: bool,
1548 ) -> cuvsError_t;
1549}
1550unsafe extern "C" {
1551 #[must_use]
1552 #[doc = " Save the CAGRA index to file in hnswlib format.\n NOTE: The saved index can only be read by the hnswlib wrapper in cuVS,\n as the serialization format is not compatible with the original hnswlib.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsCagraBuild`\n cuvsCagraSerializeHnswlib(res, \"/path/to/index\", index);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file name for saving the index\n @param[in] index CAGRA index\n"]
1553 pub fn cuvsCagraSerializeToHnswlib(
1554 res: cuvsResources_t,
1555 filename: *const ::std::os::raw::c_char,
1556 index: cuvsCagraIndex_t,
1557 ) -> cuvsError_t;
1558}
1559unsafe extern "C" {
1560 #[must_use]
1561 #[doc = " Load index from file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the name of the file that stores the index\n @param[inout] index cuvsCagraIndex_t CAGRA index loaded from disk. This index needs to be already\n created with cuvsCagraIndexCreate."]
1562 pub fn cuvsCagraDeserialize(
1563 res: cuvsResources_t,
1564 filename: *const ::std::os::raw::c_char,
1565 index: cuvsCagraIndex_t,
1566 ) -> cuvsError_t;
1567}
1568unsafe extern "C" {
1569 #[must_use]
1570 #[doc = " Load index from a dataset and graph\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] metric cuvsDistanceType to use in the index\n @param[in] graph the knn graph to use, shape (size, graph_degree)\n @param[in] dataset the dataset to use, shape (size, dim)\n @param[inout] index cuvsCagraIndex_t CAGRA index populated with the graph and dataset.\n This index needs to be already created with\n cuvsCagraIndexCreate.\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Create CAGRA index\n cuvsCagraIndex_t index;\n cuvsError_t index_create_status = cuvsCagraIndexCreate(&index);\n\n // Assume a populated `DLManagedTensor` type here for the graph and dataset\n DLManagedTensor dataset;\n DLManagedTensor graph;\n\n cuvsDistanceType metric = L2Expanded;\n\n // Build the CAGRA Index from the graph/dataset\n cuvsError_t status = cuvsCagraIndexFromArgs(res, metric, &graph, &dataset, index);\n\n @endcode"]
1571 pub fn cuvsCagraIndexFromArgs(
1572 res: cuvsResources_t,
1573 metric: cuvsDistanceType,
1574 graph: *mut DLManagedTensor,
1575 dataset: *mut DLManagedTensor,
1576 index: cuvsCagraIndex_t,
1577 ) -> cuvsError_t;
1578}
1579unsafe extern "C" {
1580 #[must_use]
1581 #[doc = " @brief Merge multiple CAGRA indices into a single CAGRA index.\n\n All input indices must have been built with the same data type (`index.dtype`) and\n have the same dimensionality (`index.dims`). The merged index uses the output\n parameters specified in `cuvsCagraIndexParams`.\n\n Input indices must have:\n - `index.dtype.code` and `index.dtype.bits` matching across all indices.\n - Supported data types for indices:\n a. `kDLFloat` with `bits = 32`\n b. `kDLFloat` with `bits = 16`\n c. `kDLInt` with `bits = 8`\n d. `kDLUInt` with `bits = 8`\n\n The resulting output index will have the same data type as the input indices.\n\n Example:\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n cuvsCagraIndex_t index1, index2, merged_index;\n cuvsCagraIndexCreate(&index1);\n cuvsCagraIndexCreate(&index2);\n cuvsCagraIndexCreate(&merged_index);\n\n // Assume index1 and index2 have been built using cuvsCagraBuild\n\n cuvsCagraIndexParams_t merge_params;\n cuvsError_t params_create_status = cuvsCagraIndexParamsCreate(&merge_params);\n\n cuvsError_t merge_status = cuvsCagraMerge(res, merge_params, (cuvsCagraIndex_t[]){index1,\n index2}, 2, merged_index);\n\n // Use merged_index for search operations\n\n cuvsError_t params_destroy_status = cuvsCagraIndexParamsDestroy(merge_params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsCagraIndexParams_t parameters controlling merge behavior\n @param[in] indices Array of input cuvsCagraIndex_t handles to merge\n @param[in] num_indices Number of input indices\n @param[in] filter Filter that can be used to filter out vectors from the merged index\n @param[out] output_index Output handle that will store the merged index.\n Must be initialized using `cuvsCagraIndexCreate` before use."]
1582 pub fn cuvsCagraMerge(
1583 res: cuvsResources_t,
1584 params: cuvsCagraIndexParams_t,
1585 indices: *mut cuvsCagraIndex_t,
1586 num_indices: usize,
1587 filter: cuvsFilter,
1588 output_index: cuvsCagraIndex_t,
1589 ) -> cuvsError_t;
1590}
1591#[doc = " @defgroup ivf_flat_c_index_params IVF-Flat index build parameters\n @{\n/\n/**\n @brief Supplemental parameters to build IVF-Flat Index\n"]
1592#[repr(C)]
1593#[derive(Debug, Copy, Clone)]
1594pub struct cuvsIvfFlatIndexParams {
1595 #[doc = " Distance type."]
1596 pub metric: cuvsDistanceType,
1597 #[doc = " The argument used by some distance metrics."]
1598 pub metric_arg: f32,
1599 #[doc = " Whether to add the dataset content to the index, i.e.:\n\n - `true` means the index is filled with the dataset vectors and ready to search after calling\n `build`.\n - `false` means `build` only trains the underlying model (e.g. quantizer or clustering), but\n the index is left empty; you'd need to call `extend` on the index afterwards to populate it."]
1600 pub add_data_on_build: bool,
1601 #[doc = " The number of inverted lists (clusters)"]
1602 pub n_lists: u32,
1603 #[doc = " The number of iterations searching for kmeans centers (index building)."]
1604 pub kmeans_n_iters: u32,
1605 #[doc = " The fraction of data to use during iterative kmeans building."]
1606 pub kmeans_trainset_fraction: f64,
1607 #[doc = " By default (adaptive_centers = false), the cluster centers are trained in `ivf_flat::build`,\n and never modified in `ivf_flat::extend`. As a result, you may need to retrain the index\n from scratch after invoking (`ivf_flat::extend`) a few times with new data, the distribution of\n which is no longer representative of the original training set.\n\n The alternative behavior (adaptive_centers = true) is to update the cluster centers for new\n data when it is added. In this case, `index.centers()` are always exactly the centroids of the\n data in the corresponding clusters. The drawback of this behavior is that the centroids depend\n on the order of adding new data (through the classification of the added data); that is,\n `index.centers()` \"drift\" together with the changing distribution of the newly added data."]
1608 pub adaptive_centers: bool,
1609 #[doc = " By default, the algorithm allocates more space than necessary for individual clusters\n (`list_data`). This allows to amortize the cost of memory allocation and reduce the number of\n data copies during repeated calls to `extend` (extending the database).\n\n The alternative is the conservative allocation behavior; when enabled, the algorithm always\n allocates the minimum amount of memory required to store the given number of records. Set this\n flag to `true` if you prefer to use as little GPU memory for the database as possible."]
1610 pub conservative_memory_allocation: bool,
1611}
1612#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1613const _: () = {
1614 ["Size of cuvsIvfFlatIndexParams"][::std::mem::size_of::<cuvsIvfFlatIndexParams>() - 40usize];
1615 ["Alignment of cuvsIvfFlatIndexParams"]
1616 [::std::mem::align_of::<cuvsIvfFlatIndexParams>() - 8usize];
1617 ["Offset of field: cuvsIvfFlatIndexParams::metric"]
1618 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, metric) - 0usize];
1619 ["Offset of field: cuvsIvfFlatIndexParams::metric_arg"]
1620 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, metric_arg) - 4usize];
1621 ["Offset of field: cuvsIvfFlatIndexParams::add_data_on_build"]
1622 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, add_data_on_build) - 8usize];
1623 ["Offset of field: cuvsIvfFlatIndexParams::n_lists"]
1624 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, n_lists) - 12usize];
1625 ["Offset of field: cuvsIvfFlatIndexParams::kmeans_n_iters"]
1626 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, kmeans_n_iters) - 16usize];
1627 ["Offset of field: cuvsIvfFlatIndexParams::kmeans_trainset_fraction"]
1628 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, kmeans_trainset_fraction) - 24usize];
1629 ["Offset of field: cuvsIvfFlatIndexParams::adaptive_centers"]
1630 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, adaptive_centers) - 32usize];
1631 ["Offset of field: cuvsIvfFlatIndexParams::conservative_memory_allocation"]
1632 [::std::mem::offset_of!(cuvsIvfFlatIndexParams, conservative_memory_allocation) - 33usize];
1633};
1634pub type cuvsIvfFlatIndexParams_t = *mut cuvsIvfFlatIndexParams;
1635unsafe extern "C" {
1636 #[must_use]
1637 #[doc = " @brief Allocate IVF-Flat Index params, and populate with default values\n\n @param[in] index_params cuvsIvfFlatIndexParams_t to allocate\n @return cuvsError_t"]
1638 pub fn cuvsIvfFlatIndexParamsCreate(index_params: *mut cuvsIvfFlatIndexParams_t)
1639 -> cuvsError_t;
1640}
1641unsafe extern "C" {
1642 #[must_use]
1643 #[doc = " @brief De-allocate IVF-Flat Index params\n\n @param[in] index_params\n @return cuvsError_t"]
1644 pub fn cuvsIvfFlatIndexParamsDestroy(index_params: cuvsIvfFlatIndexParams_t) -> cuvsError_t;
1645}
1646#[doc = " @defgroup ivf_flat_c_search_params IVF-Flat index search parameters\n @{\n/\n/**\n @brief Supplemental parameters to search IVF-Flat index\n"]
1647#[repr(C)]
1648#[derive(Debug, Copy, Clone)]
1649pub struct cuvsIvfFlatSearchParams {
1650 #[doc = " The number of clusters to search."]
1651 pub n_probes: u32,
1652}
1653#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1654const _: () = {
1655 ["Size of cuvsIvfFlatSearchParams"][::std::mem::size_of::<cuvsIvfFlatSearchParams>() - 4usize];
1656 ["Alignment of cuvsIvfFlatSearchParams"]
1657 [::std::mem::align_of::<cuvsIvfFlatSearchParams>() - 4usize];
1658 ["Offset of field: cuvsIvfFlatSearchParams::n_probes"]
1659 [::std::mem::offset_of!(cuvsIvfFlatSearchParams, n_probes) - 0usize];
1660};
1661pub type cuvsIvfFlatSearchParams_t = *mut cuvsIvfFlatSearchParams;
1662unsafe extern "C" {
1663 #[must_use]
1664 #[doc = " @brief Allocate IVF-Flat search params, and populate with default values\n\n @param[in] params cuvsIvfFlatSearchParams_t to allocate\n @return cuvsError_t"]
1665 pub fn cuvsIvfFlatSearchParamsCreate(params: *mut cuvsIvfFlatSearchParams_t) -> cuvsError_t;
1666}
1667unsafe extern "C" {
1668 #[must_use]
1669 #[doc = " @brief De-allocate IVF-Flat search params\n\n @param[in] params\n @return cuvsError_t"]
1670 pub fn cuvsIvfFlatSearchParamsDestroy(params: cuvsIvfFlatSearchParams_t) -> cuvsError_t;
1671}
1672#[doc = " @defgroup ivf_flat_c_index IVF-Flat index\n @{\n/\n/**\n @brief Struct to hold address of cuvs::neighbors::ivf_flat::index and its active trained dtype\n"]
1673#[repr(C)]
1674#[derive(Debug, Copy, Clone)]
1675pub struct cuvsIvfFlatIndex {
1676 pub addr: usize,
1677 pub dtype: DLDataType,
1678}
1679#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1680const _: () = {
1681 ["Size of cuvsIvfFlatIndex"][::std::mem::size_of::<cuvsIvfFlatIndex>() - 16usize];
1682 ["Alignment of cuvsIvfFlatIndex"][::std::mem::align_of::<cuvsIvfFlatIndex>() - 8usize];
1683 ["Offset of field: cuvsIvfFlatIndex::addr"]
1684 [::std::mem::offset_of!(cuvsIvfFlatIndex, addr) - 0usize];
1685 ["Offset of field: cuvsIvfFlatIndex::dtype"]
1686 [::std::mem::offset_of!(cuvsIvfFlatIndex, dtype) - 8usize];
1687};
1688pub type cuvsIvfFlatIndex_t = *mut cuvsIvfFlatIndex;
1689unsafe extern "C" {
1690 #[must_use]
1691 #[doc = " @brief Allocate IVF-Flat index\n\n @param[in] index cuvsIvfFlatIndex_t to allocate\n @return cuvsError_t"]
1692 pub fn cuvsIvfFlatIndexCreate(index: *mut cuvsIvfFlatIndex_t) -> cuvsError_t;
1693}
1694unsafe extern "C" {
1695 #[must_use]
1696 #[doc = " @brief De-allocate IVF-Flat index\n\n @param[in] index cuvsIvfFlatIndex_t to de-allocate"]
1697 pub fn cuvsIvfFlatIndexDestroy(index: cuvsIvfFlatIndex_t) -> cuvsError_t;
1698}
1699unsafe extern "C" {
1700 #[must_use]
1701 #[doc = " Get the number of clusters/inverted lists"]
1702 pub fn cuvsIvfFlatIndexGetNLists(index: cuvsIvfFlatIndex_t, n_lists: *mut i64) -> cuvsError_t;
1703}
1704unsafe extern "C" {
1705 #[must_use]
1706 #[doc = " Get the dimensionality of the data"]
1707 pub fn cuvsIvfFlatIndexGetDim(index: cuvsIvfFlatIndex_t, dim: *mut i64) -> cuvsError_t;
1708}
1709unsafe extern "C" {
1710 #[must_use]
1711 #[doc = " @brief Get the cluster centers corresponding to the lists [n_lists, dim]\n\n @param[in] index cuvsIvfFlatIndex_t Built Ivf-Flat Index\n @param[out] centers Preallocated array on host or device memory to store output, [n_lists, dim]\n @return cuvsError_t"]
1712 pub fn cuvsIvfFlatIndexGetCenters(
1713 index: cuvsIvfFlatIndex_t,
1714 centers: *mut DLManagedTensor,
1715 ) -> cuvsError_t;
1716}
1717unsafe extern "C" {
1718 #[must_use]
1719 #[doc = " @defgroup ivf_flat_c_index_build IVF-Flat index build\n @{\n/\n/**\n @brief Build a IVF-Flat index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n 3. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/ivf_flat.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create default index params\n cuvsIvfFlatIndexParams_t index_params;\n cuvsError_t params_create_status = cuvsIvfFlatIndexParamsCreate(&index_params);\n\n // Create IVF-Flat index\n cuvsIvfFlatIndex_t index;\n cuvsError_t index_create_status = cuvsIvfFlatIndexCreate(&index);\n\n // Build the IVF-Flat Index\n cuvsError_t build_status = cuvsIvfFlatBuild(res, index_params, &dataset, index);\n\n // de-allocate `index_params`, `index` and `res`\n cuvsError_t params_destroy_status = cuvsIvfFlatIndexParamsDestroy(index_params);\n cuvsError_t index_destroy_status = cuvsIvfFlatIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index_params cuvsIvfFlatIndexParams_t used to build IVF-Flat index\n @param[in] dataset DLManagedTensor* training dataset\n @param[out] index cuvsIvfFlatIndex_t Newly built IVF-Flat index\n @return cuvsError_t"]
1720 pub fn cuvsIvfFlatBuild(
1721 res: cuvsResources_t,
1722 index_params: cuvsIvfFlatIndexParams_t,
1723 dataset: *mut DLManagedTensor,
1724 index: cuvsIvfFlatIndex_t,
1725 ) -> cuvsError_t;
1726}
1727unsafe extern "C" {
1728 #[must_use]
1729 #[doc = " @defgroup ivf_flat_c_index_search IVF-Flat index search\n @{\n/\n/**\n @brief Search a IVF-Flat index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`.\n It is also important to note that the IVF-Flat Index must have been built\n with the same type of `queries`, such that `index.dtype.code ==\n queries.dl_tensor.dtype.code` Types for input are:\n 1. `queries`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `neighbors`: `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 32`\n 3. `distances`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/ivf_flat.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n\n // Create default search params\n cuvsIvfFlatSearchParams_t search_params;\n cuvsError_t params_create_status = cuvsIvfFlatSearchParamsCreate(&search_params);\n\n // Search the `index` built using `ivfFlatBuild`\n cuvsError_t search_status = cuvsIvfFlatSearch(res, search_params, index, &queries, &neighbors,\n &distances);\n\n // de-allocate `search_params` and `res`\n cuvsError_t params_destroy_status = cuvsIvfFlatSearchParamsDestroy(search_params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] search_params cuvsIvfFlatSearchParams_t used to search IVF-Flat index\n @param[in] index ivfFlatIndex which has been returned by `ivfFlatBuild`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries\n @param[in] filter cuvsFilter input filter that can be used\nto filter queries and neighbors based on the given bitset."]
1730 pub fn cuvsIvfFlatSearch(
1731 res: cuvsResources_t,
1732 search_params: cuvsIvfFlatSearchParams_t,
1733 index: cuvsIvfFlatIndex_t,
1734 queries: *mut DLManagedTensor,
1735 neighbors: *mut DLManagedTensor,
1736 distances: *mut DLManagedTensor,
1737 filter: cuvsFilter,
1738 ) -> cuvsError_t;
1739}
1740unsafe extern "C" {
1741 #[must_use]
1742 #[doc = " @defgroup ivf_flat_c_index_serialize IVF-Flat C-API serialize functions\n @{\n/\n/**\n Save the index to file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @code{.cpp}\n #include <cuvs/neighbors/ivf_flat.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsIvfFlatBuild`\n cuvsIvfFlatSerialize(res, \"/path/to/index\", index, true);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file name for saving the index\n @param[in] index IVF-Flat index"]
1743 pub fn cuvsIvfFlatSerialize(
1744 res: cuvsResources_t,
1745 filename: *const ::std::os::raw::c_char,
1746 index: cuvsIvfFlatIndex_t,
1747 ) -> cuvsError_t;
1748}
1749unsafe extern "C" {
1750 #[must_use]
1751 #[doc = " Load index from file.\n\n Experimental, both the API and the serialization format are subject to change.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the name of the file that stores the index\n @param[out] index IVF-Flat index loaded disk"]
1752 pub fn cuvsIvfFlatDeserialize(
1753 res: cuvsResources_t,
1754 filename: *const ::std::os::raw::c_char,
1755 index: cuvsIvfFlatIndex_t,
1756 ) -> cuvsError_t;
1757}
1758unsafe extern "C" {
1759 #[must_use]
1760 #[doc = " @defgroup ivf_flat_c_index_extend IVF-Flat index extend\n @{\n/\n/**\n @brief Extend the index with the new data.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] new_vectors DLManagedTensor* the new vectors to add to the index\n @param[in] new_indices DLManagedTensor* vector of new indices for the new vectors\n @param[inout] index IVF-Flat index to be extended\n @return cuvsError_t"]
1761 pub fn cuvsIvfFlatExtend(
1762 res: cuvsResources_t,
1763 new_vectors: *mut DLManagedTensor,
1764 new_indices: *mut DLManagedTensor,
1765 index: cuvsIvfFlatIndex_t,
1766 ) -> cuvsError_t;
1767}
1768unsafe extern "C" {
1769 #[must_use]
1770 #[doc = " @defgroup ann_refine_c Approximate Nearest Neighbors Refinement C-API\n @{\n/\n/**\n @brief Refine nearest neighbor search.\n\n Refinement is an operation that follows an approximate NN search. The approximate search has\n already selected n_candidates neighbor candidates for each query. We narrow it down to k\n neighbors. For each query, we calculate the exact distance between the query and its\n n_candidates neighbor candidate, and select the k nearest ones.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] dataset device matrix that stores the dataset [n_rows, dims]\n @param[in] queries device matrix of the queries [n_queris, dims]\n @param[in] candidates indices of candidate vectors [n_queries, n_candidates], where\n n_candidates >= k\n @param[in] metric distance metric to use. Euclidean (L2) is used by default\n @param[out] indices device matrix that stores the refined indices [n_queries, k]\n @param[out] distances device matrix that stores the refined distances [n_queries, k]"]
1771 pub fn cuvsRefine(
1772 res: cuvsResources_t,
1773 dataset: *mut DLManagedTensor,
1774 queries: *mut DLManagedTensor,
1775 candidates: *mut DLManagedTensor,
1776 metric: cuvsDistanceType,
1777 indices: *mut DLManagedTensor,
1778 distances: *mut DLManagedTensor,
1779 ) -> cuvsError_t;
1780}
1781#[repr(u32)]
1782#[doc = " @brief Enum to hold which ANN algorithm is being used in the tiered index"]
1783#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
1784pub enum cuvsTieredIndexANNAlgo {
1785 CUVS_TIERED_INDEX_ALGO_CAGRA = 0,
1786 CUVS_TIERED_INDEX_ALGO_IVF_FLAT = 1,
1787 CUVS_TIERED_INDEX_ALGO_IVF_PQ = 2,
1788}
1789#[doc = " @defgroup tiered_index_c_index Tiered Index\n @{\n/\n/**\n @brief Struct to hold address of cuvs::neighbors::tiered_index::index and its active trained\n dtype\n"]
1790#[repr(C)]
1791#[derive(Debug, Copy, Clone)]
1792pub struct cuvsTieredIndex {
1793 pub addr: usize,
1794 pub dtype: DLDataType,
1795 pub algo: cuvsTieredIndexANNAlgo,
1796}
1797#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1798const _: () = {
1799 ["Size of cuvsTieredIndex"][::std::mem::size_of::<cuvsTieredIndex>() - 16usize];
1800 ["Alignment of cuvsTieredIndex"][::std::mem::align_of::<cuvsTieredIndex>() - 8usize];
1801 ["Offset of field: cuvsTieredIndex::addr"]
1802 [::std::mem::offset_of!(cuvsTieredIndex, addr) - 0usize];
1803 ["Offset of field: cuvsTieredIndex::dtype"]
1804 [::std::mem::offset_of!(cuvsTieredIndex, dtype) - 8usize];
1805 ["Offset of field: cuvsTieredIndex::algo"]
1806 [::std::mem::offset_of!(cuvsTieredIndex, algo) - 12usize];
1807};
1808pub type cuvsTieredIndex_t = *mut cuvsTieredIndex;
1809unsafe extern "C" {
1810 #[must_use]
1811 #[doc = " @brief Allocate Tiered Index\n\n @param[in] index cuvsTieredIndex_t to allocate\n @return cuvsError_t"]
1812 pub fn cuvsTieredIndexCreate(index: *mut cuvsTieredIndex_t) -> cuvsError_t;
1813}
1814unsafe extern "C" {
1815 #[must_use]
1816 #[doc = " @brief De-allocate Tiered index\n\n @param[in] index cuvsTieredIndex_t to de-allocate"]
1817 pub fn cuvsTieredIndexDestroy(index: cuvsTieredIndex_t) -> cuvsError_t;
1818}
1819#[doc = " @defgroup tiered_c_index_params Tiered Index build parameters\n @{\n/\n/**\n @brief Supplemental parameters to build a TieredIndex"]
1820#[repr(C)]
1821#[derive(Debug, Copy, Clone)]
1822pub struct cuvsTieredIndexParams {
1823 #[doc = " Distance type."]
1824 pub metric: cuvsDistanceType,
1825 #[doc = " The type of ANN algorithm we are using"]
1826 pub algo: cuvsTieredIndexANNAlgo,
1827 #[doc = " The minimum number of rows necessary in the index to create an\nann index"]
1828 pub min_ann_rows: i64,
1829 #[doc = " Whether or not to create a new ann index on extend, if the number\nof rows in the incremental (bfknn) portion is above min_ann_rows"]
1830 pub create_ann_index_on_extend: bool,
1831 #[doc = " Optional parameters for building a cagra index"]
1832 pub cagra_params: cuvsCagraIndexParams_t,
1833 #[doc = " Optional parameters for building a ivf_flat index"]
1834 pub ivf_flat_params: cuvsIvfFlatIndexParams_t,
1835 #[doc = " Optional parameters for building a ivf-pq index"]
1836 pub ivf_pq_params: cuvsIvfPqIndexParams_t,
1837}
1838#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1839const _: () = {
1840 ["Size of cuvsTieredIndexParams"][::std::mem::size_of::<cuvsTieredIndexParams>() - 48usize];
1841 ["Alignment of cuvsTieredIndexParams"]
1842 [::std::mem::align_of::<cuvsTieredIndexParams>() - 8usize];
1843 ["Offset of field: cuvsTieredIndexParams::metric"]
1844 [::std::mem::offset_of!(cuvsTieredIndexParams, metric) - 0usize];
1845 ["Offset of field: cuvsTieredIndexParams::algo"]
1846 [::std::mem::offset_of!(cuvsTieredIndexParams, algo) - 4usize];
1847 ["Offset of field: cuvsTieredIndexParams::min_ann_rows"]
1848 [::std::mem::offset_of!(cuvsTieredIndexParams, min_ann_rows) - 8usize];
1849 ["Offset of field: cuvsTieredIndexParams::create_ann_index_on_extend"]
1850 [::std::mem::offset_of!(cuvsTieredIndexParams, create_ann_index_on_extend) - 16usize];
1851 ["Offset of field: cuvsTieredIndexParams::cagra_params"]
1852 [::std::mem::offset_of!(cuvsTieredIndexParams, cagra_params) - 24usize];
1853 ["Offset of field: cuvsTieredIndexParams::ivf_flat_params"]
1854 [::std::mem::offset_of!(cuvsTieredIndexParams, ivf_flat_params) - 32usize];
1855 ["Offset of field: cuvsTieredIndexParams::ivf_pq_params"]
1856 [::std::mem::offset_of!(cuvsTieredIndexParams, ivf_pq_params) - 40usize];
1857};
1858pub type cuvsTieredIndexParams_t = *mut cuvsTieredIndexParams;
1859unsafe extern "C" {
1860 #[must_use]
1861 #[doc = " @brief Allocate Tiered Index Params and populate with default values\n\n @param[in] index_params cuvsTieredIndexParams_t to allocate\n @return cuvsError_t"]
1862 pub fn cuvsTieredIndexParamsCreate(index_params: *mut cuvsTieredIndexParams_t) -> cuvsError_t;
1863}
1864unsafe extern "C" {
1865 #[must_use]
1866 #[doc = " @brief De-allocate Tiered Index params\n\n @param[in] index_params\n @return cuvsError_t"]
1867 pub fn cuvsTieredIndexParamsDestroy(index_params: cuvsTieredIndexParams_t) -> cuvsError_t;
1868}
1869unsafe extern "C" {
1870 #[must_use]
1871 #[doc = " @defgroup tieredindex_c_index_build Tiered index build\n @{\n/\n/**\n @brief Build a TieredIndex index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCUDA`, `kDLCUDAHost`, `kDLCUDAManaged`,\n or `kDLCPU`. Also, acceptable underlying types are:\n 1. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n 2. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 16`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/tiered_index.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n\n // Create TieredIndex index\n cuvsTieredIndex_t index;\n cuvsError_t index_create_status = cuvsTieredIndexCreate(&index);\n\n // Create default index params\n cuvsTieredIndexParams_t index_params;\n cuvsError_t params_create_status = cuvsTieredIndexParamsCreate(&index_params);\n\n // Build the TieredIndex Index\n cuvsError_t build_status = cuvsTieredIndexBuild(res, index_params, &dataset_tensor, index);\n\n // de-allocate `index` and `res`\n cuvsError_t index_destroy_status = cuvsTieredIndexDestroy(index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] dataset DLManagedTensor* training dataset\n @param[in] index_params Index parameters to use when building the index\n @param[out] index cuvsTieredIndex_t Newly built TieredIndex index\n @return cuvsError_t"]
1872 pub fn cuvsTieredIndexBuild(
1873 res: cuvsResources_t,
1874 index_params: cuvsTieredIndexParams_t,
1875 dataset: *mut DLManagedTensor,
1876 index: cuvsTieredIndex_t,
1877 ) -> cuvsError_t;
1878}
1879unsafe extern "C" {
1880 #[must_use]
1881 #[doc = " @defgroup tieredindex_c_index_search Tiered index search\n @{\n/\n/**\n @brief Search a TieredIndex index with a `DLManagedTensor`\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/tiered_index.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n DLManagedTensor bitmap;\n\n cuvsFilter prefilter{(uintptr_t)&bitmap, BITMAP};\n\n // Search the `index` built using `cuvsTieredIndexBuild`\n cuvsError_t search_status = cuvsTieredIndexSearch(res, index, &queries, &neighbors, &distances,\n prefilter);\n\n // de-allocate `res`\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] search_params params used to the ANN index, should be one of\n cuvsCagraSearchParams_t, cuvsIvfFlatSearchParams_t, cuvsIvfPqSearchParams_t\n depending on the type of the tiered index used\n @param[in] index cuvsTieredIndex which has been returned by `cuvsTieredIndexBuild`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries\n @param[in] prefilter cuvsFilter input prefilter that can be used\nto filter queries and neighbors based on the given bitmap."]
1882 pub fn cuvsTieredIndexSearch(
1883 res: cuvsResources_t,
1884 search_params: *mut ::std::os::raw::c_void,
1885 index: cuvsTieredIndex_t,
1886 queries: *mut DLManagedTensor,
1887 neighbors: *mut DLManagedTensor,
1888 distances: *mut DLManagedTensor,
1889 prefilter: cuvsFilter,
1890 ) -> cuvsError_t;
1891}
1892unsafe extern "C" {
1893 #[must_use]
1894 #[doc = " @}\n/\n/**\n @defgroup tiered_c_index_extend Tiered index extend\n @{\n/\n/**\n @brief Extend the index with the new data.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] new_vectors DLManagedTensor* the new vectors to add to the index\n @param[inout] index Tiered index to be extended\n @return cuvsError_t"]
1895 pub fn cuvsTieredIndexExtend(
1896 res: cuvsResources_t,
1897 new_vectors: *mut DLManagedTensor,
1898 index: cuvsTieredIndex_t,
1899 ) -> cuvsError_t;
1900}
1901unsafe extern "C" {
1902 #[must_use]
1903 #[doc = " @defgroup tiered_c_index_merge Tiered index merge\n @{\n/\n/**\n @brief Merge multiple indices together into a single index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index_params Index parameters to use when merging\n @param[in] indices pointers to indices to merge together\n @param[in] num_indices the number of indices to merge\n @param[out] output_index the merged index\n @return cuvsError_t"]
1904 pub fn cuvsTieredIndexMerge(
1905 res: cuvsResources_t,
1906 index_params: cuvsTieredIndexParams_t,
1907 indices: *mut cuvsTieredIndex_t,
1908 num_indices: usize,
1909 output_index: cuvsTieredIndex_t,
1910 ) -> cuvsError_t;
1911}
1912#[doc = " @brief Supplemental parameters to build Vamana Index\n\n `graph_degree`: Maximum degree of graph; corresponds to the R parameter of\n Vamana algorithm in the literature.\n `visited_size`: Maximum number of visited nodes per search during Vamana algorithm.\n Loosely corresponds to the L parameter in the literature.\n `vamana_iters`: The number of times all vectors are inserted into the graph. If > 1,\n all vectors are re-inserted to improve graph quality.\n `max_fraction`: The maximum batch size is this fraction of the total dataset size. Larger\n gives faster build but lower graph quality.\n `alpha`: Used to determine how aggressive the pruning will be."]
1913#[repr(C)]
1914#[derive(Debug, Copy, Clone)]
1915pub struct cuvsVamanaIndexParams {
1916 #[doc = " Distance type."]
1917 pub metric: cuvsDistanceType,
1918 #[doc = " Maximum degree of output graph corresponds to the R parameter in the original Vamana\n literature."]
1919 pub graph_degree: u32,
1920 #[doc = " Maximum number of visited nodes per search corresponds to the L parameter in the Vamana\n literature"]
1921 pub visited_size: u32,
1922 #[doc = " Number of Vamana vector insertion iterations (each iteration inserts all vectors)."]
1923 pub vamana_iters: f32,
1924 #[doc = " Alpha for pruning parameter"]
1925 pub alpha: f32,
1926 #[doc = " Maximum fraction of dataset inserted per batch. *\n Larger max batch decreases graph quality, but improves speed"]
1927 pub max_fraction: f32,
1928 #[doc = " Base of growth rate of batch sizes"]
1929 pub batch_base: f32,
1930 #[doc = " Size of candidate queue structure - should be (2^x)-1"]
1931 pub queue_size: u32,
1932 #[doc = " Max batchsize of reverse edge processing (reduces memory footprint)"]
1933 pub reverse_batchsize: u32,
1934}
1935#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1936const _: () = {
1937 ["Size of cuvsVamanaIndexParams"][::std::mem::size_of::<cuvsVamanaIndexParams>() - 36usize];
1938 ["Alignment of cuvsVamanaIndexParams"]
1939 [::std::mem::align_of::<cuvsVamanaIndexParams>() - 4usize];
1940 ["Offset of field: cuvsVamanaIndexParams::metric"]
1941 [::std::mem::offset_of!(cuvsVamanaIndexParams, metric) - 0usize];
1942 ["Offset of field: cuvsVamanaIndexParams::graph_degree"]
1943 [::std::mem::offset_of!(cuvsVamanaIndexParams, graph_degree) - 4usize];
1944 ["Offset of field: cuvsVamanaIndexParams::visited_size"]
1945 [::std::mem::offset_of!(cuvsVamanaIndexParams, visited_size) - 8usize];
1946 ["Offset of field: cuvsVamanaIndexParams::vamana_iters"]
1947 [::std::mem::offset_of!(cuvsVamanaIndexParams, vamana_iters) - 12usize];
1948 ["Offset of field: cuvsVamanaIndexParams::alpha"]
1949 [::std::mem::offset_of!(cuvsVamanaIndexParams, alpha) - 16usize];
1950 ["Offset of field: cuvsVamanaIndexParams::max_fraction"]
1951 [::std::mem::offset_of!(cuvsVamanaIndexParams, max_fraction) - 20usize];
1952 ["Offset of field: cuvsVamanaIndexParams::batch_base"]
1953 [::std::mem::offset_of!(cuvsVamanaIndexParams, batch_base) - 24usize];
1954 ["Offset of field: cuvsVamanaIndexParams::queue_size"]
1955 [::std::mem::offset_of!(cuvsVamanaIndexParams, queue_size) - 28usize];
1956 ["Offset of field: cuvsVamanaIndexParams::reverse_batchsize"]
1957 [::std::mem::offset_of!(cuvsVamanaIndexParams, reverse_batchsize) - 32usize];
1958};
1959pub type cuvsVamanaIndexParams_t = *mut cuvsVamanaIndexParams;
1960unsafe extern "C" {
1961 #[must_use]
1962 #[doc = " @brief Allocate Vamana Index params, and populate with default values\n\n @param[in] params cuvsVamanaIndexParams_t to allocate\n @return cuvsError_t"]
1963 pub fn cuvsVamanaIndexParamsCreate(params: *mut cuvsVamanaIndexParams_t) -> cuvsError_t;
1964}
1965unsafe extern "C" {
1966 #[must_use]
1967 #[doc = " @brief De-allocate Vamana Index params\n\n @param[in] params cuvsVamanaIndexParams_t to de-allocate\n @return cuvsError_t"]
1968 pub fn cuvsVamanaIndexParamsDestroy(params: cuvsVamanaIndexParams_t) -> cuvsError_t;
1969}
1970#[doc = " @brief Struct to hold address of cuvs::neighbors::vamana::index and its active trained dtype\n"]
1971#[repr(C)]
1972#[derive(Debug, Copy, Clone)]
1973pub struct cuvsVamanaIndex {
1974 pub addr: usize,
1975 pub dtype: DLDataType,
1976}
1977#[allow(clippy::unnecessary_operation, clippy::identity_op)]
1978const _: () = {
1979 ["Size of cuvsVamanaIndex"][::std::mem::size_of::<cuvsVamanaIndex>() - 16usize];
1980 ["Alignment of cuvsVamanaIndex"][::std::mem::align_of::<cuvsVamanaIndex>() - 8usize];
1981 ["Offset of field: cuvsVamanaIndex::addr"]
1982 [::std::mem::offset_of!(cuvsVamanaIndex, addr) - 0usize];
1983 ["Offset of field: cuvsVamanaIndex::dtype"]
1984 [::std::mem::offset_of!(cuvsVamanaIndex, dtype) - 8usize];
1985};
1986pub type cuvsVamanaIndex_t = *mut cuvsVamanaIndex;
1987unsafe extern "C" {
1988 #[must_use]
1989 #[doc = " @brief Allocate Vamana index\n\n @param[in] index cuvsVamanaIndex_t to allocate\n @return cuvsError_t"]
1990 pub fn cuvsVamanaIndexCreate(index: *mut cuvsVamanaIndex_t) -> cuvsError_t;
1991}
1992unsafe extern "C" {
1993 #[must_use]
1994 #[doc = " @brief De-allocate Vamana index\n\n @param[in] index cuvsVamanaIndex_t to de-allocate\n @return cuvsError_t"]
1995 pub fn cuvsVamanaIndexDestroy(index: cuvsVamanaIndex_t) -> cuvsError_t;
1996}
1997unsafe extern "C" {
1998 #[must_use]
1999 #[doc = " @brief Get the dimension of the index\n\n @param[in] index cuvsVamanaIndex_t to get dimension of\n @param[out] dim pointer to dimension to set\n @return cuvsError_t"]
2000 pub fn cuvsVamanaIndexGetDims(
2001 index: cuvsVamanaIndex_t,
2002 dim: *mut ::std::os::raw::c_int,
2003 ) -> cuvsError_t;
2004}
2005unsafe extern "C" {
2006 #[must_use]
2007 #[doc = " @brief Build Vamana index\n\n Build the index from the dataset for efficient DiskANN search.\n\n The build uses the Vamana insertion-based algorithm to create the graph. The algorithm\n starts with an empty graph and iteratively inserts batches of nodes. Each batch involves\n performing a greedy search for each vector to be inserted, and inserting it with edges to\n all nodes traversed during the search. Reverse edges are also inserted and robustPrune is applied\n to improve graph quality. The index_params struct controls the degree of the final graph.\n\n The following distance metrics are supported:\n - L2\n\n Usage example:\n @code{.c}\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsResourcesCreate(&res);\n\n // Assume a row-major dataset [n_rows, n_cols] is defined as `float* dataset`\n cuvsVamanaIndexParams_t index_params;\n cuvsVamanaIndexParamsCreate(&index_params);\n index_params->metric = L2Expanded; // set distance metric\n cuvsVamanaIndex_t index;\n cuvsVamanaIndexCreate(&index);\n cuvsVamanaBuild(res, index_params, dataset, index);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsVamanaIndexParams_t used to build Vamana index\n @param[in] dataset DLManagedTensor* training dataset\n @param[out] index cuvsVamanaIndex_t Vamana index\n @return cuvsError_t"]
2008 pub fn cuvsVamanaBuild(
2009 res: cuvsResources_t,
2010 params: cuvsVamanaIndexParams_t,
2011 dataset: *mut DLManagedTensor,
2012 index: cuvsVamanaIndex_t,
2013 ) -> cuvsError_t;
2014}
2015unsafe extern "C" {
2016 #[must_use]
2017 #[doc = " @brief Save Vamana index to file\n\n Matches the file format used by the DiskANN open-source repository, allowing cross-compatibility.\n\n Serialized Index is to be used by the DiskANN open-source repository for graph search.\n\n @code{.c}\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsResourcesCreate(&res);\n\n // create an index with `cuvsVamanaBuild`\n cuvsVamanaSerialize(res, \"/path/to/index\", index, true);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the file prefix for where the index is saved\n @param[in] index cuvsVamanaIndex_t to serialize\n @param[in] include_dataset whether to include the dataset in the serialized index\n @return cuvsError_t"]
2018 pub fn cuvsVamanaSerialize(
2019 res: cuvsResources_t,
2020 filename: *const ::std::os::raw::c_char,
2021 index: cuvsVamanaIndex_t,
2022 include_dataset: bool,
2023 ) -> cuvsError_t;
2024}
2025#[repr(u32)]
2026#[doc = " @brief Hierarchy for HNSW index when converting from CAGRA index\n\n NOTE: When the value is `NONE`, the HNSW index is built as a base-layer-only index."]
2027#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2028pub enum cuvsHnswHierarchy {
2029 NONE = 0,
2030 CPU = 1,
2031 GPU = 2,
2032}
2033#[doc = " Parameters for ACE (Augmented Core Extraction) graph build for HNSW.\n ACE enables building indexes for datasets too large to fit in GPU memory by:\n 1. Partitioning the dataset in core and augmented partitions using balanced k-means\n 2. Building sub-indexes for each partition independently\n 3. Concatenating sub-graphs into a final unified index"]
2034#[repr(C)]
2035#[derive(Debug, Copy, Clone)]
2036pub struct cuvsHnswAceParams {
2037 #[doc = " Number of partitions for ACE partitioned build.\n\n When set to 0 (default), the number of partitions is automatically derived\n based on available host and GPU memory to maximize partition size while\n ensuring the build fits in memory.\n\n Small values might improve recall but potentially degrade performance and\n increase memory usage. The partition size is on average 2 * (n_rows /\n npartitions) * dim * sizeof(T). 2 is because of the core and augmented\n vectors. Please account for imbalance in the partition sizes (up to 3x in\n our tests).\n\n If the specified number of partitions results in partitions that exceed\n available memory, the value will be automatically increased to fit memory\n constraints and a warning will be issued."]
2038 pub npartitions: usize,
2039 #[doc = " Directory to store ACE build artifacts (e.g., KNN graph, optimized graph).\n Used when `use_disk` is true or when the graph does not fit in memory."]
2040 pub build_dir: *const ::std::os::raw::c_char,
2041 #[doc = " Whether to use disk-based storage for ACE build.\n When true, enables disk-based operations for memory-efficient graph construction."]
2042 pub use_disk: bool,
2043 #[doc = " Maximum host memory to use for ACE build in GiB.\n When set to 0 (default), uses available host memory.\n Useful for testing or when running alongside other memory-intensive processes."]
2044 pub max_host_memory_gb: f64,
2045 #[doc = " Maximum GPU memory to use for ACE build in GiB.\n When set to 0 (default), uses available GPU memory.\n Useful for testing or when running alongside other memory-intensive processes."]
2046 pub max_gpu_memory_gb: f64,
2047}
2048#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2049const _: () = {
2050 ["Size of cuvsHnswAceParams"][::std::mem::size_of::<cuvsHnswAceParams>() - 40usize];
2051 ["Alignment of cuvsHnswAceParams"][::std::mem::align_of::<cuvsHnswAceParams>() - 8usize];
2052 ["Offset of field: cuvsHnswAceParams::npartitions"]
2053 [::std::mem::offset_of!(cuvsHnswAceParams, npartitions) - 0usize];
2054 ["Offset of field: cuvsHnswAceParams::build_dir"]
2055 [::std::mem::offset_of!(cuvsHnswAceParams, build_dir) - 8usize];
2056 ["Offset of field: cuvsHnswAceParams::use_disk"]
2057 [::std::mem::offset_of!(cuvsHnswAceParams, use_disk) - 16usize];
2058 ["Offset of field: cuvsHnswAceParams::max_host_memory_gb"]
2059 [::std::mem::offset_of!(cuvsHnswAceParams, max_host_memory_gb) - 24usize];
2060 ["Offset of field: cuvsHnswAceParams::max_gpu_memory_gb"]
2061 [::std::mem::offset_of!(cuvsHnswAceParams, max_gpu_memory_gb) - 32usize];
2062};
2063pub type cuvsHnswAceParams_t = *mut cuvsHnswAceParams;
2064unsafe extern "C" {
2065 #[must_use]
2066 #[doc = " @brief Allocate HNSW ACE params, and populate with default values\n\n @param[in] params cuvsHnswAceParams_t to allocate\n @return cuvsError_t"]
2067 pub fn cuvsHnswAceParamsCreate(params: *mut cuvsHnswAceParams_t) -> cuvsError_t;
2068}
2069unsafe extern "C" {
2070 #[must_use]
2071 #[doc = " @brief De-allocate HNSW ACE params\n\n @param[in] params\n @return cuvsError_t"]
2072 pub fn cuvsHnswAceParamsDestroy(params: cuvsHnswAceParams_t) -> cuvsError_t;
2073}
2074#[repr(C)]
2075#[derive(Debug, Copy, Clone)]
2076pub struct cuvsHnswIndexParams {
2077 pub hierarchy: cuvsHnswHierarchy,
2078 #[doc = " Size of the candidate list during hierarchy construction when hierarchy is `CPU`"]
2079 pub ef_construction: ::std::os::raw::c_int,
2080 #[doc = " Number of host threads to use to construct hierarchy when hierarchy is `CPU` or `GPU`.\nWhen the value is 0, the number of threads is automatically determined to the\nmaximum number of threads available.\nNOTE: When hierarchy is `GPU`, while the majority of the work is done on the GPU,\ninitialization of the HNSW index itself and some other work\nis parallelized with the help of CPU threads."]
2081 pub num_threads: ::std::os::raw::c_int,
2082 #[doc = " HNSW M parameter: number of bi-directional links per node (used when building with ACE).\n graph_degree = m * 2, intermediate_graph_degree = m * 3."]
2083 pub M: usize,
2084 #[doc = " Distance type for the index."]
2085 pub metric: cuvsDistanceType,
2086 #[doc = " Optional: specify ACE parameters for building HNSW index using ACE algorithm.\n Set to nullptr for default behavior (from_cagra conversion)."]
2087 pub ace_params: cuvsHnswAceParams_t,
2088}
2089#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2090const _: () = {
2091 ["Size of cuvsHnswIndexParams"][::std::mem::size_of::<cuvsHnswIndexParams>() - 40usize];
2092 ["Alignment of cuvsHnswIndexParams"][::std::mem::align_of::<cuvsHnswIndexParams>() - 8usize];
2093 ["Offset of field: cuvsHnswIndexParams::hierarchy"]
2094 [::std::mem::offset_of!(cuvsHnswIndexParams, hierarchy) - 0usize];
2095 ["Offset of field: cuvsHnswIndexParams::ef_construction"]
2096 [::std::mem::offset_of!(cuvsHnswIndexParams, ef_construction) - 4usize];
2097 ["Offset of field: cuvsHnswIndexParams::num_threads"]
2098 [::std::mem::offset_of!(cuvsHnswIndexParams, num_threads) - 8usize];
2099 ["Offset of field: cuvsHnswIndexParams::M"]
2100 [::std::mem::offset_of!(cuvsHnswIndexParams, M) - 16usize];
2101 ["Offset of field: cuvsHnswIndexParams::metric"]
2102 [::std::mem::offset_of!(cuvsHnswIndexParams, metric) - 24usize];
2103 ["Offset of field: cuvsHnswIndexParams::ace_params"]
2104 [::std::mem::offset_of!(cuvsHnswIndexParams, ace_params) - 32usize];
2105};
2106pub type cuvsHnswIndexParams_t = *mut cuvsHnswIndexParams;
2107unsafe extern "C" {
2108 #[must_use]
2109 #[doc = " @brief Allocate HNSW Index params, and populate with default values\n\n @param[in] params cuvsHnswIndexParams_t to allocate\n @return cuvsError_t"]
2110 pub fn cuvsHnswIndexParamsCreate(params: *mut cuvsHnswIndexParams_t) -> cuvsError_t;
2111}
2112unsafe extern "C" {
2113 #[must_use]
2114 #[doc = " @brief De-allocate HNSW Index params\n\n @param[in] params\n @return cuvsError_t"]
2115 pub fn cuvsHnswIndexParamsDestroy(params: cuvsHnswIndexParams_t) -> cuvsError_t;
2116}
2117#[doc = " @brief Struct to hold address of cuvs::neighbors::Hnsw::index and its active trained dtype\n"]
2118#[repr(C)]
2119#[derive(Debug, Copy, Clone)]
2120pub struct cuvsHnswIndex {
2121 pub addr: usize,
2122 pub dtype: DLDataType,
2123}
2124#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2125const _: () = {
2126 ["Size of cuvsHnswIndex"][::std::mem::size_of::<cuvsHnswIndex>() - 16usize];
2127 ["Alignment of cuvsHnswIndex"][::std::mem::align_of::<cuvsHnswIndex>() - 8usize];
2128 ["Offset of field: cuvsHnswIndex::addr"][::std::mem::offset_of!(cuvsHnswIndex, addr) - 0usize];
2129 ["Offset of field: cuvsHnswIndex::dtype"]
2130 [::std::mem::offset_of!(cuvsHnswIndex, dtype) - 8usize];
2131};
2132pub type cuvsHnswIndex_t = *mut cuvsHnswIndex;
2133unsafe extern "C" {
2134 #[must_use]
2135 #[doc = " @brief Allocate HNSW index\n\n @param[in] index cuvsHnswIndex_t to allocate\n @return HnswError_t"]
2136 pub fn cuvsHnswIndexCreate(index: *mut cuvsHnswIndex_t) -> cuvsError_t;
2137}
2138unsafe extern "C" {
2139 #[must_use]
2140 #[doc = " @brief De-allocate HNSW index\n\n @param[in] index cuvsHnswIndex_t to de-allocate"]
2141 pub fn cuvsHnswIndexDestroy(index: cuvsHnswIndex_t) -> cuvsError_t;
2142}
2143#[doc = " @defgroup hnsw_c_extend_params Parameters for extending HNSW index\n @{"]
2144#[repr(C)]
2145#[derive(Debug, Copy, Clone)]
2146pub struct cuvsHnswExtendParams {
2147 #[doc = " Number of CPU threads used to extend additional vectors"]
2148 pub num_threads: ::std::os::raw::c_int,
2149}
2150#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2151const _: () = {
2152 ["Size of cuvsHnswExtendParams"][::std::mem::size_of::<cuvsHnswExtendParams>() - 4usize];
2153 ["Alignment of cuvsHnswExtendParams"][::std::mem::align_of::<cuvsHnswExtendParams>() - 4usize];
2154 ["Offset of field: cuvsHnswExtendParams::num_threads"]
2155 [::std::mem::offset_of!(cuvsHnswExtendParams, num_threads) - 0usize];
2156};
2157pub type cuvsHnswExtendParams_t = *mut cuvsHnswExtendParams;
2158unsafe extern "C" {
2159 #[must_use]
2160 #[doc = " @brief Allocate HNSW extend params, and populate with default values\n\n @param[in] params cuvsHnswExtendParams_t to allocate\n @return cuvsError_t"]
2161 pub fn cuvsHnswExtendParamsCreate(params: *mut cuvsHnswExtendParams_t) -> cuvsError_t;
2162}
2163unsafe extern "C" {
2164 #[must_use]
2165 #[doc = " @brief De-allocate HNSW extend params\n\n @param[in] params cuvsHnswExtendParams_t to de-allocate\n @return cuvsError_t"]
2166 pub fn cuvsHnswExtendParamsDestroy(params: cuvsHnswExtendParams_t) -> cuvsError_t;
2167}
2168unsafe extern "C" {
2169 #[must_use]
2170 #[doc = " @brief Convert a CAGRA Index to an HNSW index.\n NOTE: When hierarchy is:\n 1. `NONE`: This method uses the filesystem to write the CAGRA index in\n `/tmp/<random_number>.bin` before reading it as an hnswlib index, then deleting the temporary\n file. The returned index is immutable and can only be searched by the hnswlib wrapper in cuVS,\n as the format is not compatible with the original hnswlib.\n 2. `CPU`: The returned index is mutable and can be extended with additional vectors. The\n serialized index is also compatible with the original hnswlib library.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsHnswIndexParams_t used to load Hnsw index\n @param[in] cagra_index cuvsCagraIndex_t to convert to HNSW index\n @param[out] hnsw_index cuvsHnswIndex_t to return the HNSW index\n\n @return cuvsError_t\n\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n #include <cuvs/neighbors/hnsw.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create a CAGRA index with `cuvsCagraBuild`\n\n // Convert the CAGRA index to an HNSW index\n cuvsHnswIndex_t hnsw_index;\n cuvsHnswIndexCreate(&hnsw_index);\n cuvsHnswIndexParams_t hnsw_params;\n cuvsHnswIndexParamsCreate(&hnsw_params);\n cuvsHnswFromCagra(res, hnsw_params, cagra_index, hnsw_index);\n\n // de-allocate `hnsw_params`, `hnsw_index` and `res`\n cuvsError_t hnsw_params_destroy_status = cuvsHnswIndexParamsDestroy(hnsw_params);\n cuvsError_t hnsw_index_destroy_status = cuvsHnswIndexDestroy(hnsw_index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode"]
2171 pub fn cuvsHnswFromCagra(
2172 res: cuvsResources_t,
2173 params: cuvsHnswIndexParams_t,
2174 cagra_index: cuvsCagraIndex_t,
2175 hnsw_index: cuvsHnswIndex_t,
2176 ) -> cuvsError_t;
2177}
2178unsafe extern "C" {
2179 #[must_use]
2180 pub fn cuvsHnswFromCagraWithDataset(
2181 res: cuvsResources_t,
2182 params: cuvsHnswIndexParams_t,
2183 cagra_index: cuvsCagraIndex_t,
2184 hnsw_index: cuvsHnswIndex_t,
2185 dataset_tensor: *mut DLManagedTensor,
2186 ) -> cuvsError_t;
2187}
2188unsafe extern "C" {
2189 #[must_use]
2190 #[doc = " @brief Build an HNSW index using ACE (Augmented Core Extraction) algorithm.\n\n ACE enables building HNSW indexes for datasets too large to fit in GPU memory by:\n 1. Partitioning the dataset using balanced k-means into core and augmented partitions\n 2. Building sub-indexes for each partition independently\n 3. Concatenating sub-graphs into a final unified index\n\n NOTE: This function requires CUDA to be available at runtime.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsHnswIndexParams_t with ACE parameters configured\n @param[in] dataset DLManagedTensor* host dataset to build index from\n @param[out] index cuvsHnswIndex_t to return the built HNSW index\n\n @return cuvsError_t\n\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/hnsw.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsResourcesCreate(&res);\n\n // Create ACE parameters\n cuvsHnswAceParams_t ace_params;\n cuvsHnswAceParamsCreate(&ace_params);\n ace_params->npartitions = 4;\n ace_params->use_disk = true;\n ace_params->build_dir = \"/tmp/hnsw_ace_build\";\n\n // Create index parameters\n cuvsHnswIndexParams_t params;\n cuvsHnswIndexParamsCreate(¶ms);\n params->hierarchy = GPU;\n params->ace_params = ace_params;\n params->M = 32;\n params->ef_construction = 120;\n\n // Create HNSW index\n cuvsHnswIndex_t hnsw_index;\n cuvsHnswIndexCreate(&hnsw_index);\n\n // Assume dataset is a populated DLManagedTensor with host data\n DLManagedTensor dataset;\n\n // Build the index\n cuvsHnswBuild(res, params, &dataset, hnsw_index);\n\n // Clean up\n cuvsHnswAceParamsDestroy(ace_params);\n cuvsHnswIndexParamsDestroy(params);\n cuvsHnswIndexDestroy(hnsw_index);\n cuvsResourcesDestroy(res);\n @endcode"]
2191 pub fn cuvsHnswBuild(
2192 res: cuvsResources_t,
2193 params: cuvsHnswIndexParams_t,
2194 dataset: *mut DLManagedTensor,
2195 index: cuvsHnswIndex_t,
2196 ) -> cuvsError_t;
2197}
2198unsafe extern "C" {
2199 #[must_use]
2200 #[doc = " @brief Add new vectors to an HNSW index\n NOTE: The HNSW index can only be extended when the hierarchy is `CPU`\n when converting from a CAGRA index.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsHnswExtendParams_t used to extend Hnsw index\n @param[in] additional_dataset DLManagedTensor* additional dataset to extend the index\n @param[inout] index cuvsHnswIndex_t to extend\n\n @return cuvsError_t\n\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n #include <cuvs/neighbors/hnsw.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsCagraBuild`\n\n // Convert the CAGRA index to an HNSW index\n cuvsHnswIndex_t hnsw_index;\n cuvsHnswIndexCreate(&hnsw_index);\n cuvsHnswIndexParams_t hnsw_params;\n cuvsHnswIndexParamsCreate(&hnsw_params);\n cuvsHnswFromCagra(res, hnsw_params, cagra_index, hnsw_index);\n\n // Extend the HNSW index with additional vectors\n DLManagedTensor additional_dataset;\n cuvsHnswExtendParams_t extend_params;\n cuvsHnswExtendParamsCreate(&extend_params);\n cuvsHnswExtend(res, extend_params, additional_dataset, hnsw_index);\n\n // de-allocate `hnsw_params`, `hnsw_index`, `extend_params` and `res`\n cuvsError_t hnsw_params_destroy_status = cuvsHnswIndexParamsDestroy(hnsw_params);\n cuvsError_t hnsw_index_destroy_status = cuvsHnswIndexDestroy(hnsw_index);\n cuvsError_t extend_params_destroy_status = cuvsHnswExtendParamsDestroy(extend_params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode"]
2201 pub fn cuvsHnswExtend(
2202 res: cuvsResources_t,
2203 params: cuvsHnswExtendParams_t,
2204 additional_dataset: *mut DLManagedTensor,
2205 index: cuvsHnswIndex_t,
2206 ) -> cuvsError_t;
2207}
2208#[doc = " @defgroup hnsw_c_search_params C API for hnswlib wrapper search params\n @{"]
2209#[repr(C)]
2210#[derive(Debug, Copy, Clone)]
2211pub struct cuvsHnswSearchParams {
2212 pub ef: i32,
2213 pub num_threads: i32,
2214}
2215#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2216const _: () = {
2217 ["Size of cuvsHnswSearchParams"][::std::mem::size_of::<cuvsHnswSearchParams>() - 8usize];
2218 ["Alignment of cuvsHnswSearchParams"][::std::mem::align_of::<cuvsHnswSearchParams>() - 4usize];
2219 ["Offset of field: cuvsHnswSearchParams::ef"]
2220 [::std::mem::offset_of!(cuvsHnswSearchParams, ef) - 0usize];
2221 ["Offset of field: cuvsHnswSearchParams::num_threads"]
2222 [::std::mem::offset_of!(cuvsHnswSearchParams, num_threads) - 4usize];
2223};
2224pub type cuvsHnswSearchParams_t = *mut cuvsHnswSearchParams;
2225unsafe extern "C" {
2226 #[must_use]
2227 #[doc = " @brief Allocate HNSW search params, and populate with default values\n\n @param[in] params cuvsHnswSearchParams_t to allocate\n @return cuvsError_t"]
2228 pub fn cuvsHnswSearchParamsCreate(params: *mut cuvsHnswSearchParams_t) -> cuvsError_t;
2229}
2230unsafe extern "C" {
2231 #[must_use]
2232 #[doc = " @brief De-allocate HNSW search params\n\n @param[in] params cuvsHnswSearchParams_t to de-allocate\n @return cuvsError_t"]
2233 pub fn cuvsHnswSearchParamsDestroy(params: cuvsHnswSearchParams_t) -> cuvsError_t;
2234}
2235unsafe extern "C" {
2236 #[must_use]
2237 #[doc = " @defgroup hnsw_c_index_search C API for CUDA ANN Graph-based nearest neighbor search\n @{\n/\n/**\n @brief Search a HNSW index with a `DLManagedTensor` which has underlying\n `DLDeviceType` equal to `kDLCPU`, `kDLCUDAHost`, or `kDLCUDAManaged`.\n It is also important to note that the HNSW Index must have been built\n with the same type of `queries`, such that `index.dtype.code ==\n queries.dl_tensor.dtype.code`\n Supported types for input are:\n 1. `queries`:\n a. `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n b. `kDLDataType.code == kDLInt` and `kDLDataType.bits = 8`\n c. `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 8`\n 2. `neighbors`: `kDLDataType.code == kDLUInt` and `kDLDataType.bits = 64`\n 3. `distances`: `kDLDataType.code == kDLFloat` and `kDLDataType.bits = 32`\n NOTE: When hierarchy is `NONE`, the HNSW index can only be searched by the hnswlib wrapper in\n cuVS, as the format is not compatible with the original hnswlib.\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/hnsw.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // Assume a populated `DLManagedTensor` type here\n DLManagedTensor dataset;\n DLManagedTensor queries;\n DLManagedTensor neighbors;\n\n // Create default search params\n cuvsHnswSearchParams_t params;\n cuvsError_t params_create_status = cuvsHnswSearchParamsCreate(¶ms);\n\n // Search the `index` built using `cuvsHnswFromCagra`\n cuvsError_t search_status = cuvsHnswSearch(res, params, index, &queries, &neighbors,\n &distances);\n\n // de-allocate `params` and `res`\n cuvsError_t params_destroy_status = cuvsHnswSearchParamsDestroy(params);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsHnswSearchParams_t used to search Hnsw index\n @param[in] index cuvsHnswIndex which has been returned by `cuvsHnswFromCagra`\n @param[in] queries DLManagedTensor* queries dataset to search\n @param[out] neighbors DLManagedTensor* output `k` neighbors for queries\n @param[out] distances DLManagedTensor* output `k` distances for queries"]
2238 pub fn cuvsHnswSearch(
2239 res: cuvsResources_t,
2240 params: cuvsHnswSearchParams_t,
2241 index: cuvsHnswIndex_t,
2242 queries: *mut DLManagedTensor,
2243 neighbors: *mut DLManagedTensor,
2244 distances: *mut DLManagedTensor,
2245 ) -> cuvsError_t;
2246}
2247unsafe extern "C" {
2248 #[must_use]
2249 #[doc = " @brief Serialize a CAGRA index to a file as an hnswlib index\n NOTE: When hierarchy is `NONE`, the saved hnswlib index is immutable and can only be read by\n the hnswlib wrapper in cuVS, as the serialization format is not compatible with the original\n hnswlib. However, when hierarchy is `CPU`, the saved hnswlib index is compatible with the\n original hnswlib library.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename the name of the file to save the index\n @param[in] index cuvsHnswIndex_t to serialize\n @return cuvsError_t\n\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n #include <cuvs/neighbors/hnsw.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsCagraBuild`\n\n // Convert the CAGRA index to an HNSW index\n cuvsHnswIndex_t hnsw_index;\n cuvsHnswIndexCreate(&hnsw_index);\n cuvsHnswIndexParams_t hnsw_params;\n cuvsHnswIndexParamsCreate(&hnsw_params);\n cuvsHnswFromCagra(res, hnsw_params, cagra_index, hnsw_index);\n\n // Serialize the HNSW index\n cuvsHnswSerialize(res, \"/path/to/index\", hnsw_index);\n\n // de-allocate `hnsw_params`, `hnsw_index` and `res`\n cuvsError_t hnsw_params_destroy_status = cuvsHnswIndexParamsDestroy(hnsw_params);\n cuvsError_t hnsw_index_destroy_status = cuvsHnswIndexDestroy(hnsw_index);\n cuvsError_t res_destroy_status = cuvsResourcesDestroy(res);\n @endcode"]
2250 pub fn cuvsHnswSerialize(
2251 res: cuvsResources_t,
2252 filename: *const ::std::os::raw::c_char,
2253 index: cuvsHnswIndex_t,
2254 ) -> cuvsError_t;
2255}
2256unsafe extern "C" {
2257 #[must_use]
2258 #[doc = " Load hnswlib index from file which was serialized from a HNSW index.\n NOTE: When hierarchy is `NONE`, the loaded hnswlib index is immutable, and only be read by the\n hnswlib wrapper in cuVS, as the serialization format is not compatible with the original\n hnswlib. Experimental, both the API and the serialization format are subject to change.\n\n @code{.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/neighbors/cagra.h>\n #include <cuvs/neighbors/hnsw.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsError_t res_create_status = cuvsResourcesCreate(&res);\n\n // create an index with `cuvsCagraBuild`\n cuvsCagraSerializeHnswlib(res, \"/path/to/index\", index);\n\n // Load the serialized CAGRA index from file as an hnswlib index\n // The index should have the same dtype as the one used to build CAGRA the index\n cuvsHnswIndex_t hnsw_index;\n cuvsHnswIndexCreate(&hnsw_index);\n cuvsHnsWIndexParams_t hnsw_params;\n cuvsHnswIndexParamsCreate(&hnsw_params);\n hnsw_params->hierarchy = NONE;\n hnsw_index->dtype = index->dtype;\n cuvsHnswDeserialize(res, hnsw_params, \"/path/to/index\", dim, metric hnsw_index);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params cuvsHnswIndexParams_t used to load Hnsw index\n @param[in] filename the name of the file that stores the index\n @param[in] dim the dimension of the vectors in the index\n @param[in] metric the distance metric used to build the index\n @param[out] index HNSW index loaded disk"]
2259 pub fn cuvsHnswDeserialize(
2260 res: cuvsResources_t,
2261 params: cuvsHnswIndexParams_t,
2262 filename: *const ::std::os::raw::c_char,
2263 dim: ::std::os::raw::c_int,
2264 metric: cuvsDistanceType,
2265 index: cuvsHnswIndex_t,
2266 ) -> cuvsError_t;
2267}
2268#[repr(u32)]
2269#[doc = " @brief Distribution mode for multi-GPU indexes"]
2270#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2271pub enum cuvsMultiGpuDistributionMode {
2272 #[doc = " Index is replicated on each device, favors throughput"]
2273 CUVS_NEIGHBORS_MG_REPLICATED = 0,
2274 #[doc = " Index is split on several devices, favors scaling"]
2275 CUVS_NEIGHBORS_MG_SHARDED = 1,
2276}
2277#[repr(u32)]
2278#[doc = " @brief Search mode when using a replicated index"]
2279#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2280pub enum cuvsMultiGpuReplicatedSearchMode {
2281 #[doc = " Search queries are split to maintain equal load on GPUs"]
2282 CUVS_NEIGHBORS_MG_LOAD_BALANCER = 0,
2283 #[doc = " Each search query is processed by a single GPU in a round-robin fashion"]
2284 CUVS_NEIGHBORS_MG_ROUND_ROBIN = 1,
2285}
2286#[repr(u32)]
2287#[doc = " @brief Merge mode when using a sharded index"]
2288#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2289pub enum cuvsMultiGpuShardedMergeMode {
2290 #[doc = " Search batches are merged on the root rank"]
2291 CUVS_NEIGHBORS_MG_MERGE_ON_ROOT_RANK = 0,
2292 #[doc = " Search batches are merged in a tree reduction fashion"]
2293 CUVS_NEIGHBORS_MG_TREE_MERGE = 1,
2294}
2295#[doc = " @brief Multi-GPU parameters to build CAGRA Index\n\n This structure extends the base CAGRA index parameters with multi-GPU specific settings."]
2296#[repr(C)]
2297#[derive(Debug, Copy, Clone)]
2298pub struct cuvsMultiGpuCagraIndexParams {
2299 #[doc = " Base CAGRA index parameters"]
2300 pub base_params: cuvsCagraIndexParams_t,
2301 #[doc = " Distribution mode for multi-GPU setup"]
2302 pub mode: cuvsMultiGpuDistributionMode,
2303}
2304#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2305const _: () = {
2306 ["Size of cuvsMultiGpuCagraIndexParams"]
2307 [::std::mem::size_of::<cuvsMultiGpuCagraIndexParams>() - 16usize];
2308 ["Alignment of cuvsMultiGpuCagraIndexParams"]
2309 [::std::mem::align_of::<cuvsMultiGpuCagraIndexParams>() - 8usize];
2310 ["Offset of field: cuvsMultiGpuCagraIndexParams::base_params"]
2311 [::std::mem::offset_of!(cuvsMultiGpuCagraIndexParams, base_params) - 0usize];
2312 ["Offset of field: cuvsMultiGpuCagraIndexParams::mode"]
2313 [::std::mem::offset_of!(cuvsMultiGpuCagraIndexParams, mode) - 8usize];
2314};
2315pub type cuvsMultiGpuCagraIndexParams_t = *mut cuvsMultiGpuCagraIndexParams;
2316unsafe extern "C" {
2317 #[must_use]
2318 #[doc = " @brief Allocate Multi-GPU CAGRA Index params, and populate with default values\n\n @param[in] index_params cuvsMultiGpuCagraIndexParams_t to allocate\n @return cuvsError_t"]
2319 pub fn cuvsMultiGpuCagraIndexParamsCreate(
2320 index_params: *mut cuvsMultiGpuCagraIndexParams_t,
2321 ) -> cuvsError_t;
2322}
2323unsafe extern "C" {
2324 #[must_use]
2325 #[doc = " @brief De-allocate Multi-GPU CAGRA Index params\n\n @param[in] index_params\n @return cuvsError_t"]
2326 pub fn cuvsMultiGpuCagraIndexParamsDestroy(
2327 index_params: cuvsMultiGpuCagraIndexParams_t,
2328 ) -> cuvsError_t;
2329}
2330#[doc = " @brief Multi-GPU parameters to search CAGRA index\n\n This structure extends the base CAGRA search parameters with multi-GPU specific settings."]
2331#[repr(C)]
2332#[derive(Debug, Copy, Clone)]
2333pub struct cuvsMultiGpuCagraSearchParams {
2334 #[doc = " Base CAGRA search parameters"]
2335 pub base_params: cuvsCagraSearchParams_t,
2336 #[doc = " Replicated search mode"]
2337 pub search_mode: cuvsMultiGpuReplicatedSearchMode,
2338 #[doc = " Sharded merge mode"]
2339 pub merge_mode: cuvsMultiGpuShardedMergeMode,
2340 #[doc = " Number of rows per batch"]
2341 pub n_rows_per_batch: i64,
2342}
2343#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2344const _: () = {
2345 ["Size of cuvsMultiGpuCagraSearchParams"]
2346 [::std::mem::size_of::<cuvsMultiGpuCagraSearchParams>() - 24usize];
2347 ["Alignment of cuvsMultiGpuCagraSearchParams"]
2348 [::std::mem::align_of::<cuvsMultiGpuCagraSearchParams>() - 8usize];
2349 ["Offset of field: cuvsMultiGpuCagraSearchParams::base_params"]
2350 [::std::mem::offset_of!(cuvsMultiGpuCagraSearchParams, base_params) - 0usize];
2351 ["Offset of field: cuvsMultiGpuCagraSearchParams::search_mode"]
2352 [::std::mem::offset_of!(cuvsMultiGpuCagraSearchParams, search_mode) - 8usize];
2353 ["Offset of field: cuvsMultiGpuCagraSearchParams::merge_mode"]
2354 [::std::mem::offset_of!(cuvsMultiGpuCagraSearchParams, merge_mode) - 12usize];
2355 ["Offset of field: cuvsMultiGpuCagraSearchParams::n_rows_per_batch"]
2356 [::std::mem::offset_of!(cuvsMultiGpuCagraSearchParams, n_rows_per_batch) - 16usize];
2357};
2358pub type cuvsMultiGpuCagraSearchParams_t = *mut cuvsMultiGpuCagraSearchParams;
2359unsafe extern "C" {
2360 #[must_use]
2361 #[doc = " @brief Allocate Multi-GPU CAGRA search params, and populate with default values\n\n @param[in] params cuvsMultiGpuCagraSearchParams_t to allocate\n @return cuvsError_t"]
2362 pub fn cuvsMultiGpuCagraSearchParamsCreate(
2363 params: *mut cuvsMultiGpuCagraSearchParams_t,
2364 ) -> cuvsError_t;
2365}
2366unsafe extern "C" {
2367 #[must_use]
2368 #[doc = " @brief De-allocate Multi-GPU CAGRA search params\n\n @param[in] params\n @return cuvsError_t"]
2369 pub fn cuvsMultiGpuCagraSearchParamsDestroy(
2370 params: cuvsMultiGpuCagraSearchParams_t,
2371 ) -> cuvsError_t;
2372}
2373#[doc = " @brief Struct to hold address of cuvs::neighbors::mg_index<cagra::index> and its active trained\n dtype"]
2374#[repr(C)]
2375#[derive(Debug, Copy, Clone)]
2376pub struct cuvsMultiGpuCagraIndex {
2377 pub addr: usize,
2378 pub dtype: DLDataType,
2379}
2380#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2381const _: () = {
2382 ["Size of cuvsMultiGpuCagraIndex"][::std::mem::size_of::<cuvsMultiGpuCagraIndex>() - 16usize];
2383 ["Alignment of cuvsMultiGpuCagraIndex"]
2384 [::std::mem::align_of::<cuvsMultiGpuCagraIndex>() - 8usize];
2385 ["Offset of field: cuvsMultiGpuCagraIndex::addr"]
2386 [::std::mem::offset_of!(cuvsMultiGpuCagraIndex, addr) - 0usize];
2387 ["Offset of field: cuvsMultiGpuCagraIndex::dtype"]
2388 [::std::mem::offset_of!(cuvsMultiGpuCagraIndex, dtype) - 8usize];
2389};
2390pub type cuvsMultiGpuCagraIndex_t = *mut cuvsMultiGpuCagraIndex;
2391unsafe extern "C" {
2392 #[must_use]
2393 #[doc = " @brief Allocate Multi-GPU CAGRA index\n\n @param[in] index cuvsMultiGpuCagraIndex_t to allocate\n @return cuvsError_t"]
2394 pub fn cuvsMultiGpuCagraIndexCreate(index: *mut cuvsMultiGpuCagraIndex_t) -> cuvsError_t;
2395}
2396unsafe extern "C" {
2397 #[must_use]
2398 #[doc = " @brief De-allocate Multi-GPU CAGRA index\n\n @param[in] index cuvsMultiGpuCagraIndex_t to de-allocate\n @return cuvsError_t"]
2399 pub fn cuvsMultiGpuCagraIndexDestroy(index: cuvsMultiGpuCagraIndex_t) -> cuvsError_t;
2400}
2401unsafe extern "C" {
2402 #[must_use]
2403 #[doc = " @brief Build a Multi-GPU CAGRA index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params Multi-GPU CAGRA index parameters\n @param[in] dataset_tensor DLManagedTensor* training dataset\n @param[out] index Multi-GPU CAGRA index\n @return cuvsError_t"]
2404 pub fn cuvsMultiGpuCagraBuild(
2405 res: cuvsResources_t,
2406 params: cuvsMultiGpuCagraIndexParams_t,
2407 dataset_tensor: *mut DLManagedTensor,
2408 index: cuvsMultiGpuCagraIndex_t,
2409 ) -> cuvsError_t;
2410}
2411unsafe extern "C" {
2412 #[must_use]
2413 #[doc = " @brief Search a Multi-GPU CAGRA index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params Multi-GPU CAGRA search parameters\n @param[in] index Multi-GPU CAGRA index\n @param[in] queries_tensor DLManagedTensor* queries dataset\n @param[out] neighbors_tensor DLManagedTensor* output neighbors\n @param[out] distances_tensor DLManagedTensor* output distances\n @return cuvsError_t"]
2414 pub fn cuvsMultiGpuCagraSearch(
2415 res: cuvsResources_t,
2416 params: cuvsMultiGpuCagraSearchParams_t,
2417 index: cuvsMultiGpuCagraIndex_t,
2418 queries_tensor: *mut DLManagedTensor,
2419 neighbors_tensor: *mut DLManagedTensor,
2420 distances_tensor: *mut DLManagedTensor,
2421 ) -> cuvsError_t;
2422}
2423unsafe extern "C" {
2424 #[must_use]
2425 #[doc = " @brief Extend a Multi-GPU CAGRA index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in,out] index Multi-GPU CAGRA index to extend\n @param[in] new_vectors_tensor DLManagedTensor* new vectors to add\n @param[in] new_indices_tensor DLManagedTensor* new indices (optional, can be NULL)\n @return cuvsError_t"]
2426 pub fn cuvsMultiGpuCagraExtend(
2427 res: cuvsResources_t,
2428 index: cuvsMultiGpuCagraIndex_t,
2429 new_vectors_tensor: *mut DLManagedTensor,
2430 new_indices_tensor: *mut DLManagedTensor,
2431 ) -> cuvsError_t;
2432}
2433unsafe extern "C" {
2434 #[must_use]
2435 #[doc = " @brief Serialize a Multi-GPU CAGRA index to file\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index Multi-GPU CAGRA index to serialize\n @param[in] filename Path to the output file\n @return cuvsError_t"]
2436 pub fn cuvsMultiGpuCagraSerialize(
2437 res: cuvsResources_t,
2438 index: cuvsMultiGpuCagraIndex_t,
2439 filename: *const ::std::os::raw::c_char,
2440 ) -> cuvsError_t;
2441}
2442unsafe extern "C" {
2443 #[must_use]
2444 #[doc = " @brief Deserialize a Multi-GPU CAGRA index from file\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename Path to the input file\n @param[out] index Multi-GPU CAGRA index\n @return cuvsError_t"]
2445 pub fn cuvsMultiGpuCagraDeserialize(
2446 res: cuvsResources_t,
2447 filename: *const ::std::os::raw::c_char,
2448 index: cuvsMultiGpuCagraIndex_t,
2449 ) -> cuvsError_t;
2450}
2451unsafe extern "C" {
2452 #[must_use]
2453 #[doc = " @brief Distribute a local CAGRA index to create a Multi-GPU index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename Path to the local index file\n @param[out] index Multi-GPU CAGRA index\n @return cuvsError_t"]
2454 pub fn cuvsMultiGpuCagraDistribute(
2455 res: cuvsResources_t,
2456 filename: *const ::std::os::raw::c_char,
2457 index: cuvsMultiGpuCagraIndex_t,
2458 ) -> cuvsError_t;
2459}
2460#[doc = " @brief Multi-GPU parameters to build IVF-Flat Index\n\n This structure extends the base IVF-Flat index parameters with multi-GPU specific settings."]
2461#[repr(C)]
2462#[derive(Debug, Copy, Clone)]
2463pub struct cuvsMultiGpuIvfFlatIndexParams {
2464 #[doc = " Base IVF-Flat index parameters"]
2465 pub base_params: cuvsIvfFlatIndexParams_t,
2466 #[doc = " Distribution mode for multi-GPU setup"]
2467 pub mode: cuvsMultiGpuDistributionMode,
2468}
2469#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2470const _: () = {
2471 ["Size of cuvsMultiGpuIvfFlatIndexParams"]
2472 [::std::mem::size_of::<cuvsMultiGpuIvfFlatIndexParams>() - 16usize];
2473 ["Alignment of cuvsMultiGpuIvfFlatIndexParams"]
2474 [::std::mem::align_of::<cuvsMultiGpuIvfFlatIndexParams>() - 8usize];
2475 ["Offset of field: cuvsMultiGpuIvfFlatIndexParams::base_params"]
2476 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatIndexParams, base_params) - 0usize];
2477 ["Offset of field: cuvsMultiGpuIvfFlatIndexParams::mode"]
2478 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatIndexParams, mode) - 8usize];
2479};
2480pub type cuvsMultiGpuIvfFlatIndexParams_t = *mut cuvsMultiGpuIvfFlatIndexParams;
2481unsafe extern "C" {
2482 #[must_use]
2483 #[doc = " @brief Allocate Multi-GPU IVF-Flat Index params, and populate with default values\n\n @param[in] index_params cuvsMultiGpuIvfFlatIndexParams_t to allocate\n @return cuvsError_t"]
2484 pub fn cuvsMultiGpuIvfFlatIndexParamsCreate(
2485 index_params: *mut cuvsMultiGpuIvfFlatIndexParams_t,
2486 ) -> cuvsError_t;
2487}
2488unsafe extern "C" {
2489 #[must_use]
2490 #[doc = " @brief De-allocate Multi-GPU IVF-Flat Index params\n\n @param[in] index_params\n @return cuvsError_t"]
2491 pub fn cuvsMultiGpuIvfFlatIndexParamsDestroy(
2492 index_params: cuvsMultiGpuIvfFlatIndexParams_t,
2493 ) -> cuvsError_t;
2494}
2495#[doc = " @brief Multi-GPU parameters to search IVF-Flat index\n\n This structure extends the base IVF-Flat search parameters with multi-GPU specific settings."]
2496#[repr(C)]
2497#[derive(Debug, Copy, Clone)]
2498pub struct cuvsMultiGpuIvfFlatSearchParams {
2499 #[doc = " Base IVF-Flat search parameters"]
2500 pub base_params: cuvsIvfFlatSearchParams_t,
2501 #[doc = " Replicated search mode"]
2502 pub search_mode: cuvsMultiGpuReplicatedSearchMode,
2503 #[doc = " Sharded merge mode"]
2504 pub merge_mode: cuvsMultiGpuShardedMergeMode,
2505 #[doc = " Number of rows per batch"]
2506 pub n_rows_per_batch: i64,
2507}
2508#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2509const _: () = {
2510 ["Size of cuvsMultiGpuIvfFlatSearchParams"]
2511 [::std::mem::size_of::<cuvsMultiGpuIvfFlatSearchParams>() - 24usize];
2512 ["Alignment of cuvsMultiGpuIvfFlatSearchParams"]
2513 [::std::mem::align_of::<cuvsMultiGpuIvfFlatSearchParams>() - 8usize];
2514 ["Offset of field: cuvsMultiGpuIvfFlatSearchParams::base_params"]
2515 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatSearchParams, base_params) - 0usize];
2516 ["Offset of field: cuvsMultiGpuIvfFlatSearchParams::search_mode"]
2517 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatSearchParams, search_mode) - 8usize];
2518 ["Offset of field: cuvsMultiGpuIvfFlatSearchParams::merge_mode"]
2519 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatSearchParams, merge_mode) - 12usize];
2520 ["Offset of field: cuvsMultiGpuIvfFlatSearchParams::n_rows_per_batch"]
2521 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatSearchParams, n_rows_per_batch) - 16usize];
2522};
2523pub type cuvsMultiGpuIvfFlatSearchParams_t = *mut cuvsMultiGpuIvfFlatSearchParams;
2524unsafe extern "C" {
2525 #[must_use]
2526 #[doc = " @brief Allocate Multi-GPU IVF-Flat search params, and populate with default values\n\n @param[in] params cuvsMultiGpuIvfFlatSearchParams_t to allocate\n @return cuvsError_t"]
2527 pub fn cuvsMultiGpuIvfFlatSearchParamsCreate(
2528 params: *mut cuvsMultiGpuIvfFlatSearchParams_t,
2529 ) -> cuvsError_t;
2530}
2531unsafe extern "C" {
2532 #[must_use]
2533 #[doc = " @brief De-allocate Multi-GPU IVF-Flat search params\n\n @param[in] params\n @return cuvsError_t"]
2534 pub fn cuvsMultiGpuIvfFlatSearchParamsDestroy(
2535 params: cuvsMultiGpuIvfFlatSearchParams_t,
2536 ) -> cuvsError_t;
2537}
2538#[doc = " @brief Struct to hold address of cuvs::neighbors::mg_index<ivf_flat::index> and its active\n trained dtype"]
2539#[repr(C)]
2540#[derive(Debug, Copy, Clone)]
2541pub struct cuvsMultiGpuIvfFlatIndex {
2542 pub addr: usize,
2543 pub dtype: DLDataType,
2544}
2545#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2546const _: () = {
2547 ["Size of cuvsMultiGpuIvfFlatIndex"]
2548 [::std::mem::size_of::<cuvsMultiGpuIvfFlatIndex>() - 16usize];
2549 ["Alignment of cuvsMultiGpuIvfFlatIndex"]
2550 [::std::mem::align_of::<cuvsMultiGpuIvfFlatIndex>() - 8usize];
2551 ["Offset of field: cuvsMultiGpuIvfFlatIndex::addr"]
2552 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatIndex, addr) - 0usize];
2553 ["Offset of field: cuvsMultiGpuIvfFlatIndex::dtype"]
2554 [::std::mem::offset_of!(cuvsMultiGpuIvfFlatIndex, dtype) - 8usize];
2555};
2556pub type cuvsMultiGpuIvfFlatIndex_t = *mut cuvsMultiGpuIvfFlatIndex;
2557unsafe extern "C" {
2558 #[must_use]
2559 #[doc = " @brief Allocate Multi-GPU IVF-Flat index\n\n @param[in] index cuvsMultiGpuIvfFlatIndex_t to allocate\n @return cuvsError_t"]
2560 pub fn cuvsMultiGpuIvfFlatIndexCreate(index: *mut cuvsMultiGpuIvfFlatIndex_t) -> cuvsError_t;
2561}
2562unsafe extern "C" {
2563 #[must_use]
2564 #[doc = " @brief De-allocate Multi-GPU IVF-Flat index\n\n @param[in] index cuvsMultiGpuIvfFlatIndex_t to de-allocate\n @return cuvsError_t"]
2565 pub fn cuvsMultiGpuIvfFlatIndexDestroy(index: cuvsMultiGpuIvfFlatIndex_t) -> cuvsError_t;
2566}
2567unsafe extern "C" {
2568 #[must_use]
2569 #[doc = " @brief Build a Multi-GPU IVF-Flat index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params Multi-GPU IVF-Flat index parameters\n @param[in] dataset_tensor DLManagedTensor* training dataset\n @param[out] index Multi-GPU IVF-Flat index\n @return cuvsError_t"]
2570 pub fn cuvsMultiGpuIvfFlatBuild(
2571 res: cuvsResources_t,
2572 params: cuvsMultiGpuIvfFlatIndexParams_t,
2573 dataset_tensor: *mut DLManagedTensor,
2574 index: cuvsMultiGpuIvfFlatIndex_t,
2575 ) -> cuvsError_t;
2576}
2577unsafe extern "C" {
2578 #[must_use]
2579 #[doc = " @brief Search a Multi-GPU IVF-Flat index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params Multi-GPU IVF-Flat search parameters\n @param[in] index Multi-GPU IVF-Flat index\n @param[in] queries_tensor DLManagedTensor* queries dataset\n @param[out] neighbors_tensor DLManagedTensor* output neighbors\n @param[out] distances_tensor DLManagedTensor* output distances\n @return cuvsError_t"]
2580 pub fn cuvsMultiGpuIvfFlatSearch(
2581 res: cuvsResources_t,
2582 params: cuvsMultiGpuIvfFlatSearchParams_t,
2583 index: cuvsMultiGpuIvfFlatIndex_t,
2584 queries_tensor: *mut DLManagedTensor,
2585 neighbors_tensor: *mut DLManagedTensor,
2586 distances_tensor: *mut DLManagedTensor,
2587 ) -> cuvsError_t;
2588}
2589unsafe extern "C" {
2590 #[must_use]
2591 #[doc = " @brief Extend a Multi-GPU IVF-Flat index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in,out] index Multi-GPU IVF-Flat index to extend\n @param[in] new_vectors_tensor DLManagedTensor* new vectors to add\n @param[in] new_indices_tensor DLManagedTensor* new indices (optional, can be NULL)\n @return cuvsError_t"]
2592 pub fn cuvsMultiGpuIvfFlatExtend(
2593 res: cuvsResources_t,
2594 index: cuvsMultiGpuIvfFlatIndex_t,
2595 new_vectors_tensor: *mut DLManagedTensor,
2596 new_indices_tensor: *mut DLManagedTensor,
2597 ) -> cuvsError_t;
2598}
2599unsafe extern "C" {
2600 #[must_use]
2601 #[doc = " @brief Serialize a Multi-GPU IVF-Flat index to file\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index Multi-GPU IVF-Flat index to serialize\n @param[in] filename Path to the output file\n @return cuvsError_t"]
2602 pub fn cuvsMultiGpuIvfFlatSerialize(
2603 res: cuvsResources_t,
2604 index: cuvsMultiGpuIvfFlatIndex_t,
2605 filename: *const ::std::os::raw::c_char,
2606 ) -> cuvsError_t;
2607}
2608unsafe extern "C" {
2609 #[must_use]
2610 #[doc = " @brief Deserialize a Multi-GPU IVF-Flat index from file\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename Path to the input file\n @param[out] index Multi-GPU IVF-Flat index\n @return cuvsError_t"]
2611 pub fn cuvsMultiGpuIvfFlatDeserialize(
2612 res: cuvsResources_t,
2613 filename: *const ::std::os::raw::c_char,
2614 index: cuvsMultiGpuIvfFlatIndex_t,
2615 ) -> cuvsError_t;
2616}
2617unsafe extern "C" {
2618 #[must_use]
2619 #[doc = " @brief Distribute a local IVF-Flat index to create a Multi-GPU index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename Path to the local index file\n @param[out] index Multi-GPU IVF-Flat index\n @return cuvsError_t"]
2620 pub fn cuvsMultiGpuIvfFlatDistribute(
2621 res: cuvsResources_t,
2622 filename: *const ::std::os::raw::c_char,
2623 index: cuvsMultiGpuIvfFlatIndex_t,
2624 ) -> cuvsError_t;
2625}
2626#[doc = " @brief Multi-GPU parameters to build IVF-PQ Index\n\n This structure extends the base IVF-PQ index parameters with multi-GPU specific settings."]
2627#[repr(C)]
2628#[derive(Debug, Copy, Clone)]
2629pub struct cuvsMultiGpuIvfPqIndexParams {
2630 #[doc = " Base IVF-PQ index parameters"]
2631 pub base_params: cuvsIvfPqIndexParams_t,
2632 #[doc = " Distribution mode for multi-GPU setup"]
2633 pub mode: cuvsMultiGpuDistributionMode,
2634}
2635#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2636const _: () = {
2637 ["Size of cuvsMultiGpuIvfPqIndexParams"]
2638 [::std::mem::size_of::<cuvsMultiGpuIvfPqIndexParams>() - 16usize];
2639 ["Alignment of cuvsMultiGpuIvfPqIndexParams"]
2640 [::std::mem::align_of::<cuvsMultiGpuIvfPqIndexParams>() - 8usize];
2641 ["Offset of field: cuvsMultiGpuIvfPqIndexParams::base_params"]
2642 [::std::mem::offset_of!(cuvsMultiGpuIvfPqIndexParams, base_params) - 0usize];
2643 ["Offset of field: cuvsMultiGpuIvfPqIndexParams::mode"]
2644 [::std::mem::offset_of!(cuvsMultiGpuIvfPqIndexParams, mode) - 8usize];
2645};
2646pub type cuvsMultiGpuIvfPqIndexParams_t = *mut cuvsMultiGpuIvfPqIndexParams;
2647unsafe extern "C" {
2648 #[must_use]
2649 #[doc = " @brief Allocate Multi-GPU IVF-PQ Index params, and populate with default values\n\n @param[in] index_params cuvsMultiGpuIvfPqIndexParams_t to allocate\n @return cuvsError_t"]
2650 pub fn cuvsMultiGpuIvfPqIndexParamsCreate(
2651 index_params: *mut cuvsMultiGpuIvfPqIndexParams_t,
2652 ) -> cuvsError_t;
2653}
2654unsafe extern "C" {
2655 #[must_use]
2656 #[doc = " @brief De-allocate Multi-GPU IVF-PQ Index params\n\n @param[in] index_params\n @return cuvsError_t"]
2657 pub fn cuvsMultiGpuIvfPqIndexParamsDestroy(
2658 index_params: cuvsMultiGpuIvfPqIndexParams_t,
2659 ) -> cuvsError_t;
2660}
2661#[doc = " @brief Multi-GPU parameters to search IVF-PQ index\n\n This structure extends the base IVF-PQ search parameters with multi-GPU specific settings."]
2662#[repr(C)]
2663#[derive(Debug, Copy, Clone)]
2664pub struct cuvsMultiGpuIvfPqSearchParams {
2665 #[doc = " Base IVF-PQ search parameters"]
2666 pub base_params: cuvsIvfPqSearchParams_t,
2667 #[doc = " Replicated search mode"]
2668 pub search_mode: cuvsMultiGpuReplicatedSearchMode,
2669 #[doc = " Sharded merge mode"]
2670 pub merge_mode: cuvsMultiGpuShardedMergeMode,
2671 #[doc = " Number of rows per batch"]
2672 pub n_rows_per_batch: i64,
2673}
2674#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2675const _: () = {
2676 ["Size of cuvsMultiGpuIvfPqSearchParams"]
2677 [::std::mem::size_of::<cuvsMultiGpuIvfPqSearchParams>() - 24usize];
2678 ["Alignment of cuvsMultiGpuIvfPqSearchParams"]
2679 [::std::mem::align_of::<cuvsMultiGpuIvfPqSearchParams>() - 8usize];
2680 ["Offset of field: cuvsMultiGpuIvfPqSearchParams::base_params"]
2681 [::std::mem::offset_of!(cuvsMultiGpuIvfPqSearchParams, base_params) - 0usize];
2682 ["Offset of field: cuvsMultiGpuIvfPqSearchParams::search_mode"]
2683 [::std::mem::offset_of!(cuvsMultiGpuIvfPqSearchParams, search_mode) - 8usize];
2684 ["Offset of field: cuvsMultiGpuIvfPqSearchParams::merge_mode"]
2685 [::std::mem::offset_of!(cuvsMultiGpuIvfPqSearchParams, merge_mode) - 12usize];
2686 ["Offset of field: cuvsMultiGpuIvfPqSearchParams::n_rows_per_batch"]
2687 [::std::mem::offset_of!(cuvsMultiGpuIvfPqSearchParams, n_rows_per_batch) - 16usize];
2688};
2689pub type cuvsMultiGpuIvfPqSearchParams_t = *mut cuvsMultiGpuIvfPqSearchParams;
2690unsafe extern "C" {
2691 #[must_use]
2692 #[doc = " @brief Allocate Multi-GPU IVF-PQ search params, and populate with default values\n\n @param[in] params cuvsMultiGpuIvfPqSearchParams_t to allocate\n @return cuvsError_t"]
2693 pub fn cuvsMultiGpuIvfPqSearchParamsCreate(
2694 params: *mut cuvsMultiGpuIvfPqSearchParams_t,
2695 ) -> cuvsError_t;
2696}
2697unsafe extern "C" {
2698 #[must_use]
2699 #[doc = " @brief De-allocate Multi-GPU IVF-PQ search params\n\n @param[in] params\n @return cuvsError_t"]
2700 pub fn cuvsMultiGpuIvfPqSearchParamsDestroy(
2701 params: cuvsMultiGpuIvfPqSearchParams_t,
2702 ) -> cuvsError_t;
2703}
2704#[doc = " @brief Struct to hold address of cuvs::neighbors::mg_index<ivf_pq::index> and its active trained\n dtype"]
2705#[repr(C)]
2706#[derive(Debug, Copy, Clone)]
2707pub struct cuvsMultiGpuIvfPqIndex {
2708 pub addr: usize,
2709 pub dtype: DLDataType,
2710}
2711#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2712const _: () = {
2713 ["Size of cuvsMultiGpuIvfPqIndex"][::std::mem::size_of::<cuvsMultiGpuIvfPqIndex>() - 16usize];
2714 ["Alignment of cuvsMultiGpuIvfPqIndex"]
2715 [::std::mem::align_of::<cuvsMultiGpuIvfPqIndex>() - 8usize];
2716 ["Offset of field: cuvsMultiGpuIvfPqIndex::addr"]
2717 [::std::mem::offset_of!(cuvsMultiGpuIvfPqIndex, addr) - 0usize];
2718 ["Offset of field: cuvsMultiGpuIvfPqIndex::dtype"]
2719 [::std::mem::offset_of!(cuvsMultiGpuIvfPqIndex, dtype) - 8usize];
2720};
2721pub type cuvsMultiGpuIvfPqIndex_t = *mut cuvsMultiGpuIvfPqIndex;
2722unsafe extern "C" {
2723 #[must_use]
2724 #[doc = " @brief Allocate Multi-GPU IVF-PQ index\n\n @param[in] index cuvsMultiGpuIvfPqIndex_t to allocate\n @return cuvsError_t"]
2725 pub fn cuvsMultiGpuIvfPqIndexCreate(index: *mut cuvsMultiGpuIvfPqIndex_t) -> cuvsError_t;
2726}
2727unsafe extern "C" {
2728 #[must_use]
2729 #[doc = " @brief De-allocate Multi-GPU IVF-PQ index\n\n @param[in] index cuvsMultiGpuIvfPqIndex_t to de-allocate\n @return cuvsError_t"]
2730 pub fn cuvsMultiGpuIvfPqIndexDestroy(index: cuvsMultiGpuIvfPqIndex_t) -> cuvsError_t;
2731}
2732unsafe extern "C" {
2733 #[must_use]
2734 #[doc = " @brief Build a Multi-GPU IVF-PQ index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params Multi-GPU IVF-PQ index parameters\n @param[in] dataset_tensor DLManagedTensor* training dataset\n @param[out] index Multi-GPU IVF-PQ index\n @return cuvsError_t"]
2735 pub fn cuvsMultiGpuIvfPqBuild(
2736 res: cuvsResources_t,
2737 params: cuvsMultiGpuIvfPqIndexParams_t,
2738 dataset_tensor: *mut DLManagedTensor,
2739 index: cuvsMultiGpuIvfPqIndex_t,
2740 ) -> cuvsError_t;
2741}
2742unsafe extern "C" {
2743 #[must_use]
2744 #[doc = " @brief Search a Multi-GPU IVF-PQ index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params Multi-GPU IVF-PQ search parameters\n @param[in] index Multi-GPU IVF-PQ index\n @param[in] queries_tensor DLManagedTensor* queries dataset\n @param[out] neighbors_tensor DLManagedTensor* output neighbors\n @param[out] distances_tensor DLManagedTensor* output distances\n @return cuvsError_t"]
2745 pub fn cuvsMultiGpuIvfPqSearch(
2746 res: cuvsResources_t,
2747 params: cuvsMultiGpuIvfPqSearchParams_t,
2748 index: cuvsMultiGpuIvfPqIndex_t,
2749 queries_tensor: *mut DLManagedTensor,
2750 neighbors_tensor: *mut DLManagedTensor,
2751 distances_tensor: *mut DLManagedTensor,
2752 ) -> cuvsError_t;
2753}
2754unsafe extern "C" {
2755 #[must_use]
2756 #[doc = " @brief Extend a Multi-GPU IVF-PQ index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in,out] index Multi-GPU IVF-PQ index to extend\n @param[in] new_vectors_tensor DLManagedTensor* new vectors to add\n @param[in] new_indices_tensor DLManagedTensor* new indices (optional, can be NULL)\n @return cuvsError_t"]
2757 pub fn cuvsMultiGpuIvfPqExtend(
2758 res: cuvsResources_t,
2759 index: cuvsMultiGpuIvfPqIndex_t,
2760 new_vectors_tensor: *mut DLManagedTensor,
2761 new_indices_tensor: *mut DLManagedTensor,
2762 ) -> cuvsError_t;
2763}
2764unsafe extern "C" {
2765 #[must_use]
2766 #[doc = " @brief Serialize a Multi-GPU IVF-PQ index to file\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] index Multi-GPU IVF-PQ index to serialize\n @param[in] filename Path to the output file\n @return cuvsError_t"]
2767 pub fn cuvsMultiGpuIvfPqSerialize(
2768 res: cuvsResources_t,
2769 index: cuvsMultiGpuIvfPqIndex_t,
2770 filename: *const ::std::os::raw::c_char,
2771 ) -> cuvsError_t;
2772}
2773unsafe extern "C" {
2774 #[must_use]
2775 #[doc = " @brief Deserialize a Multi-GPU IVF-PQ index from file\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename Path to the input file\n @param[out] index Multi-GPU IVF-PQ index\n @return cuvsError_t"]
2776 pub fn cuvsMultiGpuIvfPqDeserialize(
2777 res: cuvsResources_t,
2778 filename: *const ::std::os::raw::c_char,
2779 index: cuvsMultiGpuIvfPqIndex_t,
2780 ) -> cuvsError_t;
2781}
2782unsafe extern "C" {
2783 #[must_use]
2784 #[doc = " @brief Distribute a local IVF-PQ index to create a Multi-GPU index\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] filename Path to the local index file\n @param[out] index Multi-GPU IVF-PQ index\n @return cuvsError_t"]
2785 pub fn cuvsMultiGpuIvfPqDistribute(
2786 res: cuvsResources_t,
2787 filename: *const ::std::os::raw::c_char,
2788 index: cuvsMultiGpuIvfPqIndex_t,
2789 ) -> cuvsError_t;
2790}
2791#[repr(u32)]
2792#[doc = " @brief Solver algorithm for PCA eigen decomposition."]
2793#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2794pub enum cuvsPcaSolver {
2795 #[doc = " Covariance + divide-and-conquer eigen decomposition"]
2796 CUVS_PCA_COV_EIG_DQ = 0,
2797 #[doc = " Covariance + Jacobi eigen decomposition"]
2798 CUVS_PCA_COV_EIG_JACOBI = 1,
2799}
2800#[doc = " @brief Parameters for PCA decomposition."]
2801#[repr(C)]
2802#[derive(Debug, Copy, Clone)]
2803pub struct cuvsPcaParams {
2804 #[doc = " Number of principal components to keep."]
2805 pub n_components: ::std::os::raw::c_int,
2806 #[doc = " If false, data passed to fit are overwritten and running fit(X).transform(X) will\n not yield the expected results; use fit_transform(X) instead."]
2807 pub copy: bool,
2808 #[doc = " When true the component vectors are multiplied by the square root of n_samples and then\n divided by the singular values to ensure uncorrelated outputs with unit component-wise\n variances."]
2809 pub whiten: bool,
2810 #[doc = " Solver algorithm to use."]
2811 pub algorithm: cuvsPcaSolver,
2812 #[doc = " Tolerance for singular values (used by Jacobi solver)."]
2813 pub tol: f32,
2814 #[doc = " Number of iterations for the power method (Jacobi solver)."]
2815 pub n_iterations: ::std::os::raw::c_int,
2816}
2817#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2818const _: () = {
2819 ["Size of cuvsPcaParams"][::std::mem::size_of::<cuvsPcaParams>() - 20usize];
2820 ["Alignment of cuvsPcaParams"][::std::mem::align_of::<cuvsPcaParams>() - 4usize];
2821 ["Offset of field: cuvsPcaParams::n_components"]
2822 [::std::mem::offset_of!(cuvsPcaParams, n_components) - 0usize];
2823 ["Offset of field: cuvsPcaParams::copy"][::std::mem::offset_of!(cuvsPcaParams, copy) - 4usize];
2824 ["Offset of field: cuvsPcaParams::whiten"]
2825 [::std::mem::offset_of!(cuvsPcaParams, whiten) - 5usize];
2826 ["Offset of field: cuvsPcaParams::algorithm"]
2827 [::std::mem::offset_of!(cuvsPcaParams, algorithm) - 8usize];
2828 ["Offset of field: cuvsPcaParams::tol"][::std::mem::offset_of!(cuvsPcaParams, tol) - 12usize];
2829 ["Offset of field: cuvsPcaParams::n_iterations"]
2830 [::std::mem::offset_of!(cuvsPcaParams, n_iterations) - 16usize];
2831};
2832pub type cuvsPcaParams_t = *mut cuvsPcaParams;
2833unsafe extern "C" {
2834 #[must_use]
2835 #[doc = " @brief Allocate PCA params and populate with default values.\n\n @param[out] params cuvsPcaParams_t to allocate\n @return cuvsError_t"]
2836 pub fn cuvsPcaParamsCreate(params: *mut cuvsPcaParams_t) -> cuvsError_t;
2837}
2838unsafe extern "C" {
2839 #[must_use]
2840 #[doc = " @brief De-allocate PCA params.\n\n @param[in] params cuvsPcaParams_t to de-allocate\n @return cuvsError_t"]
2841 pub fn cuvsPcaParamsDestroy(params: cuvsPcaParams_t) -> cuvsError_t;
2842}
2843unsafe extern "C" {
2844 #[must_use]
2845 #[doc = " @brief Perform PCA fit operation.\n\n Computes the principal components, explained variances, singular values, and column means\n from the input data.\n\n @code {.c}\n #include <cuvs/core/c_api.h>\n #include <cuvs/preprocessing/pca.h>\n\n // Create cuvsResources_t\n cuvsResources_t res;\n cuvsResourcesCreate(&res);\n\n // Create PCA params\n cuvsPcaParams_t params;\n cuvsPcaParamsCreate(¶ms);\n params->n_components = 2;\n\n // Assume populated DLManagedTensor objects (col-major, float32, device memory)\n DLManagedTensor input; // [n_rows x n_cols]\n DLManagedTensor components; // [n_components x n_cols]\n DLManagedTensor explained_var; // [n_components]\n DLManagedTensor explained_var_ratio; // [n_components]\n DLManagedTensor singular_vals; // [n_components]\n DLManagedTensor mu; // [n_cols]\n DLManagedTensor noise_vars; // [1] (scalar)\n\n cuvsPcaFit(res, params, &input, &components, &explained_var,\n &explained_var_ratio, &singular_vals, &mu, &noise_vars, false);\n\n // Cleanup\n cuvsPcaParamsDestroy(params);\n cuvsResourcesDestroy(res);\n @endcode\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params PCA parameters\n @param[inout] input input data [n_rows x n_cols] (col-major, float32, device)\n @param[out] components principal components [n_components x n_cols] (col-major, float32, device)\n @param[out] explained_var explained variances [n_components] (float32, device)\n @param[out] explained_var_ratio explained variance ratios [n_components] (float32, device)\n @param[out] singular_vals singular values [n_components] (float32, device)\n @param[out] mu column means [n_cols] (float32, device)\n @param[out] noise_vars noise variance [1] (float32, device)\n @param[in] flip_signs_based_on_U whether to determine signs by U (true) or V.T (false)\n @return cuvsError_t"]
2846 pub fn cuvsPcaFit(
2847 res: cuvsResources_t,
2848 params: cuvsPcaParams_t,
2849 input: *mut DLManagedTensor,
2850 components: *mut DLManagedTensor,
2851 explained_var: *mut DLManagedTensor,
2852 explained_var_ratio: *mut DLManagedTensor,
2853 singular_vals: *mut DLManagedTensor,
2854 mu: *mut DLManagedTensor,
2855 noise_vars: *mut DLManagedTensor,
2856 flip_signs_based_on_U: bool,
2857 ) -> cuvsError_t;
2858}
2859unsafe extern "C" {
2860 #[must_use]
2861 #[doc = " @brief Perform PCA fit and transform in a single operation.\n\n Computes the principal components and transforms the input data into the eigenspace.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params PCA parameters\n @param[inout] input input data [n_rows x n_cols] (col-major, float32, device)\n @param[out] trans_input transformed data [n_rows x n_components] (col-major, float32, device)\n @param[out] components principal components [n_components x n_cols] (col-major, float32, device)\n @param[out] explained_var explained variances [n_components] (float32, device)\n @param[out] explained_var_ratio explained variance ratios [n_components] (float32, device)\n @param[out] singular_vals singular values [n_components] (float32, device)\n @param[out] mu column means [n_cols] (float32, device)\n @param[out] noise_vars noise variance [1] (float32, device)\n @param[in] flip_signs_based_on_U whether to determine signs by U (true) or V.T (false)\n @return cuvsError_t"]
2862 pub fn cuvsPcaFitTransform(
2863 res: cuvsResources_t,
2864 params: cuvsPcaParams_t,
2865 input: *mut DLManagedTensor,
2866 trans_input: *mut DLManagedTensor,
2867 components: *mut DLManagedTensor,
2868 explained_var: *mut DLManagedTensor,
2869 explained_var_ratio: *mut DLManagedTensor,
2870 singular_vals: *mut DLManagedTensor,
2871 mu: *mut DLManagedTensor,
2872 noise_vars: *mut DLManagedTensor,
2873 flip_signs_based_on_U: bool,
2874 ) -> cuvsError_t;
2875}
2876unsafe extern "C" {
2877 #[must_use]
2878 #[doc = " @brief Perform PCA transform operation.\n\n Transforms the input data into the eigenspace using previously computed principal components.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params PCA parameters\n @param[inout] input data to transform [n_rows x n_cols] (col-major, float32, device)\n @param[in] components principal components [n_components x n_cols] (col-major, float32, device)\n @param[in] singular_vals singular values [n_components] (float32, device)\n @param[in] mu column means [n_cols] (float32, device)\n @param[out] trans_input transformed data [n_rows x n_components] (col-major, float32, device)\n @return cuvsError_t"]
2879 pub fn cuvsPcaTransform(
2880 res: cuvsResources_t,
2881 params: cuvsPcaParams_t,
2882 input: *mut DLManagedTensor,
2883 components: *mut DLManagedTensor,
2884 singular_vals: *mut DLManagedTensor,
2885 mu: *mut DLManagedTensor,
2886 trans_input: *mut DLManagedTensor,
2887 ) -> cuvsError_t;
2888}
2889unsafe extern "C" {
2890 #[must_use]
2891 #[doc = " @brief Perform PCA inverse transform operation.\n\n Transforms data from the eigenspace back to the original space.\n\n @param[in] res cuvsResources_t opaque C handle\n @param[in] params PCA parameters\n @param[in] trans_input transformed data [n_rows x n_components] (col-major, float32, device)\n @param[in] components principal components [n_components x n_cols] (col-major, float32, device)\n @param[in] singular_vals singular values [n_components] (float32, device)\n @param[in] mu column means [n_cols] (float32, device)\n @param[out] output reconstructed data [n_rows x n_cols] (col-major, float32, device)\n @return cuvsError_t"]
2892 pub fn cuvsPcaInverseTransform(
2893 res: cuvsResources_t,
2894 params: cuvsPcaParams_t,
2895 trans_input: *mut DLManagedTensor,
2896 components: *mut DLManagedTensor,
2897 singular_vals: *mut DLManagedTensor,
2898 mu: *mut DLManagedTensor,
2899 output: *mut DLManagedTensor,
2900 ) -> cuvsError_t;
2901}
2902#[repr(u32)]
2903#[doc = " @defgroup preprocessing_c_binary C API for Binary Quantizer\n @{\n/\n/**\n @brief In the cuvsBinaryQuantizerTransform function, a bit is set if the corresponding element in\n the dataset vector is greater than the corresponding element in the threshold vector. The mean\n and sampling_median thresholds are calculated separately for each dimension.\n"]
2904#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2905pub enum cuvsBinaryQuantizerThreshold {
2906 ZERO = 0,
2907 MEAN = 1,
2908 SAMPLING_MEDIAN = 2,
2909}
2910#[doc = " @brief Binary quantizer parameters."]
2911#[repr(C)]
2912#[derive(Debug, Copy, Clone)]
2913pub struct cuvsBinaryQuantizerParams {
2914 pub threshold: cuvsBinaryQuantizerThreshold,
2915 pub sampling_ratio: f32,
2916}
2917#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2918const _: () = {
2919 ["Size of cuvsBinaryQuantizerParams"]
2920 [::std::mem::size_of::<cuvsBinaryQuantizerParams>() - 8usize];
2921 ["Alignment of cuvsBinaryQuantizerParams"]
2922 [::std::mem::align_of::<cuvsBinaryQuantizerParams>() - 4usize];
2923 ["Offset of field: cuvsBinaryQuantizerParams::threshold"]
2924 [::std::mem::offset_of!(cuvsBinaryQuantizerParams, threshold) - 0usize];
2925 ["Offset of field: cuvsBinaryQuantizerParams::sampling_ratio"]
2926 [::std::mem::offset_of!(cuvsBinaryQuantizerParams, sampling_ratio) - 4usize];
2927};
2928pub type cuvsBinaryQuantizerParams_t = *mut cuvsBinaryQuantizerParams;
2929unsafe extern "C" {
2930 #[must_use]
2931 #[doc = " @brief Allocate Binary Quantizer params, and populate with default values\n\n @param[in] params cuvsBinaryQuantizerParams_t to allocate\n @return cuvsError_t"]
2932 pub fn cuvsBinaryQuantizerParamsCreate(params: *mut cuvsBinaryQuantizerParams_t)
2933 -> cuvsError_t;
2934}
2935unsafe extern "C" {
2936 #[must_use]
2937 #[doc = " @brief De-allocate Binary Quantizer params\n\n @param[in] params\n @return cuvsError_t"]
2938 pub fn cuvsBinaryQuantizerParamsDestroy(params: cuvsBinaryQuantizerParams_t) -> cuvsError_t;
2939}
2940#[doc = " @brief Defines and stores threshold for quantization upon training\n\n The quantization is performed by a linear mapping of an interval in the\n float data type to the full range of the quantized int type."]
2941#[repr(C)]
2942#[derive(Debug, Copy, Clone)]
2943pub struct cuvsBinaryQuantizer {
2944 pub addr: usize,
2945 pub dtype: DLDataType,
2946}
2947#[allow(clippy::unnecessary_operation, clippy::identity_op)]
2948const _: () = {
2949 ["Size of cuvsBinaryQuantizer"][::std::mem::size_of::<cuvsBinaryQuantizer>() - 16usize];
2950 ["Alignment of cuvsBinaryQuantizer"][::std::mem::align_of::<cuvsBinaryQuantizer>() - 8usize];
2951 ["Offset of field: cuvsBinaryQuantizer::addr"]
2952 [::std::mem::offset_of!(cuvsBinaryQuantizer, addr) - 0usize];
2953 ["Offset of field: cuvsBinaryQuantizer::dtype"]
2954 [::std::mem::offset_of!(cuvsBinaryQuantizer, dtype) - 8usize];
2955};
2956pub type cuvsBinaryQuantizer_t = *mut cuvsBinaryQuantizer;
2957unsafe extern "C" {
2958 #[must_use]
2959 #[doc = " @brief Allocate Binary Quantizer and populate with default values\n\n @param[in] quantizer cuvsBinaryQuantizer_t to allocate\n @return cuvsError_t"]
2960 pub fn cuvsBinaryQuantizerCreate(quantizer: *mut cuvsBinaryQuantizer_t) -> cuvsError_t;
2961}
2962unsafe extern "C" {
2963 #[must_use]
2964 #[doc = " @brief De-allocate Binary Quantizer\n\n @param[in] quantizer\n @return cuvsError_t"]
2965 pub fn cuvsBinaryQuantizerDestroy(quantizer: cuvsBinaryQuantizer_t) -> cuvsError_t;
2966}
2967unsafe extern "C" {
2968 #[must_use]
2969 #[doc = " @brief Trains a binary quantizer to be used later for quantizing the dataset.\n\n @param[in] res raft resource\n @param[in] params configure binary quantizer, e.g. threshold\n @param[in] dataset a row-major host or device matrix\n @param[out] quantizer trained binary quantizer"]
2970 pub fn cuvsBinaryQuantizerTrain(
2971 res: cuvsResources_t,
2972 params: cuvsBinaryQuantizerParams_t,
2973 dataset: *mut DLManagedTensor,
2974 quantizer: cuvsBinaryQuantizer_t,
2975 ) -> cuvsError_t;
2976}
2977unsafe extern "C" {
2978 #[must_use]
2979 #[doc = " @brief Applies binary quantization transform to the given dataset\n\n This applies binary quantization to a dataset, changing any positive\n values to a bitwise 1. This is useful for searching with the\n BitwiseHamming distance type.\n\n @param[in] res raft resource\n @param[in] dataset a row-major host or device matrix to transform\n @param[out] out a row-major host or device matrix to store transformed data"]
2980 pub fn cuvsBinaryQuantizerTransform(
2981 res: cuvsResources_t,
2982 dataset: *mut DLManagedTensor,
2983 out: *mut DLManagedTensor,
2984 ) -> cuvsError_t;
2985}
2986unsafe extern "C" {
2987 #[must_use]
2988 #[doc = " @brief Applies binary quantization transform to the given dataset\n\n This applies binary quantization to a dataset, changing any values that are larger than the\n threshold specified in the param to a bitwise 1. This is useful for searching with the\n BitwiseHamming distance type.\n\n @param[in] res raft resource\n @param[in] quantizer binary quantizer\n @param[in] dataset a row-major host or device matrix to transform\n @param[out] out a row-major host or device matrix to store transformed data"]
2989 pub fn cuvsBinaryQuantizerTransformWithParams(
2990 res: cuvsResources_t,
2991 quantizer: cuvsBinaryQuantizer_t,
2992 dataset: *mut DLManagedTensor,
2993 out: *mut DLManagedTensor,
2994 ) -> cuvsError_t;
2995}
2996#[doc = " @defgroup preprocessing_c_pq C API for Product Quantizer\n @{\n/\n/**\n @brief Product quantizer parameters."]
2997#[repr(C)]
2998#[derive(Debug, Copy, Clone)]
2999pub struct cuvsProductQuantizerParams {
3000 #[doc = " The bit length of the vector element after compression by PQ.\n\n Possible values: within [4, 16].\n\n Hint: the smaller the 'pq_bits', the smaller the index size and the better the search\n performance, but the lower the recall."]
3001 pub pq_bits: u32,
3002 #[doc = " The dimensionality of the vector after compression by PQ.\n When zero, an optimal value is selected using a heuristic.\n\n TODO: at the moment `dim` must be a multiple `pq_dim`."]
3003 pub pq_dim: u32,
3004 #[doc = " Whether to use subspaces for product quantization (PQ).\n When true, one PQ codebook is used for each subspace. Otherwise, a single\n PQ codebook is used."]
3005 pub use_subspaces: bool,
3006 #[doc = " Whether to use Vector Quantization (KMeans) before product quantization (PQ).\n When true, VQ is used before PQ. When false, only product quantization is used."]
3007 pub use_vq: bool,
3008 #[doc = " Vector Quantization (VQ) codebook size - number of \"coarse cluster centers\".\n When zero, an optimal value is selected using a heuristic.\n When one, only product quantization is used."]
3009 pub vq_n_centers: u32,
3010 #[doc = " The number of iterations searching for kmeans centers (both VQ & PQ phases)."]
3011 pub kmeans_n_iters: u32,
3012 #[doc = " The type of kmeans algorithm to use for PQ training."]
3013 pub pq_kmeans_type: cuvsKMeansType,
3014 #[doc = " The max number of data points to use per PQ code during PQ codebook training. Using more data\n points per PQ code may increase the quality of PQ codebook but may also increase the build\n time. We will use `pq_n_centers * max_train_points_per_pq_code` training\n points to train each PQ codebook."]
3015 pub max_train_points_per_pq_code: u32,
3016 #[doc = " The max number of data points to use per VQ cluster."]
3017 pub max_train_points_per_vq_cluster: u32,
3018}
3019#[allow(clippy::unnecessary_operation, clippy::identity_op)]
3020const _: () = {
3021 ["Size of cuvsProductQuantizerParams"]
3022 [::std::mem::size_of::<cuvsProductQuantizerParams>() - 32usize];
3023 ["Alignment of cuvsProductQuantizerParams"]
3024 [::std::mem::align_of::<cuvsProductQuantizerParams>() - 4usize];
3025 ["Offset of field: cuvsProductQuantizerParams::pq_bits"]
3026 [::std::mem::offset_of!(cuvsProductQuantizerParams, pq_bits) - 0usize];
3027 ["Offset of field: cuvsProductQuantizerParams::pq_dim"]
3028 [::std::mem::offset_of!(cuvsProductQuantizerParams, pq_dim) - 4usize];
3029 ["Offset of field: cuvsProductQuantizerParams::use_subspaces"]
3030 [::std::mem::offset_of!(cuvsProductQuantizerParams, use_subspaces) - 8usize];
3031 ["Offset of field: cuvsProductQuantizerParams::use_vq"]
3032 [::std::mem::offset_of!(cuvsProductQuantizerParams, use_vq) - 9usize];
3033 ["Offset of field: cuvsProductQuantizerParams::vq_n_centers"]
3034 [::std::mem::offset_of!(cuvsProductQuantizerParams, vq_n_centers) - 12usize];
3035 ["Offset of field: cuvsProductQuantizerParams::kmeans_n_iters"]
3036 [::std::mem::offset_of!(cuvsProductQuantizerParams, kmeans_n_iters) - 16usize];
3037 ["Offset of field: cuvsProductQuantizerParams::pq_kmeans_type"]
3038 [::std::mem::offset_of!(cuvsProductQuantizerParams, pq_kmeans_type) - 20usize];
3039 ["Offset of field: cuvsProductQuantizerParams::max_train_points_per_pq_code"][::std::mem::offset_of!(
3040 cuvsProductQuantizerParams,
3041 max_train_points_per_pq_code
3042 ) - 24usize];
3043 ["Offset of field: cuvsProductQuantizerParams::max_train_points_per_vq_cluster"][::std::mem::offset_of!(
3044 cuvsProductQuantizerParams,
3045 max_train_points_per_vq_cluster
3046 ) - 28usize];
3047};
3048pub type cuvsProductQuantizerParams_t = *mut cuvsProductQuantizerParams;
3049unsafe extern "C" {
3050 #[must_use]
3051 #[doc = " @brief Allocate Product Quantizer params, and populate with default values\n\n @param[in] params cuvsProductQuantizerParams_t to allocate\n @return cuvsError_t"]
3052 pub fn cuvsProductQuantizerParamsCreate(
3053 params: *mut cuvsProductQuantizerParams_t,
3054 ) -> cuvsError_t;
3055}
3056unsafe extern "C" {
3057 #[must_use]
3058 #[doc = " @brief De-allocate Product Quantizer params\n\n @param[in] params\n @return cuvsError_t"]
3059 pub fn cuvsProductQuantizerParamsDestroy(params: cuvsProductQuantizerParams_t) -> cuvsError_t;
3060}
3061#[doc = " @brief Defines and stores product quantizer upon training\n\n The quantization is performed by a linear mapping of an interval in the\n float data type to the full range of the quantized int type."]
3062#[repr(C)]
3063#[derive(Debug, Copy, Clone)]
3064pub struct cuvsProductQuantizer {
3065 pub addr: usize,
3066 pub dtype: DLDataType,
3067}
3068#[allow(clippy::unnecessary_operation, clippy::identity_op)]
3069const _: () = {
3070 ["Size of cuvsProductQuantizer"][::std::mem::size_of::<cuvsProductQuantizer>() - 16usize];
3071 ["Alignment of cuvsProductQuantizer"][::std::mem::align_of::<cuvsProductQuantizer>() - 8usize];
3072 ["Offset of field: cuvsProductQuantizer::addr"]
3073 [::std::mem::offset_of!(cuvsProductQuantizer, addr) - 0usize];
3074 ["Offset of field: cuvsProductQuantizer::dtype"]
3075 [::std::mem::offset_of!(cuvsProductQuantizer, dtype) - 8usize];
3076};
3077pub type cuvsProductQuantizer_t = *mut cuvsProductQuantizer;
3078unsafe extern "C" {
3079 #[must_use]
3080 #[doc = " @brief Allocate Product Quantizer\n\n @param[in] quantizer cuvsProductQuantizer_t to allocate\n @return cuvsError_t"]
3081 pub fn cuvsProductQuantizerCreate(quantizer: *mut cuvsProductQuantizer_t) -> cuvsError_t;
3082}
3083unsafe extern "C" {
3084 #[must_use]
3085 #[doc = " @brief De-allocate Product Quantizer\n\n @param[in] quantizer\n @return cuvsError_t"]
3086 pub fn cuvsProductQuantizerDestroy(quantizer: cuvsProductQuantizer_t) -> cuvsError_t;
3087}
3088unsafe extern "C" {
3089 #[must_use]
3090 #[doc = " @brief Builds a product quantizer to be used later for quantizing the dataset.\n\n @param[in] res raft resource\n @param[in] params Parameters for product quantizer training\n @param[in] dataset a row-major host or device matrix\n @param[out] quantizer trained product quantizer"]
3091 pub fn cuvsProductQuantizerBuild(
3092 res: cuvsResources_t,
3093 params: cuvsProductQuantizerParams_t,
3094 dataset: *mut DLManagedTensor,
3095 quantizer: cuvsProductQuantizer_t,
3096 ) -> cuvsError_t;
3097}
3098unsafe extern "C" {
3099 #[must_use]
3100 #[doc = " @brief Applies product quantization transform to the given dataset\n\n This applies product quantization to a dataset.\n\n @param[in] res raft resource\n @param[in] quantizer product quantizer\n @param[in] dataset a row-major host or device matrix to transform\n @param[out] codes_out a row-major device matrix to store transformed data\n @param[out] vq_labels a device vector to store VQ labels.\n Optional, can be NULL."]
3101 pub fn cuvsProductQuantizerTransform(
3102 res: cuvsResources_t,
3103 quantizer: cuvsProductQuantizer_t,
3104 dataset: *mut DLManagedTensor,
3105 codes_out: *mut DLManagedTensor,
3106 vq_labels: *mut DLManagedTensor,
3107 ) -> cuvsError_t;
3108}
3109unsafe extern "C" {
3110 #[must_use]
3111 #[doc = " @brief Applies product quantization inverse transform to the given quantized codes\n\n This applies product quantization inverse transform to the given quantized codes.\n\n @param[in] res raft resource\n @param[in] quantizer product quantizer\n @param[in] pq_codes a row-major device matrix of quantized codes\n @param[out] out a row-major device matrix to store the original data\n @param[out] vq_labels a device vector containing the VQ labels when VQ is used.\n Optional, can be NULL."]
3112 pub fn cuvsProductQuantizerInverseTransform(
3113 res: cuvsResources_t,
3114 quantizer: cuvsProductQuantizer_t,
3115 pq_codes: *mut DLManagedTensor,
3116 out: *mut DLManagedTensor,
3117 vq_labels: *mut DLManagedTensor,
3118 ) -> cuvsError_t;
3119}
3120unsafe extern "C" {
3121 #[must_use]
3122 #[doc = " @brief Get the bit length of the vector element after compression by PQ.\n\n @param[in] quantizer product quantizer\n @param[out] pq_bits bit length of the vector element after compression by PQ"]
3123 pub fn cuvsProductQuantizerGetPqBits(
3124 quantizer: cuvsProductQuantizer_t,
3125 pq_bits: *mut u32,
3126 ) -> cuvsError_t;
3127}
3128unsafe extern "C" {
3129 #[must_use]
3130 #[doc = " @brief Get the dimensionality of the vector after compression by PQ.\n\n @param[in] quantizer product quantizer\n @param[out] pq_dim dimensionality of the vector after compression by PQ"]
3131 pub fn cuvsProductQuantizerGetPqDim(
3132 quantizer: cuvsProductQuantizer_t,
3133 pq_dim: *mut u32,
3134 ) -> cuvsError_t;
3135}
3136unsafe extern "C" {
3137 #[must_use]
3138 #[doc = " @brief Get the PQ codebook.\n\n @param[in] quantizer product quantizer\n @param[out] pq_codebook PQ codebook"]
3139 pub fn cuvsProductQuantizerGetPqCodebook(
3140 quantizer: cuvsProductQuantizer_t,
3141 pq_codebook: *mut DLManagedTensor,
3142 ) -> cuvsError_t;
3143}
3144unsafe extern "C" {
3145 #[must_use]
3146 #[doc = " @brief Get the VQ codebook.\n\n @param[in] quantizer product quantizer\n @param[out] vq_codebook VQ codebook"]
3147 pub fn cuvsProductQuantizerGetVqCodebook(
3148 quantizer: cuvsProductQuantizer_t,
3149 vq_codebook: *mut DLManagedTensor,
3150 ) -> cuvsError_t;
3151}
3152unsafe extern "C" {
3153 #[must_use]
3154 #[doc = " @brief Get the encoded dimension of the quantized dataset.\n\n @param[in] quantizer product quantizer\n @param[out] encoded_dim encoded dimension of the quantized dataset"]
3155 pub fn cuvsProductQuantizerGetEncodedDim(
3156 quantizer: cuvsProductQuantizer_t,
3157 encoded_dim: *mut u32,
3158 ) -> cuvsError_t;
3159}
3160unsafe extern "C" {
3161 #[must_use]
3162 #[doc = " @brief Get whether VQ is used.\n\n @param[in] quantizer product quantizer\n @param[out] use_vq whether VQ is used"]
3163 pub fn cuvsProductQuantizerGetUseVq(
3164 quantizer: cuvsProductQuantizer_t,
3165 use_vq: *mut bool,
3166 ) -> cuvsError_t;
3167}
3168#[doc = " @defgroup preprocessing_c_scalar C API for Scalar Quantizer\n @{\n/\n/**\n @brief Scalar quantizer parameters."]
3169#[repr(C)]
3170#[derive(Debug, Copy, Clone)]
3171pub struct cuvsScalarQuantizerParams {
3172 pub quantile: f32,
3173}
3174#[allow(clippy::unnecessary_operation, clippy::identity_op)]
3175const _: () = {
3176 ["Size of cuvsScalarQuantizerParams"]
3177 [::std::mem::size_of::<cuvsScalarQuantizerParams>() - 4usize];
3178 ["Alignment of cuvsScalarQuantizerParams"]
3179 [::std::mem::align_of::<cuvsScalarQuantizerParams>() - 4usize];
3180 ["Offset of field: cuvsScalarQuantizerParams::quantile"]
3181 [::std::mem::offset_of!(cuvsScalarQuantizerParams, quantile) - 0usize];
3182};
3183pub type cuvsScalarQuantizerParams_t = *mut cuvsScalarQuantizerParams;
3184unsafe extern "C" {
3185 #[must_use]
3186 #[doc = " @brief Allocate Scalar Quantizer params, and populate with default values\n\n @param[in] params cuvsScalarQuantizerParams_t to allocate\n @return cuvsError_t"]
3187 pub fn cuvsScalarQuantizerParamsCreate(params: *mut cuvsScalarQuantizerParams_t)
3188 -> cuvsError_t;
3189}
3190unsafe extern "C" {
3191 #[must_use]
3192 #[doc = " @brief De-allocate Scalar Quantizer params\n\n @param[in] params\n @return cuvsError_t"]
3193 pub fn cuvsScalarQuantizerParamsDestroy(params: cuvsScalarQuantizerParams_t) -> cuvsError_t;
3194}
3195#[doc = " @brief Defines and stores scalar for quantisation upon training\n\n The quantization is performed by a linear mapping of an interval in the\n float data type to the full range of the quantized int type."]
3196#[repr(C)]
3197#[derive(Debug, Copy, Clone)]
3198pub struct cuvsScalarQuantizer {
3199 pub min_: f64,
3200 pub max_: f64,
3201}
3202#[allow(clippy::unnecessary_operation, clippy::identity_op)]
3203const _: () = {
3204 ["Size of cuvsScalarQuantizer"][::std::mem::size_of::<cuvsScalarQuantizer>() - 16usize];
3205 ["Alignment of cuvsScalarQuantizer"][::std::mem::align_of::<cuvsScalarQuantizer>() - 8usize];
3206 ["Offset of field: cuvsScalarQuantizer::min_"]
3207 [::std::mem::offset_of!(cuvsScalarQuantizer, min_) - 0usize];
3208 ["Offset of field: cuvsScalarQuantizer::max_"]
3209 [::std::mem::offset_of!(cuvsScalarQuantizer, max_) - 8usize];
3210};
3211pub type cuvsScalarQuantizer_t = *mut cuvsScalarQuantizer;
3212unsafe extern "C" {
3213 #[must_use]
3214 #[doc = " @brief Allocate Scalar Quantizer and populate with default values\n\n @param[in] quantizer cuvsScalarQuantizer_t to allocate\n @return cuvsError_t"]
3215 pub fn cuvsScalarQuantizerCreate(quantizer: *mut cuvsScalarQuantizer_t) -> cuvsError_t;
3216}
3217unsafe extern "C" {
3218 #[must_use]
3219 #[doc = " @brief De-allocate Scalar Quantizer\n\n @param[in] quantizer\n @return cuvsError_t"]
3220 pub fn cuvsScalarQuantizerDestroy(quantizer: cuvsScalarQuantizer_t) -> cuvsError_t;
3221}
3222unsafe extern "C" {
3223 #[must_use]
3224 #[doc = " @brief Trains a scalar quantizer to be used later for quantizing the dataset.\n\n @param[in] res raft resource\n @param[in] params configure scalar quantizer, e.g. quantile\n @param[in] dataset a row-major host or device matrix\n @param[out] quantizer trained scalar quantizer"]
3225 pub fn cuvsScalarQuantizerTrain(
3226 res: cuvsResources_t,
3227 params: cuvsScalarQuantizerParams_t,
3228 dataset: *mut DLManagedTensor,
3229 quantizer: cuvsScalarQuantizer_t,
3230 ) -> cuvsError_t;
3231}
3232unsafe extern "C" {
3233 #[must_use]
3234 #[doc = " @brief Applies quantization transform to given dataset\n\n @param[in] res raft resource\n @param[in] quantizer a scalar quantizer\n @param[in] dataset a row-major host or device matrix to transform\n @param[out] out a row-major host or device matrix to store transformed data"]
3235 pub fn cuvsScalarQuantizerTransform(
3236 res: cuvsResources_t,
3237 quantizer: cuvsScalarQuantizer_t,
3238 dataset: *mut DLManagedTensor,
3239 out: *mut DLManagedTensor,
3240 ) -> cuvsError_t;
3241}
3242unsafe extern "C" {
3243 #[must_use]
3244 #[doc = " @brief Perform inverse quantization step on previously quantized dataset\n\n Note that depending on the chosen data types train dataset the conversion is\n not lossless.\n\n @param[in] res raft resource\n @param[in] quantizer a scalar quantizer\n @param[in] dataset a row-major host or device matrix\n @param[out] out a row-major host or device matrix\n"]
3245 pub fn cuvsScalarQuantizerInverseTransform(
3246 res: cuvsResources_t,
3247 quantizer: cuvsScalarQuantizer_t,
3248 dataset: *mut DLManagedTensor,
3249 out: *mut DLManagedTensor,
3250 ) -> cuvsError_t;
3251}