From c272038df808a05f0dddd4e4fdbe084cecfdaff3 Mon Sep 17 00:00:00 2001 From: tsuki <12711693+enp1s0@users.noreply.github.com> Date: Fri, 6 Oct 2023 10:59:19 +0800 Subject: [PATCH] [BUG] Fix a bug in NN descent (#1869) I got errors when compiling a program using raft NN-descent. This PR fixes the bug. ## Error e.g. ``` /home/.../include/raft/neighbors/detail/nn_descent.cuh(1158): error: invalid narrowing conversion from "unsigned long" to "int" h_rev_graph_old_{static_cast(nrow_ * NUM_SAMPLES)}, ``` - nvcc ``` Built on Tue_Aug_15_22:02:13_PDT_2023 Cuda compilation tools, release 12.2, V12.2.140 Build cuda_12.2.r12.2/compiler.33191640_0 ``` - gcc ``` gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0 ``` - thrust : 2.2 (This is the cause of this error [[detail](https://github.com/rapidsai/raft/pull/1869#issuecomment-1746637944)]) # Change Use `Class(...)` instead of `Class{...}`. # Cause The NN-descent code calls constructors of `thrust::host_vector` as shown below: ```cpp graph_host_buffer_{static_cast(nrow_ * DEGREE_ON_DEVICE)}, ``` However, this constructor is regarded as a list initialization. This is the same as the following code outputting 1 instead of 2. ```cpp #include #include int main() { std::vector list{2}; std::cout << list.size() << std::endl; } ``` [detail](https://en.cppreference.com/w/cpp/language/list_initialization) Authors: - tsuki (https://github.com/enp1s0) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Corey J. Nolet (https://github.com/cjnolet) - Divye Gala (https://github.com/divyegala) URL: https://github.com/rapidsai/raft/pull/1869 --- cpp/include/raft/neighbors/detail/nn_descent.cuh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cpp/include/raft/neighbors/detail/nn_descent.cuh b/cpp/include/raft/neighbors/detail/nn_descent.cuh index 009ffd4684..1fb568a934 100644 --- a/cpp/include/raft/neighbors/detail/nn_descent.cuh +++ b/cpp/include/raft/neighbors/detail/nn_descent.cuh @@ -980,9 +980,9 @@ GnndGraph::GnndGraph(const size_t nrow, num_samples(num_samples), bloom_filter(nrow, internal_node_degree / segment_size, 3), h_dists{raft::make_host_matrix(nrow, node_degree)}, - h_graph_new{nrow * num_samples}, - h_list_sizes_new{nrow}, - h_graph_old{nrow * num_samples}, + h_graph_new(nrow * num_samples), + h_list_sizes_new(nrow), + h_graph_old(nrow * num_samples), h_list_sizes_old{nrow} { // node_degree must be a multiple of segment_size; @@ -1150,12 +1150,12 @@ GNND::GNND(raft::resources const& res, const BuildConfig& build raft::make_device_matrix(res, nrow_, DEGREE_ON_DEVICE)}, dists_buffer_{ raft::make_device_matrix(res, nrow_, DEGREE_ON_DEVICE)}, - graph_host_buffer_{static_cast(nrow_ * DEGREE_ON_DEVICE)}, - dists_host_buffer_{static_cast(nrow_ * DEGREE_ON_DEVICE)}, + graph_host_buffer_(nrow_ * DEGREE_ON_DEVICE), + dists_host_buffer_(nrow_ * DEGREE_ON_DEVICE), d_locks_{raft::make_device_vector(res, nrow_)}, - h_rev_graph_new_{static_cast(nrow_ * NUM_SAMPLES)}, - h_graph_old_{static_cast(nrow_ * NUM_SAMPLES)}, - h_rev_graph_old_{static_cast(nrow_ * NUM_SAMPLES)}, + h_rev_graph_new_(nrow_ * NUM_SAMPLES), + h_graph_old_(nrow_ * NUM_SAMPLES), + h_rev_graph_old_(nrow_ * NUM_SAMPLES), d_list_sizes_new_{raft::make_device_vector(res, nrow_)}, d_list_sizes_old_{raft::make_device_vector(res, nrow_)} {