[CUDA] Avoid copying transposed inputs in row reductions - #4081
Open
Magnushst wants to merge 1 commit into
Open
Conversation
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.
Proposed changes
CUDA reductions currently materialise every non-contiguous input as a contiguous temporary, even when
GeneralContiguousReducecan compute the non-reduction-axis offsets directly.This change uses the direct row-reduction path for
GeneralContiguousReduceinputs when the output contains at least 1,024 elements. General reductions, broadcasted inputs, and smaller outputs retain the existing copy path. This removes one full-input allocation, copy, and kernel launch for sufficiently parallel transposed reductions.A C++ test checks exact CPU/GPU equivalence for the transposed layout handled by the new path.
Validation
pre-commit run --all-filespassed.git diff --checkpassed.The broader Python CUDA suite did not complete because CUDA 13 runtime JIT compilation could not locate
cute/tensor.hpp. This header-discovery problem is tracked by #3995; the dedicated reduction suite and complete C++ CUDA suite passed.Apple Silicon wasn't tested here.
Performance
Environment:
8d666298652fdac2e7727ecdcf507b1d199bba16The benchmark interleaved the previous copy-plus-reduce path with the direct path in one warmed process. It used 1,000 warm-up evaluations per path, followed by 15 alternating rounds of 500 evaluations. Reported values are medians of the per-round means.
16x4096x64, axis 132x2048x128, axis 116x8192x128, axis 132x8192x128, axis 1No eligible measured case regressed. Outputs below the 1,024-element threshold retain the existing path. No API or documentation changes are required.
Checklist
Put an x in the boxes that apply.
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes