Skip to content

Commit 5e8600d

Browse files
committed
fp32 dis computation
1 parent 9b371e4 commit 5e8600d

File tree

9 files changed

+495
-122
lines changed

9 files changed

+495
-122
lines changed

c/include/cuvs/neighbors/nn_descent.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ extern "C" {
3434
* `max_iterations`: The number of iterations that nn-descent will refine
3535
* the graph for. More iterations produce a better quality graph at cost of performance
3636
* `termination_threshold`: The delta at which nn-descent will terminate its iterations
37+
* `return_distances`: Boolean to decide whether to return distances array
38+
* `fp32_dist_computation`: Boolean to decide whether to use fp32 distance computation for better
39+
* precision at the cost of performance and memory usage. We recommend using this for smaller
40+
* dimensions or if the distances array is needed for precision-sensitive workloads.
3741
*/
3842
struct cuvsNNDescentIndexParams {
3943
cuvsDistanceType metric;
@@ -43,6 +47,7 @@ struct cuvsNNDescentIndexParams {
4347
size_t max_iterations;
4448
float termination_threshold;
4549
bool return_distances;
50+
bool fp32_dist_computation;
4651
};
4752

4853
typedef struct cuvsNNDescentIndexParams* cuvsNNDescentIndexParams_t;

c/src/neighbors/nn_descent.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void* _build(cuvsResources_t res,
4343
build_params.max_iterations = params.max_iterations;
4444
build_params.termination_threshold = params.termination_threshold;
4545
build_params.return_distances = params.return_distances;
46+
build_params.fp32_dist_computation = params.fp32_dist_computation;
4647

4748
using graph_type = raft::host_matrix_view<IdxT, int64_t, raft::row_major>;
4849
std::optional<graph_type> graph;
@@ -177,7 +178,8 @@ extern "C" cuvsError_t cuvsNNDescentIndexParamsCreate(cuvsNNDescentIndexParams_t
177178
.intermediate_graph_degree = cpp_params.intermediate_graph_degree,
178179
.max_iterations = cpp_params.max_iterations,
179180
.termination_threshold = cpp_params.termination_threshold,
180-
.return_distances = cpp_params.return_distances};
181+
.return_distances = cpp_params.return_distances,
182+
.fp32_dist_computation = cpp_params.fp32_dist_computation};
181183
});
182184
}
183185

cpp/include/cuvs/neighbors/nn_descent.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ namespace cuvs::neighbors::nn_descent {
3737
* the graph for. More iterations produce a better quality graph at cost of performance
3838
* - `termination_threshold`: The delta at which nn-descent will terminate its iterations
3939
* - `return_distances`: Boolean to decide whether to return distances array
40+
* - `fp32_dist_computation`: Boolean to decide whether to use fp32 distance computation for better
41+
* precision at the cost of performance and memory usage. We recommend using this for smaller
42+
* dimensions or if the distances array is needed for precision-sensitive workloads.
4043
*/
4144
struct index_params : cuvs::neighbors::index_params {
4245
size_t graph_degree = 64;
4346
size_t intermediate_graph_degree = 128;
4447
size_t max_iterations = 20;
4548
float termination_threshold = 0.0001;
4649
bool return_distances = true;
50+
bool fp32_dist_computation = false;
4751

4852
/** @brief Construct NN descent parameters for a specific kNN graph degree
4953
*

0 commit comments

Comments
 (0)