Commit Graph

32 Commits

Author SHA1 Message Date
c9e1bffe54 hw_oracle: recognize cl.exe behind a Windows path separator on any host
Oliwettoo's Linux check of #342 caught test_is_msvc_recognizes_cl_variants
failing off Windows: os.path.basename does not split on backslash there.
Normalize separators in _is_msvc so a Windows-style path is recognized on
every host.
2026-11-25 12:51:19 +05:00
b68ce6cccd hw_oracle: remove the temp workdir when the constructor fails (HW-ORACLE-WORKDIR-LEAK)
DrmOracle.__init__ and Oracle.__init__ create a temporary workdir and then
can raise Unavailable (a skipped probe, exit 77). close() is never reached
for an object whose constructor raised, so every skipped run left a
leonida-hw-oracle-* directory in the temp dir.

Remove the directory when the constructor made it and then fails. A
caller-supplied workdir is left alone. tests/test_hw_oracle_workdir_leak.py
covers the early, late and caller-supplied cases with no GPU or libdrm.
2026-11-24 10:53:58 +01:00
4e42451d55 hw_oracle: select AMDGPU ELF emulation for HIP code objects (#6289)
Squash-merged after diff review of PR #6289 - Windows hardware oracle: select AMDGPU ELF when linking HIP code objects
2026-11-23 08:25:06 -06:00
d7f08f4dd2 Merge pull request #4549 from mohamedsaad.lahlou
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:15:49 -05:00
41aa4c8f1a Merge pull request #4422 from Størm
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:14:35 -05:00
c33196304f Merge pull request #4075 from 0xTehuti
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:11:02 -05:00
a8a59bd647 Merge pull request #3972 from tedin7
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:10:03 -05:00
7db1e35da1 Merge pull request #3949 from PeterGrieffindor
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 23:09:50 -05:00
e3a855ea81 TEST-982: handle LLVM true16 spelling in VALU kernels 2026-11-23 03:21:45 +01:00
fbdc638aed hw_oracle: name op_sel halves on the VGPRs of 16-bit integer VOP3 ops for GFX11+
AMD LLVM 23 (rocm-sdk-core 10.0.0) rejects `v_max_u16_e64 v14, s12, v5 op_sel:[1,0,0]`
on gfx1100, gfx1150 and gfx1201 ("operands are not valid for this GPU or mode") and takes
`v_max_u16_e64 v14.l, s12, v5.l op_sel:[1,0,0]`. So `pk16_diff --oracle hw` skipped every
op_sel form of v_lshlrev/lshrrev/ashrrev_b16/i16, v_min/max_u16/i16 and v_mul_lo_u16 there:
80 of 200 programs on an RX 9070 XT.

asm.opsel16_spelling() writes each VGPR operand of those lines as the half its op_sel bit
picks and keeps the op_sel list for SGPR and constant sources. The runner applies it on
every non-gfx10 architecture, apart from the true16 probe: this assembler takes a bare
`v_cvt_f16_f32 v8, v1` on GFX11/12, so that probe says no.

All 2,551 distinct op_sel lines pk16_diff generates for the eight ops now assemble for
gfx1100, gfx1150 and gfx1201, with the same op_sel bits and operands as gfx1036's bare form.
RX 9070 XT: pk16_diff --oracle hw 200 programs 120 pass / 80 skipped -> 200 pass, 0 skipped;
2000 programs 2000 pass, 0 mismatch. gfx1036 unchanged (200/200, 2000/2000).

AI-assisted (Claude Code).
2026-11-22 20:21:02 -05:00
a96cf503b1 hw_oracle: retry probe as code object v5 on hip error 303 as well as 209 2026-11-23 00:16:43 +01:00
bf7fc223fb hw_oracle: a launcher quarantined by Windows Defender (WinError 225) is Unavailable with an exclusion hint, plus a Known problems row (BUILD-1127) 2026-11-22 23:44:24 +01:00
8c799453fb hw_oracle: an amdclang launcher on PATH is followed to the clang it is installed as
The rocm-sdk wheels put `amdclang` in the Python environment's Scripts (bin)
folder. find_clang() takes it first, because it is on PATH and lists the amdgcn
target, but ld.lld and amdgpu-arch sit beside the real clang, in the folder the
launcher reports as InstalledDir. With the wheels in a Python outside the
checkout the oracle then stopped with "no ld.lld next to the AMD clang", also
when HIP_PATH named a complete toolchain, and LEONIDA_AMD_CLANG was the only
way around it.

find_clang() now returns the clang in InstalledDir when the one it found has no
ld.lld beside it. A clang that has its linker is used where it was found, and a
launcher that names a folder without a clang is kept, so every setup that
worked resolves to the same compiler as before.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
2026-11-23 00:37:22 +02:00
02700eb4a2 Merge pull request #3603 from ezbyDev 2026-11-22 17:02:57 -05:00
8599cfccd3 hw_oracle: start build_hw_oracle.cmd as .\ from the work folder
build_command() returned `cmd.exe /d /c <full path of build_hw_oracle.cmd>`
for the vcvars toolchain. cmd.exe loses a full path's quotes when it holds
& or ^ (and list2cmdline adds none when there is no space), so from a work
folder such as `a & b`, `a&b` or `x^y` the script never ran and the oracle
reported that hw_oracle.c did not build. The only caller already runs the
command with cwd=self.workdir, the folder the script is written to, so it
now starts `.\build_hw_oracle.cmd`, which NoDefaultCurrentDirectoryInExePath
does not block either.

tests/test_hw_oracle.py runs the returned command on a stub vcvars from
plain, `sp (x)`, `a & b`, `a&b`, `x^y` and Turkish-named work folders with
that variable set, and the tests that read the script open it from the work
folder.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 22:04:17 +01:00
8a62436cf5 Merge pull request #3113 from kapitche 2026-11-22 15:14:53 -05:00
844b2cd24c hw_oracle: drop target features from the amdgpu-arch name
amdgpu-arch prints 'gfx1010:xnack-' on some GPUs; detect_arch handed that to
asm.family(), which rejects it, so the oracle was skipped unless
LEONIDA_HW_ARCH was set.
2026-11-22 14:26:15 -05:00
58b0cf94b1 hw_oracle: the comment no longer cites build_runtime.ps1 as writing UTF-8
That script has the chcp 65001 line but writes its .cmd as ASCII, so it is not a precedent for the encoding
(review of #2667). Comment only.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
2026-11-22 21:06:20 +03:00
978d1f0a9f hw_oracle: the vcvars build script survives paths outside ASCII
Without gcc or cl on PATH, the host launcher is built through a .cmd that calls vcvars64.bat. It was written as
ASCII, and it holds the checkout, %TEMP% and Visual Studio paths, so a character outside ASCII in any of them
(a Windows user name, the Turkish default folder name "Yeni klasör") raised UnicodeEncodeError: a traceback
instead of a build, and not the Unavailable that callers turn into exit code 77. The script is now UTF-8 with
`chcp 65001`, as scripts/build_runtime.ps1 writes its own, and the compiler's output is decoded leniently.

Co-Authored-By: Claude Mythos 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016ABh36DZ2sZNq3ChN6EZJs
2026-11-22 20:44:25 +03: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
e1ac59e7a0 Merge pull request #1620 from Luiz Neves 2026-11-22 08:08:13 -05:00
53064a29fa hw_oracle: a MODE that gfx1170+ cannot set is reported, not assembled (FUZZ-43)
AMD clang rejects .amdhsa_ieee_mode and .amdhsa_dx10_clamp on gfx1170+
(GFX11.7 and GFX12, where the behaviour is fixed). A kernel asking for
either reached the assembler, and when a chunk held only such kernels the
run died with 'the assembler rejected every program in a chunk'.

asm.mode_skip_reason names the field and the architecture; Oracle.run
returns that reason for those kernels and never assembles them, so the
others still run and the MODE probes fail with a clear message. The
denormal and rounding fields are unaffected.

tests/test_hw_oracle.py covers the reason per architecture, a mixed run
and a run where every kernel is skipped. docs/shader_validation.md notes
it.
2026-11-22 09:41:01 -03:00
34cff2a47c hw_oracle: report unsupported float MODE fields on gfx1170+
AMD clang rejects .amdhsa_ieee_mode and .amdhsa_dx10_clamp on gfx1170 and later, but the oracle emitted both whenever a fuzz run asked for them. The assembler then rejected every kernel in a chunk and the caller only saw a generic rejection.

Raise ModeUnavailable before emitting those directives, and have Oracle.run turn it into Unavailable so the existing exit-77 path reports the requested fields as unavailable. The denormal and rounding fields are still emitted. Add text tests for gfx1170/gfx1200/gfx1201, a gfx1150 control and the runner's skip conversion.

The focused tests pass (33 tests, one hardware skip). No RDNA4 GPU was available to confirm the hardware side; this is the directive-level fix. No game files.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
2026-11-22 06:40:00 -06:00
244f1510c4 hw_oracle: work with 2024 HIP runtimes and LLVM 23's true16
LLVM 23 writes code object v6, which amdhip64_6.dll refuses with error
209: retry the probe as v5 and keep that version for the run.

LLVM 23 also wants v8.l for 16-bit operands on GFX11: ask the assembler
once, and use that spelling for the f16 ops the oracle's tools run.

Tested on a Radeon 780M (gfx1103), driver 32.0.11020.1002.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 10:38:35 +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
7249dcb87d hw_oracle: build the launcher with MSVC when there is no MinGW gcc
find_cc() accepted only gcc, so a Windows contributor with Visual Studio (already required for the runtime)
got "hardware oracle unavailable: no MinGW gcc". hw_oracle.c builds cleanly with cl /O1.

- Order: LEONIDA_HOST_CC (gcc, or cl.exe / clang-cl), gcc on PATH or in C:\msys64, then on Windows a cl on
  PATH (Developer shell), then the Visual Studio vswhere finds, through its vcvars64.bat in a .cmd script.
- cl's objects go to the oracle's work folder, its errors (on stdout) reach the Unavailable message, and the
  temporary launcher name ends in .exe so cl doesn't append another one.
- Unit tests for the choice and the commands; docs/shader_validation.md says the runtime's VS is enough.

Checked end to end on an RX 9070 with no gcc and no cl on PATH: the launcher is built through vcvars64.bat,
salu_diff and crosslane_fuzz --oracle hw run with 0 mismatches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:35:02 +00:00
b75cca011c Merge pull request #1228 from Dominik 2026-11-22 04:07:46 -05:00
4f7ce665f7 hw_oracle: run on RDNA4 (gfx12xx); an unknown architecture is unavailable, not a traceback
On a gfx1201 card asm.family() raised ValueError out of Oracle(), so runner.py and salu_diff --oracle hw
crashed and tests/test_hw_oracle.py errored in setUpClass on any RDNA4 machine with the tools installed.

- family() accepts gfx12xx. The kernels use GFX11's spellings there (s_load_b64, global_store_b128).
- GFX12_REMOVED adds the twelve SOPK compares, which AMD clang (rocm-sdk-core 10.0.0) assembles for gfx1150
  and rejects for gfx1201. They are now named skips, not generic assembler rejections.
- Oracle() turns an unsupported architecture into Unavailable (exit 77), as the module docstring promises.

Measured on a Radeon RX 9070 (gfx1201, driver 26.11.2): salu_diff --oracle hw, 10,000 programs, 0 mismatches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 08:37:04 +00:00
5636ae8313 hw oracle: hypothesis mismatches are mismatches, wave-size probe, --keep writes the kernel that ran
- run_hw: a failing hypothesis op counts as a mismatch (exit 1) and in hyp_only;
  --minimize marks the hypothesis ops that remain
- Oracle startup probe: a wave64 kernel must see lane 32 as 32, a wave32 kernel
  as lane 0 of the second wave
- test_on_hardware also asserts rejected == 0, no mismatches, no hyp_only
- --keep / --minimize write hw_lines() for hardware failures
- docs: where the permlane FI=0 (#374, #580) and DPP8 (#238) hypotheses come from,
  and the re-run table (24,000 programs, hyp_only 0)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:13:05 +01:00
45c7911148 crosslane_fuzz: optional hardware oracle (--oracle hw, translator,hw)
Runs each FUZZ-7 program natively on the AMD GPU in wave32 and native
wave64, with its real group size and EXEC setup, every thread storing its
14 words, and compares them with the model. hw_oracle gains raw kernels
(own stores), per-kernel workgroup size and wave64 code objects; the
launcher takes name:threads:words tokens.

24,000 programs on gfx1150: 0 mismatches; the permlane FI=0 and DPP8
inactive-source hypotheses hold on the hardware too. Translator mismatches
all trace to masks read as data (#293) and permlane (#580).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-22 09:05:34 +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