Skip to content

Commit 591f9d6

Browse files
authored
Merge branch 'branch-25.12' into byte-array-interleaved
2 parents 35174e6 + a05de3e commit 591f9d6

File tree

19 files changed

+302
-78
lines changed

19 files changed

+302
-78
lines changed

c/CMakeLists.txt

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,37 @@ set_target_properties(
106106
EXPORT_NAME c_api
107107
)
108108

109-
target_compile_definitions(cuvs_c PUBLIC $<$<BOOL:${BUILD_CAGRA_HNSWLIB}>:CUVS_BUILD_CAGRA_HNSWLIB>)
109+
# Encode what optional components we are building
110+
set(CUVS_BUILD_CAGRA_HNSWLIB ${BUILD_CAGRA_HNSWLIB})
111+
set(CUVS_BUILD_MG_ALGOS ${BUILD_MG_ALGOS})
112+
# cmake-lint: disable=E1126
113+
file(
114+
CONFIGURE
115+
OUTPUT
116+
"${CMAKE_CURRENT_BINARY_DIR}/include/cuvs/core/c_config.h"
117+
CONTENT
118+
[=[
119+
#pragma once
120+
#ifndef CUVS_BUILD_CAGRA_HNSWLIB
121+
#cmakedefine CUVS_BUILD_CAGRA_HNSWLIB
122+
#endif
123+
#ifndef CUVS_BUILD_MG_ALGOS
124+
#cmakedefine CUVS_BUILD_MG_ALGOS
125+
#endif
126+
]=]
127+
)
128+
target_compile_definitions(
129+
cuvs_c PUBLIC $<$<BOOL:${BUILD_CAGRA_HNSWLIB}>:CUVS_BUILD_CAGRA_HNSWLIB>
130+
$<$<BOOL:${BUILD_MG_ALGOS}>:CUVS_BUILD_MG_ALGOS>
131+
)
110132

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

113135
target_include_directories(
114136
cuvs_c
115137
PUBLIC "$<BUILD_INTERFACE:${DLPACK_INCLUDE_DIR}>"
116138
"$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
139+
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>"
117140
INTERFACE "$<INSTALL_INTERFACE:include>"
118141
)
119142

@@ -160,6 +183,11 @@ if(PROJECT_IS_TOP_LEVEL)
160183
COMPONENT cuvs_c
161184
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
162185
)
186+
install(
187+
FILES ${CMAKE_CURRENT_BINARY_DIR}/include/cuvs/core/c_config.h
188+
COMPONENT cuvs_c
189+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/cuvs/core/
190+
)
163191
endif()
164192

165193
# ##################################################################################################

c/include/cuvs/core/all.h

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// This is a list of required header files that cuvs_c rust/go/java
18+
// will bind to.
19+
20+
#pragma once
21+
22+
#include <cuvs/core/c_config.h>
23+
#include <cuvs/core/c_api.h>
24+
25+
#include <cuvs/cluster/kmeans.h>
26+
27+
#include <cuvs/distance/distance.h>
28+
#include <cuvs/distance/pairwise_distance.h>
29+
30+
#include <cuvs/neighbors/all_neighbors.h>
31+
#include <cuvs/neighbors/brute_force.h>
32+
#include <cuvs/neighbors/cagra.h>
33+
#include <cuvs/neighbors/common.h>
34+
#include <cuvs/neighbors/ivf_flat.h>
35+
#include <cuvs/neighbors/ivf_pq.h>
36+
#include <cuvs/neighbors/nn_descent.h>
37+
#include <cuvs/neighbors/refine.h>
38+
#include <cuvs/neighbors/tiered_index.h>
39+
#include <cuvs/neighbors/vamana.h>
40+
41+
#ifdef CUVS_BUILD_CAGRA_HNSWLIB
42+
#include <cuvs/neighbors/hnsw.h>
43+
#endif
44+
45+
#ifdef CUVS_BUILD_MG_ALGOS
46+
#include <cuvs/neighbors/mg_cagra.h>
47+
#include <cuvs/neighbors/mg_common.h>
48+
#include <cuvs/neighbors/mg_ivf_flat.h>
49+
#include <cuvs/neighbors/mg_ivf_pq.h>
50+
#endif
51+
52+
#include <cuvs/preprocessing/quantize/binary.h>
53+
#include <cuvs/preprocessing/quantize/scalar.h>

c/include/cuvs/neighbors/cagra.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ enum cuvsCagraSearchAlgo {
214214
/** For small batch sizes. */
215215
MULTI_CTA = 1,
216216
MULTI_KERNEL = 2,
217-
AUTO = 3
217+
AUTO = 100
218218
};
219219

