Repository navigation
K D3D12 softmax: exact mix-FMA form for the weight rounding (draft) - #230
Closed
phantoslayer21 wants to merge 1 commit into
Closed
phantoslayer21 wants to merge 1 commit into
phantoslayer21 wants to merge 1 commit into
Conversation
…16), round-odd fallback, negative-control define Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Owner
Author
|
Superseded by #254. |
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.
Draft: work in progress, parked while M and L speed take priority. Not ready for review.
What it does
The K softmax needs A = f16(w * inv) rounded once from the exact product (HIP:
v_fma_mixlo_f16 w, inv, 0). The D3D12 port emulates that with a round-to-odd sequence: 7 VALU, 1 convert and 2 VCC hazard waits per weight.This branch writes the weight as the exact two-term sum
p + e(p = w * inv in FP32, e = fma(w, inv, -p), so w * inv = p + e exactly) and feeds it into the driver's round-to-nearest-even matrix conversion. The gfx1201 D3D12 compiler folds that add intov_fma_mixlo_f16 / v_fma_mixhi_f16 p, 1.0, e, whose single rounding of p + e is RN16(w * inv), the same bits as HIP.KB_SMX 2(new default) is the mix form,KB_SMX 1keeps the round-to-odd form for the fallback ports, andKB_SMX_MUT 1is a negative-control mutant (residual dropped), never shipped.Rejected shapes (RGA): the product or an fma fed straight into the conversion stays
v_mul/v_fma+v_cvt_f16_f32(double rounding); a native(half)cast givesv_fma_mixlo_f16, but unders_round_moderound-toward-zero.Where it stands
Still to do before review
Tested
Not tested