-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CAGRA binary Hamming distance support (#610)
This PR adds the binary Hamming distance support to CAGRA. dependency: #612 TODO: - [x] Add Hamming distance dist_op for CAGRA search - Add `DistanceType::BinaryHamming` (because `HammingUnexpanded` is not bitwise operation) - [x] Support graph build - Want to use the iterative graph build method that uses the CAGRA search for graph build (anaruse@5a80659) because otherwise the binary Hamming distance support for IVFPQ or NN Descent is additionally required. - [x] Add CI test - GT creation - Add test cases - [x] Test on some benchmark datasets - [x] Add `preprocessing::quantize::binary` Authors: - tsuki (https://github.com/enp1s0) - Akira Naruse (https://github.com/anaruse) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Tamas Bela Feher (https://github.com/tfeher) - Corey J. Nolet (https://github.com/cjnolet) URL: #610
- Loading branch information
Showing
20 changed files
with
838 additions
and
62 deletions.
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
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,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 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
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
Oops, something went wrong.