220220
/**
221221
* @brief Enum to denote Hash Mode used while searching CAGRA index
222222
*
223223
*/
224-
enum cuvsCagraHashMode { HASH = 0, SMALL = 1, AUTO_HASH = 2 };
224+
enum cuvsCagraHashMode { HASH = 0, SMALL = 1, AUTO_HASH = 100 };
225225

226226
/**
227227
* @brief Supplemental parameters to search CAGRA index

c/include/cuvs/neighbors/common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#pragma once
1818

19-
#include <cuvs/distance/distance.h>
2019
#include <stdint.h>
2120

2221
#ifdef __cplusplus

c/include/cuvs/neighbors/mg_common.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
#pragma once
1818

19-
#include <cuvs/core/c_api.h>
2019
#include <stdint.h>
2120

2221
#ifdef __cplusplus

c/include/cuvs/preprocessing/quantize/binary.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ extern "C" {
3030
* and sampling_median thresholds are calculated separately for each dimension.
3131
*
3232
*/
33-
enum cuvsBinaryQuantizerThreshold { ZERO, MEAN, SAMPLING_MEDIAN };
33+
enum cuvsBinaryQuantizerThreshold {
34+
ZERO=0,
35+
MEAN=1,
36+
SAMPLING_MEDIAN=2
37+
};
3438

3539
/**
3640
* @brief Binary quantizer parameters.
@@ -39,12 +43,12 @@ struct cuvsBinaryQuantizerParams {
3943
/*
4044
* specifies the threshold to set a bit in cuvsBinaryQuantizerTransform
4145
*/
42-
cuvsBinaryQuantizerThreshold threshold = MEAN;
46+
enum cuvsBinaryQuantizerThreshold threshold;
4347

4448
/*
4549
* specifies the sampling ratio
4650
*/
47-
float sampling_ratio = 0.1;
51+
float sampling_ratio;
4852
};
4953

5054
typedef struct cuvsBinaryQuantizerParams* cuvsBinaryQuantizerParams_t;

