Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
8b35602
Add SuperKMeans k-means API with an unpruned fallback
sherylll Oct 26, 2026
e83a28f
Add SuperKMeans' fused first-filter cuTile kernel
sherylll Oct 26, 2026
19b3fb4
Add SuperKMeans' pruned assignment
sherylll Oct 26, 2026
443bb05
Order SuperKMeans' pruning by survivor count (LPT)
sherylll Oct 26, 2026
669fcc1
Run SuperKMeans' row batches on the handle's stream pool
sherylll Oct 26, 2026
844f2f0
Move SuperKMeans' pruned assignment into a pruned 1-NN distance
sherylll Oct 26, 2026
4bf9ccc
Prune survivor lists in place, out of shared memory
sherylll Oct 28, 2026
18779b1
Write one contiguous first-filter survivor list per row
sherylll Oct 28, 2026
e58ee5c
Prune only with dims past the first filter's; simplify the kernel
sherylll Oct 28, 2026
1edbba5
Return early from pruning rows with no survivors
sherylll Oct 28, 2026
75ea3ab
Overlap row batches on the main stream and one pool stream
sherylll Oct 28, 2026
fca97b1
Fix style: SuperKMeans API reference, formatting, copyright
sherylll Oct 28, 2026
2d869df
Compute the filter's norms from its FP16 values, with the FP16 copy
sherylll Oct 30, 2026
6a2ae57
Compute the pruning ratios from eps0 in the kernel, not from a device…
sherylll Nov 2, 2026
a57a157
Assign in full for half rows the filter can't read in place; document…
sherylll Nov 2, 2026
e7cb068
Load the pruning kernel's tiles in 16-byte loads; drop its launch bounds
sherylll Nov 2, 2026
0ee37a6
Add license
sherylll Nov 3, 2026
e02f9db
Replace custom warp reduce with cub::WarpReduceBatched
sherylll Nov 3, 2026
31b9674
Merge branch 'main' into superkmeans
sherylll Nov 4, 2026
6b3a662
Hardcode eps0
sherylll Nov 5, 2026
f2355d4
Halve pruned 1-NN centroid batch to 1024
sherylll Nov 6, 2026
9565eb9
Merge branch 'main' into superkmeans
sherylll Nov 6, 2026
4760f3b
Merge branch 'main' into superkmeans
sherylll Nov 8, 2026
79bdbba
Prepare SuperKMeans filter rows per batch
sherylll Nov 9, 2026
b3e9476
Require supported layouts for high-dimensional SuperKMeans pruning
sherylll Nov 9, 2026
a71429f
Size SuperKMeans row batches from workspace budget
sherylll Nov 9, 2026
3b2571b
Tune tile sizes for different arch (coarsely)
sherylll Nov 9, 2026
4c2585a
Fix style
sherylll Nov 9, 2026
26372e2
Add sm103 for completeness; update tile sizes based on measurements on
sherylll Nov 10, 2026
0bbf70c
Merge upstream/main into superkmeans
sherylll Nov 11, 2026
78d844a
Remove duplicate kmeans_type definition
sherylll Nov 11, 2026
5a45435
Small refactor
sherylll Nov 11, 2026
976b372
More refactoring: in F32 mode, use F32 data to calculate norm, even t…
sherylll Nov 11, 2026
f92bdc4
Use raft launch_kernel
sherylll Nov 12, 2026
6f9fb0a
Peel single-survivor tail from pruned nearest-neighbor search
sherylll Nov 13, 2026
91ee26a
Order pruning rows from each fused-filter tile
sherylll Nov 13, 2026
7054a3f
Small cleanup
sherylll Nov 16, 2026
3e2964b
Merge branch 'release/26.12' into superkmeans
sherylll Nov 16, 2026
e3a2550
Mark SuperKMeans API experimental
sherylll Nov 18, 2026
0a70f8c
Use RAFT warp primitives in pruned assignment
sherylll Nov 18, 2026
572253e
Support partial dimension tiles in pruned assignment
sherylll Nov 18, 2026
d2713a5
Remove redundant initial survivor check in prune
sherylll Nov 18, 2026
7fa7a8b
Merge branch 'release/26.12' into superkmeans
sherylll Nov 18, 2026
8cb98b7
Simplify prune survivor arguments and use RAFT warp helpers
sherylll Nov 18, 2026
29970b1
Use workspace memory and dry-run sizing in SuperKMeans
sherylll Nov 19, 2026
82ac907
Add NVTX ranges for pruned 1-NN filter and pruning
sherylll Nov 19, 2026
20e5fbb
Use dry-run execution and round up SuperKMeans batches
sherylll Nov 19, 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
Next Next commit
Add SuperKMeans k-means API with an unpruned fallback
superkmeans_params and fit / fit_predict overloads for float and half
input. Without pruning (dim below one 256-dim tile, or at most 256
clusters) fit runs Lloyd's iterations from SuperKMeans' random start
rows; the pruned path is not implemented yet and fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
  • Loading branch information
