okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-021-iE' into f-021-int3616148bb

main
3.4 KiB74 linesraw
1"""#3219: sycl/tools/build.sh stops before the long compile when this image's ocloc is the one that crashes on the Battlemage int8 kernels,
2and I8_ESIMD=OFF reaches cmake. A fake ocloc and a fake cmake stand in for the oneAPI image; skipped without bash."""
3import os
4import shutil
5import stat
6import subprocess
7import tempfile
8import unittest
9from pathlib import Path
10
11ROOT = Path(__file__).resolve().parents[1]
12BUILD_SH = ROOT / "sycl" / "tools" / "build.sh"
13BASH = shutil.which("bash")
14
15
16@unittest.skipUnless(BASH, "needs bash")
17class BuildGuard(unittest.TestCase):
18    def setUp(self):
19        self.tmp = tempfile.TemporaryDirectory()
20        self.bin = Path(self.tmp.name) / "bin"
21        self.bin.mkdir()
22        self.log = Path(self.tmp.name) / "cmake.log"
23        (self.bin / "cmake").write_text('#!/bin/sh\necho "cmake $*" >> "%s"\nexit 0\n' % self.log.as_posix(), encoding="utf-8", newline="\n")
24        self.build = Path(self.tmp.name) / "b"
25
26    def tearDown(self):
27        self.tmp.cleanup()
28
29    def ocloc(self, version):
30        path = self.bin / "ocloc"
31        path.write_text('#!/bin/sh\necho "Intel(R) Compute Runtime ocloc %s"\n' % version, encoding="utf-8", newline="\n")
32        path.chmod(path.stat().st_mode | stat.S_IEXEC)
33        (self.bin / "cmake").chmod(0o755)
34
35    def run_build(self, **env):
36        (self.bin / "cmake").chmod(0o755)
37        merged = dict(os.environ, PATH=self.bin.as_posix() + os.pathsep + os.environ["PATH"], REPO=ROOT.as_posix(),
38                      BUILD_DIR=self.build.as_posix())
39        for key in ("AOT", "I8_ESIMD", "ALLOW_BAD_OCLOC"):
40            merged.pop(key, None)
41        merged.update(env)
42        return subprocess.run([BASH, BUILD_SH.as_posix(), "strata"], env=merged, capture_output=True, text=True, timeout=120)
43
44    def test_known_bad_ocloc_stops_a_battlemage_aot_build(self):
45        self.ocloc("26.22.38646.4")
46        r = self.run_build(AOT="bmg-g31")
47        self.assertEqual(r.returncode, 2, r.stderr)
48        for word in ("26.22.38646.4", "docker build --pull", "I8_ESIMD=OFF", "ALLOW_BAD_OCLOC=1"):
49            self.assertIn(word, r.stderr)
50        self.assertFalse(self.log.exists(), "cmake never started")
51
52    def test_other_versions_other_devices_and_the_switches_go_on(self):
53        self.ocloc("26.31.39395.14")
54        r = self.run_build(AOT="bmg-g31")
55        self.assertEqual(r.returncode, 0, r.stderr)
56        self.assertIn("-DSTRATA_SYCL_I8_ESIMD=AUTO", self.log.read_text())
57        self.log.unlink()
58        self.ocloc("26.22.38646.4")
59        self.assertEqual(self.run_build(AOT="acm-g10").returncode, 0)              # not a Battlemage build
60        self.assertEqual(self.run_build().returncode, 0)                           # the JIT build
61        self.assertEqual(self.run_build(AOT="bmg-g31", ALLOW_BAD_OCLOC="1").returncode, 0)
62        self.log.unlink()
63        r = self.run_build(AOT="bmg-g31", I8_ESIMD="OFF")                          # the workaround: stubs, no check needed
64        self.assertEqual(r.returncode, 0, r.stderr)
65        self.assertIn("-DSTRATA_SYCL_I8_ESIMD=OFF", self.log.read_text())
66
67    def test_the_cmake_switch_is_declared(self):
68        text = (ROOT / "sycl" / "CMakeLists.txt").read_text(encoding="utf-8")
69        self.assertIn('set(STRATA_SYCL_I8_ESIMD "AUTO" CACHE STRING', text)
70        self.assertIn("add_compile_definitions(STRATA_I8_NO_ESIMD=1)", text)
71
72
73if __name__ == "__main__":
74    unittest.main()