From 946ecbf04941eca460985ea28fa83407b8e3a79d Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Wed, 2 Dec 2026 12:53:43 +0100 Subject: [PATCH] Hy4 hand-written build lines compile hy4_cpu_k512.cpp (PLAN-0224 item 12) The CMake target builds hy4_cpu_k512.cpp (the AVX-512 CPU expert kernels); the B70 Hy4 job in .github/workflows/intel-runner.yml and tools/hy4/build_hy4_hip_linux.sh list the host files by hand and missed it. The file carries its own target pragmas, so it needs no -m flag; the intel-runner line skips it for the old v0.2.19 base tree, which does not have it. A source-scan test pins that every host source of the CMake target is in every hand-written build (CI, HIP, SYCL). --- .github/workflows/intel-runner.yml | 6 ++- .../terminal/test_hy4_build_lines_0225.py | 49 +++++++++++++++++++ tools/hy4/build_hy4_hip_linux.sh | 2 +- 3 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 terminal/tests/terminal/test_hy4_build_lines_0225.py diff --git a/.github/workflows/intel-runner.yml b/.github/workflows/intel-runner.yml index 06f68ac3ad..ff24186fac 100644 --- a/.github/workflows/intel-runner.yml +++ b/.github/workflows/intel-runner.yml @@ -79,8 +79,12 @@ jobs: g++ -O3 -std=c++17 -fPIC $INC -c "$SRC/engine/src/ngram/hy4_engram_reader.cpp" -o "$OUT/obj/hy4_engram_reader.o" & g++ -O3 -std=c++17 -fPIC $INC -c "$SRC/engine/src/hy4flash/run/hy4_engram.cpp" -o "$OUT/obj/hy4_engram.o" & g++ -O3 -std=c++17 -fPIC -pthread $INC -c "$SRC/engine/src/hy4flash/run/hy4_cpu_experts.cpp" -o "$OUT/obj/hy4_cpu_experts.o" & + # hy4_cpu_k512.cpp (the AVX-512 expert kernels) carries its own target pragmas, so it needs no -m flag; the old v0.2.19 base tree does not have the file + local K512="$SRC/engine/src/hy4flash/run/hy4_cpu_k512.cpp" + if [ -f "$K512" ]; then g++ -O3 -std=c++17 -fPIC -pthread $INC -c "$K512" -o "$OUT/obj/hy4_cpu_k512.o" & fi wait local HOBJS="$OUT/obj/strata_reader.o $OUT/obj/sk_codecs.o $OUT/obj/hy4_engram_reader.o $OUT/obj/hy4_engram.o $OUT/obj/hy4_cpu_experts.o" + if [ -f "$K512" ]; then HOBJS="$HOBJS $OUT/obj/hy4_cpu_k512.o"; fi icpx -O3 -std=c++17 -fiopenmp $SYCL_FLAGS $MKL_FLAGS $INC \ "$SRC/engine/src/hy4flash/sycl/sy_main.cpp" \ "$SRC/engine/src/hy4flash/sycl/sy_mla.cpp" \ @@ -93,7 +97,7 @@ jobs: echo "== Build sy_opt_test (bmg_g31 GPU) ==" INC_OPT="-I$PWD/engine/include -I$PWD/engine/src/hy4flash/sycl -I$PWD/engine/src/hy4flash/run -I$PWD/engine/third_party/stb -I$PWD/engine/third_party/zstd-dec" - HOBJS_OPT="$BUILD/opt/obj/strata_reader.o $BUILD/opt/obj/sk_codecs.o $BUILD/opt/obj/hy4_engram_reader.o $BUILD/opt/obj/hy4_engram.o $BUILD/opt/obj/hy4_cpu_experts.o" + HOBJS_OPT="$BUILD/opt/obj/strata_reader.o $BUILD/opt/obj/sk_codecs.o $BUILD/opt/obj/hy4_engram_reader.o $BUILD/opt/obj/hy4_engram.o $BUILD/opt/obj/hy4_cpu_experts.o $BUILD/opt/obj/hy4_cpu_k512.o" icpx -O3 -std=c++17 -fiopenmp $SYCL_FLAGS $MKL_FLAGS $INC_OPT \ "$PWD/engine/src/hy4flash/sycl/sy_opt_test.cpp" \ "$PWD/engine/src/hy4flash/sycl/sy_mla.cpp" \ diff --git a/terminal/tests/terminal/test_hy4_build_lines_0225.py b/terminal/tests/terminal/test_hy4_build_lines_0225.py new file mode 100644 index 0000000000..409d583494 --- /dev/null +++ b/terminal/tests/terminal/test_hy4_build_lines_0225.py @@ -0,0 +1,49 @@ +"""0.2.25 (PLAN-0224 item 12): the hand-written Hy4 build lines name every host source file the CMake target builds. + +`hy4_cpu_k512.cpp` (the AVX-512 CPU expert kernels) was added to the CMake target but not to the lines of `.github/workflows/intel-runner.yml` (the B70 Hy4 job) and +`tools/hy4/build_hy4_hip_linux.sh`, which list the host objects by hand. This pins that no host source of the target can be missing from them again. +""" +from __future__ import annotations + +import re +import unittest +from pathlib import Path + +REPO = Path(__file__).resolve().parents[3] +CMAKE = REPO / "engine" / "src" / "hy4flash" / "run" / "CMakeLists.txt" +HAND_BUILDS = [REPO / ".github" / "workflows" / "intel-runner.yml", REPO / "tools" / "hy4" / "build_hy4_hip_linux.sh", REPO / "engine" / "src" / "hy4flash" / "sycl" / "build_hy4_sycl.sh"] +# the two that carry the engine-side files (reader, codecs) are compiled by their own lines; what matters is the hy4flash/run host sources +HOST_SOURCES_OF_THE_TARGET = re.compile(r"add_executable\(strata-hy4 ([^)]*)\)", re.S) + + +def target_host_sources() -> list[str]: + text = CMAKE.read_text(encoding="utf-8") + body = HOST_SOURCES_OF_THE_TARGET.search(text).group(1) + names = [tok for tok in re.findall(r"[\w./-]+\.cpp", body) if "/" not in tok and not tok.endswith(".hip.cpp")] + return names + + +class Hy4HandBuildLines(unittest.TestCase): + def test_the_target_has_the_host_sources_the_test_expects(self): + names = target_host_sources() + self.assertIn("hy4_cpu_experts.cpp", names) + self.assertIn("hy4_cpu_k512.cpp", names) + + def test_every_host_source_of_the_target_is_compiled_by_each_hand_written_build(self): + names = target_host_sources() + for path in HAND_BUILDS: + text = path.read_text(encoding="utf-8") + for name in names: + self.assertIn(name, text, f"{path.relative_to(REPO)} does not compile {name}, which the CMake target builds") + + def test_the_k512_object_is_linked_not_only_compiled(self): + for path in HAND_BUILDS: + text = path.read_text(encoding="utf-8") + if path.suffix == ".sh" and path.name == "build_hy4_hip_linux.sh": + self.assertIn("hy4_cpu_k512.cpp", text) # its loop compiles every listed file into objs[] that the link line takes + else: + self.assertGreaterEqual(text.count("hy4_cpu_k512.o"), 2, f"{path.name}: the object is made but never listed for the link") + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/hy4/build_hy4_hip_linux.sh b/tools/hy4/build_hy4_hip_linux.sh index ef2a0f6e0f..7ea6fcb18c 100644 --- a/tools/hy4/build_hy4_hip_linux.sh +++ b/tools/hy4/build_hy4_hip_linux.sh @@ -23,7 +23,7 @@ for c in "$Z"/common/*.c "$Z"/decompress/*.c; do [ "$o" -nt "$c" ] || "$CC" -O3 -DZSTD_DISABLE_ASM=1 -DXXH_NAMESPACE=ZSTD_ $INC -c "$c" -o "$o" & objs+=("$o") done -for c in "$E/src/artifact/strata_reader.cpp" "$E/src/quant/sk_codecs.cpp" "$RUN/hy4_engram.cpp" "$RUN/hy4_cpu_experts.cpp"; do +for c in "$E/src/artifact/strata_reader.cpp" "$E/src/quant/sk_codecs.cpp" "$RUN/hy4_engram.cpp" "$RUN/hy4_cpu_experts.cpp" "$RUN/hy4_cpu_k512.cpp"; do # hy4_cpu_k512.cpp (AVX-512 expert kernels): its own target pragmas, no -m flag o="$OUT/obj/$(basename "$c" .cpp).o" [ "$o" -nt "$c" ] || "$CXX" -std=c++17 -O3 -pthread $INC -c "$c" -o "$o" & objs+=("$o")