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

ivf-flat: fix incorrect recomputed size of the index #1525

Merged
Show file tree
Hide file tree
Changes from all 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
27 changes: 16 additions & 11 deletions cpp/include/raft/neighbors/ivf_flat_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,18 @@
#include <raft/core/error.hpp>
#include <raft/core/host_mdarray.hpp>
#include <raft/core/mdspan_types.hpp>
#include <raft/core/operators.hpp>
#include <raft/core/resource/thrust_policy.hpp>
#include <raft/core/resources.hpp>
#include <raft/distance/distance_types.hpp>
#include <raft/neighbors/ivf_list_types.hpp>
#include <raft/util/integer_utils.hpp>

#include <thrust/reduce.h>

#include <algorithm> // std::max
#include <memory>
#include <optional>
#include <thrust/fill.h>
#include <type_traits>

namespace raft::neighbors::ivf_flat {
Expand Down Expand Up @@ -303,20 +306,22 @@ struct index : ann::index {
auto stream = resource::get_cuda_stream(res);

// Actualize the list pointers
auto this_lists = lists();
auto this_data_ptrs = data_ptrs();
auto this_inds_ptrs = inds_ptrs();
IdxT recompute_total_size = 0;
auto this_lists = lists();
auto this_data_ptrs = data_ptrs();
auto this_inds_ptrs = inds_ptrs();
for (uint32_t label = 0; label < this_lists.size(); label++) {
auto& list = this_lists[label];
const auto data_ptr = list ? list->data.data_handle() : nullptr;
const auto inds_ptr = list ? list->indices.data_handle() : nullptr;
const auto list_size = list ? IdxT(list->size) : 0;
auto& list = this_lists[label];
const auto data_ptr = list ? list->data.data_handle() : nullptr;
const auto inds_ptr = list ? list->indices.data_handle() : nullptr;
copy(&this_data_ptrs(label), &data_ptr, 1, stream);
copy(&this_inds_ptrs(label), &inds_ptr, 1, stream);
recompute_total_size += list_size;
}
total_size_ = recompute_total_size;
auto this_list_sizes = list_sizes().data_handle();
total_size_ = thrust::reduce(resource::get_thrust_policy(res),
this_list_sizes,
this_list_sizes + this_lists.size(),
0,
raft::add_op{});
check_consistency();
}

Expand Down
1 change: 1 addition & 0 deletions cpp/test/neighbors/ann_ivf_flat.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ class AnnIVFFlatTest : public ::testing::TestWithParam<AnnIvfFlatInputs<IdxT>> {
ivf_flat::detail::serialize(handle_, "ivf_flat_index", index_2);

auto index_loaded = ivf_flat::detail::deserialize<DataT, IdxT>(handle_, "ivf_flat_index");
ASSERT_EQ(index_2.size(), index_loaded.size());

ivf_flat::search(handle_,
search_params,
Expand Down