Repository navigation
perf(rocke): enable exp2_fast for bf16 head_dim=128 in gfx942 dense prefill #10832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
AviralGoelAMD
wants to merge
3
commits into
develop
from
users/avirgoel/ck/gfx942-dense-bf16-exp2-pr
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
d4de8c1
perf(rocke): enable exp2_fast for bf16 head_dim=128 in gfx942 dense p…
AviralGoelAMD 8aa1b28
test(rocke): update exp2_fast gate matrix for bf16 D128 enablement
AviralGoelAMD e775fe9
chore(rocke): format exp2_fast gate case + cite code-object read for …
AviralGoelAMD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,8 +81,8 @@ | |
| ----------------------------------------------------------------------------- | ||
| * P0 enablement + 32x32x8 atom + K-loop doubling ............ DONE (this file) | ||
| * P1 conflict-free V (perm_b32 store-path transpose) ........ DONE (D128 fp16) | ||
| * P2 exp2_fast + fused/lazy rescale ........................ DONE (exp2_fast all | ||
| but bf16 D128; fused rescale bit-identical, enables bf16 D64 exp2_fast) | ||
| * P2 exp2_fast + fused/lazy rescale ........................ DONE (exp2_fast for | ||
| ALL configs incl. bf16 D128; fused rescale bit-identical, bf16 D64 exp2_fast) | ||
| * P3 occupancy: waves-per-eu tune (bf16 D64 -> wpe4 = 2 WG/CU), | ||
| D64 K bank-pad, wide4 (WG=256), K single-buffer ........... IN PROGRESS | ||
| (waves-per-eu DONE via _tuned_waves_per_eu; **D64 K bank-pad DONE and ADOPTED** | ||
|
|
@@ -326,7 +326,7 @@ class Gfx942DenseTuning: | |
|
|
||
| # use_exp2_fast: force the P2 single-instruction exp2 on/off. | ||
| # None (default) -> :func:`_use_exp2_fast`, which owns the measured verdict | ||
| # (on everywhere except bf16 D128, which spills). Numerically safe in both | ||
| # (now on for ALL configs; the former bf16-D128 spill holdout is stale). Numerically safe in both | ||
| # directions here -- both softmax arguments are always <= 0 -- so unlike | ||
| # ``use_cfvst`` this one is a pure perf A/B and is not gated. | ||
| use_exp2_fast: bool | None = None | ||
|
|
@@ -518,22 +518,25 @@ def _rows_per_instr(head_size: int) -> int: | |
| def _use_exp2_fast(head_size: int, dtype: str) -> bool: | ||
| """Whether softmax uses ``exp2_fast`` (one v_exp_f32, no range-reduction guard). | ||
|
|
||
| Enabled everywhere EXCEPT bf16 D128. exp2_fast is a strict VALU reduction and the | ||
| dominant P2 lever on the (post-P1) VALU-bound path, and is always numerically safe | ||
| here -- both softmax args (alpha's m_i - m_new and p's s - m_new) are <= 0, exactly | ||
| exp2_fast's precondition. | ||
|
|
||
| bf16 D128 is the sole holdout. Its ``.1k`` MFMA schedule keeps more registers live, | ||
| and exp2_fast makes the exp result available in one instruction (vs plain exp2's | ||
| ~5-op range reduction), which the scheduler hoists -- lengthening the exp live | ||
| ranges. Measured post-fused-rescale (plan §6.1): bf16 D128 goes 175 VGPR / 0 spill | ||
| (plain exp2) -> 256 VGPR / 22 spill (exp2_fast), over the waves-per-eu=2 cap. The | ||
| fused rescale freed ~28 VGPR but not enough to absorb that hoist on the .1k path; | ||
| fp16 D128 (213, cfvst) and bf16 D64 (215) both have the headroom. A bf16 D128 | ||
| exp2_fast unblock is a P3 occupancy/scheduling item. Spill re-verified across the | ||
| fp16/bf16 x D64/D128 cohort. | ||
| Enabled for all configs. exp2_fast is a strict VALU reduction and the dominant P2 | ||
| lever on the (post-P1) VALU-bound path, and is always numerically safe here -- both | ||
| softmax args (alpha's m_i - m_new and p's s - m_new) are <= 0, exactly exp2_fast's | ||
| precondition, independent of head_size and dtype. | ||
|
|
||
| bf16 D128 was previously the sole holdout. An earlier fused-rescale schedule | ||
| (plan §6.1) spilled with exp2_fast (175 -> 256 VGPR / 22 spill, over the | ||
| waves-per-eu=2 cap), so the policy disabled it. The current lazy-rescale schedule | ||
| does not spill: an ``llvm-readelf --notes`` read of the compiled code object | ||
| (``.private_segment_fixed_size``/``.vgpr_count``) on the shipped bf16-D128 kernel -- | ||
| both the default and persistent grids -- reports 0 scratch and a lower VGPR count | ||
| with exp2_fast than without, numerically identical to plain exp2. | ||
| The holdout is therefore stale and removed. (The stale numbers were measured against | ||
| the pre-lazy-rescale body; the register profile has since changed sign.) head_size is | ||
| no longer a gate -- correctness holds for every head_size (the <= 0 precondition is | ||
| universal); a new head_size would only warrant a fresh occupancy check, never a | ||
| correctness one. | ||
| """ | ||
| return dtype == "fp16" or head_size != 128 | ||
| return True | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The reason I keep this function to just return true is becasuse we can reuse this later in a new scenario where some datatype would need to be excluded. |
||
|
|
||
|
|
||
| def _use_cfvst(head_size: int, dtype: str) -> bool: | ||
|
|
@@ -1447,8 +1450,8 @@ def do_mask(s_reg, tile_idx): | |
| # s) -- exactly exp2_fast's precondition (no overflow; v_exp_f32 flushes | ||
| # large negatives to 0). Cuts ~99 VALU/tile at D128, the dominant | ||
| # MFMA-starving residual once conflict-free V (P1) lands. Enabled for | ||
| # every config except bf16 D128, which spills on the .1k schedule -- the | ||
| # spill rationale and the matrix live in _use_exp2_fast's docstring. | ||
| # every config, including bf16 D128 -- its former spill holdout is stale on | ||
| # the current lazy-rescale schedule; rationale + matrix in _use_exp2_fast's docstring. | ||
| exp2 = b.exp2_fast if tuning.resolved_use_exp2_fast(spec) else b.exp2 | ||
| alpha = exp2(b.fsub(m_i, m_new)) | ||
|
|
||
|
|
||
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.