-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds python wrappers to IVF-PQ. Authors: - Tamas Bela Feher (https://github.com/tfeher) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Corey J. Nolet (https://github.com/cjnolet) URL: #970
- Loading branch information
Showing
16 changed files
with
1,710 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
cpp/include/raft/neighbors/specializations/ivf_pq_specialization.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <raft/neighbors/ivf_pq_types.hpp> | ||
|
||
namespace raft::neighbors ::ivf_pq { | ||
|
||
#define RAFT_INST_SEARCH(T, IdxT) \ | ||
void search(const handle_t&, \ | ||
const search_params&, \ | ||
const index<IdxT>&, \ | ||
const T*, \ | ||
uint32_t, \ | ||
uint32_t, \ | ||
IdxT*, \ | ||
float*, \ | ||
rmm::mr::device_memory_resource*); | ||
|
||
RAFT_INST_SEARCH(float, uint64_t); | ||
RAFT_INST_SEARCH(int8_t, uint64_t); | ||
RAFT_INST_SEARCH(uint8_t, uint64_t); | ||
|
||
#undef RAFT_INST_SEARCH | ||
|
||
// We define overloads for build and extend with void return type. This is used in the Cython | ||
// wrappers, where exception handling is not compatible with return type that has nontrivial | ||
// constructor. | ||
#define RAFT_INST_BUILD_EXTEND(T, IdxT) \ | ||
auto build(const handle_t& handle, \ | ||
const index_params& params, \ | ||
const T* dataset, \ | ||
IdxT n_rows, \ | ||
uint32_t dim) \ | ||
->index<IdxT>; \ | ||
\ | ||
auto extend(const handle_t& handle, \ | ||
const index<IdxT>& orig_index, \ | ||
const T* new_vectors, \ | ||
const IdxT* new_indices, \ | ||
IdxT n_rows) \ | ||
->index<IdxT>; \ | ||
\ | ||
void build(const handle_t& handle, \ | ||
const index_params& params, \ | ||
const T* dataset, \ | ||
IdxT n_rows, \ | ||
uint32_t dim, \ | ||
index<IdxT>* idx); \ | ||
\ | ||
void extend(const handle_t& handle, \ | ||
index<IdxT>* idx, \ | ||
const T* new_vectors, \ | ||
const IdxT* new_indices, \ | ||
IdxT n_rows); | ||
|
||
RAFT_INST_BUILD_EXTEND(float, uint64_t) | ||
RAFT_INST_BUILD_EXTEND(int8_t, uint64_t) | ||
RAFT_INST_BUILD_EXTEND(uint8_t, uint64_t) | ||
|
||
#undef RAFT_INST_BUILD_EXTEND | ||
|
||
} // namespace raft::neighbors::ivf_pq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <raft/neighbors/ivf_pq.cuh> | ||
#include <raft/neighbors/specializations/ivf_pq_specialization.hpp> | ||
|
||
namespace raft::neighbors::ivf_pq { | ||
|
||
#define RAFT_INST_BUILD_EXTEND(T, IdxT) \ | ||
auto build(const handle_t& handle, \ | ||
const index_params& params, \ | ||
const T* dataset, \ | ||
IdxT n_rows, \ | ||
uint32_t dim) \ | ||
->index<IdxT> \ | ||
{ \ | ||
return build<T, IdxT>(handle, params, dataset, n_rows, dim); \ | ||
} \ | ||
auto extend(const handle_t& handle, \ | ||
const index<IdxT>& orig_index, \ | ||
const T* new_vectors, \ | ||
const IdxT* new_indices, \ | ||
IdxT n_rows) \ | ||
->index<IdxT> \ | ||
{ \ | ||
return extend<T, IdxT>(handle, orig_index, new_vectors, new_indices, n_rows); \ | ||
} \ | ||
\ | ||
void build(const handle_t& handle, \ | ||
const index_params& params, \ | ||
const T* dataset, \ | ||
IdxT n_rows, \ | ||
uint32_t dim, \ | ||
index<IdxT>* idx) \ | ||
{ \ | ||
*idx = build<T, IdxT>(handle, params, dataset, n_rows, dim); \ | ||
} \ | ||
void extend(const handle_t& handle, \ | ||
index<IdxT>* idx, \ | ||
const T* new_vectors, \ | ||
const IdxT* new_indices, \ | ||
IdxT n_rows) \ | ||
{ \ | ||
extend<T, IdxT>(handle, idx, new_vectors, new_indices, n_rows); \ | ||
} | ||
|
||
RAFT_INST_BUILD_EXTEND(float, uint64_t); | ||
RAFT_INST_BUILD_EXTEND(int8_t, uint64_t); | ||
RAFT_INST_BUILD_EXTEND(uint8_t, uint64_t); | ||
|
||
#undef RAFT_INST_BUILD_EXTEND | ||
|
||
} // namespace raft::neighbors::ivf_pq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (c) 2022, NVIDIA CORPORATION. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <raft/neighbors/ivf_pq.cuh> | ||
#include <raft/neighbors/specializations/detail/ivf_pq_search.cuh> | ||
#include <raft/neighbors/specializations/ivf_pq_specialization.hpp> | ||
|
||
namespace raft::neighbors::ivf_pq { | ||
|
||
#define RAFT_SEARCH_INST(T, IdxT) \ | ||
void search(const handle_t& handle, \ | ||
const search_params& params, \ | ||
const index<IdxT>& idx, \ | ||
const T* queries, \ | ||
uint32_t n_queries, \ | ||
uint32_t k, \ | ||
IdxT* neighbors, \ | ||
float* distances, \ | ||
rmm::mr::device_memory_resource* mr) \ | ||
{ \ | ||
search<T, IdxT>(handle, params, idx, queries, n_queries, k, neighbors, distances, mr); \ | ||
} | ||
|
||
RAFT_SEARCH_INST(float, uint64_t); | ||
RAFT_SEARCH_INST(int8_t, uint64_t); | ||
RAFT_SEARCH_INST(uint8_t, uint64_t); | ||
|
||
#undef RAFT_INST_SEARCH | ||
|
||
} // namespace raft::neighbors::ivf_pq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# ============================================================================= | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License | ||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing permissions and limitations under | ||
# the License. | ||
# ============================================================================= | ||
|
||
# Set the list of Cython files to build | ||
set(linked_libraries raft::raft raft::distance) | ||
|
||
# Build all of the Cython targets | ||
rapids_cython_create_modules( | ||
CXX | ||
SOURCE_FILES "" | ||
LINKED_LIBRARIES "${linked_libraries}" MODULE_PREFIX neighbors_ | ||
) | ||
|
||
foreach(cython_module IN LISTS RAPIDS_CYTHON_CREATED_TARGETS) | ||
set_target_properties(${cython_module} PROPERTIES INSTALL_RPATH "\$ORIGIN;\$ORIGIN/../library") | ||
endforeach() | ||
|
||
add_subdirectory(ivf_pq) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# |
28 changes: 28 additions & 0 deletions
28
python/pylibraft/pylibraft/neighbors/ivf_pq/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# ============================================================================= | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except | ||
# in compliance with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software distributed under the License | ||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express | ||
# or implied. See the License for the specific language governing permissions and limitations under | ||
# the License. | ||
# ============================================================================= | ||
|
||
# Set the list of Cython files to build | ||
set(cython_sources ivf_pq.pyx) | ||
set(linked_libraries raft::raft raft::distance) | ||
|
||
# Build all of the Cython targets | ||
rapids_cython_create_modules( | ||
CXX | ||
SOURCE_FILES "${cython_sources}" | ||
LINKED_LIBRARIES "${linked_libraries}" MODULE_PREFIX neighbors_ivfpq_ | ||
) | ||
|
||
foreach(cython_module IN LISTS RAPIDS_CYTHON_CREATED_TARGETS) | ||
set_target_properties(${cython_module} PROPERTIES INSTALL_RPATH "\$ORIGIN;\$ORIGIN/../library") | ||
endforeach() |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright (c) 2022, NVIDIA CORPORATION. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
from .ivf_pq import Index, IndexParams, SearchParams, build, extend, search |
Oops, something went wrong.