Skip to content

Model L on D3D12: the frame blocks' GELU table with the cheaper offsets for every tile - #164

Merged
phantoslayer21 merged 1 commit into
mainfrom
model-l/c32-gelu-bn
Nov 14, 2026
Merged

phantoslayer21 merged 1 commit into
mainfrom
model-l/c32-gelu-bn

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Model L speed on D3D12, sixth change, from the ISA audit of the C = 32 blocks. The frame blocks
l_swin_block_c32_enc_nc and l_swin_block_c32_dec_coef12_nc read q8(GELU) from the arena table with
sw_gelu_fetch8_bn's cheaper offsets for every hidden tile (swin_block.hlsl SW_GELU 3, pattern 13333) instead of
wg_gelu_lut_fetch8's (SW_GELU 1). Same entries, same bytes (HIP's transcendental chain + pack); nothing is
approximated.

The audit (RGA ISA, gfx1201)

What changes

  • clean/dx12/kernels/l_swin.hlsl: SW_GELU=3,SW_GELU_PAT=13333 on _enc_nc and _dec_coef12_nc; header comment.
    _dec_nc (the fallback route) keeps SW_GELU 1.
  • clean/l/runner/l_d3d12_check.py: every other encoder / decoder block case has large inputs and special values in
    a twentieth of them.
    • Encoder (FP16): NaN, +-infinity, +-65504, +-0, the smallest subnormal.
    • Decoder (FP8): both NaN codes, +-448, +-0, subnormals.
    • These cases mostly give NaN windows (a NaN spreads through the window's attention): about half the output values.

Refs #89

Byte identity (one GPU slot each; records in the rr-plugin build folder)

  • clean/l/runner/l_d3d12_check.py --kernels l_swin_block_c32_enc_nc,l_swin_block_c32_dec_nc: D3D12 against HIP, raw
    bytes, sentinel-filled outputs (record records/gelu-bn-identity-blocks.json).
    • _enc_nc 28 of 28 cases identical, _dec_nc 28 of 28; Model M's swin_block_c96_nc control 16 of 16.
    • Negative control (half grid, _enc_nc): caught, 768 bytes differ.
  • clean/l/runner/l_fold_check.py (with Model L on D3D12: the folded decoder block's epilogue on the driver's conversions #163's special cases): _dec_coef12_nc against the pair on D3D12 and on HIP
    (record records/gelu-bn-identity-fold.json).
    • 84 of 84 cases identical in all three comparisons; negative control caught (16,384 bytes); Model M control 8 of 8.
  • The DXILs checked are the ones built from this commit and the ones timed.

Frame check (clean/l/runner/l_frame_check.py --compare-d3d12, synthetic models; record
records/gelu-bn-frame-check.json)

  • Model L: every stage against the reference 11 of 11 frames; the default kernels against the all-outputs run byte for
    byte 11 of 11; its post against Model M's post reference 11 of 11.
  • Model M: D3D12 against HIP 11 of 11. Pass.
  • Against the base build (main with Model L on D3D12: the folded decoder block's epilogue on the driver's conversions #163), every recorded array of both models' D3D12 runs (default and all-outputs, 11
    frames each) is byte-identical (record records/gelu-bn-frame-vs-base.json).

Timing (l_d3d12_profile.py, 1080p Quality, synthetic models). Build A is main (with #163); build B is A with these
two DXILs. Two sets of 3 interleaved rounds, every run in its own GPU slot; records records/gelubn1-ab.json and
records/gelubn2-ab.json.

  • l_swin_block_c32_enc_nc: 0.2826 / 0.2834 -> 0.2740 / 0.2764 ms (medians of the two sets: -9 / -7 us).
  • l_swin_block_c32_dec_coef12_nc: 0.3191 / 0.3207 -> 0.3061 / 0.3056 ms (-13 / -15 us). One B round has 0.3248.
  • The other kernels move by at most 0.002 ms, except lev/input_encoder (+10 us) and color_divide (+5 us) in the
    second set.
  • Whole-frame span: A 2.329 / 2.113 / 2.109, 2.125 / 2.120 / 2.120 ms; B 2.296 / 2.098 / 2.099, 2.088 / 2.106 /
    2.103 ms. B is faster in every round.

Tested

  • The identity checks, the frame check and the timing above; public gates.

Not tested

  • In a game (the next game timing run).
  • Real model weights: the table entries are exact for every input, the same bytes as HIP's chain.

…ts for every tile

l_swin_block_c32_enc_nc and l_swin_block_c32_dec_coef12_nc read q8(GELU) from the arena
table with sw_gelu_fetch8_bn's offsets for every hidden tile (swin_block.hlsl SW_GELU 3,
pattern 13333) instead of wg_gelu_lut_fetch8's (SW_GELU 1): the same entries, the same
bytes (HIP's transcendental chain + pack), fewer instructions. 95 / 96 VGPRs (bound 96;
patterns with a transcendental-chain tile need 108 .. 112). l_swin_block_c32_dec_nc (the
fallback route) keeps SW_GELU 1.

- clean/l/runner/l_d3d12_check.py: every other encoder / decoder block case with large
  inputs and special values (FP16 NaN, +-infinity, +-65504, +-0, subnormal; FP8 NaN,
  +-448, +-0, subnormals).

Refs #89

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 11:32
@phantoslayer21
phantoslayer21 merged commit 80e2470 into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/c32-gelu-bn branch November 14, 2026 11:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant