Skip to content

Frame generation: probe of the gfx12 matrix instructions against net1's chunk arithmetic - #193

Merged
phantoslayer21 merged 2 commits into
mainfrom
fg/wmma-probe
Nov 14, 2026
Merged

phantoslayer21 merged 2 commits into
mainfrom
fg/wmma-probe

Conversation

@phantoslayer21

Copy link
Copy Markdown
Owner

Refs #96 (frame generation). Step 1 of the net1 fast path: a probe of gfx12's 16 x 16 x 16 matrix instructions against net1's chunk arithmetic. This PR is the tool and its record only; nothing in any runtime changes.

Question

In net1's convolutions, the float16 accumulator takes 16-term chunks: acc = RN16(acc + sum of 16 products), with one rounding. One WMMA has K = 16 and adds C in the same instruction, so each of its 256 outputs is one chunk when C is the accumulator. Does either matrix form compute that sum exactly and round it once?

What's in it

  • clean/fg/kernels/fg_probe.hip:

    • the exact chunk reference: the shared integer code of fg_exact16.h, plus an RN32 rounding of the same exact sum;
    • v_wmma_f16_16x16x16_f16 (float16 accumulate), chained like net1's chunks (D fed back as C);
    • v_wmma_f32_16x16x16_f16 (float32 accumulate), with the float16 accumulator in between: each chunk's float32 result is rounded to float16. The kernel also flags results that land exactly on a float16 midpoint (fg_probe_mid.h), the only place where RN16 of an exactly rounded float32 sum could differ from RN16 of the exact sum.
  • clean/dx12/kernels/fg_probe.hlsl: both forms on D3D12 through the driver channel, with the same fragments and outputs. The final stores read their pointers through wg_uniform(): on this driver, two stores at one per-lane offset through two pointers were merged, the documented driver exception, and the sentinel check showed it here.

  • clean/fg/runner/fg_wmma_probe.py runs these case classes:

    • random chunks in four distributions (uniform, any finite value, any finite value below 16 incl. subnormals, net1-like values);
    • net1_01's zero input channels;
    • adversarial chunks: big products cancelling down to tiny residues; the accumulator cancelling a big product; exact ties decided by a 2^-48 term or by nothing; the 65504 / 65520 overflow boundary and 2^30 products that cancel; subnormal results; exact-zero sums with signed zeros, incl. the zero-channel case; NaN / ±inf inputs;
    • every net1 layer's chunk chain (2 to 72 chunks).

    For each form and class it counts equal / mismatching outputs, the distance in float16 steps (max, over 1, over 4), and up to three mismatching examples (inputs, expected, got). It re-checks a sample of the GPU reference on the CPU (fp16acc.acc_dot16, Python integers). The D3D12 outputs are compared byte for byte with HIP, with sentinels 0xA5 / 0x5A and slack bytes.

  • clean/fg/records/wmma-probe-2026-11-14.json: the record.

Result (record above)

Neither form equals the exact chunk, so by the probe this is tier C. In detail, on HIP (150.5 million chunk evaluations):

  • float32 accumulate:
    • its result is not RN32 of the exact sum (50.9 million mismatches);
    • it drops small terms when the accumulator cancels a big product.
  • float32 accumulate, rounded to float16 per chunk: on ordinary data (random, net1-like, layer chains; 62.4 million outputs), 1,216 outputs are more than one step off, 211 more than four, and the maximum is 256 steps.
  • float16 accumulate: on the same data, 6.05 million outputs are more than one step off and 1.86 million more than four.
  • Exact-zero sums: 110 outputs differ only in the sign of zero. The reference rounds an exact zero to +0.

D3D12 gives the same bytes as HIP in every class (60 cases).

Tested

  • GPU, one GPU slot under its cap (ran 24 s), with each launch a single short dispatch:
    • HIP: 30 classes;
    • D3D12: the first batch of each class, byte-identical to HIP with the slack sentinels intact;
    • the CPU re-check of the GPU reference: all equal.
  • python -m unittest discover -s clean/fg/tests -t .: 81 OK, including 4 new tests: the midpoint test against brute force over float16 neighbours, RN32 against exact fractions, the case classes. clean/dx12/tests/test_kernel_sets.py: 4 OK (fg_ kernels in no set).
  • public_gates.py: must-pass gates pass; the LOOK lines are at main's baseline.

Not tested

  • Other GPUs and drivers: the record is one gfx1201 card and its current driver.
  • Any runtime use: this PR changes no runtime or model kernel set.

…'s chunk arithmetic (evidence)

- kernels/fg_probe.hip: the exact chunk reference (fg_exact16.h, plus RN32), v_wmma_f16_16x16x16_f16 and
  v_wmma_f32_16x16x16_f16 chained like net1's chunks; fg_probe_mid.h: the float16-midpoint test
- clean/dx12/kernels/fg_probe.hlsl: both forms on D3D12 through the driver channel, byte-identical to HIP
- runner/fg_wmma_probe.py: random, adversarial and per-layer chain classes, counts, step distances, examples,
  a CPU re-check of the GPU reference
- records/wmma-probe-2026-11-14.json: neither form equals the exact chunk (tier C by the probe)
- No runtime change; fg_ kernels still built only through --only

Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
Signed-off-by: phantoslayer21 <156617979+phantoslayer21@users.noreply.github.com>
@phantoslayer21
phantoslayer21 marked this pull request as ready for review November 14, 2026 20:29
@phantoslayer21
phantoslayer21 merged commit f4816cf into main Nov 14, 2026
9 checks passed
@phantoslayer21
phantoslayer21 deleted the fg/wmma-probe branch November 14, 2026 20:31
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