okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1#!/bin/sh 2# Build the Linux Intel Arc (SYCL) engine package for the release feed. 3# 4# packaging/build_sycl_linux.sh # the release package: GPU code JIT-compiled from SPIR-V (A-series and B-series) 5# AOT=bmg-g21,bmg-g31 packaging/build_sycl_linux.sh # a Battlemage-only build of your own, GPU code built ahead of time (not a release package) 6# SHAPE=q4_lite packaging/build_sycl_linux.sh # the engine of a model shape, its own component (packaging/shape_build.sh) 7# 8# Run it on a Linux x86_64 box with Intel oneAPI DPC++ (icx / icpx 2026.1 or newer, oneMKL) installed under $ONEAPI (default 9# /opt/intel/oneapi), `patchelf` (apt install patchelf, or pip install patchelf in a venv and put it on PATH) and, for an AOT build, 10# `ocloc` (apt: intel-ocloc). The Alchemist cards (A-series, DG2) have no FP64 units and ocloc cannot build the engine's double 11# kernels for them, so the JIT package is the one an A-series card runs; a Battlemage card runs it too (the first start compiles the 12# kernels, the persistent JIT cache stays off on Xe2, docs/INTEL_ARC.md). 13# The level-zero loader and the compute runtime stay the PC's own (the Intel graphics PPA / `apt install libze1 intel-opencl-icd`); 14# the oneAPI runtime the engine loads (libsycl, the Unified Runtime adapters, the MKL SYCL libraries) is bundled by collect_libs.py. 15# Every ELF file of the package gets RUNPATH $ORIGIN, so the package finds its own libraries with no environment 16# (`env -i ./strata --version` runs); Intel's libraries ship without it (libur_loader has $ORIGIN/../lib, libmkl_core none). 17# The package lands in $OUT (default ./out-engine-sycl). Nothing is uploaded or signed. 18set -eu 19repo =$( CDPATH = cd -- " $( dirname -- " $ 0" ) /.." && pwd -P ) 20aot =${ AOT :-} 21case " $ aot " in 22"" | bmg-*| bmg-*,bmg-*) ;; 23 *)echo "build_sycl_linux.sh: AOT is empty (the release package) or a Battlemage device list such as bmg-g21,bmg-g31" >&2;exit 2 ;; 24esac 25oneapi =${ ONEAPI :-/opt/intel/oneapi} 26out =${ OUT :- $ repo /out-engine-sycl} 27build =${ BUILD :- $ repo /build-sycl} 28py =${ PYTHON :-python3} 29jobs =${ JOBS :-$( nproc )} 30command -v patchelf> /dev/null || {echo "build_sycl_linux.sh: patchelf is not on PATH" >&2;exit 2; } 31# setvars.sh is not written for `set -u` 32set +u 33# shellcheck disable=SC1091 34. " $ oneapi /setvars.sh" > /dev/null2 >&1 || {echo "build_sycl_linux.sh: $ oneapi /setvars.sh not found or failed" >&2;exit 2; } 35set -u 36command -v icpx> /dev/null || {echo "build_sycl_linux.sh: icpx is not on PATH after setvars.sh" >&2;exit 2; } 37[ -z" $ aot " ] ||command -v ocloc> /dev/null || {echo "build_sycl_linux.sh: AOT needs ocloc (apt install intel-ocloc)" >&2;exit 2; } 38iccver =$( icpx --version | sed -n 's/.*Compiler \([0-9][0-9.]*\).*/\1/p' | head -1 ) 39 40cd " $ repo " 41. " $ repo /packaging/shape_build.sh" ;shape_setup " $ repo " 42ggml ="" 43# ggml is the vendored third_party/strata-ggml. STRATA_GGML_DIR=<llama.cpp checkout> (or LLAMA_CPP=, the name this script used before) builds from that 44# checkout instead: an override kept for two releases. (LLAMA_CPP used to set a FetchContent variable that the CMake files stopped reading when ggml was 45# vendored, so it did nothing, and a llama.cpp tree downloaded into third_party/ was picked up by itself; neither happens now.) 46override =${ STRATA_GGML_DIR :-${ LLAMA_CPP :-}} 47[ -z" $ override " ] ||ggml ="-DSTRATA_GGML_DIR= $ override " 48# shellcheck disable=SC2086 49cmake -S sycl-B " $ build " -G Ninja-DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx \ 50-DSTRATA_SYCL_PARITY=OFF -DSTRATA_SYCL_IQ_DECODE_FAST= ${ IQ_DECODE_FAST :-ON} ${ aot :+ "-DSTRATA_SYCL_AOT= $ aot " } $ ggml ${ STRATA_CMAKE_EXTRA :-} $ shape_cmake # STRATA_CMAKE_EXTRA: e.g. -DSTRATA_GEOMETRY_FILE=/abs/path/geometry.hpp 51cmake --build " $ build " --target strata-j " $ jobs " 52 53ver =$( sed -n 's/^[[:space:]]*project([^)]*VERSION[[:space:]]*\([0-9][0-9.]*\).*/\1/p' CMakeLists.txt | head -1 ) 54commit =${ COMMIT :-$( git rev-parse --short=12 HEAD 2 > /dev/null || echo unknown)} # a git archive has no .git: pass COMMIT= 55stage =$( mktemp -d " ${ TMPDIR :-/tmp} /strata-sycl-stage.XXXXXX" ) 56trap 'rm -rf "$stage"' EXIT 57cp " $ build /strata" " $ stage /" 58code =${ aot :+AOT $ aot } ;code =${ code :-JIT from SPIR-V} 59echo "{\"version\": \" $ ver \", \"source\": \"packaging/build_sycl_linux.sh\", \"sycl\": \"oneAPI DPC++ $ iccver ( $ code )\", \"portable\": false}" > " $ stage /BUILD.json" 60# libsycl and the MKL SYCL libraries come through ldd; the Unified Runtime adapters (level zero, opencl) are dlopen'd, so they are named 61" $ py " packaging/collect_libs.py--binary " $ build /strata" --search " $ oneapi /compiler/latest/lib" --search " $ oneapi /mkl/latest/lib" \ 62--also 'libur_adapter_level_zero*.so*' --also 'libur_adapter_opencl*.so*' --out " $ stage " 63# RUNPATH $ORIGIN on the engine and on every bundled library (the same way packaging/build_hip_linux.sh does it) 64for f in " $ stage /strata" " $ stage " /*.so" $ stage " /*.so.*;do 65 [ -f" $ f " ]&& [ ! -L" $ f " ]&& patchelf --set-rpath '$ORIGIN' " $ f " 66done 67for f in " $ stage /strata" " $ stage " /*.so" $ stage " /*.so.*;do 68 [ -f" $ f " ]&& [ ! -L" $ f " ]&& {readelf -d " $ f " | grep -q 'RUNPATH.*\[\$ORIGIN\]' || {echo "build_sycl_linux.sh: $( basename " $ f " ) has no RUNPATH \$ORIGIN" >&2;exit 1; }; } 69done 70shape_check " $ stage /strata" 71if [ -n" $ aot " ];then arch_args =$( echo " $ aot " | tr ',' '\n' | sed 's/^/--arch /' | tr '\n' ' ' ) ;else arch_args ="--arch intel-arc" ;fi 72mkdir -p " $ out " 73# shellcheck disable=SC2086 74" $ py " packaging/package_engine.py--src " $ stage " --backend sycl--version " $ ver " --out " $ out " $ arch_args \ 75--platform linux-x86_64--build-id " ${ commit } -oneapi ${ iccver } " --include SYSTEM-LIBS.txt$ shape_pkg 76for d in " $ out " /*/;do 77" $ py " packaging/package_engine.py--verify " $ d " ;" $ py " packaging/binary_deps.py" $ d " 78env -i " $ d /strata" --version > /dev/null || {echo "build_sycl_linux.sh: env -i $ d /strata --version does not run" >&2;exit 1; } 79done 80echo "built: $ out "