sherylll and claude committed Nov 2, 2026
commit 8b35602173a66834a4511fc38ebd3e63ab1264f4
1 change: 1 addition & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,7 @@ if(NOT BUILD_CPU_ONLY)
src/cluster/kmeans_balanced_fit_predict_int8.cu
src/cluster/kmeans_balanced_predict_int8.cu
src/cluster/kmeans_balanced_predict_uint8.cu
src/cluster/kmeans_superkmeans.cu
src/cluster/kmeans_transform_double.cu
src/cluster/kmeans_transform_float.cu
src/cluster/single_linkage_float.cu
Expand Down
198 changes: 198 additions & 0 deletions cpp/include/cuvs/cluster/kmeans.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,33 @@ struct balanced_params : base_params {
bool is_packed_binary = false;
};

/**
* Simple object to specify hyper-parameters to the SuperKMeans algorithm.
*
* SuperKMeans is Lloyd's k-means with a pruned assignment step: the first iteration assigns every
* row with the fused 1-NN over all dimensions; later iterations compute partial distances over the
* first 256 dimensions, discard centroids that cannot beat a row's current one
* (ADSampling bound), and finish the remaining dimensions only for the survivors.
*
* The number of clusters is taken from the `centroids` argument. The start centroids are rows
* sampled at random, as with kmeans::params::InitMethod::Random; all `n_iters` iterations run
* (there is no convergence test), and an empty cluster keeps its previous centroid.
*
* The following metrics are currently supported:
* - L2Expanded
*/
struct superkmeans_params : base_params {
/**
* Number of training iterations.
*/
uint32_t n_iters = 10;

/**
* Seed to the random number generator (the start rows).
*/
raft::random::RngState rng_state{0};
};

/**
* @brief Type of k-means algorithm.
*/
Expand Down Expand Up @@ -770,6 +797,63 @@ void fit(const raft::resources& handle,
raft::device_matrix_view<float, int64_t> centroids,
std::optional<raft::host_scalar_view<float>> inertia = std::nullopt);

/**
* @brief Find clusters with the SuperKMeans algorithm.
*
* @code{.cpp}
* #include <raft/core/resources.hpp>
* #include <cuvs/cluster/kmeans.hpp>
* using namespace cuvs::cluster;
* ...
* raft::resources handle;
* cuvs::cluster::kmeans::superkmeans_params params;
* int64_t n_features = 1024, n_clusters = 4096;
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
*
* kmeans::fit(handle,
* params,
* X,
* centroids.view());
* @endcode
*
* @param[in] handle The raft handle.
* @param[in] params Parameters for SuperKMeans.
* @param[in] X Training instances to cluster. The data must
* be in row-major format.
* [dim = n_samples x n_features]
* @param[out] centroids The generated centroids.
* [dim = n_clusters x n_features]
* @param[out] inertia Sum of squared distances of samples to their
* closest cluster center.
*/
void fit(const raft::resources& handle,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we put this into an experimental namespace?

cuvs::cluster::kmeans::superkmeans_params const& params,
raft::device_matrix_view<const float, int64_t> X,
raft::device_matrix_view<float, int64_t> centroids,
std::optional<raft::host_scalar_view<float>> inertia = std::nullopt);

/**
* @brief Find clusters with the SuperKMeans algorithm.
*
* With half input the distance GEMMs run on FP16 tensor cores against an FP16 copy of the
* centroids, which are accumulated and returned in FP32.
*
* @param[in] handle The raft handle.
* @param[in] params Parameters for SuperKMeans.
* @param[in] X Training instances to cluster. The data must
* be in row-major format.
* [dim = n_samples x n_features]
* @param[out] centroids The generated centroids.
* [dim = n_clusters x n_features]
* @param[out] inertia Sum of squared distances of samples to their
* closest cluster center.
*/
void fit(const raft::resources& handle,
cuvs::cluster::kmeans::superkmeans_params const& params,
raft::device_matrix_view<const half, int64_t> X,
raft::device_matrix_view<float, int64_t> centroids,
std::optional<raft::host_scalar_view<float>> inertia = std::nullopt);

