Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6322bef
Refactor libcuvs_c header and source locations
robertmaynard Sep 22, 2025
515b331
Adress issues found in code revie
robertmaynard Sep 23, 2025
03c0a2c
All C API enums are now given explicit values
robertmaynard Sep 23, 2025
06f374f
Move C API sources and headers to new root directory
robertmaynard Oct 3, 2025
069e6ce
Move interop header to be part of C api as intended
robertmaynard Oct 6, 2025
122ffd8
Correct style and code issues found by CI
robertmaynard Oct 6, 2025
3de73e9
Refactor so that the c/ directory has a CMakeLists.txt
robertmaynard Oct 6, 2025
0f29709
Refactor so that C tests reside in c/tests
robertmaynard Oct 6, 2025
d982c52
Correct style and code issues found by CI
robertmaynard Oct 7, 2025
36790a6
Make sure CUVS_CXX_FLAGS always exists for c build
robertmaynard Oct 7, 2025
ccac907
More updates needed as found by CI
robertmaynard Oct 7, 2025
80df255
Correct style issues found by CI
robertmaynard Oct 7, 2025
9bce3ef
Correct export issue found by CI
robertmaynard Oct 7, 2025
6734ba3
Correct test install issue found by CI
robertmaynard Oct 7, 2025
f0b46bc
Update rust and java bindings to only see C headers
robertmaynard Oct 7, 2025
7fffa93
Attempt to fix doc builds
robertmaynard Oct 7, 2025
8afc1c1
Merge branch 'branch-25.12' into fea/move_capi_files_to_separate_dire…
mythrocks Oct 8, 2025
690285c
Remove interop API docs as it is meant to be internal only
robertmaynard Oct 8, 2025
a6ff31d
Merge branch 'branch-25.12' into fea/move_capi_files_to_separate_dire…
robertmaynard Oct 8, 2025
3da377e
Correct crashes in cagra tests
robertmaynard Oct 8, 2025
6856731
Update Java API to new enum values
robertmaynard Oct 9, 2025
14a6271
Merge branch 'branch-25.12' into fea/move_capi_files_to_separate_dire…
robertmaynard Oct 9, 2025
eb0a170
Restore cuvsCagraGraphBuildAlgo enum values to be contigious
robertmaynard Oct 10, 2025
537b63d
Install C API headers into `include/cuvs` and not `include/`
robertmaynard Oct 10, 2025
5ee2f96
Merge branch 'branch-25.12' into fea/move_capi_files_to_separate_dire…
benfred Oct 10, 2025
71f43b3
Restore cuvsCagraSearchParams enum values to be contigious
robertmaynard Oct 13, 2025
89b8b2c
Restore cuvsCagraSearchParams enum values to be contigious
robertmaynard Oct 13, 2025
3601242
Restore cuvsCagraGraphBuildAlgo enum values to be contigious
robertmaynard Oct 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
# =============================================================================
# Copyright (c) 2025, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
# =============================================================================

cmake_minimum_required(VERSION 3.30.4 FATAL_ERROR)
include(../cmake/rapids_config.cmake)
include(rapids-cmake)
include(rapids-cpm)
include(rapids-export)
include(rapids-find)

project(
CUVS_C
VERSION "${RAPIDS_VERSION}"
LANGUAGES CXX C
)
set(CMAKE_INSTALL_MESSAGE LAZY)

# ##################################################################################################
# * User Options ------------------------------------------------------------

option(BUILD_SHARED_LIBS "Build cuvs_c shared libraries" ON)
option(BUILD_TESTS "Build cuvs unit-tests" ON)

option(BUILD_CAGRA_HNSWLIB "Build CAGRA+hnswlib interface" ON)
option(BUILD_MG_ALGOS "Build with multi-GPU support" ON)

option(CUVSC_STATIC_CUVS_LIBRARY "Link against statical version of libcuvs" OFF)

# Check if cuVS is already available. If so, it is the user's responsibility to ensure that the
# CMake package is also available at build time of the Python cuvs package.
if(NOT TARGET cuvs::cuvs)
find_package(cuvs "${RAPIDS_VERSION}" REQUIRED)
else()
set(BUILDING_FROM_CUVS ON)
endif()

# ##################################################################################################
# * build type ---------------------------------------------------------------

# Set a default build type if none was specified
rapids_cmake_build_type(Release)

# this is needed for clang-tidy runs
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(NOT DEFINED CUVS_CXX_FLAGS)
include(../cpp/cmake/modules/ConfigureCUDA.cmake)
endif()

# ##################################################################################################
# * Requirements -------------------------------------------------------------

# add third party dependencies using CPM
rapids_cpm_init()

# add third party dependencies using CPM
include(../cpp/cmake/thirdparty/get_dlpack.cmake)

if(BUILD_CAGRA_HNSWLIB)
include(../cpp/cmake/thirdparty/get_hnswlib.cmake)
endif()

