Skip to main content

cuvs_sys/
lib.rs

1/*
2 * SPDX-FileCopyrightText: Copyright (c) 2024-2026, NVIDIA CORPORATION.
3 * SPDX-License-Identifier: Apache-2.0
4 */
5
6//! Raw FFI bindings to libcuvs_c.
7
8use std::os::raw::c_uint;
9
10/// Opaque CUDA stream handle used by the current cuVS C ABI.
11#[repr(C)]
12#[derive(Debug, Copy, Clone)]
13pub struct CUstream_st {
14    _private: [u8; 0],
15}
16
17#[allow(non_camel_case_types)]
18pub type cudaStream_t = *mut CUstream_st;
19
20/// Temporary ABI shim for `cudaDataType_t` while the cuVS C API exposes CUDA types.
21/// TODO: Remove this once the cuVS C API removes `cudaDataType_t` reliance.
22#[allow(non_camel_case_types)]
23#[repr(transparent)]
24#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
25pub struct cudaDataType_t(c_uint);
26
27impl cudaDataType_t {
28    pub const CUDA_R_32F: Self = Self(0);
29    pub const CUDA_R_16F: Self = Self(2);
30    pub const CUDA_R_8I: Self = Self(3);
31    pub const CUDA_R_8U: Self = Self(8);
32
33    pub const fn from_raw(value: c_uint) -> Self {
34        Self(value)
35    }
36
37    pub const fn as_raw(self) -> c_uint {
38        self.0
39    }
40}
41
42// Bindings are pre-generated and checked in at src/bindings.rs.
43// Use `rust/scripts/generate-bindings.sh` to regenerate them.
44#[allow(non_upper_case_globals, non_camel_case_types, non_snake_case, unused_attributes)]
45mod bindings;
46
47// Bindgen cannot derive these for cuvsIvfPqSearchParams once cudaDataType_t is
48// supplied by this crate instead of generated from CUDA headers.
49impl Copy for bindings::cuvsIvfPqSearchParams {}
50
51impl Clone for bindings::cuvsIvfPqSearchParams {
52    fn clone(&self) -> Self {
53        *self
54    }
55}
56
57impl std::fmt::Debug for bindings::cuvsIvfPqSearchParams {
58    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
59        f.debug_struct("cuvsIvfPqSearchParams")
60            .field("n_probes", &self.n_probes)
61            .field("lut_dtype", &self.lut_dtype)
62            .field("internal_distance_dtype", &self.internal_distance_dtype)
63            .field("coarse_search_dtype", &self.coarse_search_dtype)
64            .field("max_internal_batch_size", &self.max_internal_batch_size)
65            .field("preferred_shmem_carveout", &self.preferred_shmem_carveout)
66            .finish()
67    }
68}
69
70pub use bindings::*;