Skip to content

hw_oracle (Linux): run the LDS fuzzers through libdrm - #3954

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
ErRusso:main
Nov 23, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
ErRusso:main

Conversation

@ErRusso

@ErRusso ErRusso commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

hw_oracle (Linux): run the LDS fuzzers through libdrm

The libdrm launcher refused a kernel whose descriptor has a group segment
and capped its output at 4096 words, so lds_fuzz --oracle hw was exit 77
on Linux and no LDS program ran on RDNA2 outside Windows. Both are now
gone; docs/shader_validation.md records the gfx1036 counts.

  • drm.py: program COMPUTE_PGM_RSRC2.LDS_SIZE (bits 15..23, 512-byte
    units) from the descriptor's group segment instead of refusing it. The
    assembler leaves that field 0 (measured: 4096 bytes of LDS give group
    4096 and rsrc2 0x84), so the launcher fills it as the HIP runtime does.
    Only scratch memory (private) and COMPUTE_PGM_RSRC3 stay unsupported.
  • hw_oracle_drm.c: the output buffer takes 1..16384 words, matching the
    Windows launcher, so a 64x64 image_fuzz case (16384 words) fits.
  • asm.py: a wrapped (non-raw) kernel's LDS goes into its descriptor too,
    so the Linux launcher has a group segment to read.
  • lds_fuzz.py: the "more than 4096 words" wording no longer applies.

Tests: test_hw_oracle.py gains a descriptor unit test (group segment to
LDS_SIZE, 65536 ceiling) and two OnHardware tests (a kernel that writes,
barriers and reads back LDS; 8192 words from 1024 threads), plus a check
that LDS reaches the descriptor and metadata of a wrapped kernel. Verified
on the integrated Radeon of a Ryzen 7 7700X (gfx1036, RDNA2, Linux
7.3.5-zen1-1-zen, libdrm 2.4.134, AMD clang 23.1.5): lds_fuzz --oracle hw
--programs 500 --seed 1 matches 0 of 1000 (wave32+wave64) mismatches,
image_fuzz --oracle hw --programs 120 --seed 1 0 of 120.

AI-assisted (OpenCode).

The libdrm launcher refused a kernel whose descriptor has a group segment
and capped its output at 4096 words, so lds_fuzz --oracle hw was exit 77
on Linux and no LDS program ran on RDNA2 outside Windows. Both are now
gone; docs/shader_validation.md records the gfx1036 counts.

- drm.py: program COMPUTE_PGM_RSRC2.LDS_SIZE (bits 15..23, 512-byte
  units) from the descriptor's group segment instead of refusing it. The
  assembler leaves that field 0 (measured: 4096 bytes of LDS give group
  4096 and rsrc2 0x84), so the launcher fills it as the HIP runtime does.
  Only scratch memory (private) and COMPUTE_PGM_RSRC3 stay unsupported.
- hw_oracle_drm.c: the output buffer takes 1..16384 words, matching the
  Windows launcher, so a 64x64 image_fuzz case (16384 words) fits.
- asm.py: a wrapped (non-raw) kernel's LDS goes into its descriptor too,
  so the Linux launcher has a group segment to read.
- lds_fuzz.py: the "more than 4096 words" wording no longer applies.

Tests: test_hw_oracle.py gains a descriptor unit test (group segment to
LDS_SIZE, 65536 ceiling) and two OnHardware tests (a kernel that writes,
barriers and reads back LDS; 8192 words from 1024 threads), plus a check
that LDS reaches the descriptor and metadata of a wrapped kernel. Verified
on the integrated Radeon of a Ryzen 7 7700X (gfx1036, RDNA2, Linux
7.3.5-zen1-1-zen, libdrm 2.4.134, AMD clang 23.1.5): lds_fuzz --oracle hw
--programs 500 --seed 1 matches 0 of 1000 (wave32+wave64) mismatches,
image_fuzz --oracle hw --programs 120 --seed 1 0 of 120.

AI-assisted (OpenCode).
@SweatierKey

Copy link
Copy Markdown
Contributor