c/src/preprocessing/quantize/binary.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,10 @@ void* _train(cuvsResources_t res,
105105

106106
extern "C" cuvsError_t cuvsBinaryQuantizerParamsCreate(cuvsBinaryQuantizerParams_t* params)
107107
{
108-
return cuvs::core::translate_exceptions([=] { *params = new cuvsBinaryQuantizerParams; });
108+
return cuvs::core::translate_exceptions([=] {
109+
*params =
110+
new cuvsBinaryQuantizerParams{.threshold = MEAN, .sampling_ratio = 0.1};
111+
});
109112
}
110113

111114
extern "C" cuvsError_t cuvsBinaryQuantizerParamsDestroy(cuvsBinaryQuantizerParams_t params)

c/tests/CMakeLists.txt

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -89,36 +89,22 @@ if(BUILD_CAGRA_HNSWLIB)
8989
target_compile_definitions(HNSW_C_TEST PUBLIC CUVS_BUILD_CAGRA_HNSWLIB)
9090
endif()
9191

92-
add_executable(cuvs_c_test core/c_api.c)
93-
target_link_libraries(cuvs_c_test PUBLIC cuvs::c_api)
92+
# ##################################################################################################
93+
# * Validate C API ---------------------------------------------------------------
9494

95-
add_executable(cuvs_c_neighbors_test neighbors/c_api.c)
96-
target_link_libraries(cuvs_c_neighbors_test PUBLIC cuvs::c_api)
95+
ConfigureTest(NAME cuvs_c_headers PATH core/headers.c)
96+
ConfigureTest(NAME cuvs_c_test PATH core/c_api.c)
97+
ConfigureTest(NAME cuvs_c_neighbors_test PATH neighbors/c_api.c)
9798

98-
set_target_properties(
99-
cuvs_c_test cuvs_c_neighbors_test
100-
PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$<BUILD_INTERFACE:${CUVS_C_BINARY_DIR}/gtests>"
101-
INSTALL_RPATH "\$ORIGIN/../../../lib"
102-
)
99+
# ##################################################################################################
100+
# * Validate installed headers are listed in `all.h`
103101

104-
rapids_test_add(
105-
NAME cuvs_c_test
106-
COMMAND cuvs_c_test
107-
GPUS 1
108-
PERCENT 100
109-
INSTALL_COMPONENT_SET testing
110-
)
111-
rapids_test_add(
112-
NAME cuvs_c_neighbors_test
113-
COMMAND cuvs_c_neighbors_test
114-
GPUS 1
115-
PERCENT 100
116-
INSTALL_COMPONENT_SET testing
117-
)
102+
include(cmake/header_check.cmake)
103+
cuvs_c_add_header_check("${CUVS_C_SOURCE_DIR}" "cuvs/core/all.h" INSTALL_COMPONENT_SET testing)
118104

119105
# ##################################################################################################
120-
# Install tests ####################################################################################
121-
# ##################################################################################################
106+
# * Install Tests ---------------------------------------------------------------
107+
122108
if(PROJECT_IS_TOP_LEVEL)
123109
rapids_test_install_relocatable(INSTALL_COMPONENT_SET testing DESTINATION bin/gtests/libcuvs)
124110
endif()

c/tests/cmake/header_check.cmake

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# =============================================================================
2+
# Copyright (c) 2025, NVIDIA CORPORATION.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
# in compliance with the License. You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software distributed under the License
10+
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
# or implied. See the License for the specific language governing permissions and limitations under
12+
# the License.
13+
# =============================================================================
14+
15+
# Build a list of all headers in `c/include/cuvs`
16+
#
17+
# cmake-lint: disable=E1126
18+
function(cuvs_c_add_header_check project_root binding_header COMPONENT_PLACEHOLDER install_set)
19+
file(
20+
GLOB_RECURSE all_headers_to_match
21+
RELATIVE "${project_root}/include/"
22+
"${project_root}/include/*.h"
23+
)
24+
25+
set(template_contents
26+
[=[
27+
set(all_headers_to_match @all_headers_to_match@)
28+
set(binding_header_name @binding_header@)
29+
set(binary_dir @CMAKE_CURRENT_BINARY_DIR@)
30+
set(src_dir @CMAKE_SOURCE_DIR@)
31+
32+
function(check_binding_header mode header_list_var)
33+
34+
if(mode STREQUAL BUILD)
35+
set(path "${src_dir}/include/${binding_header_name}")
36+
else()
37+
# Walk up the binary dir till we
38+
set(path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include/${binding_header_name}")
39+
endif()
40+
41+
if(EXISTS "${path}")
42+
file(READ "${path}" binding_header_contents)
43+
string(REPLACE "\n" "" binding_header_contents "${binding_header_contents}")
44+
foreach(entry ${${header_list_var}})
45+
if(NOT entry STREQUAL binding_header_name)
46+
string(FIND "${binding_header_contents}" "<${entry}>" contains)
47+
if(contains STREQUAL "-1")
48+
message(FATAL_ERROR "include \"${entry}\" not found in contents of ${binding_header_name}.")
49+
endif()
50+
endif()
51+
endforeach()
52+
else()
53+
message(FATAL_ERROR "check_binding_header failed to find ${binding_header_name} on disk.")
54+
endif()
55+
endfunction()
56+
57+
function(check_installed_headers )
58+
set(path "${CMAKE_CURRENT_FUNCTION_LIST_DIR}/include/")
59+
file(GLOB_RECURSE installed_headers RELATIVE "${path}/" "${path}/cuvs/*.h")
60+
check_binding_header(INSTALL installed_headers)
61+
endfunction()
62+
63+
if(CMAKE_CURRENT_LIST_DIR STREQUAL binary_dir)
64+
# Build directory checks
65+
#
66+
# 1. Check that binding header content includes all headers
67+
# that we cached
68+
#
69+
check_binding_header(BUILD all_headers_to_match)
70+
else()
71+
# Install directory checks
72+
#
73+
# 1. Check that all headers we have in our cached list are installed
74+
# 2. Check that binding header content includes all headers
75+
# that have have installed
76+
check_binding_header(INSTALL all_headers_to_match)
77+
check_installed_headers()
78+
endif()
79+
80+
]=]
81+
)
82+
83+
set(output_path "${CMAKE_CURRENT_BINARY_DIR}/cuvs_header_check.cmake")
84+
file(CONFIGURE OUTPUT "${output_path}" CONTENT "${template_contents}" @ONLY)
85+
86+
# Most likely need to roll all this into a CMake
87+
add_test(NAME cuvs_c_verify_install_headers COMMAND ${CMAKE_COMMAND} "-P=${output_path}")
88+
install(
89+
FILES "${output_path}"
90+
COMPONENT testing
91+
DESTINATION "."
92+
EXCLUDE_FROM_ALL
93+
)
94+
set_property(
95+
TARGET rapids_test_install_${install_set}
96+
APPEND
97+
PROPERTY "TESTS_TO_RUN" "cuvs_c_verify_install_headers"
98+
)
99+
endfunction()

c/tests/core/headers.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright (c) 2025, NVIDIA CORPORATION.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
// Basic smoke test to verify non of the C API headers
18+
// ever use a C++ only construct
19+
#include <cuvs/core/all.h>
20+
#include <cuvs/core/all.h> //smoke out missing include guards
21+
22+
int main()
23+
{
24+
return 0;
25+
}

0 commit comments

Comments
 (0)