Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
742dba9
Fuse RaBitQ block reductions into one templated blockReduceSumN<N>
Stardust-SJF Jul 24, 2026
22172a1
Fix rescale-search shared-memory races by restructuring
Stardust-SJF Jul 25, 2026
f3a31aa
Add a standalone RaBitQ quantizer under preprocessing/quantize
Stardust-SJF Jul 26, 2026
1a5e2a3
Make the RaBitQ quantizer detail layer stream- and resource-aware
Stardust-SJF Jul 26, 2026
2c64068
Rename the RaBitQ factories init_* -> make_*
Stardust-SJF Jul 27, 2026
36028d1
Add the C API for the RaBitQ preprocessing quantizer
Stardust-SJF Jul 28, 2026
a2c5747
Merge branch 'main' into cuvs_ivf_rabitq_syn_fix_fused
tfeher Aug 3, 2026
2a1c334
Replace the RaBitQ glue kernels with raft primitives
Stardust-SJF Oct 29, 2026
93ea433
Generate the RaBitQ matmul rotation with the shared IVF-PQ helper
Stardust-SJF Oct 29, 2026
3af40d4
Add cuvsRabitqRotatorMakeFromState to restore a saved rotator
Stardust-SJF Oct 29, 2026
33020da
Batch RaBitQ transform() internally, sized to the L2 cache
Stardust-SJF Oct 29, 2026
69d8b96
Fix 32-bit factor index overflow in the RaBitQ full-factor kernel
Stardust-SJF Oct 29, 2026
e8cd13c
Accept host input in RaBitQ transform()
Stardust-SJF Oct 29, 2026
1618145
Rename pipeline to quantizer and the old quantizer to encoder in RaBitQ
Stardust-SJF Oct 30, 2026
140fab3
Merge branch 'pull-request/2362' into cuvs_ivf_rabitq_standalone_quan…
achirkin Nov 2, 2026
128268a
Merge branch 'main' into cuvs_ivf_rabitq_syn_fix_fused
achirkin Nov 2, 2026
e837738
Merge remote-tracking branch 'sjf/cuvs_ivf_rabitq_syn_fix_fused' into…
achirkin Nov 2, 2026
b5ccd94
Merge remote-tracking branch 'rapidsai/main' into pull-request/2362
achirkin Nov 2, 2026
42fcdfb
Merge branch 'pull-request/2362' into cuvs_ivf_rabitq_standalone_quan…
achirkin Nov 2, 2026
a6ad49e
Merge branch 'main' into cuvs_ivf_rabitq_standalone_quantizer
achirkin Nov 3, 2026
89d518e
Spec-based dataset api
achirkin Nov 3, 2026
8f1b9ce
Fix style
achirkin Nov 3, 2026
4a9e8f3
Fix style
achirkin Nov 3, 2026
f02247a
Merge branch 'cuvs_ivf_rabitq_standalone_quantizer' into fea-rabitq-spec
achirkin Nov 3, 2026
7db6e2f
Fix build errors
achirkin Nov 3, 2026
28ccd92
Merge branch 'cuvs_ivf_rabitq_standalone_quantizer' into fea-rabitq-spec
achirkin Nov 3, 2026
afb5f91
Merge pull request #1 from achirkin/fea-rabitq-spec
Stardust-SJF Nov 4, 2026
82b1325
Merge branch 'main' into cuvs_ivf_rabitq_standalone_quantizer
achirkin Nov 4, 2026
8e68cde
Merge remote-tracking branch 'rapidsai/main' into cuvs_ivf_rabitq_sta…
achirkin Nov 4, 2026
c6632a7
Fix the symbol visibility
achirkin Nov 4, 2026
d42a40a
Merge remote-tracking branch 'public/main' into cuvs_ivf_rabitq_stand…
Stardust-SJF Nov 5, 2026
a7f80d5
Throw instead of exiting on unsupported RaBitQ FHT dimensions
Stardust-SJF Nov 5, 2026
12ed643
Opt in to more shared memory for the RaBitQ scaling-factor kernel
Stardust-SJF Nov 5, 2026
2e5d05a
Request shared memory in the RaBitQ quantize kernels only when needed
Stardust-SJF Nov 5, 2026
b3db6d9
Forward the rescale sample counts to the RaBitQ full-factor path
Stardust-SJF Nov 5, 2026
2cc3b97
Document that RaBitQ delta is computed from signed code levels
Stardust-SJF Nov 5, 2026
6d27955
Document the 16-bit code requirement for RaBitQ ex_bits = 8
Stardust-SJF Nov 5, 2026
0a1302e
Show the RaBitQ delta formulas in the API page tables
Stardust-SJF Nov 5, 2026
3a5fa14
Update cpp/include/cuvs/preprocessing/quantize/rabitq.hpp
Stardust-SJF Nov 11, 2026
d3c0cab
Update cpp/tests/preprocessing/rabitq_quantization.cu
Stardust-SJF Nov 11, 2026
d916649
Apply the review cleanups to the RaBitQ quantizer
Stardust-SJF Nov 11, 2026
b741b07
Use cub::BlockReduce for the RaBitQ quantizer block reductions
Stardust-SJF Nov 11, 2026
c11432f
Take mdspan views in the RaBitQ quantizer detail layer
Stardust-SJF Nov 12, 2026
94ed09e
Use raft::warpReduce for the RaBitQ quantizer warp sums
Stardust-SJF Nov 22, 2026
1540b4c
Add missing cub includes
tfeher Nov 23, 2026
049f6d6
Merge branch 'release/26.12' into cuvs_ivf_rabitq_standalone_quantizer
tfeher Nov 23, 2026
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
14 changes: 7 additions & 7 deletions c/src/preprocessing/quantize/rabitq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ rabitq::params _convert_params(cuvsRabitqQuantizerParams_t params)
return out;
}