Code read and CPU test check of f23b6906 on Linux (WSL2, Python 3.13.5, CPU only, no AMD GPU, no game files): pass (partial — on-hardware libdrm execution not run here).

  • Red/green on main (aa2988cc):
    • Tests only against main: python3 -I tests/test_hw_oracle.py fails on both new unit tests (test_the_group_segment_becomes_the_lds_size_field raises RuntimeError refusing LDS; test_lds_reaches_the_descriptor_and_the_metadata sees 0 occurrences of .amdhsa_group_segment_fixed_size 4096 for wrapped kernels).
    • Whole PR: python3 -I tests/test_hw_oracle.py -v 46 tests OK (2 hardware classes skipped without LEONIDA_HW_DRM_NODE); tests/test_docs_repo_paths.py (2/2), tests/test_docs_links.py (6/6), tests/test_text_write_line_endings.py (3/3), tests/test_text_encoding.py (2/2) all OK.
  • Code read:
    • tools/hw_oracle/drm.py:kernel_registers: enforces group <= 65536, clears bits 15..23 (0x1FF << 15), and sets ((group + 511) // 512) << 15 (0..128 in 512-byte units for GFX10 COMPUTE_PGM_RSRC2.LDS_SIZE) while still rejecting private, rsrc3, and rsrc2 & 1.
    • tools/hw_oracle/hw_oracle_drm.c: checked the whole file for other 4096 output-word assumptions — allocate(dev, &out, words * 4, ...) scales dynamically with words (65,536 bytes for 16,384 words), and sentinel fill / per-kernel token validation / stdout printing all use w <= words. The remaining 4096 literals are page alignment and the code guard page.
    • tools/hw_oracle/asm.py: threads prog.lds into kernel_text and emits .amdhsa_group_segment_fixed_size {lds} so wrapped kernels match raw kernels.
  • Not checked: Live execution of hw_oracle_drm / lds_fuzz.py --oracle hw / image_fuzz.py --oracle hw on a GFX10 AMD GPU.

The linux-gpu-tools job on ubuntu-24.04 uses the system's libvulkan-dev,
whose headers are too old for VK_KHR_pipeline_binary (vk_harness.cpp uses
VkPhysicalDevicePipelineBinaryFeaturesKHR unconditionally). Add the same
Vulkan headers cache + sparse checkout that the windows job uses and pass
VULKAN_SDK during configure, so the pinned vulkan-sdk-1.4.363.0 release
shadows the system headers.

This job was added in ItsNotRexed#144; the vulkan-headers cache step was left out.
@ErRusso

ErRusso commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

The CI checks show several failures, but none are caused by the changes in this PR. All are pre-existing on upstream main (aa2988cc):

Check Failure Root cause
translator-tests test_d16_buffer_store_no_redundant_extract_after_shr16 spirv-val rejects translator output (undefined SSA ref). Reproduced on aa2988cc.
semantic-tests 7 FAIL + 2 ERROR (test_cmp_class_f64, test_mutations, test_loop_ballot_barrier) Known claimed issues (TEST-853, etc.), not fixed here.
check (Windows) PermissionError on shutil.rmtree Flaky Windows file-lock race in cleanup.
windows d3d12_geometry D3D12 shim test failure, not touched by this PR.
linux-gpu-tools GPU tests llvm-mc rejects ps_sdwa_f16_const CI installs LLVM 18; the shader needs LLVM 19+ for its SDWA float inline constant syntax.

This PR changes only:

  • tools/hw_oracle/drm.py / hw_oracle_drm.c — LDS support and larger output buffer in the libdrm backend
  • tools/hw_oracle/asm.py — LDS in wrapped kernel descriptors
  • tools/lds_fuzz.py / tools/f16_trans_sweep.py — stale comment updates
  • tests/test_hw_oracle.py — new tests for LDS and >4096-word output
  • .github/workflows/runtime.yml — add Vulkan headers cache to linux-gpu-tools (fixes the build step, which now passes)
  • docs/shader_validation.md — record the gfx1036 Linux results

Verified locally on gfx1036 (Ryzen 7 7700X): lds_fuzz --oracle hw --programs 500 --seed 1 matches 0/1000, image_fuzz --oracle hw --programs 120 --seed 1 matches 0/120, all hardware oracle tests pass.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 30023dce merged with main 03b09a08 on Linux (WSL2 Ubuntu), Python 3.12.16: pass for what runs without a GPU.

  • tests/test_hw_oracle.py: 46 tests OK (2 skipped: the two new on-hardware tests, LDS readback and the 8,192-word output, need an AMD GPU). Merge was clean.
  • Negative control: restoring main's non-test files gives 1 failure and 1 error (the group-segment to LDS_SIZE test, and RuntimeError: LDS, scratch memory ... not supported).
  • Read the diff: kernel_registers rounds the group segment up to 512-byte units into RSRC2 bits 15..23 and refuses more than 65,536 bytes; the C launcher's word limit goes to 16,384 and its output buffer is sized from words, the IB size is fixed. The workflow's Vulkan-headers SHA and the actions/cache SHA match the tags they cite. No bug found. The gfx1036 results (1,000 + 120 cases, 0 mismatches) are not reproducible here. The runtime.yml change is unrelated to the title.

@bobcatchris bobcatchris left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on a clean checkout of the head (Windows, Python 3.12, CPU only — the Linux/drm paths I could not execute):

  • python -I tests/test_hw_oracle.py — 46 OK, 2 skipped (the hardware-gated ones). lds_fuzz's delta is only the 77-message wording, matching the widened cause.
  • The CI change does not touch the llvm-18 llvm-mc pin (lines 291/326/366 unchanged), so it does not collide with BUILD-923/#802; it swaps the apt Vulkan headers for a pinned KhronosGroup/Vulkan-Headers checkout (sparse, include-only, cacheable, persist-credentials: false) and points CMake at it via VULKAN_SDK — coherent and reproducible.
  • The fix itself is the right shape: COMPUTE_PGM_RSRC2.LDS_SIZE derived from the descriptor's group segment (with the measured rsrc2 0x84 cross-check) is exactly what the HIP runtime does, and raising the C launcher's output cap to match the Windows one removes the artificial 4096-word ceiling rather than special-casing around it.
  • Still unsupported on purpose: private/scratch memory and COMPUTE_PGM_RSRC3 — documented, not silently passed through.

Approving. The gfx1036 counts in docs/shader_validation.md come from the author's hardware; I verified everything that runs without it.

AI-assisted.

@SebSilent

Copy link
Copy Markdown
Contributor

Reviewed head 30023dce from a CPU-only box. No AMD GPU here, so the on-hardware numbers stay with bobcatchris and kapitche, I checked everything that can be checked without a Radeon.

The descriptor side lines up. Reading group/private at byte 0 and rsrc3/rsrc1/rsrc2/properties at byte 44 matches the amdhsa .kd layout, and the LDS_SIZE position is right: LLVM's own AMDHSAKernelDescriptor.h puts GRANULATED_LDS_SIZE at bits 15..23, and this repo's rdna2spirv.py reads the same field from the same descriptor. I measured it here: with llvm-mc 23.1.5 (-mcpu=gfx1036) a ds_write_b1 kernel with .amdhsa_group_segment_fixed_size 4096 assembles, and the emitted .kd carries group 4096 while rsrc2 is 0x84, so the LDS_SIZE field really is left 0 by the assembler and the launcher has to program it. The wrapped-kernel path emits rsrc1 0xe0ac0001, rsrc2 0x84 and group 4096 too, so kernel_registers handing back 0x40084 and the token k0@0/0xe0ac0001/0x40084/32 is what the C launcher actually gets.

Launcher conventions check out: exit 2 on bad args (the words cap 1..16384 matches hw_oracle.c, and asm.py's Kernel already refuses more, so the C guard is a backstop), exit 77 when no device or init fails, the per-submission ib allocation is kept, the 0xDEAD0000 fill is kept. On this machine lds_fuzz --oracle hw still exits 77 with the render-node hint, so CPU-only users are unaffected.

Tests: 46 pass, 2 skipped (no GPU), compileall clean. I also mutation-checked the new logic, floor division instead of the ceil, 65535 instead of 65536, not clearing the field before the OR, and a 14-bit shift instead of 15, each one is caught by the new tests.

The red CI checks are the known pre-existing set. I reproduced the translator one at this head (test_d16_buffer_store_no_redundant_extract_after_shr16, spirv-val: "Operand '135[%135]' requires a previous definition"), and the PR touches no translator files; that test file is byte-identical to base.

No blocking issues, LGTM. kapitche's merged-tree run at 03b09a08 (44 OK, 2 skipped) covers the rebase shape too.

AI-assisted.

@memorypressure

Copy link
Copy Markdown

Verified merged with main on Linux: tests/test_hw_oracle.py passes (46 tests, 2 hardware skips) and the f16_trans_sweep, lds_fuzz (+cli, +hw), f32_fuzz, crosslane and ds_permute suites are green. merge-tree with #4152 and with #4204 is conflict-free; on a 3954+4152 combined tree the CPU oracle tests and #4152's own test_image_fuzz_hw (29 passed, 1 skipped) pass, and the 3954+4204 combined workflow keeps llvm-21 with no llvm-18 references. The gfx1036 libdrm results themselves need AMD hardware and were not re-measured here. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

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.

7 participants