reductions: frobenius/cosine/triplet (CUDA) + Triton parity for the reduction family - #38
Open
plotfi wants to merge 1 commit into
Open
reductions: frobenius/cosine/triplet (CUDA) + Triton parity for the reduction family#38plotfi wants to merge 1 commit into
plotfi wants to merge 1 commit into
Conversation
… for the reduction family
Implement the remaining reduction-shaped kernels on the shared SmemTreeReduce
block-reduction primitive, one per reduction shape:
* frobenius-norm — global sum-of-squares + broadcast normalize (two-pass)
* cosine-similarity — per-row, three accumulators (dot, ||p||^2, ||t||^2)
* triplet-margin — two-level: per-triplet distance reduce -> atomic batch mean
Add Triton parity for the reduction family so run-bench -C compares both backends:
solutions-triton/{mse-loss,kl-loss,frobenius-norm,cosine-similarity,triplet-margin}.py.
Also fix the mse-loss harness to size via bench_size (M*N) instead of a hardcoded
64*64 so it honors TENSOR_*/-B, mirror that in the Triton mse (M*N), and add an
mse-loss entry to run-bench's benchmark profile (sets both dims).
Verified: CUDA 35/35 and Triton 35/35 tests pass; run-bench -C -B shows ~1.0x
CUDA-vs-Triton parity across all reductions (all bandwidth-bound).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012o3X6Kr1cr8yS6CaosQTa8
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Implements the remaining reduction-shaped kernels on the shared
SmemTreeReduceblock-reduction primitive — one per reduction shape — plus Triton parity sorun-bench -Ccompares both backends.CUDA kernels (each a different reduction shape, all reusing
SmemTreeReduce)Y = X/‖X‖_F), two-pass.atomicAddbatch mean.Triton parity
solutions-triton/{mse-loss,kl-loss,frobenius-norm,cosine-similarity,triplet-margin}.py, each checked against a torch reference.mse-loss sizing fix
The CUDA
mse-lossharness hardcoded64*64and ignoredTENSOR_*, so-C -Bcompared mismatched sizes. Now it sizes viabench_size(M)*bench_size(N), the Triton mse mirrors that, andrun-bench'sbench_profilegets anmse-lossentry (sets both dims).Reference value
Together with huber/hinge/mse/kl this is a complete reference for reduction shapes, all sharing one block-reduction implementation:
Verified
run-bench -C -B= ~1.0× CUDA-vs-Triton parity across all reductions (all bandwidth-bound; e.g. mse-loss 1.14 vs 1.12 ms at matched 67M).🤖 Generated with Claude Code