Skip to content

Commit

Permalink
[BUG] Fix a bug in NN descent (#1869)
Browse files Browse the repository at this point in the history
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<size_t>(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](#1869 (comment))])

# 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<size_t>(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 <iostream>
#include <vector>

int main() {
  std::vector<float> 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: #1869
  • Loading branch information
enp1s0 authored Oct 6, 2023
1 parent 3241add commit d9fde97
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions cpp/include/raft/neighbors/detail/nn_descent.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -980,9 +980,9 @@ GnndGraph<Index_t>::GnndGraph(const size_t nrow,
num_samples(num_samples),
bloom_filter(nrow, internal_node_degree / segment_size, 3),
h_dists{raft::make_host_matrix<DistData_t, size_t, raft::row_major>(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;
Expand Down Expand Up @@ -1150,12 +1150,12 @@ GNND<Data_t, Index_t>::GNND(raft::resources const& res, const BuildConfig& build
raft::make_device_matrix<ID_t, Index_t, raft::row_major>(res, nrow_, DEGREE_ON_DEVICE)},
dists_buffer_{
raft::make_device_matrix<DistData_t, Index_t, raft::row_major>(res, nrow_, DEGREE_ON_DEVICE)},
graph_host_buffer_{static_cast<size_t>(nrow_ * DEGREE_ON_DEVICE)},
dists_host_buffer_{static_cast<size_t>(nrow_ * DEGREE_ON_DEVICE)},
graph_host_buffer_(nrow_ * DEGREE_ON_DEVICE),
dists_host_buffer_(nrow_ * DEGREE_ON_DEVICE),
d_locks_{raft::make_device_vector<int, Index_t>(res, nrow_)},
h_rev_graph_new_{static_cast<size_t>(nrow_ * NUM_SAMPLES)},
h_graph_old_{static_cast<size_t>(nrow_ * NUM_SAMPLES)},
h_rev_graph_old_{static_cast<size_t>(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<int2, Index_t>(res, nrow_)},
d_list_sizes_old_{raft::make_device_vector<int2, Index_t>(res, nrow_)}
{
Expand Down

0 comments on commit d9fde97

Please sign in to comment.