Commit Graph

16 Commits

Author SHA1 Message Date
08ea049fbf salu_diff: drop duplicate sext8 left over from rebase 2026-11-22 22:13:27 +03:00
99b151be4a salu_diff: add 11 scalar ALU ops (64-bit bfe/brev/bitset/flbit/quadmask, mul_hi_i32) 2026-11-22 21:52:07 +03:00
3bf4e6e574 Merge pull request #2200 from d7ommy
# Conflicts:
#	docs/design.md
2026-11-22 11:42:44 -05:00
fe7edb58bd Address review on #2087: commit the s_cmov_b64 probe cases
Add the salu_cmov_b64 group (14 cases) to tools/int_hw_probe.py so the
gfx1036 measurement in docs/design.md is reproducible, name the command in
the row, drop the pointer to the duplicate row, and point the salu_diff.py
comment at the design.md counts instead of a second number.

AI-assisted.
2026-11-22 17:36:15 +01:00
06f36cec6b tools/salu_diff: add integer SALU ops and gfx1036 RDNA2 follow-up to #1746 (SHADER-137) 2026-11-22 19:29:38 +03:00
00452cfaa3 Merge pull request #1615 from Ewann 2026-11-22 09:48:04 -05:00
ec9b6cf22b tools: text reports are written with LF line ends on every platform (BUILD-468)
open(path, "w") without newline= turns each \n into \r\n on Windows, so the same JSON report, manifest or assembly
listing was CRLF there and LF elsewhere. 91 text-mode writes (open, os.fdopen, Path.write_text) under tools/, scripts/,
make_game.py and runtime/test/shaders/ now pass newline="\n". tests/test_text_write_line_endings.py reads the source
with ast and fails for a writer that forgets it; CONTRIBUTING.md names the convention.

AI-assisted (Claude), on behalf of dev-ewann.
2026-11-22 14:20:30 +00:00
a178a06b34 salu_diff: s_nand/s_nor/s_xnor_b64 in the generator; hardware-checked nand/nor/xnor
The translator already handles s_nand/nor/xnor_b32 and _b64 (rdna2spirv.py,
tests/semantic), so no translator change. What was missing: the _b64 forms in
salu_diff's generator, a GPU test of the translated output, and a hardware
comparison. Adds the three _b64 ops to salu_diff (and LANE_MASK_OPS),
ps_scc_logic32/64.asm (values and SCC by hand) registered in check.py and
run_gpu_tests.py, and a docs/design.md row with the hardware counts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 15:00:17 +01:00
f698bf2206 tools: a path outside the console's code page no longer crashes a tool's output
On Windows a redirected stdout uses the console's ANSI code page, and python -I ignores PYTHONUTF8 and
PYTHONIOENCODING, so a caller path with a character outside that code page ended a run with
UnicodeEncodeError as soon as a tool printed it. #1406 fixed make_game.py; every CLI tool in tools/ now starts
its __main__ block the same way (stdout errors="replace").

tests/test_tool_stdout_encoding.py checks every tool's __main__ block and reruns two measured crashes
(analyze_4240_full.py, meshlet_page.py) with a private-use-named input. Found by @abilliontokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 11:27:00 +00:00
d3ca882585 Tools: a Linux backend for the hardware oracle through libdrm_amdgpu, and its first runs on RDNA2
tools/hw_oracle ran only on Windows, through the HIP runtime in the AMD
driver, and so far only on gfx1150. On Linux the same kernels now run as
raw compute dispatches through the kernel driver: no ROCm, only clang
with the amdgcn target, gcc and the libdrm headers.

- hw_oracle_drm.c is the launcher. Its command stream is libdrm's own
  compute dispatch test for GFX10 (amdgpu_test_dispatch_memset), with
  what belongs to the kernel put in: the entry point, the group size,
  the kernarg pointer in two user SGPRs, and COMPUTE_PGM_RSRC1,
  COMPUTE_PGM_RSRC2 and the wave size as the kernel's descriptor has
  them. So the .amdhsa_* directives (register counts, float rounding
  and denormal modes, IEEE, DX10 clamp) take effect as under the HIP
  runtime. It prints the same lines as hw_oracle.c. Compute engine
  version 10 only (RDNA1 and RDNA2).
- drm.py is the backend: it assembles with clang, takes .text, the
  kernel offsets and the kernel descriptors out of the object, and runs
  the launcher. A descriptor that asks for what the launcher does not
  provide (LDS, scratch, more user SGPRs) is refused. The render node
  must be named in LEONIDA_HW_DRM_NODE, and a node with a display
  connected is refused unless LEONIDA_HW_DRM_ALLOW_DISPLAY=1.
- runner.open_oracle() picks the backend for the platform. The Windows
  path is unchanged.
- asm.raw_kernel_text puts the GFX10 names of the global memory
  instructions back for gfx10xx. crosslane_fuzz stores with
  global_store_b32, which a GFX10 assembler does not have, so on RDNA2
  every one of its programs was rejected.

One thing the launcher had to learn: while it rewrote one command buffer
in place, the second kernel of every process ran the first kernel's
commands (200 of 200 runs). Every submission now gets command memory of
its own; 24,500 distinct kernels in both wave sizes then each returned
their own words, and a test runs 300 of them.

