diff --git a/clean/runner/build.py b/clean/runner/build.py index 9590238e..2fc0a101 100644 --- a/clean/runner/build.py +++ b/clean/runner/build.py @@ -415,6 +415,11 @@ def main(argv=None): sub += (["--rocm", args.rocm] if args.rocm else []) + (["--clang", args.clang] if args.clang else []) sub += (["--no-device-libs"] if args.no_device_libs else []) + (["--soft-fp8"] if args.soft_fp8 else []) sub += ["--no-resource-gate"] if args.no_resource_gate else [] + # as the ordinary branch's child: the defines of an experiment build (without them the child builds the + # kernels the experiment changes unchanged, and runs the resource gate that the parent skips for defines) + sub += ["--report"] if args.report else [] + for d in args.define: + sub += ["--define", d] print(f"-- motion-at-output-resolution code objects for {arch}", flush=True) if subprocess.run(sub, env={**os.environ, "WG_GPU_ARCH": arch}).returncode != 0: raise SystemExit(f"build for {arch} failed") diff --git a/clean/tests/test_build_motion_define.py b/clean/tests/test_build_motion_define.py new file mode 100644 index 00000000..af6fd35f --- /dev/null +++ b/clean/tests/test_build_motion_define.py @@ -0,0 +1,64 @@ +# SPDX-License-Identifier: MIT +"""Issue #55: `build.py --motion-outres-only --extra-archs ...` starts one child build per extra architecture; the +child's command line must carry the parent's --define (and --report) like the ordinary branch's child does. No compiler +and no GPU: the subprocess call and the parent's own kernel builds are stubs, nothing is executed and nothing is written.""" +import contextlib +import io +import subprocess +import tempfile +import unittest +from unittest.mock import patch + +from clean.runner import build + + +def child_commands(argv): + """The child commands `build.main` starts for the extra architectures, for the given extra arguments.""" + started = [] + + def fake_run(cmd, *args, **kwargs): + started.append((list(cmd), dict(kwargs.get("env") or {}))) + return subprocess.CompletedProcess(cmd, 0) + + with tempfile.TemporaryDirectory() as out, patch.object(build, "EXTRA_ARCHS", []), \ + patch.object(build, "build_motion_outres") as parent, patch.object(build.subprocess, "run", fake_run), \ + contextlib.redirect_stdout(io.StringIO()): + # (--rocm is given: the default would be the ROCM_PATH of the environment this runs in) + build.main(["--out", out, "--motion-outres-only", "--rocm", "dummy-rocm", "--no-device-libs", "--clang", "dummy-clang", + "--extra-archs", "gfx1200,gfx1201"] + argv) + parent.assert_called_once() + return started + + +def values_of(cmd, flag): + return [cmd[i + 1] for i, a in enumerate(cmd[:-1]) if a == flag] + + +class MotionOutresChild(unittest.TestCase): + def test_every_define_reaches_the_child(self): + started = child_commands(["--define", "WG_GELU_MODE=1", "--define", "OTHER=2"]) + self.assertEqual(len(started), 1) # one extra architecture besides the primary one + cmd, env = started[0] + self.assertIn("--motion-outres-only", cmd) + self.assertEqual(values_of(cmd, "--define"), ["WG_GELU_MODE=1", "OTHER=2"]) + self.assertIn(env.get("WG_GPU_ARCH"), ("gfx1200", "gfx1201")) + + def test_report_reaches_the_child(self): + cmd = child_commands(["--report"])[0][0] + self.assertIn("--report", cmd) + self.assertEqual(values_of(cmd, "--define"), []) + + def test_without_them_the_child_has_neither(self): + cmd = child_commands([])[0][0] + self.assertNotIn("--report", cmd) + self.assertNotIn("--define", cmd) + + def test_the_options_that_were_forwarded_before_still_are(self): + cmd = child_commands(["--soft-fp8", "--no-resource-gate", "--define", "X=1"])[0][0] + for flag in ("--no-device-libs", "--soft-fp8", "--no-resource-gate"): + self.assertIn(flag, cmd) + self.assertEqual(values_of(cmd, "--clang"), ["dummy-clang"]) + + +if __name__ == "__main__": + unittest.main()