Skip to content

Introduce fused GEMM + 1-NN primitive using cuTile - #2249

Open
divyegala wants to merge 35 commits into
NVIDIA:mainfrom
divyegala:cutile-python-to-cpp
Open

Introduce fused GEMM + 1-NN primitive using cuTile#2249
divyegala wants to merge 35 commits into
NVIDIA:mainfrom
divyegala:cutile-python-to-cpp

Conversation

@divyegala

@divyegala divyegala commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

This PR adds infrastructure built on top of existing JIT LTO architecture to generate kernels using cutile-python at build time, and embed them in the C++ library to make them callable from C++.

@copy-pr-bot

copy-pr-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@divyegala divyegala changed the title cuTile Python to CPP embedding example Introduce fused GEMM + 1-NN primitive using cuTile Jun 24, 2026
Comment thread cpp/tests/CMakeLists.txt Outdated
@divyegala
divyegala marked this pull request as ready for review August 6, 2026 22:38
@divyegala
divyegala requested review from a team as code owners August 6, 2026 22:38
@divyegala
divyegala requested a review from msarahan August 6, 2026 22:38
@divyegala divyegala added feature request New feature or request non-breaking Introduces a non-breaking change labels Aug 6, 2026
@divyegala

Copy link
Copy Markdown
Contributor Author

/ok to test 2fdd7f7

@divyegala

Copy link
Copy Markdown
Contributor Author

/ok to test 2fb6253

@divyegala

Copy link
Copy Markdown
Contributor Author

/ok to test e28ecd9

@divyegala

Copy link
Copy Markdown
Contributor Author

/ok to test 169309d

if metric_code == METRIC_L2_EXPANDED:
# The A norm is constant across centroids. Reduce
# 0.5 * ||y||^2 - dot(x, y), then recover full L2 once.
score = (0.5 * b_norm)[None, :] - accumulator

@huuanhhuyn huuanhhuyn Aug 7, 2026

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.

I guess for L2, b_normand a_norm below are not yet squared? Because for cosine, we dropped the squared root on b_norm

if require_tma_friendly_pitch
else (1, 1)
),
shape_divisible_by=(1, 1),

@huuanhhuyn huuanhhuyn Aug 7, 2026

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.

Should we make shape_divisible_by=(2, 1) for sm_80 and sm_89 when elem_dtype is float16 and for strict ABI? This should already improve those sm's for 13.4 and float16

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If this will be fixed in 13.5 anyway, I think we can just wait and document the requirement to make sure we don't have too many conditionals lying around.

else:
# Defer the A-norm division until after selecting the
# winning centroid.
score = -(accumulator / b_norm[None, :])

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.

Nit: I guess accumulator / (-b_norm)[None, :] might reduce slightly the number of flops as accumulator has the shape [tm, tn] while b_norm has [tn]


if constexpr (std::is_same_v<LabelT, IdxT>) {
auto labels_view = raft::make_device_vector_view<IdxT, IdxT>(labels, n_rows);
cuvs::cluster::kmeans::detail::minClusterAndDistanceCompute<MathT, IdxT>(

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.

One small thing to fix along the way: we can use the public API here: min_cluster_and_distance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature request New feature or request non-breaking Introduces a non-breaking change

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

5 participants