/**
* @brief Predict the closest cluster each sample in X belongs to.
*
Expand Down Expand Up @@ -1281,6 +1365,58 @@ void predict(const raft::resources& handle,
raft::device_matrix_view<const float, int64_t> centroids,
raft::device_vector_view<uint32_t, int64_t> labels);

/**
* @brief Predict the closest cluster each sample in X belongs to, for SuperKMeans centroids.
*
* @code{.cpp}
* #include <raft/core/resources.hpp>
* #include <cuvs/cluster/kmeans.hpp>
* using namespace cuvs::cluster;
* ...
* raft::resources handle;
* cuvs::cluster::kmeans::superkmeans_params params;
* auto labels = raft::make_device_vector<uint32_t, int64_t>(handle, X.extent(0));
*
* kmeans::predict(handle,
* params,
* X,
* centroids,
* labels.view());
* @endcode
*
* @param[in] handle The raft handle.
* @param[in] params Parameters for SuperKMeans.
* @param[in] X New data to predict.
* [dim = n_samples x n_features]
* @param[in] centroids Cluster centroids. The data must be in row-major format.
* [dim = n_clusters x n_features]
* @param[out] labels Index of the closest centroid for each sample.
* [len = n_samples]
*/
void predict(const raft::resources& handle,
cuvs::cluster::kmeans::superkmeans_params const& params,
raft::device_matrix_view<const float, int64_t> X,
raft::device_matrix_view<const float, int64_t> centroids,
raft::device_vector_view<uint32_t, int64_t> labels);

/**
* @brief Predict the closest cluster each sample in X belongs to, for SuperKMeans centroids.
*
* @param[in] handle The raft handle.
* @param[in] params Parameters for SuperKMeans.
* @param[in] X New data to predict.
* [dim = n_samples x n_features]
* @param[in] centroids Cluster centroids. The data must be in row-major format.
* [dim = n_clusters x n_features]
* @param[out] labels Index of the closest centroid for each sample.
* [len = n_samples]
*/
void predict(const raft::resources& handle,
cuvs::cluster::kmeans::superkmeans_params const& params,
raft::device_matrix_view<const half, int64_t> X,
raft::device_matrix_view<const float, int64_t> centroids,
raft::device_vector_view<uint32_t, int64_t> labels);

/**
* @brief Compute k-means clustering and predicts cluster index for each sample
* in the input.
Expand Down Expand Up @@ -1589,6 +1725,68 @@ void fit_predict(const raft::resources& handle,
raft::device_matrix_view<float, int64_t> centroids,
raft::device_vector_view<uint32_t, int64_t> labels);

/**
* @brief Compute SuperKMeans clusters and predict the cluster index of each sample.
*
* @code{.cpp}
* #include <raft/core/resources.hpp>
* #include <cuvs/cluster/kmeans.hpp>
* using namespace cuvs::cluster;
* ...
* raft::resources handle;
* cuvs::cluster::kmeans::superkmeans_params params;
* int64_t n_features = 1024, n_clusters = 4096;
* auto centroids = raft::make_device_matrix<float, int64_t>(handle, n_clusters, n_features);
* auto labels = raft::make_device_vector<uint32_t, int64_t>(handle, X.extent(0));
*
* kmeans::fit_predict(handle,
* params,
* X,
* centroids.view(),
* labels.view());
* @endcode
*
* @param[in] handle The raft handle.
* @param[in] params Parameters for SuperKMeans.
* @param[in] X Training instances to cluster. The data must be
* in row-major format.
* [dim = n_samples x n_features]
* @param[out] centroids The generated centroids.
* [dim = n_clusters x n_features]
* @param[out] labels Index of the closest centroid for each sample.
* [len = n_samples]
* @param[out] inertia Sum of squared distances of samples to their
* closest cluster center.
*/
void fit_predict(const raft::resources& handle,
cuvs::cluster::kmeans::superkmeans_params const& params,
raft::device_matrix_view<const float, int64_t> X,
raft::device_matrix_view<float, int64_t> centroids,
raft::device_vector_view<uint32_t, int64_t> labels,
std::optional<raft::host_scalar_view<float>> inertia = std::nullopt);

/**
* @brief Compute SuperKMeans clusters and predict the cluster index of each sample.
*
* @param[in] handle The raft handle.
* @param[in] params Parameters for SuperKMeans.
* @param[in] X Training instances to cluster. The data must be
* in row-major format.
* [dim = n_samples x n_features]
* @param[out] centroids The generated centroids.
* [dim = n_clusters x n_features]
* @param[out] labels Index of the closest centroid for each sample.
* [len = n_samples]
* @param[out] inertia Sum of squared distances of samples to their
* closest cluster center.
*/
void fit_predict(const raft::resources& handle,
cuvs::cluster::kmeans::superkmeans_params const& params,
raft::device_matrix_view<const half, int64_t> X,
raft::device_matrix_view<float, int64_t> centroids,
raft::device_vector_view<uint32_t, int64_t> labels,
std::optional<raft::host_scalar_view<float>> inertia = std::nullopt);

/**
* @brief Transform X to a cluster-distance space.
*
Expand Down
Loading