Results on the integrated GPU of a Ryzen 9 7950X3D (Raphael, gfx1036),
Linux 7.3.5, libdrm 2.4.134, clang 23.1.5:

- salu_diff --oracle hw: 70,000 programs, 69,021 run, 0 mismatches
  (seeds 1-8; seeds 1-4 with --bfe-any; seeds 1-2 with --inline64). The
  s_bfe_i32 rule measured on gfx1150 holds on RDNA2, and s_ff0_i32_b32
  and s_ff0_i32_b64, which gfx1150 lacks, match (2,000 programs).
  --oracle translator,hw: 3,000 programs pass.
- crosslane_fuzz --oracle hw: 32,000 programs, 0 mismatches: seeds 1-6
  (12,000 wave32, 12,000 wave64, 6,586 with the permlane hypothesis)
  and seeds 1-2 with --dpp (8,000, 972 with the DPP hypothesis).
- f32_fuzz --oracle hw, seeds 1-6: 38,858 programs, 28,671 match, 0
  mismatches, 56 known deviations (an output modifier turns -0 into +0,
  as on gfx1150), the rest skipped or not judged. The four MODE settings
  read back as the descriptors set them.
- Controls: a reference with s_min_i32's SCC changed from < to <= gives
  2 mismatches in 5,000 programs, minimized to that instruction;
  crosslane_fuzz --permlane-fetch-inactive mismatches in 239 of 1,000;
  f32_fuzz --negative-control catches all six wrong models.
- No GPU fault, timeout or reset in the kernel log.

Tests: tests/test_hw_oracle.py gains tests of the backend that need no
GPU (reading the object and its descriptors, tokens, the display check,
the platform choice, the GFX10 mnemonics) and two on hardware: 300
distinct kernels, and an f32 rounding mode set in the descriptor that
must change a sum. The HIP-only test skips on Linux.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 04:57:17 -05:00
2e33dc681a salu_diff: SCC consumers in control flow (--branches, FUZZ-4 follow-up)
With --branches every SCC producer may be followed by a chain of 1..3
consumers (s_cselect_b32, s_addc_u32, s_subb_u32) or by s_cbranch_scc0/scc1
forward over the next 1..3 scalar instructions (one lane, no loops, no
nesting). Half the instructions are drawn from the SCC producers. Program
lines write a branch as "+N" instructions; the listing for the translator
carries the dword offset and ; encoding: placeholders of each instruction's
size (literal = 8 bytes), which place the branch targets. The reference
models the skip, the shrinker keeps skipped ranges consistent, and a
mismatch prints the real offsets. Default runs are unchanged so existing
seeds keep their programs; the hardware oracle refuses --branches.

8000 branch programs (8 seeds, max-ops 6/12/20, one with --bfe-any) match
on main. Also drops the stale "until #349 lands" note (#349 is merged).

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:40:38 +01:00
0767aea96f hw_oracle: review fixes (HIP DLL override, wording, design.md row, harness errors)
- LEONIDA_HIP_DLL is now passed to the launcher and loaded
- an all-rejected chunk is a RuntimeError (harness error), not skips
- -1 and 0xffffffff count as one literal; clang is no longer found by
  globbing */.venv under the cwd (env, PATH, HIP_PATH, ROCM_PATH, repo .venv)
- s_bfe past bit 31: say "analogous to LLVM's v_bfe fold", rule rests on the
  gfx1150 measurement; contract row in docs/design.md; Linux/ROCm note

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 08:47:19 +01:00
ed64990837 salu_diff: optional hardware oracle (--oracle hw), reference s_bfe past bit 31
tools/hw_oracle wraps the generated scalar programs in GFX10/GFX11 kernels,
assembles them with AMD clang and runs them through the HIP runtime of the
AMD Windows driver (hw_oracle.c, loaded with LoadLibrary, no SDK). salu_diff
compares the hardware's three SGPRs + SCC with the reference, alone or
together with the translator. A missing tool prints "unavailable" and exits 77.

First finding: s_bfe_i32 with offset + width > 32 stops the field at bit 31
on gfx1150 (width = min(width, 32 - offset)); the reference followed the
pseudocode literally. The translator already did the hardware thing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 08:43:11 +01:00
d29ae77858 salu_diff.py: strip and deduplicate --ops and report invalid --ops via ap.error 2026-11-22 01:32:04 +00:00
eaae31f609 Merge main; leave the s_ff fix to #349; review fixes for salu_diff
SHADER-46 (#349) fixes the same s_ff0_i32_b32 bug and was opened first, so
this branch drops its translator change and ps_salu_ff and keeps the
fuzzer. s_bfe_* control words stay inside offset + width <= 32 unless
--bfe-any; --programs/--max-ops below 1 is an argument error; the tests
no longer exclude s_min/max_i32 (#332 is on main) and check the BFE range.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:50:03 +01:00
fc7a3d9ca7 FUZZ-4: scalar ALU differential fuzzer; s_ff0_i32_b32 on a constant
tools/salu_diff.py runs seeded SOP1/SOP2/SOPC/SOPK programs through its
own reference and through the translator plus spirv_mini_interp, and
compares three SGPRs and SCC. It found that s_ff0_i32_b32 read a 32-bit
constant source as a lane mask; constants are now values, as for
s_bcnt*_b32. GPU-checked with ps_salu_ff.asm.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 00:21:00 +01:00