diff --git a/BUILDING.md b/BUILDING.md index 117f1d40..2808d42e 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -176,8 +176,18 @@ repository (the synthetic converter library stand-ins `WGC_SYNTH_BINS`, a model ### Comparing kernels with a release The kernels are deterministic for a given DXC / HIP SDK version: `out\rr-rt\kernels.json` (name, arguments, SHA-256 of -each DXIL), `out\runtime\dx12\manifest.json` (SHA-256 of each DXIL) and the code objects `out\runtime\*.co` can be -compared file by file with another build of the same source. +each DXIL) and `out\runtime\dx12\manifest.json` (SHA-256 of each DXIL) can be compared with another build of the same +source: for `kernels.json`, compare each kernel's `nargs` and `sha256`. + +The code objects `out\runtime\*.co` and `out\runtime\gfx1200\*.co` of builds made with `-cuid` (the compilation-unit +id that `clean\runner\build.py` now fixes) can be compared file by file. In a check of two build folders, all 54 +compiled code objects (gfx1201 and gfx1200) were byte-identical. + +Release 0.6.0 was built without `-cuid`, so none of its code objects is byte-identical to a new build: the +`__hip_cuid_...` symbol differs. Compare the `.text` and `.note` sections instead (extract them with an ELF tool, for +example `llvm-objcopy --dump-section`); they were identical in all 54, as was the section list. The `.rodata` section +was identical in 52. In `post_w64__orig.co` (both targets) it moves by 64 bytes, and its 93 kernel descriptors differ +only in their code-entry offset, by that amount; so do not use `.rodata` as the comparison for 0.6.0. ## 7. GPU steps (optional; not needed to build) diff --git a/clean/runner/build.py b/clean/runner/build.py index 5a498154..9590238e 100644 --- a/clean/runner/build.py +++ b/clean/runner/build.py @@ -11,13 +11,14 @@ 8; the FidelityFX front end loads it through wgGetUpscalerBackend), built with the HIP SDK's clang against the static Microsoft C runtime (/MT). The converter map is copied next to it (the runtime reads it to check model.wgcm). -Each kernel source is compiled with the command given in spec 90: - clang -x hip --offload-arch=gfx1201 --cuda-device-only -nogpuinc -O3 --no-gpu-bundle-output +Each kernel source is compiled with the command given in spec 90, plus a fixed compilation-unit id (device_command): + clang -x hip --offload-arch=gfx1201 --cuda-device-only -nogpuinc -O3 --no-gpu-bundle-output -cuid=wg_ --rocm-path= --rocm-device-lib-path=/amdgcn/bitcode -o .co """ import argparse import json import os +import re import shutil import subprocess import sys @@ -96,8 +97,11 @@ def find_clang(rocm): def device_command(clang, rocm, src, out, device_libs=True, report=False, extra=(), soft_fp8=False, defines=None): + # a fixed compilation-unit id from the output file's name, so the __hip_cuid_... symbol of a code object is the same + # in every build folder (without -cuid, clang derives the id itself) + cuid = "wg_" + re.sub(r"[^A-Za-z0-9_]", "_", os.path.splitext(os.path.basename(out))[0]) cmd = [clang, "-x", "hip", f"--offload-arch={ARCH}", "--cuda-device-only", "-nogpuinc", "-O3", - "--no-gpu-bundle-output"] + "--no-gpu-bundle-output", f"-cuid={cuid}"] if device_libs: cmd += [f"--rocm-path={rocm}", f"--rocm-device-lib-path={os.path.join(rocm, 'amdgcn', 'bitcode')}"] else: diff --git a/clean/tests/test_build_cuid.py b/clean/tests/test_build_cuid.py new file mode 100644 index 00000000..5814ccf8 --- /dev/null +++ b/clean/tests/test_build_cuid.py @@ -0,0 +1,49 @@ +# SPDX-License-Identifier: MIT +"""The HIP device compile command carries a fixed compilation-unit id; nothing is executed, the paths are dummies.""" +import os +import unittest +from clean.runner import build + +CLANG = "dummy-clang" +ROCM = os.path.join("dummy-rocm", "7.2") +SRC = "src.hip" + + +def cuid_flags(cmd): + return [a for a in cmd if a.startswith("-cuid")] + + +class DeviceCommandCuid(unittest.TestCase): + def test_cuid_flag_is_in_the_command(self): + cmd = build.device_command(CLANG, ROCM, SRC, os.path.join("out", "post_w64.co")) + self.assertEqual(cuid_flags(cmd), ["-cuid=wg_post_w64"]) + + def test_cuid_does_not_depend_on_the_output_folder(self): + a = build.device_command(CLANG, ROCM, SRC, os.path.join("one", "folder", "post_w64.co")) + b = build.device_command(CLANG, ROCM, SRC, os.path.join("another", "place", "wg", "post_w64.co")) + self.assertEqual(cuid_flags(a), cuid_flags(b)) + self.assertEqual(len(cuid_flags(a)), 1) + + def test_cuid_has_no_path_in_it(self): + flag = cuid_flags(build.device_command(CLANG, ROCM, SRC, os.path.join("a b", "c-d", "post.w64__orig.co")))[0] + value = flag.split("=", 1)[1] + self.assertTrue(value.startswith("wg_")) + self.assertEqual(value, "wg_post_w64__orig") + self.assertNotIn(os.sep, value) + self.assertNotIn("/", value) + self.assertNotIn(" ", value) + + def test_cuid_follows_the_output_name(self): + a = cuid_flags(build.device_command(CLANG, ROCM, SRC, "swin.co")) + b = cuid_flags(build.device_command(CLANG, ROCM, SRC, "post.co")) + self.assertEqual(a, ["-cuid=wg_swin"]) + self.assertNotEqual(a, b) + + def test_cuid_is_also_in_the_compile_check_command(self): + cmd = build.device_command(CLANG, ROCM, SRC, "swin.co", device_libs=False) + self.assertEqual(cuid_flags(cmd), ["-cuid=wg_swin"]) + self.assertIn("-nogpulib", cmd) + + +if __name__ == "__main__": + unittest.main()