Skip to content

Model L own post: previous exposure by its reciprocal (HIP + D3D12), speed levers and floor (Q5) - #169

Merged
phantoslayer21 merged 2 commits into
mainfrom
model-l/lpost-exposure-rcp
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
model-l/lpost-exposure-rcp

Conversation

@phantoslayer21

@phantoslayer21 phantoslayer21 commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Refs #89

Model L's own post (l_post=own), speed step 3: the reordering levers allowed by the spec answer Q5, measured one by
one. One lever is kept. Everything else came out neutral or slower, so this PR also gives the floor breakdown of
l_post_recon_p12 for oversight.

Base: main (after #167, merge 069827e).

Change (HIP and D3D12 together)

  • L_i = D(H_i) · r_prev with r_prev = 1 / e_prev (one IEEE division per launch). This replaces D(H_i) / e_prev per
    channel and candidate.
    • Same change in clean/l/kernels/l_post.hip (l_post_core) and in its D3D12 port clean/dx12/kernels/l_post.hlsl.
    • The port drops its correctly rounded division window (ep_window / ep_div3): −5.6 KB of ISA.
  • Spec basis: answer Q5 (preset L part 3, "which evaluation-order details are facts"), section 1. "True division
    by the weight total instead of × reciprocal" and "exposure removal by true division" are both listed as free:
    0 values more than 1 ulp off on the spec's frames. No order that Q5 marks as a fact is touched: the gather, the
    history partial sums and the 5-read form, the ranking, the 1/255 cut-off, the blend form, the NaN guard and the
    special values all stay as they are.
  • Model M is untouched: post.hip and every M HLSL file are unchanged.

Records (GPU, gfx1201)

  • New HIP against Model L's oracle, l_post_check.py --seeds 6, 60 cases:

    • pass, with the negative control caught;
    • run: 6 of 431784 FP16 values more than 1 ulp off (history and display alike), the same count as main's kernel on
      the same cases.
    • Old against new l_post.co on those 60 cases: 0 output bytes differ (history, display, reduced). The previous
      exposure there is random in [0.5, 2]. The 1-ulp FP32 differences of the product do not survive the FP16 / code
      rounding on these cases.
  • New HIP on all frames (l_frame_check.py --compare, 11 frames, Model L post acceptance): L pass, M pass. The
    default kernels against the six-launch bottleneck: 11 of 11 identical, negative controls caught.

  • D3D12 byte-identical to the new HIP:

    • l_d3d12_ops_check.py --seeds 6:
      • l_post_recon 72 of 72 and l_post_recon_p12 72 of 72 identical, 0 differing bytes;
      • the cases include the extreme previous-exposure cases;
      • p12 = base on HIP 72 of 72;
      • Model M control swin_block_c96_nc 36 of 36;
      • half-grid negative control caught (8498 bytes differ).
    • Frame, l_d3d12_own_post_check.py (raw bytes; sentinels HIP 0xA5 / D3D12 0x5A / D3D12 stages 0x3C):
      • against the HIP run: 11 of 11 frames identical, 28 outputs, 0 differing; negative controls 4 of 4 caught;
      • per stage against the reference under Model L's post acceptance: 11 of 11;
      • default against stages: 11 of 11 identical.
  • Model M DXILs unchanged: the M fused posts (w64/post_tf*, pmo/post_tf*, buffer and direct forms) and
    swin_block_c96_nc were rebuilt from this tree: 15 of 15 DXILs byte-identical to main's.

  • Timing (l_d3d12_profile.py, 200 frames, two alternating runs each, l_post_recon_p12 ms per frame):

    Shape main (D3D12 l_post_recon(_p12): smaller and faster, byte for byte the same (l_post=own speed, step 1) #166 + l_post=own direct route: the filter writes the game's texture (speed step 2) #167) this PR
    1080p Quality 0.6018 / 0.6018 0.5861 / 0.5854
    1440p Quality 1.0647 / 1.0639 1.0353 / 1.0349

Levers measured and not kept (D3D12, 1080p Quality, same build, base 0.588–0.590 ms; noise about ±0.01 ms)

Lever ms Why it does not help
Packed FP16 (half2) for the two rows' tap weights (same per-operation roundings) 0.602 The driver already pairs them: same ISA. Its 160 v_pk_fma_f16 already pair the two rows' half accumulators.
History addresses by steps instead of 4 multiplies 0.595 No gain (ISA +0.5 KB).
wave64 instead of wave32 0.709 The FP16 conversions must then be software (the driver conversion is wave32 only).
Two pixel pairs per lane 0.671 (unrolled, ISA 86 KB) / 0.632 (loop kept) Twice the LDS per workgroup: occupancy 10 → 8 waves. Staging gets cheaper per pixel, but that does not pay.
Occupancy: row loop and column loop kept as loops (VGPRs 138 → 111, ISA 39 → 17 KB, with the reciprocal) 0.585 vs 0.574 The kernel is ALU bound, not latency bound.
Branchless decode (select of polynomial and exponential, with the reciprocal) 0.598 vs 0.574 Both paths always run.
Gather straight from memory, no LDS staging (with the reciprocal) 0.957 Each texel converted once per tap instead of once per workgroup.
Reconstruction + filter fused (negative result in #167) 0.951 Slower than the pair.

Floor breakdown (1080p Quality)

  • Now: reconstruction 0.586 + filter 0.075 = 0.661 ms. Model M's fused post on the same frames is 0.328 ms:
    a gap of about 0.33 ms.
  • The ablations below were measured on the kernel before the reciprocal (base 0.598–0.606 ms). Each one removes one
    part, so the parts overlap and do not add up.
  • The ablations use the synthetic frames of the profiler, whose random motion overstates the history-read cost
    against real motion.
Part Removal saves (ms) Fixed by (Q5 / item 3 / item 4)
Gather, 16 taps in half precision (≈ 0.058 per tap column) ≈ 0.23 FACT: tap order i outer / j inner, half ε with the fused last term, h(w), one fused half accumulate per feature, flush-to-zero
History Catmull-Rom, up to 4 per lane (2 rows × 2 candidates), 12 single-precision taps each 0.133 (all fetches + arithmetic) FACT: single-precision partials, 5-read form values and positions
History decode + exposure (now with the reciprocal) 0.058 → ≈ 0.04 FACT: candidates decoded to linear before combining (item 4)
Second candidate 0.13 (overlaps the two rows above) FACT: ranking with ties to the earlier candidate, 1/255 cut-off
Texel staging (item-3 FP16 values, encode logs, code table) ≈ 0.07 FACT: staged values are item 3's FP16 values
Current-colour decode (Cl) 0.022 spec decode
Store encodes (log2 of history and display) 0.022 spec encode

Against Model M's fused post: 9 taps instead of 16, one Catmull-Rom in the encoded domain instead of up to two
per row with per-candidate decode, and the filter fused. Each difference is a spec fact of Model L, not an
implementation choice. With every lever above measured, I see no free reorder left that is worth more than about
0.01 ms. Reaching about 0.1 ms of the fused post would need changes to the facts in the table.

Tested / Not tested

  • Tested: the GPU records above; leak scan 0 hits; public gates at the baseline.
  • Not tested: game captures (the change is free per Q5 on the spec side; the byte identity HIP ↔ D3D12 is checked
    above); the native direct test (the change is inside l_post_recon_p12, which both routes run unchanged).

Update: on main after #167 (merge 069827e)

Main also brought #168 (WG_REV_ORDER in wg_platform.hlsli, reverse workgroup order for l_swin_block_c32_enc_nc).
The header change is preprocessor-only for kernels that do not set it: l_post_recon and l_post_recon_p12 rebuilt on
the merged tree are byte-identical to the DXILs of the records above, so the oracle, ops and timing records stand.
Frame record re-run on the merged tree (with #168's encoder), raw bytes: against the HIP run 11 of 11 identical, 28
outputs, 0 differing, negative controls 4 of 4 caught; per stage against the reference 11 of 11; default against
stages 11 of 11 identical. Leak scan 0 hits; public gates at the baseline.

… D3D12)

L_i = D(H_i) r_prev with r_prev = 1 / e_prev (one IEEE division per launch) instead of D(H_i) / e_prev per channel
and candidate, in l_post.hip and its D3D12 port l_post.hlsl alike. The spec answer Q5 (preset L part 3, section 1)
lists the division by the weight total or the exposure as a product with the reciprocal as free within Model L's post
tolerance. The D3D12 port drops its correctly rounded division window (ep_window / ep_div3).

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Base automatically changed from model-l/lpost-filter-direct to main November 14, 2026 14:23
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 14:33
@phantoslayer21
phantoslayer21 merged commit 4fb31b4 into main Nov 14, 2026
18 of 27 checks passed
@phantoslayer21
phantoslayer21 deleted the model-l/lpost-exposure-rcp branch November 14, 2026 14:38
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