Repository navigation
Fix zero-alpha NaN propagation in LinearCombination - #3930
Open
Miya555orz wants to merge 1 commit into
Open
Miya555orz wants to merge 1 commit into
Miya555orz wants to merge 1 commit into
Conversation
This branch has not been deployed
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.
Summary
Fixes #3901.
This change makes the default
LinearCombinationepilogue avoid evaluatingthe accumulator term when
alpha == 0.In that case:
beta * sourceis returned directly when the source is required;beta == 0or the source is not required;alpha * accumulatornorbeta * sourcewith a zero coefficientis evaluated.
The Fragment and scalar overloads use the same semantics.
Root cause
The SIMT GEMM mainloop may produce a NaN accumulator when A or B contains
NaN. The default epilogue previously evaluated:
unconditionally. Under IEEE 754,
0 * NaNis NaN, so settingalphato zerodid not prevent NaNs from the accumulator from reaching the output.
The same problem can occur for the source term when both
beta == 0and thesource contains NaN.
The new zero-alpha path returns before converting or multiplying the
accumulator. It also produces zero directly when the source coefficient is
zero.
Scope
This patch changes the default
LinearCombinationoperator used by thereported
device::Gemmpath. Specialized epilogues with additionalactivation or elementwise semantics remain unchanged.
The normal
alpha != 0arithmetic path remains the same after the uniformguard. An sm_89
ptxascomparison showed identical resource usage beforeand after the change:
Tests
Added thread-level tests covering:
alpha = 0, beta = 1with a NaN accumulator;alpha = 0, beta = 0with both accumulator and source set to NaN;Added a device-level SM80 SIMT SGEMM regression test using an 8x8x8 problem:
quiet_NaN();alpha = 0, beta = 1verifies that D equals C;alpha = 0, beta = 0uses a NaN C tensor and verifies that D is zero.Validated on:
sm_89)nvcc 13.2.86)All targeted tests pass.