# ##################################################################################################
# * cuvs_c -------------------------------------------------------------------------------
add_library(
cuvs_c SHARED
src/core/c_api.cpp
src/cluster/kmeans.cpp
src/neighbors/brute_force.cpp
src/neighbors/ivf_flat.cpp
src/neighbors/ivf_pq.cpp
src/neighbors/cagra.cpp
$<$<BOOL:${BUILD_CAGRA_HNSWLIB}>:src/neighbors/hnsw.cpp>
$<$<BOOL:${BUILD_MG_ALGOS}>:src/neighbors/mg_ivf_pq.cpp>
$<$<BOOL:${BUILD_MG_ALGOS}>:src/neighbors/mg_ivf_flat.cpp>
$<$<BOOL:${BUILD_MG_ALGOS}>:src/neighbors/mg_cagra.cpp>
src/neighbors/nn_descent.cpp
src/neighbors/vamana.cpp
src/neighbors/refine.cpp
src/neighbors/tiered_index.cpp
src/neighbors/all_neighbors.cpp
src/preprocessing/quantize/binary.cpp
src/preprocessing/quantize/scalar.cpp
src/distance/pairwise_distance.cpp
)
add_library(cuvs::c_api ALIAS cuvs_c)
set_target_properties(
cuvs_c
PROPERTIES BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN"
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
POSITION_INDEPENDENT_CODE ON
INTERFACE_POSITION_INDEPENDENT_CODE ON
EXPORT_NAME c_api
)

target_compile_definitions(cuvs_c PUBLIC $<$<BOOL:${BUILD_CAGRA_HNSWLIB}>:CUVS_BUILD_CAGRA_HNSWLIB>)

target_compile_options(cuvs_c PRIVATE "$<$<COMPILE_LANGUAGE:CXX>:${CUVS_CXX_FLAGS}>")

target_include_directories(
cuvs_c
PUBLIC "$<BUILD_INTERFACE:${DLPACK_INCLUDE_DIR}>"
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
INTERFACE "$<INSTALL_INTERFACE:include>"
)

target_link_libraries(
cuvs_c
PUBLIC $<IF:$<BOOL:${CUVSC_STATIC_CUVS_LIBRARY}>,cuvs::cuvs_static,cuvs::cuvs>
PRIVATE raft::raft $<TARGET_NAME_IF_EXISTS:hnswlib::hnswlib>
)

# ##################################################################################################
# * install targets-----------------------------------------------------------
if(PROJECT_IS_TOP_LEVEL)
rapids_cmake_install_lib_dir(lib_dir)
include(GNUInstallDirs)
include(CPack)

# Add CUDAToolkit as an export dependency
rapids_export_package(INSTALL CUDAToolkit cuvs-c-exports)
rapids_export_package(BUILD CUDAToolkit cuvs-c-exports)

install(
TARGETS cuvs_c
DESTINATION ${lib_dir}
COMPONENT cuvs_c
EXPORT cuvs-c-exports
)

