Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use slicing kernel to copy distances inside NN Descent #2380

Merged
merged 17 commits into from
Jul 22, 2024
21 changes: 15 additions & 6 deletions cpp/include/raft/neighbors/detail/nn_descent.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

#include "../nn_descent_types.hpp"

#include <raft/core/copy.cuh>
#include <raft/core/device_mdarray.hpp>
#include <raft/core/error.hpp>
#include <raft/core/host_mdarray.hpp>
#include <raft/core/operators.hpp>
#include <raft/core/resource/cuda_stream.hpp>
#include <raft/core/resources.hpp>
#include <raft/matrix/slice.cuh>
#include <raft/neighbors/detail/cagra/device_common.hpp>
#include <raft/spatial/knn/detail/ann_utils.cuh>
#include <raft/util/arch.cuh> // raft::util::arch::SM_*
Expand Down Expand Up @@ -1365,12 +1367,19 @@ void GNND<Data_t, Index_t, epilogue_op>::build(Data_t* data,
static_assert(sizeof(decltype(*(graph_.h_dists.data_handle()))) >= sizeof(Index_t));

if (return_distances) {
for (size_t i = 0; i < (size_t)nrow_; i++) {
raft::copy(output_distances + i * build_config_.output_graph_degree,
graph_.h_dists.data_handle() + i * build_config_.node_degree,
build_config_.output_graph_degree,
raft::resource::get_cuda_stream(res));
}
auto graph_d_dists = raft::make_device_matrix<DistData_t, int64_t, raft::row_major>(
res, nrow_, build_config_.node_degree);
raft::copy(res, graph_d_dists.view(), graph_.h_dists.view());

auto output_dist_view = raft::make_device_matrix_view<DistData_t, int64_t, raft::row_major>(
output_distances, nrow_, build_config_.output_graph_degree);

raft::matrix::slice_coordinates coords{static_cast<int64_t>(0),
static_cast<int64_t>(0),
static_cast<int64_t>(nrow_),
static_cast<int64_t>(build_config_.output_graph_degree)};
raft::matrix::slice<DistData_t, int64_t, raft::row_major>(
res, raft::make_const_mdspan(graph_d_dists.view()), output_dist_view, coords);
}

Index_t* graph_shrink_buffer = (Index_t*)graph_.h_dists.data_handle();
Expand Down
Loading