-
Notifications
You must be signed in to change notification settings - Fork 143
CAGRA binary Hamming distance support #610
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
Merged
rapids-bot
merged 52 commits into
rapidsai:branch-25.02
from
enp1s0:cagra-hamming-distance
Feb 4, 2025
Merged
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit
Hold shift + click to select a range
109b964
Add binary Hamming distance
enp1s0 d679511
Add HammingUnexpanded test
enp1s0 911c088
Add `BinaryHamming` metric
enp1s0 f54bf25
Update file names
enp1s0 7ea2f12
Add `BinaryHamming` to `naive_distance_kernel`
enp1s0 d3f3f73
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 2c8636e
Fix test
enp1s0 8eadf19
Iteratively build index using cagra search
anaruse 0842607
Remove unused code and add comments
anaruse 891ca8e
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 d7badb5
Merge branch 'branch-25.02' into iteratively_build_graph_index
cjnolet 851caa8
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 ff755d7
Iteratively build index using cagra search
anaruse 81f0bb0
Remove unused code and add comments
anaruse 5e85808
Support for datasets that do not meet the alighment restriction
anaruse 01482d5
Merge remote-tracking branch 'anaruse/iteratively_build_graph_index' …
anaruse 99d7ccc
Merge branch 'iteratively_build_graph_index' into cagra-hamming-dista…
enp1s0 2da5a59
Update str_metric
enp1s0 8525f29
Add tests for iterative_build_graph_index
anaruse 48dace3
Merge branch 'iteratively_build_graph_index' into cagra-hamming-dista…
enp1s0 22c0830
Merge branch 'cagra-hamming-distance-iterative-build' of ssh://gitlab…
enp1s0 1d8f4f9
Fix `GTEST_SKIP`
enp1s0 cae5c2b
Merge branch 'branch-25.02' into cagra-hamming-distance-iterative-build
enp1s0 5d6316d
Update test
enp1s0 5182203
Merge branch 'branch-25.02' into cagra-hamming-distance-iterative-build
enp1s0 ee5978f
Fix dist_op T
enp1s0 04b6623
Fix binary Hamming distance
enp1s0 135b452
Fix test
enp1s0 9ebf83e
Update test skip
enp1s0 aaf814a
Update test cases
enp1s0 61e20f1
Add metric and build algo check
enp1s0 36f91e1
Fix BinaryHamming
enp1s0 d4098d6
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 e29cd4d
Rename BinaryHamming to BitwiseHamming
enp1s0 8f83822
Add `preprocessing::quantize::binary::transform`
enp1s0 799b45a
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 702565d
Rename `set_bit`
enp1s0 d71dbd6
Merge branch 'cagra-hamming-distance' of github.com:enp1s0/cuvs into …
enp1s0 1bb162c
Fix comment
enp1s0 2f32d65
Add binary::transform for half
enp1s0 c0335e8
Add CPU/GPU binarization identity test
enp1s0 82c725c
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 89553f1
Merge branch 'branch-25.02' into cagra-hamming-distance
cjnolet efb149a
Iteratively build graph index (#612)
anaruse 68de96b
Merge branch 'branch-25.02' into cagra-hamming-distance
enp1s0 128ed0c
Add out dataset size validation
enp1s0 c0fb3eb
Remove unnecessary test cases
enp1s0 f9a89ac
Update cpp/include/cuvs/preprocessing/quantize/binary.hpp
enp1s0 9dbb965
Update binary quantization sample code
enp1s0 a4c3e63
Fix RAFT_EXPECTS message
enp1s0 9461602
Fix compilation error
enp1s0 72fa542
Fix RAFT_EXPECTS message
enp1s0 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,170 @@ | ||
| /* | ||
| * Copyright (c) 2024, 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/core/device_mdarray.hpp> | ||
| #include <raft/core/device_mdspan.hpp> | ||
| #include <raft/core/handle.hpp> | ||
| #include <raft/core/host_mdarray.hpp> | ||
| #include <raft/core/host_mdspan.hpp> | ||
|
|
||
| #include <cuda_fp16.h> | ||
|
|
||
| namespace cuvs::preprocessing::quantize::binary { | ||
|
|
||
| /** | ||
| * @defgroup binary Binary quantizer utilities | ||
| * @{ | ||
| */ | ||
|
|
||
| /** | ||
| * @brief Applies binary quantization transform to given dataset. If a dataset element is positive, | ||
| * set the corresponding bit to 1. | ||
| * | ||
| * Usage example: | ||
| * @code{.cpp} | ||
| * raft::handle_t handle; | ||
| * auto quantized_dataset = raft::make_device_matrix<uint8_t, int64_t>(handle, samples, | ||
| * features); cuvs::preprocessing::quantize::binary::transform(handle, dataset, | ||
| * quantized_dataset.view()); | ||
| * @endcode | ||
| * | ||
| * @param[in] res raft resource | ||
| * @param[in] dataset a row-major matrix view on device | ||
| * @param[out] out a row-major matrix view on device | ||
| * | ||
| */ | ||
| void transform(raft::resources const& res, | ||
| raft::device_matrix_view<const double, int64_t> dataset, | ||
| raft::device_matrix_view<uint8_t, int64_t> out); | ||
|
|
||
| /** | ||
| * @brief Applies binary quantization transform to given dataset. If a dataset element is positive, | ||
| * set the corresponding bit to 1. | ||
| * | ||
| * Usage example: | ||
| * @code{.cpp} | ||
| * raft::handle_t handle; | ||
| * auto quantized_dataset = raft::make_host_matrix<uint8_t, int64_t>(handle, samples, | ||
| * features); cuvs::preprocessing::quantize::binary::transform(handle, dataset, | ||
| * quantized_dataset.view()); | ||
| * @endcode | ||
| * | ||
| * @param[in] res raft resource | ||
| * @param[in] dataset a row-major matrix view on host | ||
| * @param[out] out a row-major matrix view on host | ||
| * | ||
| */ | ||
| void transform(raft::resources const& res, | ||
| raft::host_matrix_view<const double, int64_t> dataset, | ||
| raft::host_matrix_view<uint8_t, int64_t> out); | ||
|
|
||
| /** | ||
| * @brief Applies binary quantization transform to given dataset. If a dataset element is positive, | ||
| * set the corresponding bit to 1. | ||
| * | ||
| * Usage example: | ||
| * @code{.cpp} | ||
| * raft::handle_t handle; | ||
| * raft::device_matrix<float, uint64_t> dataset = read_dataset(filename); | ||
| * int64_t quantized_dim = raft::div_rounding_up_safe(dataset.extent(1), sizeof(uint8_t) * 8); | ||
| * auto quantized_dataset = raft::make_device_matrix<uint8_t, int64_t>( | ||
| * handle, dataset.extent(0), quantized_dim); | ||
| * cuvs::preprocessing::quantize::binary::transform(handle, dataset, quantized_dataset.view()); | ||
| * @endcode | ||
| * | ||
| * @param[in] res raft resource | ||
| * @param[in] dataset a row-major matrix view on device | ||
| * @param[out] out a row-major matrix view on device | ||
| * | ||
| */ | ||
| void transform(raft::resources const& res, | ||
| raft::device_matrix_view<const float, int64_t> dataset, | ||
| raft::device_matrix_view<uint8_t, int64_t> out); | ||
|
|
||
| /** | ||
| * @brief Applies binary quantization transform to given dataset. If a dataset element is positive, | ||
| * set the corresponding bit to 1. | ||
| * | ||
| * Usage example: | ||
| * @code{.cpp} | ||
| * raft::handle_t handle; | ||
| * raft::host_matrix<float, uint64_t> dataset = read_dataset(filename); | ||
| * int64_t quantized_dim = raft::div_rounding_up_safe(dataset.extent(1), sizeof(uint8_t) * 8); | ||
| * auto quantized_dataset = raft::make_host_matrix<uint8_t, int64_t>( | ||
| * handle, dataset.extent(0), quantized_dim); | ||
| * cuvs::preprocessing::quantize::binary::transform(handle, dataset, quantized_dataset.view()); | ||
| * @endcode | ||
| * | ||
| * @param[in] res raft resource | ||
| * @param[in] dataset a row-major matrix view on host | ||
| * @param[out] out a row-major matrix view on host | ||
| * | ||
| */ | ||
| void transform(raft::resources const& res, | ||
| raft::host_matrix_view<const float, int64_t> dataset, | ||
| raft::host_matrix_view<uint8_t, int64_t> out); | ||
|
|
||
| /** | ||
| * @brief Applies binary quantization transform to given dataset. If a dataset element is positive, | ||
| * set the corresponding bit to 1. | ||
| * | ||
| * Usage example: | ||
| * @code{.cpp} | ||
| * raft::handle_t handle; | ||
| * raft::device_matrix<half, uint64_t> dataset = read_dataset(filename); | ||
| * int64_t quantized_dim = raft::div_rounding_up_safe(dataset.extent(1), sizeof(uint8_t) * 8); | ||
| * auto quantized_dataset = raft::make_device_matrix<uint8_t, int64_t>( | ||
| * handle, dataset.extent(0), quantized_dim); | ||
| * cuvs::preprocessing::quantize::binary::transform(handle, dataset, quantized_dataset.view()); | ||
| * @endcode | ||
| * | ||
| * @param[in] res raft resource | ||
| * @param[in] dataset a row-major matrix view on device | ||
| * @param[out] out a row-major matrix view on device | ||
| * | ||
| */ | ||
| void transform(raft::resources const& res, | ||
| raft::device_matrix_view<const half, int64_t> dataset, | ||
| raft::device_matrix_view<uint8_t, int64_t> out); | ||
|
|
||
| /** | ||
| * @brief Applies binary quantization transform to given dataset. If a dataset element is positive, | ||
| * set the corresponding bit to 1. | ||
| * | ||
| * Usage example: | ||
| * @code{.cpp} | ||
| * raft::handle_t handle; | ||
| * raft::host_matrix<half, uint64_t> dataset = read_dataset(filename); | ||
| * int64_t quantized_dim = raft::div_rounding_up_safe(dataset.extent(1), sizeof(uint8_t) * 8); | ||
| * auto quantized_dataset = raft::make_host_matrix<uint8_t, int64_t>( | ||
| * handle, dataset.extent(0), quantized_dim); | ||
| * cuvs::preprocessing::quantize::binary::transform(handle, dataset, quantized_dataset.view()); | ||
| * @endcode | ||
| * | ||
| * @param[in] res raft resource | ||
| * @param[in] dataset a row-major matrix view on host | ||
| * @param[out] out a row-major matrix view on host | ||
| * | ||
| */ | ||
| void transform(raft::resources const& res, | ||
| raft::host_matrix_view<const half, int64_t> dataset, | ||
| raft::host_matrix_view<uint8_t, int64_t> out); | ||
|
|
||
| /** @} */ // end of group binary | ||
|
|
||
| } // namespace cuvs::preprocessing::quantize::binary | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.