Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion docs/shader_validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ Setup on Windows, about 800 MB and no admin rights:
target. The ROCm wheel has one:
`py -m venv .venv` then `.venv\Scripts\python -m pip install --index-url https://stable.repo.amd.com/rocm/whl-next/ "rocm-sdk-core==10.0.0"`;
`clang.exe` ends up in `.venv\Lib\site-packages\_rocm_sdk_core\lib\llvm\bin`. A `.venv` in the working
directory or repository is found by itself; otherwise set `LEONIDA_AMD_CLANG` to that `clang.exe`.
directory or repository is found by itself, and so is the wheels' `amdclang` on PATH: that launcher has no
`ld.lld` beside it, so the oracle uses the `clang.exe` in the folder it reports as `InstalledDir`. Otherwise set
`LEONIDA_AMD_CLANG` to that `clang.exe`.
- **Linux** has a launcher of its own, without ROCm: see the next list. `hw_oracle.c` is the Windows one (it loads
the driver's DLL).
- **Host C compiler.** `tools/hw_oracle/hw_oracle.c` is built once into the temp folder by MinGW gcc (on PATH or in
Expand Down Expand Up @@ -977,6 +979,9 @@ every scalar. `vk_compute_test` reads them back with `VKC_OUT_WORDS` / `VKC_DUMP
On a discrete RDNA2 card (RX 6700 XT, gfx1031, Windows, Adrenalin 26.8.1, through the HIP DLL of the driver;
BUILD-162): with `--dpp`, seeds 1 to 8, 1,000 programs each (500 per wave size), all 8,000 match, 984 of them
`hyp_dpp` and 1,964 `hyp_permlane`.
On RDNA4 (RX 9070 XT, gfx1201, Windows, Adrenalin 26.11.2, `amdhip64_7.dll`, AMD clang 23.0.0git from the
`rocm-sdk` wheels): the same eight runs, all 8,000 match, with the same 984 `hyp_dpp` and 1,964 `hyp_permlane`
programs. gfx1201 is not RDNA2: the match supports the model and settles nothing about the console.
- **DPP sweep (`--dpp-sweep`, BUILD-162).** The random `--dpp` programs run full waves, four ops and mostly
`row_mask`/`bank_mask` 0xF, so a rare control or mask pair can go untested for many seeds. `--dpp-sweep` replaces
the random programs with one short program per case: an EXEC write, then one DPP op. It covers every DPP16 control
Expand All @@ -998,6 +1003,9 @@ every scalar. `vk_compute_test` reads them back with `VKC_OUT_WORDS` / `VKC_DUMP
run (`--oracle translator,hw`), the translator matches all of them as well: 7,206 wave32 native and 7,206 wave64
`--wave64-emulate`, with 0 rejected and 0 harness errors. One `vk_compute_test` runs per case, so the translator
side takes about 90 minutes there; the hardware side takes about one.
On the RX 9070 XT (gfx1201, the setup above), `--dpp-sweep --oracle hw --wave both`: 14,412 cases, match 14,412,
mismatch 0 in every family, 40 of them `hyp_dpp`, in half a minute. The same DPP rules hold on RDNA4; the
translator side was not run there.
First results (Radeon 880M, driver 26.11.2): 24,000 programs on the hardware, half wave32 and half native
wave64, seeds 11 to 16 (4,000 programs each), with and without `--dpp`, 12 to 60 ops, with and without
`--no-maskdata` and `--no-hw-guard`: match 24,000, mismatch 0, hyp_only 0, rejected 0. 7,652 of them contained
Expand Down
54 changes: 54 additions & 0 deletions tests/test_hw_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,60 @@ def test_unknown_oracle_is_a_usage_error(self):
self.assertEqual(r.returncode, 2)


class ClangOnPath(unittest.TestCase):
"""find_clang when the compiler comes from PATH: real files in a folder, and a stand-in for what each compiler
prints for `--print-targets` and `--version`."""
EXT = ".exe" if os.name == "nt" else ""

def setUp(self):
tmp = tempfile.TemporaryDirectory()
self.addCleanup(tmp.cleanup)
self.root = Path(tmp.name)

def tool(self, *parts):
p = self.root.joinpath(*parts[:-1], parts[-1] + self.EXT)
p.parent.mkdir(parents=True, exist_ok=True)
p.write_bytes(b"")
return str(p)

def tools(self, on_path, installed):
"""PATH holds on_path ({name: file}); the compiler `c` reports installed[c] as its InstalledDir."""
def run(cmd, **kw):
out = "amdgcn" if "--print-targets" in cmd else f"clang version 23.0.0\nInstalledDir: {installed[cmd[0]]}\n"
return subprocess.CompletedProcess(cmd, 0, out, "")
patches = [unittest.mock.patch.object(runner.shutil, "which", side_effect=lambda n: on_path.get(n)),
unittest.mock.patch.object(runner.subprocess, "run", side_effect=run),
unittest.mock.patch.dict(os.environ, {"LEONIDA_AMD_CLANG": "", "HIP_PATH": "", "ROCM_PATH": ""})]
for p in patches:
p.start()
self.addCleanup(p.stop)

def test_a_launcher_on_path_stands_for_the_clang_it_is_installed_as(self):
# The rocm-sdk wheels in a Python outside the checkout: `amdclang` in Scripts has the amdgcn target, while
# clang, ld.lld and amdgpu-arch sit in the folder it names as InstalledDir.
launcher = self.tool("Scripts", "amdclang")
clang, lld = self.tool("llvm", "bin", "clang"), self.tool("llvm", "bin", "ld.lld")
self.tools({"amdclang": launcher}, {launcher: str(self.root / "llvm" / "bin")})
found = runner.find_clang()
self.assertEqual(found, clang)
self.assertEqual(runner._find_lld(found), lld)

def test_a_clang_with_its_linker_beside_it_is_used_where_it_was_found(self):
clang = self.tool("bin", "clang")
self.tool("bin", "ld.lld")
self.tool("other", "clang")
self.tools({"clang": clang}, {clang: str(self.root / "other")})
self.assertEqual(runner.find_clang(), clang)

def test_a_launcher_that_names_a_folder_without_a_clang_is_kept(self):
launcher = self.tool("Scripts", "amdclang")
self.tools({"amdclang": launcher}, {launcher: str(self.root / "nothing-here")})
found = runner.find_clang()
self.assertEqual(found, launcher)
with self.assertRaises(runner.Unavailable):
runner._find_lld(found)


def relocatable(sections, symbols):
"""A little-endian ELF64 relocatable object: sections is [(name, bytes, address)], symbols [(name, section
number from 1, value)]. Only what drm.text_section reads is filled in."""
Expand Down
23 changes: 21 additions & 2 deletions tools/hw_oracle/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

Tools are located through environment variables first, then by looking in the usual places:
LEONIDA_AMD_CLANG AMD clang (its folder must also hold ld.lld); default: amdclang / clang on PATH that lists
the amdgcn target, %HIP_PATH% / %ROCM_PATH%, a .venv holding the `rocm-sdk-core` wheel
the amdgcn target (a launcher without ld.lld beside it is followed to the clang it is
installed as), %HIP_PATH% / %ROCM_PATH%, a .venv holding the `rocm-sdk-core` wheel
LEONIDA_HIP_DLL the HIP runtime (amdhip64_7.dll); default: the one in System32 (it ships with the driver)
LEONIDA_HOST_CC a C compiler for hw_oracle.c (MinGW gcc, or cl.exe from a Developer shell); default: gcc on
PATH, C:\\msys64\\ucrt64\\bin, then on Windows a cl on PATH or Visual Studio's (vswhere)
Expand Down Expand Up @@ -47,6 +48,24 @@ def _has_amdgcn(clang):
return "amdgcn" in out


def _installed_clang(clang):
"""The clang a launcher stands for. The rocm-sdk wheels put `amdclang` in the Python environment's Scripts (bin)
folder: it has the amdgcn target, but ld.lld and amdgpu-arch sit beside the real clang, in the folder `--version`
names as InstalledDir. A clang with its ld.lld beside it, or one that names no such folder, is returned as it is."""
if os.path.isfile(os.path.join(os.path.dirname(clang), _exe("ld.lld"))):
return clang
try:
out = subprocess.run([clang, "--version"], capture_output=True, text=True, timeout=60).stdout
except (OSError, subprocess.SubprocessError):
return clang
for line in out.splitlines():
if line.startswith("InstalledDir:"):
real = os.path.join(line.split(":", 1)[1].strip(), _exe("clang"))
if os.path.isfile(real):
return real
return clang


def find_clang():
env = os.environ.get("LEONIDA_AMD_CLANG")
if env:
Expand All @@ -62,7 +81,7 @@ def find_clang():
cands.append(os.path.join(REPO, ".venv", tail)) # only the repo root's venv, never a glob under the cwd
for c in cands:
if c and os.path.isfile(c) and _has_amdgcn(c):
return c
return _installed_clang(c)
raise Unavailable("no AMD clang (set LEONIDA_AMD_CLANG; `pip install rocm-sdk-core` from "
"https://stable.repo.amd.com/rocm/whl-next/ provides one)")

Expand Down