okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3616148bb
main
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 ): 18def setUp (self ): 19self .tmp = tempfile .TemporaryDirectory () 20self .bin = Path (self .tmp .name )/ "bin" 21self .bin .mkdir () 22self .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" ) 24self .build = Path (self .tmp .name )/ "b" 25 26def tearDown (self ): 27self .tmp .cleanup () 28 29def ocloc (self ,version ): 30path = self .bin / "ocloc" 31path .write_text ('#!/bin/sh\necho "Intel(R) Compute Runtime ocloc %s"\n' % version ,encoding = "utf-8" ,newline = "\n" ) 32path .chmod (path .stat ().st_mode | stat .S_IEXEC ) 33 (self .bin / "cmake" ).chmod (0o755 ) 34 35def run_build (self ,** env ): 36 (self .bin / "cmake" ).chmod (0o755 ) 37merged = dict (os .environ ,PATH = self .bin .as_posix ()+ os .pathsep + os .environ ["PATH" ],REPO = ROOT .as_posix (), 38BUILD_DIR = self .build .as_posix ()) 39for key in ("AOT" ,"I8_ESIMD" ,"ALLOW_BAD_OCLOC" ): 40merged .pop (key ,None ) 41merged .update (env ) 42return subprocess .run ([BASH ,BUILD_SH .as_posix (),"strata" ],env = merged ,capture_output = True ,text = True ,timeout = 120 ) 43 44def test_known_bad_ocloc_stops_a_battlemage_aot_build (self ): 45self .ocloc ("26.22.38646.4" ) 46r = self .run_build (AOT = "bmg-g31" ) 47self .assertEqual (r .returncode ,2 ,r .stderr ) 48for word in ("26.22.38646.4" ,"docker build --pull" ,"I8_ESIMD=OFF" ,"ALLOW_BAD_OCLOC=1" ): 49self .assertIn (word ,r .stderr ) 50self .assertFalse (self .log .exists (),"cmake never started" ) 51 52def test_other_versions_other_devices_and_the_switches_go_on (self ): 53self .ocloc ("26.31.39395.14" ) 54r = self .run_build (AOT = "bmg-g31" ) 55self .assertEqual (r .returncode ,0 ,r .stderr ) 56self .assertIn ("-DSTRATA_SYCL_I8_ESIMD=AUTO" ,self .log .read_text ()) 57self .log .unlink () 58self .ocloc ("26.22.38646.4" ) 59self .assertEqual (self .run_build (AOT = "acm-g10" ).returncode ,0 )# not a Battlemage build 60self .assertEqual (self .run_build ().returncode ,0 )# the JIT build 61self .assertEqual (self .run_build (AOT = "bmg-g31" ,ALLOW_BAD_OCLOC = "1" ).returncode ,0 ) 62self .log .unlink () 63r = self .run_build (AOT = "bmg-g31" ,I8_ESIMD = "OFF" )# the workaround: stubs, no check needed 64self .assertEqual (r .returncode ,0 ,r .stderr ) 65self .assertIn ("-DSTRATA_SYCL_I8_ESIMD=OFF" ,self .log .read_text ()) 66 67def test_the_cmake_switch_is_declared (self ): 68text = (ROOT / "sycl" / "CMakeLists.txt" ).read_text (encoding = "utf-8" ) 69self .assertIn ('set(STRATA_SYCL_I8_ESIMD "AUTO" CACHE STRING' ,text ) 70self .assertIn ("add_compile_definitions(STRATA_I8_NO_ESIMD=1)" ,text ) 71 72 73if __name__ == "__main__" : 74unittest .main ()