add softmax kernel 9: online softmax with 4x unrolled loads#841
Open
RahulPatnaik wants to merge 1 commit intokarpathy:masterfrom
Open
add softmax kernel 9: online softmax with 4x unrolled loads#841RahulPatnaik wants to merge 1 commit intokarpathy:masterfrom
RahulPatnaik wants to merge 1 commit intokarpathy:masterfrom
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.
Add softmax forward kernel 9
Adds a new kernel variant to
dev/cuda/softmax_forward.cuthat builds on kernel 8 (online softmax with warp-level reductions).What changed
Kernel 9 unrolls the coarsening loops by a factor of 4, issuing multiple global memory loads together to increase memory-level parallelism. The online softmax algorithm (fused max + sum in a single pass) and warp shuffle reductions are kept from kernel 8. A precomputed reciprocal replaces per-element division in the output pass.
Results (RTX 4060 Laptop GPU)
~9% wall-clock improvement. The gain comes from better memory bus utilization through overlapped loads, not from reduced memory traffic (both kernels make the same number of global memory passes).
Notes
min(C-1, ...)out-of-bounds clamping trick from kernel 7 to keep loads branchless