rapids_export(
INSTALL cuvs_c
VERSION "${RAPIDS_VERSION}"
EXPORT_SET cuvs-c-exports
GLOBAL_TARGETS cuvs_c
NAMESPACE cuvs::
)
rapids_export(
BUILD cuvs_c
VERSION "${RAPIDS_VERSION}"
EXPORT_SET cuvs-c-exports
GLOBAL_TARGETS cuvs_c
NAMESPACE cuvs::
)
install(
DIRECTORY include/cuvs
COMPONENT cuvs_c
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
endif()

# ##################################################################################################
# * build tests ----------------------------------------------------
if(BUILD_TESTS)
enable_language(CUDA)
find_package(CUDAToolkit REQUIRED)

enable_testing()
add_subdirectory(tests)
endif()
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ typedef enum {
/**
* Sample the centroids using the kmeans++ strategy
*/
KMeansPlusPlus,
KMeansPlusPlus = 0,

/**
* Sample the centroids uniformly at random
*/
Random,
Random = 1,

/**
* User provides the array of initial centroids
*/
Array
Array = 2
} cuvsKMeansInitMethod;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extern "C" {
* @brief An enum denoting error statuses for function calls
*
*/
typedef enum { CUVS_ERROR, CUVS_SUCCESS } cuvsError_t;
typedef enum { CUVS_ERROR = 0, CUVS_SUCCESS = 1 } cuvsError_t;

/** @brief Returns a string describing the last seen error on this thread, or
* NULL if the last function succeeded.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ extern "C" {
*/
enum cuvsCagraGraphBuildAlgo {
/* Select build algorithm automatically */
AUTO_SELECT,
AUTO_SELECT = 0,
/* Use IVF-PQ to build all-neighbors knn graph */
IVF_PQ,
IVF_PQ = 1,
/* Experimental, use NN-Descent to build all-neighbors knn graph */
NN_DESCENT,
NN_DESCENT = 2,
/* Experimental, use iterative cagra search and optimize to build the knn graph */
ITERATIVE_CAGRA_SEARCH
ITERATIVE_CAGRA_SEARCH = 3
};

/** Parameters for VPQ compression. */
Expand Down Expand Up @@ -210,18 +210,18 @@ cuvsError_t cuvsCagraExtendParamsDestroy(cuvsCagraExtendParams_t params);
*/
enum cuvsCagraSearchAlgo {
/** For large batch sizes. */
SINGLE_CTA,
SINGLE_CTA = 0,
/** For small batch sizes. */
MULTI_CTA,
MULTI_KERNEL,
AUTO
MULTI_CTA = 1,
MULTI_KERNEL = 2,
AUTO = 3
};

/**
* @brief Enum to denote Hash Mode used while searching CAGRA index
*
*/
enum cuvsCagraHashMode { HASH, SMALL, AUTO_HASH };
enum cuvsCagraHashMode { HASH = 0, SMALL = 1, AUTO_HASH = 2 };

/**
* @brief Supplemental parameters to search CAGRA index
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -34,11 +34,11 @@ extern "C" {
*/
enum cuvsFilterType {
/* No filter */
NO_FILTER,
NO_FILTER = 0,
/* Filter an index with a bitset */
BITSET,
BITSET = 1,
/* Filter an index with a bitmap */
BITMAP
BITMAP = 2
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ extern "C" {
*/
enum cuvsHnswHierarchy {
/* Flat hierarchy, search is base-layer only */
NONE,
NONE = 0,
/* Full hierarchy is built using the CPU */
CPU,
CPU = 1,
/* Full hierarchy is built using the GPU */
GPU
GPU = 2
};

struct cuvsHnswIndexParams {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ extern "C" {
*/
typedef enum {
/** Index is replicated on each device, favors throughput */
CUVS_NEIGHBORS_MG_REPLICATED,
CUVS_NEIGHBORS_MG_REPLICATED = 0,
/** Index is split on several devices, favors scaling */
CUVS_NEIGHBORS_MG_SHARDED
CUVS_NEIGHBORS_MG_SHARDED = 1
} cuvsMultiGpuDistributionMode;

/**
* @brief Search mode when using a replicated index
*/
typedef enum {
/** Search queries are split to maintain equal load on GPUs */
CUVS_NEIGHBORS_MG_LOAD_BALANCER,
CUVS_NEIGHBORS_MG_LOAD_BALANCER = 0,
/** Each search query is processed by a single GPU in a round-robin fashion */
CUVS_NEIGHBORS_MG_ROUND_ROBIN
CUVS_NEIGHBORS_MG_ROUND_ROBIN = 1
} cuvsMultiGpuReplicatedSearchMode;

/**
* @brief Merge mode when using a sharded index
*/
typedef enum {
/** Search batches are merged on the root rank */
CUVS_NEIGHBORS_MG_MERGE_ON_ROOT_RANK,
CUVS_NEIGHBORS_MG_MERGE_ON_ROOT_RANK = 0,
/** Search batches are merged in a tree reduction fashion */
CUVS_NEIGHBORS_MG_TREE_MERGE
CUVS_NEIGHBORS_MG_TREE_MERGE = 1
} cuvsMultiGpuShardedMergeMode;

/**
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ extern "C" {
* @brief Enum to hold which ANN algorithm is being used in the tiered index
*/
typedef enum {
CUVS_TIERED_INDEX_ALGO_CAGRA,
CUVS_TIERED_INDEX_ALGO_IVF_FLAT,
CUVS_TIERED_INDEX_ALGO_IVF_PQ
CUVS_TIERED_INDEX_ALGO_CAGRA = 0,
CUVS_TIERED_INDEX_ALGO_IVF_FLAT = 1,
CUVS_TIERED_INDEX_ALGO_IVF_PQ = 2
} cuvsTieredIndexANNAlgo;

/**
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions cpp/src/cluster/kmeans_c.cpp → c/src/cluster/kmeans.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
#include <cuvs/cluster/kmeans.h>
#include <cuvs/cluster/kmeans.hpp>
#include <cuvs/core/c_api.h>
#include <cuvs/core/exceptions.hpp>
#include <cuvs/core/interop.hpp>

#include "../core/exceptions.hpp"
#include "../core/interop.hpp"

namespace {

Expand Down
3 changes: 2 additions & 1 deletion cpp/src/core/c_api.cpp → c/src/core/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/

#include <cuvs/core/c_api.h>
#include <cuvs/core/exceptions.hpp>
#include <cuvs/version_config.h>

#include <raft/core/device_resources_snmg.hpp>
Expand All @@ -32,6 +31,8 @@
#include <rmm/mr/device/pool_memory_resource.hpp>
#include <rmm/mr/host/pinned_memory_resource.hpp>

#include "../core/exceptions.hpp"

#include <cstdint>
#include <memory>
#include <thread>
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,7 +16,7 @@

#pragma once

#include "c_api.h"
#include <cuvs/core/c_api.h>

#include <exception>

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Copyright (c) 2024, NVIDIA CORPORATION.
* Copyright (c) 2024-2025, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -23,10 +23,11 @@
#include <raft/core/resources.hpp>

#include <cuvs/core/c_api.h>
#include <cuvs/core/exceptions.hpp>
#include <cuvs/core/interop.hpp>
#include <cuvs/distance/distance.hpp>

#include "../core/exceptions.hpp"
#include "../core/interop.hpp"

namespace {

template <typename T, typename DistT, typename LayoutT = raft::row_major>
Expand Down
Loading