rabitq::rotator* _rotator_ptr(cuvsRabitqRotator_t rotator)
rabitq::rotator<float>* _rotator_ptr(cuvsRabitqRotator_t rotator)
{
if (rotator == nullptr || rotator->addr == 0) { RAFT_FAIL("rotator is not initialized"); }
return reinterpret_cast<rabitq::rotator*>(rotator->addr);
return reinterpret_cast<rabitq::rotator<float>*>(rotator->addr);
}

rabitq::encoder* _encoder_ptr(cuvsRabitqEncoder_t encoder)
Expand Down Expand Up @@ -278,7 +278,7 @@ extern "C" cuvsError_t cuvsRabitqRotatorDestroy(cuvsRabitqRotator_t rotator)
{
return cuvs::core::translate_exceptions([=] {
if (rotator == nullptr) { return; }
delete reinterpret_cast<rabitq::rotator*>(rotator->addr);
delete reinterpret_cast<rabitq::rotator<float>*>(rotator->addr);
delete rotator;
});
}
Expand Down Expand Up @@ -307,7 +307,7 @@ extern "C" cuvsError_t cuvsRabitqRotatorMake(cuvsResources_t res,
auto res_ptr = reinterpret_cast<raft::resources*>(res);
auto quantizer_params = _convert_params(params);
auto* ret = new rabitq::rotator(rabitq::make_rotator(*res_ptr, quantizer_params, dim));
delete reinterpret_cast<rabitq::rotator*>(rotator->addr);
delete reinterpret_cast<rabitq::rotator<float>*>(rotator->addr);
rotator->addr = reinterpret_cast<uintptr_t>(ret);
});
}
Expand All @@ -321,7 +321,7 @@ extern "C" cuvsError_t cuvsRabitqRotatorMakeFromState(cuvsResources_t res,
if (rotator == nullptr) { RAFT_FAIL("rotator is not allocated"); }
auto res_ptr = reinterpret_cast<raft::resources*>(res);
auto stream = raft::resource::get_cuda_stream(*res_ptr);
auto ret = std::make_unique<rabitq::rotator>(*res_ptr);
auto ret = std::make_unique<rabitq::rotator<float>>(*res_ptr);
switch (kind) {
case CUVS_RABITQ_ROTATOR_KIND_MATMUL: {
auto [src, ext] = _saved_state<float, raft::matrix_extent<int64_t>>(state);
Expand Down Expand Up @@ -353,7 +353,7 @@ extern "C" cuvsError_t cuvsRabitqRotatorMakeFromState(cuvsResources_t res,
}
// `state` may be freed as soon as this returns.
raft::resource::sync_stream(*res_ptr);
delete reinterpret_cast<rabitq::rotator*>(rotator->addr);
delete reinterpret_cast<rabitq::rotator<float>*>(rotator->addr);
rotator->addr = reinterpret_cast<uintptr_t>(ret.release());
});
}
Expand Down Expand Up @@ -389,7 +389,7 @@ extern "C" cuvsError_t cuvsRabitqQuantizerMake(cuvsResources_t res,
auto* new_rotator = new rabitq::rotator(std::move(built.rotator));
auto* new_encoder = new rabitq::encoder(built.encoder);

delete reinterpret_cast<rabitq::rotator*>(rotator->addr);
delete reinterpret_cast<rabitq::rotator<float>*>(rotator->addr);
delete reinterpret_cast<rabitq::encoder*>(encoder->addr);
rotator->addr = reinterpret_cast<uintptr_t>(new_rotator);
encoder->addr = reinterpret_cast<uintptr_t>(new_encoder);
Expand Down
153 changes: 153 additions & 0 deletions cpp/include/cuvs/core/dataset/rabitq.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
/*
* SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cuvs/core/dataset/type.hpp>
#include <cuvs/core/export.hpp>
#include <cuvs/preprocessing/quantize/rabitq.hpp>

#include <raft/core/device_mdarray.hpp>
#include <raft/core/host_mdarray.hpp>
#include <raft/core/mdarray.hpp>

#include <cstdint>
#include <type_traits>

namespace CUVS_EXPORT cuvs {

/**
* RaBitQ-quantized dataset specification.
*
* The data holds everything that scales with the number of rows:
* - `codes` [n_rows, padded_dim]: one `CodeT` per padded dimension, each holding an
* unsigned `ex_bits + 1` bit value;
* - `factors` [n_rows, 3]: the per-row `(f_add, f_rescale, f_error)` triplet.
* Both are what the full-factor `preprocessing::quantize::rabitq::transform()` writes when it is
* called without a centroid.
*
* The manifest is the RaBitQ quantizer (rotator and encoder) that produced them. It also knows the
* logical dimension `dim`, which the codes cannot tell: their width is padded to a multiple of 32.
*
* @tparam MathT the element type of the rotation matrix of the quantizer
* @tparam CodeT the element type of the codes (`uint8_t` or `uint16_t`)
* @tparam CodePolicy the container policy of the codes (elements of `CodeT`)
* @tparam FactorPolicy the container policy of the factors (elements of `float`)
*/
template <typename MathT, typename CodeT, typename CodePolicy, typename FactorPolicy>
struct rabitq_spec {
using codes_type =
raft::mdarray<CodeT, raft::matrix_extent<int64_t>, raft::layout_c_contiguous, CodePolicy>;
using factors_type =
raft::mdarray<float, raft::matrix_extent<int64_t>, raft::layout_c_contiguous, FactorPolicy>;

// The codes and the factors of the same rows, owning or viewed alike.
template <typename CodesT, typename FactorsT>
struct data_of {
CodesT codes;
FactorsT factors;
};
using data_type = data_of<codes_type, factors_type>;
using data_view_type = data_of<typename codes_type::view_type, typename factors_type::view_type>;
using const_data_view_type =
data_of<typename codes_type::const_view_type, typename factors_type::const_view_type>;

// The element type of the rotation matrix; the input and the factors are always `float`.
using math_type = MathT;

using manifest_type = preprocessing::quantize::rabitq::quantizer<math_type>;
using manifest_view_type = preprocessing::quantize::rabitq::quantizer_view<math_type>;
using const_manifest_view_type = preprocessing::quantize::rabitq::quantizer_view<const math_type>;

template <typename T, typename IdxT>
struct apply {
// The dataset stores codes, but it still represents vectors of `T`.
using value_type = std::remove_cv_t<T>;
using index_type = std::remove_cv_t<IdxT>;
using code_type = CodeT;
// NOTE: re-exported rather than declared here, so that they do not belong to one instantiation
// of `apply`; qualified lookup into `apply` does not reach the enclosing spec on its own.
using math_type = rabitq_spec::math_type;
using codes_type = rabitq_spec::codes_type;
using factors_type = rabitq_spec::factors_type;
using data_type = rabitq_spec::data_type;
using data_view_type = rabitq_spec::data_view_type;
using const_data_view_type = rabitq_spec::const_data_view_type;
using manifest_type = rabitq_spec::manifest_type;
using manifest_view_type = rabitq_spec::manifest_view_type;
using const_manifest_view_type = rabitq_spec::const_manifest_view_type;

[[nodiscard]] static auto get_data_view(data_type& data) noexcept -> data_view_type
{
return {data.codes.view(), data.factors.view()};
}
[[nodiscard]] static auto get_data_const_view(const data_type& data) noexcept
-> const_data_view_type
{
return {data.codes.view(), data.factors.view()};
}
[[nodiscard]] static auto get_data_const_view(data_view_type data) noexcept
-> const_data_view_type
{
return {raft::make_const_mdspan(data.codes), raft::make_const_mdspan(data.factors)};
}
// NOTE: the shape accessors take the data and the manifest in either form - the storage an
// owning dataset holds, or the views a `dataset_view` holds.
[[nodiscard]] static auto get_n_rows(const auto& data) noexcept -> index_type
{
return static_cast<index_type>(data.codes.extent(0));
}
[[nodiscard]] static auto get_dim(const auto&, const auto& manifest) noexcept -> uint32_t
{
return static_cast<uint32_t>(manifest.encoder.dim);
}
[[nodiscard]] static auto get_manifest_view(manifest_type& manifest) noexcept
-> manifest_view_type
{
return manifest.view();
}
[[nodiscard]] static auto get_manifest_const_view(const manifest_type& manifest) noexcept
-> const_manifest_view_type
{
return manifest.view();
}
[[nodiscard]] static auto get_manifest_const_view(manifest_view_type manifest) noexcept
-> const_manifest_view_type
{
return manifest;
}
};
};

template <typename T,
typename IdxT,
typename MathT,
typename CodeT,
typename CodePolicy,
typename FactorPolicy>
using rabitq_dataset = dataset<T, IdxT, rabitq_spec<MathT, CodeT, CodePolicy, FactorPolicy>>;
template <typename T, typename IdxT, typename MathT = float, typename CodeT = uint8_t>
using device_rabitq_dataset =
rabitq_dataset<T,
IdxT,
MathT,
CodeT,
raft::device_accessor<raft::device_container_policy<CodeT>>,
raft::device_accessor<raft::device_container_policy<float>>>;
/** The codes and the factors are on host; the manifest (the quantizer) is on device. */
template <typename T, typename IdxT, typename MathT = float, typename CodeT = uint8_t>
using host_rabitq_dataset = rabitq_dataset<T,
IdxT,
MathT,
CodeT,
raft::host_accessor<raft::host_container_policy<CodeT>>,
raft::host_accessor<raft::host_container_policy<float>>>;

/** A read-only non-owning view of a RaBitQ-quantized dataset in device memory. */
template <typename T, typename IdxT, typename MathT = float, typename CodeT = uint8_t>
using device_rabitq_dataset_view =
typename device_rabitq_dataset<T, IdxT, MathT, CodeT>::const_view_type;

} // namespace CUVS_EXPORT cuvs
Loading
Loading