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

FP16 API for CAGRA and IVF-PQ #264

Merged
merged 19 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Fix build instantiation
  • Loading branch information
tfeher committed Jul 30, 2024
commit ef2d8c5df6b0f0795d59c3aec32557ab246fa6d3
4 changes: 2 additions & 2 deletions cpp/include/cuvs/neighbors/cagra.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ auto build(raft::resources const& res,
auto build(raft::resources const& res,
const cuvs::neighbors::cagra::index_params& params,
raft::device_matrix_view<const half, int64_t, raft::row_major> dataset)
-> cuvs::neighbors::cagra::index<float, uint32_t>;
-> cuvs::neighbors::cagra::index<half, uint32_t>;

/**
* @brief Build the index from the dataset for efficient search.
Expand Down Expand Up @@ -586,7 +586,7 @@ auto build(raft::resources const& res,
auto build(raft::resources const& res,
const cuvs::neighbors::cagra::index_params& params,
raft::host_matrix_view<const half, int64_t, raft::row_major> dataset)
-> cuvs::neighbors::cagra::index<float, uint32_t>;
-> cuvs::neighbors::cagra::index<half, uint32_t>;

/**
* @brief Build the index from the dataset for efficient search.
Expand Down
1 change: 1 addition & 0 deletions cpp/src/neighbors/cagra.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ index<T, IdxT> build(
const index_params& params,
raft::mdspan<const T, raft::matrix_extent<int64_t>, raft::row_major, Accessor> dataset)
{
// return cuvs::neighbors::cagra::index(res, params.metric);
return cuvs::neighbors::cagra::detail::build<T, IdxT, Accessor>(res, params, dataset);
}

Expand Down
49 changes: 14 additions & 35 deletions cpp/src/neighbors/cagra_build_half.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,20 @@

namespace cuvs::neighbors::cagra {

#define RAFT_INST_CAGRA_BUILD(T, IdxT) \
auto build(raft::resources const& handle, \
const cuvs::neighbors::cagra::index_params& params, \
raft::device_matrix_view<const T, int64_t, raft::row_major> dataset) \
-> cuvs::neighbors::cagra::index<T, IdxT> \
{ \
return cuvs::neighbors::cagra::build<T, IdxT>(handle, params, dataset); \
} \
\
auto build(raft::resources const& handle, \
const cuvs::neighbors::cagra::index_params& params, \
raft::host_matrix_view<const T, int64_t, raft::row_major> dataset) \
-> cuvs::neighbors::cagra::index<T, IdxT> \
{ \
return cuvs::neighbors::cagra::build<T, IdxT>(handle, params, dataset); \
} \
\
void build_device(raft::resources const& handle, \
const cuvs::neighbors::cagra::index_params& params, \
raft::device_matrix_view<const T, int64_t, raft::row_major> dataset, \
cuvs::neighbors::cagra::index<T, IdxT>& idx) \
{ \
idx = build(handle, params, dataset); \
} \
\
void build_host(raft::resources const& handle, \
const cuvs::neighbors::cagra::index_params& params, \
raft::host_matrix_view<const T, int64_t, raft::row_major> dataset, \
cuvs::neighbors::cagra::index<T, IdxT>& idx) \
{ \
idx = build(handle, params, dataset); \
}
cuvs::neighbors::cagra::index<half, uint32_t> build(
raft::resources const& handle,
const cuvs::neighbors::cagra::index_params& params,
raft::device_matrix_view<const half, int64_t, raft::row_major> dataset)
{
return cuvs::neighbors::cagra::build<half, uint32_t>(handle, params, dataset);
}

RAFT_INST_CAGRA_BUILD(half, uint32_t);

#undef RAFT_INST_CAGRA_BUILD
cuvs::neighbors::cagra::index<half, uint32_t> build(
raft::resources const& handle,
const cuvs::neighbors::cagra::index_params& params,
raft::host_matrix_view<const half, int64_t, raft::row_major> dataset)
{
return cuvs::neighbors::cagra::build<half, uint32_t>(handle, params, dataset);
}

} // namespace cuvs::neighbors::cagra
59 changes: 1 addition & 58 deletions cpp/src/neighbors/cagra_serialize_half.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,68 +15,11 @@
*/

#include "cagra_serialize.cuh"
#include <raft/core/device_resources.hpp>

#include <cuvs/neighbors/cagra.hpp>

#include <cuda_fp16.h>

#include <sstream>
#include <string>

namespace cuvs::neighbors::cagra {

#define RAFT_INST_CAGRA_SERIALIZE(DTYPE) \
void serialize_file(raft::resources const& handle, \
const std::string& filename, \
const cuvs::neighbors::cagra::index<DTYPE, uint32_t>& index, \
bool include_dataset) \
{ \
cuvs::neighbors::cagra::serialize<DTYPE, uint32_t>(handle, filename, index, include_dataset); \
}; \
\
void deserialize_file(raft::resources const& handle, \
const std::string& filename, \
cuvs::neighbors::cagra::index<DTYPE, uint32_t>* index) \
{ \
if (!index) { RAFT_FAIL("Invalid index pointer"); } \
*index = cuvs::neighbors::cagra::deserialize<DTYPE, uint32_t>(handle, filename); \
}; \
void serialize(raft::resources const& handle, \
std::string& str, \
const cuvs::neighbors::cagra::index<DTYPE, uint32_t>& index, \
bool include_dataset) \
{ \
std::stringstream os; \
cuvs::neighbors::cagra::serialize<DTYPE, uint32_t>(handle, os, index, include_dataset); \
str = os.str(); \
} \
\
void serialize_to_hnswlib_file(raft::resources const& handle, \
const std::string& filename, \
const cuvs::neighbors::cagra::index<DTYPE, uint32_t>& index) \
{ \
cuvs::neighbors::cagra::serialize_to_hnswlib<DTYPE, uint32_t>(handle, filename, index); \
}; \
void serialize_to_hnswlib(raft::resources const& handle, \
std::string& str, \
const cuvs::neighbors::cagra::index<DTYPE, uint32_t>& index) \
{ \
std::stringstream os; \
cuvs::neighbors::cagra::serialize_to_hnswlib<DTYPE, uint32_t>(handle, os, index); \
str = os.str(); \
} \
\
void deserialize(raft::resources const& handle, \
const std::string& str, \
cuvs::neighbors::cagra::index<DTYPE, uint32_t>* index) \
{ \
std::istringstream is(str); \
if (!index) { RAFT_FAIL("Invalid index pointer"); } \
*index = cuvs::neighbors::cagra::deserialize<DTYPE, uint32_t>(handle, is); \
}

RAFT_INST_CAGRA_SERIALIZE(half);
CUVS_INST_CAGRA_SERIALIZE(half);

#undef RAFT_INST_CAGRA_SERIALIZE
} // namespace cuvs::neighbors::cagra
1 change: 1 addition & 0 deletions cpp/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ if(BUILD_TESTS)
NEIGHBORS_ANN_CAGRA_TEST
PATH
neighbors/ann_cagra/test_float_uint32_t.cu
neighbors/ann_cagra/test_half_uint32_t.cu
neighbors/ann_cagra/test_int8_t_uint32_t.cu
neighbors/ann_cagra/test_uint8_t_uint32_t.cu
GPUS
Expand Down
2 changes: 1 addition & 1 deletion cpp/test/neighbors/ann_cagra/test_half_uint32_t.cu
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

namespace cuvs::neighbors::cagra {

typedef AnnCagraTest<float, half, std::uint32_t> AnnCagraTestF_U32;
typedef AnnCagraTest<float, half, std::uint32_t> AnnCagraTestF16_U32;
TEST_P(AnnCagraTestF16_U32, AnnCagra) { this->testCagra(); }

INSTANTIATE_TEST_CASE_P(AnnCagraTest, AnnCagraTestF16_U32, ::testing::ValuesIn(inputs));
Expand Down