From bbca1f0e8f9141869e4ef656fe9a8197ef32c9c5 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Mon, 5 Oct 2026 04:32:21 -0500 Subject: [PATCH 1/2] Upload the IVF list pointers with one copy per array recompute_internal_state copied the data and indices pointers of every list to the device with a separate one-element copy from pageable host memory, i.e. 2 * n_lists small copies. Gather the pointers on the host and upload each array with one copy; the function already synchronizes the stream before returning. --- cpp/src/neighbors/ivf_common.cuh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/cpp/src/neighbors/ivf_common.cuh b/cpp/src/neighbors/ivf_common.cuh index c445e3b6b7..07adcceee4 100644 --- a/cpp/src/neighbors/ivf_common.cuh +++ b/cpp/src/neighbors/ivf_common.cuh @@ -14,6 +14,8 @@ #include #include // matrix::detail::select::warpsort::warp_sort_distributed +#include + namespace cuvs::neighbors::ivf::detail { // Forward declaration of helper function to avoid including cub/device/* in header @@ -260,16 +262,19 @@ void recompute_internal_state(const raft::resources& res, Index& index) auto tmp_res = raft::resource::get_workspace_resource_ref(res); rmm::device_uvector sorted_sizes(index.n_lists(), stream, tmp_res); - // Actualize the list pointers + // Actualize the list pointers: gather them on the host and upload each array with a single copy + // instead of one tiny pageable H2D copy per list. The host buffers outlive the sync_stream below. auto data_ptrs = index.data_ptrs(); auto inds_ptrs = index.inds_ptrs(); + std::vector data_ptrs_host(index.n_lists()); + std::vector inds_ptrs_host(index.n_lists()); for (uint32_t label = 0; label < index.n_lists(); label++) { - auto& list = index.lists()[label]; - const auto data_ptr = list ? list->data_ptr() : nullptr; - const auto inds_ptr = list ? list->indices_ptr() : nullptr; - raft::copy(&data_ptrs(label), &data_ptr, 1, stream); - raft::copy(&inds_ptrs(label), &inds_ptr, 1, stream); + auto& list = index.lists()[label]; + data_ptrs_host[label] = list ? list->data_ptr() : nullptr; + inds_ptrs_host[label] = list ? list->indices_ptr() : nullptr; } + raft::copy(data_ptrs.data_handle(), data_ptrs_host.data(), data_ptrs_host.size(), stream); + raft::copy(inds_ptrs.data_handle(), inds_ptrs_host.data(), inds_ptrs_host.size(), stream); // Sort the cluster sizes in the descending order. // Use helper function to avoid including cub/device/* in this header From bf503b6b8aca4494476aa67fcb1cd7efbb0c41f1 Mon Sep 17 00:00:00 2001 From: Bradley Dice Date: Mon, 16 Nov 2026 14:15:27 -0600 Subject: [PATCH 2/2] Drop the historical comparison from the IVF list pointer upload comment --- cpp/src/neighbors/ivf_common.cuh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp/src/neighbors/ivf_common.cuh b/cpp/src/neighbors/ivf_common.cuh index 07adcceee4..36c420305a 100644 --- a/cpp/src/neighbors/ivf_common.cuh +++ b/cpp/src/neighbors/ivf_common.cuh @@ -262,8 +262,8 @@ void recompute_internal_state(const raft::resources& res, Index& index) auto tmp_res = raft::resource::get_workspace_resource_ref(res); rmm::device_uvector sorted_sizes(index.n_lists(), stream, tmp_res); - // Actualize the list pointers: gather them on the host and upload each array with a single copy - // instead of one tiny pageable H2D copy per list. The host buffers outlive the sync_stream below. + // Actualize the list pointers: gather them on the host and upload each array with a single copy. + // The host buffers outlive the sync_stream below. auto data_ptrs = index.data_ptrs(); auto inds_ptrs = index.inds_ptrs(); std::vector data_ptrs_host(index.n_lists());