Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
5 changes: 4 additions & 1 deletion cpp/bench/ann/src/cuvs/cuvs_cagra_hnswlib.cu
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/

Expand All @@ -20,6 +20,9 @@ auto parse_build_param(const nlohmann::json& conf) ->
typename cuvs::bench::cuvs_cagra_hnswlib<T, IdxT>::build_param param;
auto& hnsw_params = param.hnsw_index_params;
auto& cagra_params = param.cagra_build_params;
if (conf.contains("use_original_id_graph")) {
param.use_original_id_graph = conf.at("use_original_id_graph");
}
if (conf.contains("hierarchy")) {
if (conf.at("hierarchy") == "none") {
hnsw_params.hierarchy = cuvs::neighbors::hnsw::HnswHierarchy::NONE;
Expand Down
18 changes: 15 additions & 3 deletions cpp/bench/ann/src/cuvs/cuvs_cagra_hnswlib_wrapper.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2023-2025, NVIDIA CORPORATION.
* SPDX-FileCopyrightText: Copyright (c) 2023-2026, NVIDIA CORPORATION.
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
Expand All @@ -22,6 +22,7 @@ class cuvs_cagra_hnswlib : public algo<T>, public algo_gpu {
using cagra_wrapper_params = typename cuvs_cagra<T, IdxT>::build_param;
cagra_wrapper_params cagra_build_params;
cuvs::neighbors::hnsw::index_params hnsw_index_params;
bool use_original_id_graph = false;
};

struct search_param : public search_param_base {
Expand Down Expand Up @@ -102,9 +103,20 @@ void cuvs_cagra_hnswlib<T, IdxT>::build(const T* dataset, size_t nrow)
cagra_wrapper.build(dataset, nrow);
auto& cagra_index = *cagra_wrapper.get_index();

// pass the dataset directly to HNSW if it's on the host
const bool is_ace_disk_build = cagra_index.dataset_fd().has_value() &&
cagra_index.graph_fd().has_value() &&
cagra_index.mapping_fd().has_value();

std::optional<raft::host_matrix_view<const T, int64_t>> opt_dataset_view = std::nullopt;
if (dataset_is_on_host) {
// Regular CAGRA build: pass the dataset directly to HNSW if it's on the host
if (dataset_is_on_host && !is_ace_disk_build) {
opt_dataset_view.emplace(
raft::make_host_matrix_view<const T, int64_t>(dataset, nrow, this->dim_));
}
// ACE disk build with original id graph: pass the dataset directly to HNSW to remap the graph to
// original ids
if (is_ace_disk_build && build_param_.use_original_id_graph) {
RAFT_EXPECTS(dataset_is_on_host, "Dataset must be on host for original id graph remapping.");
opt_dataset_view.emplace(
raft::make_host_matrix_view<const T, int64_t>(dataset, nrow, this->dim_));
}
Expand Down
12 changes: 8 additions & 4 deletions cpp/include/cuvs/neighbors/hnsw.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,8 @@ std::unique_ptr<index<int8_t>> build(
* @param[in] res raft resources
* @param[in] params hnsw index parameters
* @param[in] cagra_index cagra index
* @param[in] dataset optional dataset to avoid extra memory copy when hierarchy is `CPU`
* @param[in] dataset optional dataset in the original row order. When provided for a disk-backed
* ACE index, cuVS remaps the on-disk ACE graph back to original ids before exporting.
*
* Usage example:
* @code{.cpp}
Expand Down Expand Up @@ -488,7 +489,8 @@ std::unique_ptr<index<float>> from_cagra(
* @param[in] res raft resources
* @param[in] params hnsw index parameters
* @param[in] cagra_index cagra index
* @param[in] dataset optional dataset to avoid extra memory copy when hierarchy is `CPU`
* @param[in] dataset optional dataset in the original row order. When provided for a disk-backed
* ACE index, cuVS remaps the on-disk ACE graph back to original ids before exporting.
*
* Usage example:
* @code{.cpp}
Expand Down Expand Up @@ -524,7 +526,8 @@ std::unique_ptr<index<half>> from_cagra(
* @param[in] res raft resources
* @param[in] params hnsw index parameters
* @param[in] cagra_index cagra index
* @param[in] dataset optional dataset to avoid extra memory copy when hierarchy is `CPU`
* @param[in] dataset optional dataset in the original row order. When provided for a disk-backed
* ACE index, cuVS remaps the on-disk ACE graph back to original ids before exporting.
*
* Usage example:
* @code{.cpp}
Expand Down Expand Up @@ -560,7 +563,8 @@ std::unique_ptr<index<uint8_t>> from_cagra(
* @param[in] res raft resources
* @param[in] params hnsw index parameters
* @param[in] cagra_index cagra index
* @param[in] dataset optional dataset to avoid extra memory copy when hierarchy is `CPU`
* @param[in] dataset optional dataset in the original row order. When provided for a disk-backed
* ACE index, cuVS remaps the on-disk ACE graph back to original ids before exporting.
*
* Usage example:
* @code{.cpp}
Expand Down
Loading
Loading