From 424b364a88a61c5cac672152e5cdd802ca98be31 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 22 Oct 2026 12:12:30 +0200 Subject: [PATCH 1/2] SYCL engine: strata --version answers before any GPU is touched; no SYCL device is built before main The migrated generate.cpp had no --version (the CUDA and HIP engines answer it first thing), and three things in dpct's helper headers built a SYCL device at program start: blas::descriptor's inline _saved_queue_ptr, the dpct::device_memory constructor (pointer table, mem_mgr, dev_mgr) and its default-built sycl::queue member. On a PC whose user cannot open the GPU the engine therefore aborted with 'No device of requested type available' before it could print anything, which also failed the engine smoke test of strata update. The headers are edited and sycl/tools/fixups.py reproduces each edit after a re-migration. A frozen first-token-logits run on an Arc A750 (4095-token prompt, IQ3_XXS) is byte-identical before and after. --- sycl/include/dpct/blas_utils.hpp | 4 +- sycl/include/dpct/detail/memory_detail.hpp | 14 ++++--- sycl/src/program/generate.cpp | 9 ++++ sycl/tools/fixups.py | 48 ++++++++++++++++++++++ 4 files changed, 67 insertions(+), 8 deletions(-) diff --git a/sycl/include/dpct/blas_utils.hpp b/sycl/include/dpct/blas_utils.hpp index 4a58aad3..60afdfb2 100644 --- a/sycl/include/dpct/blas_utils.hpp +++ b/sycl/include/dpct/blas_utils.hpp @@ -303,14 +303,14 @@ public: _saved_queue_ptr = q_ptr; } static inline sycl::queue &get_saved_queue() noexcept { + if (!_saved_queue_ptr) _saved_queue_ptr = &::dpct::cs::get_default_queue(); return *_saved_queue_ptr; } private: ::dpct::cs::queue_ptr _queue_ptr = &::dpct::cs::get_default_queue(); math_mode _mm = math_mode::mm_default; - static inline ::dpct::cs::queue_ptr _saved_queue_ptr = - &::dpct::cs::get_default_queue(); + static inline ::dpct::cs::queue_ptr _saved_queue_ptr = nullptr; }; using descriptor_ptr = descriptor *; diff --git a/sycl/include/dpct/detail/memory_detail.hpp b/sycl/include/dpct/detail/memory_detail.hpp index e0bad438..1c4c5d9e 100644 --- a/sycl/include/dpct/detail/memory_detail.hpp +++ b/sycl/include/dpct/detail/memory_detail.hpp @@ -822,14 +822,11 @@ public: /// Constructor with range device_memory(const sycl::range &range_in) : _size(range_in.size() * sizeof(T)), _range(range_in), _reference(false), - _host_ptr(nullptr), _device_ptrs(get_ptrs_size(), nullptr) { + _host_ptr(nullptr) { static_assert((Memory == global) || (Memory == constant) || (Memory == shared), "device memory region should be global, constant or shared"); - // Make sure that singleton class mem_mgr and dev_mgr will destruct later - // than this. - detail::mem_mgr::instance(); - dev_mgr::instance(); + // Strata: the pointer table, mem_mgr and dev_mgr are made at the first get_ptr_impl() (sycl/tools/fixups.py) } /// Constructor with range @@ -927,6 +924,11 @@ private: } value_t *get_ptr_impl(sycl::queue &q) { + if (_device_ptrs.empty()) { + detail::mem_mgr::instance(); + dev_mgr::instance(); + _device_ptrs.assign(get_ptrs_size(), nullptr); + } #ifdef DPCT_USM_LEVEL_NONE auto &ptr = _device_ptrs.front(); #else @@ -953,7 +955,7 @@ private: bool _reference; value_t *_host_ptr; std::vector _device_ptrs; - sycl::queue _q; + std::optional _q; // Strata: a default-built sycl::queue picks a device (sycl/tools/fixups.py) }; template class device_memory : public device_memory { diff --git a/sycl/src/program/generate.cpp b/sycl/src/program/generate.cpp index 5a4d9f0a..2a4db4d1 100644 --- a/sycl/src/program/generate.cpp +++ b/sycl/src/program/generate.cpp @@ -1723,6 +1723,15 @@ int main(int argc, char **argv) try { // pipe or a file is block-buffered, so a program that dies loses every line it had already printed - which // turns "it crashed at step 7" into "it crashed somewhere", and the difference is a debugging session. std::setvbuf(stdout, nullptr, _IONBF, 0); + // `strata --version` / `-V` (also `strata generate --version`): the version and nothing else, before any GPU is touched, as the CUDA + // and HIP engines have answered it. `strata update` runs it as the engine's smoke test, and the Intel package build runs it with + // an empty environment. + for (int i = 1; i < argc && i < 3; ++i) { + if (std::strcmp(argv[i], "--version") == 0 || std::strcmp(argv[i], "-V") == 0) { + std::printf("strata %s\n", STRATA_VERSION); + return 0; + } + } #if (defined(STRATA_USE_HIP) || defined(STRATA_HIP_GFX906)) && !defined(_WIN32) // AMD, a file-backed arena (STRATA_ARENA_MMAP): ROCclr copies a pageable source of 1 MiB or more by locking its // pages in place (a GPU userptr), and keeps them - so every expert the VRAM fill copied from the mapped diff --git a/sycl/tools/fixups.py b/sycl/tools/fixups.py index 053d2810..b26e2bc9 100644 --- a/sycl/tools/fixups.py +++ b/sycl/tools/fixups.py @@ -340,3 +340,51 @@ edit("src/kernels/cuda/native_router.dp.cpp", lambda s: s.replace( edit("include/strata/core/mtp.hpp", lambda s: s.replace( " dpct::queue_ptr cs_ = &dpct::get_in_order_queue();\n", " dpct::queue_ptr cs_ = nullptr; // load() creates it; not the device's queue, which ~MtpDrafter would destroy\n")) + +# `strata --version` must print before any GPU is touched (the engine smoke test of `strata update` runs it, and a user outside the +# `render` group has no usable device). Two things in dpct's helper headers looked up the SYCL devices before main: +# 1. blas::descriptor's `static inline queue_ptr _saved_queue_ptr = &get_default_queue();` (an inline variable): the default is +# looked up in get_saved_queue() instead. +def lazy_saved_queue(s): + s = s.replace(" static inline ::dpct::cs::queue_ptr _saved_queue_ptr =\n &::dpct::cs::get_default_queue();", + " static inline ::dpct::cs::queue_ptr _saved_queue_ptr = nullptr;") + return s.replace(" static inline sycl::queue &get_saved_queue() noexcept {\n return *_saved_queue_ptr;", + " static inline sycl::queue &get_saved_queue() noexcept {\n" + " if (!_saved_queue_ptr) _saved_queue_ptr = &::dpct::cs::get_default_queue();\n" + " return *_saved_queue_ptr;") +edit("include/dpct/blas_utils.hpp", lazy_saved_queue) + +# 2. dpct::device_memory (global_memory / constant_memory) sized its per-device pointer table, and so built mem_mgr and dev_mgr, in its +# constructor. The engine's namespace-scope tables (iq4nl_values, c_codes) are heap objects built before main. Both now happen at the +# first get_ptr_impl(); the destruction order the original comment protected does not arise for objects that are never freed. +def lazy_device_memory(s): + s = s.replace(" _host_ptr(nullptr), _device_ptrs(get_ptrs_size(), nullptr) {\n", " _host_ptr(nullptr) {\n") + s = s.replace(" // Make sure that singleton class mem_mgr and dev_mgr will destruct later\n // than this.\n" + " detail::mem_mgr::instance();\n dev_mgr::instance();\n }\n", + " // Strata: the pointer table, mem_mgr and dev_mgr are made at the first get_ptr_impl() (sycl/tools/fixups.py)\n }\n") + s = s.replace(" std::vector _device_ptrs;\n sycl::queue _q;\n};", # a default-built sycl::queue picks a device + " std::vector _device_ptrs;\n std::optional _q; // Strata: a default-built sycl::queue picks a device (sycl/tools/fixups.py)\n};") + return s.replace(" value_t *get_ptr_impl(sycl::queue &q) {\n#ifdef DPCT_USM_LEVEL_NONE\n", + " value_t *get_ptr_impl(sycl::queue &q) {\n" + " if (_device_ptrs.empty()) {\n detail::mem_mgr::instance();\n dev_mgr::instance();\n" + " _device_ptrs.assign(get_ptrs_size(), nullptr);\n }\n#ifdef DPCT_USM_LEVEL_NONE\n") +edit("include/dpct/detail/memory_detail.hpp", lazy_device_memory) + +# 3. the migrated generate.cpp has no `--version` (src/program/generate.cpp answers it before any GPU is touched): the engine printed its +# usage and exited 2. Same lines as the CUDA tree, at the top of main(). +def version_flag(s): + if '"--version"' in s: + return s + return s.replace(" std::setvbuf(stdout, nullptr, _IONBF, 0);\n#if (defined(STRATA_USE_HIP)", + " std::setvbuf(stdout, nullptr, _IONBF, 0);\n" + " // `strata --version` / `-V` (also `strata generate --version`): the version and nothing else, before any GPU is touched, as the CUDA\n" + " // and HIP engines have answered it. `strata update` runs it as the engine's smoke test, and the Intel package build runs it with\n" + " // an empty environment.\n" + " for (int i = 1; i < argc && i < 3; ++i) {\n" + " if (std::strcmp(argv[i], \"--version\") == 0 || std::strcmp(argv[i], \"-V\") == 0) {\n" + " std::printf(\"strata %s\\n\", STRATA_VERSION);\n" + " return 0;\n" + " }\n" + " }\n" + "#if (defined(STRATA_USE_HIP)", 1) +edit("src/program/generate.cpp", version_flag) From 8be3f916f21e90bd2881f6474490341bb01a335d Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Thu, 22 Oct 2026 12:12:30 +0200 Subject: [PATCH 2/2] Intel Arc engine package: packaging/build_sycl_linux.sh, tests, docs No release feed ever carried a linux-x86_64-sycl engine package, because no recipe built one (the 0.1.45 package of stream split-s1 was made by hand). build_sycl_linux.sh builds the JIT engine with oneAPI, bundles the oneAPI runtime and the Unified Runtime adapters with collect_libs.py, sets RUNPATH $ORIGIN on every ELF file (Intel's libraries have none or a wrong one), packages it with archs intel-arc and checks the package with --verify, binary_deps.py and an env -i strata --version. _drm_vendor_backend takes the sysfs root so the Arc detection can be tested with a fake /sys/class/drm; tests/terminal/test_sycl_package.py covers the choice (an Arc PC with no oneAPI tools gets the package, nobody else does, Windows gets a reason) and the recipe; the release-matrix test has the sycl package. --- docs/INTEL_ARC.md | 6 +- packaging/ENGINE-COMPONENT.md | 2 +- packaging/README.md | 2 +- packaging/build_sycl_linux.sh | 74 +++++++++++++++ strata_control/engine_component.py | 6 +- tests/terminal/test_release_matrix.py | 2 + tests/terminal/test_sycl_package.py | 127 ++++++++++++++++++++++++++ 7 files changed, 209 insertions(+), 10 deletions(-) create mode 100644 packaging/build_sycl_linux.sh create mode 100644 tests/terminal/test_sycl_package.py diff --git a/docs/INTEL_ARC.md b/docs/INTEL_ARC.md index d3f0b423..0e55edaf 100644 --- a/docs/INTEL_ARC.md +++ b/docs/INTEL_ARC.md @@ -10,11 +10,7 @@ Intel GPU and every result on Arc hardware came from the community. Since 0.1.40 (32 GB, `xe`) and an Arc A750 (8 GB, `i915`); the results from those two cards are marked in the table below. Other cards are still community reports. The NVIDIA and AMD engines are unchanged: the Intel build is a separate CMake target, off by default. -**Where the engine comes from.** There is **no Intel engine in the release zips** (the ones `START-HERE.bat` and `setup.sh` -use): you build it from source on Linux, as described below. The Docker route is a ready-made image, -`ghcr.io/niko1221/strata:0.2.2-sycl`, which is published only for a release that carries a Linux Intel engine package; with none, [build -the image yourself](DOCKER.md#build-it-yourself) from the engine you built (the image needs prepared model files; see -[Docker: Intel Arc](DOCKER.md#intel-arc)). The Mac and Windows builds have no Intel engine. +**Where the engine comes from.** On Linux, `strata update` (Terminal) and Settings > Update (app) download the Intel engine package, `linux-x86_64-sycl`, for a PC whose graphics card is made by Intel, when the release feed lists one (`strata update --check` shows what it would install). One package serves Alchemist (A-series) and Battlemage (B-series) cards: the GPU code is compiled from SPIR-V at the first start, because the A-series cards have no FP64 units and the engine's FP64 kernels cannot be built ahead of time for them. It carries oneAPI's runtime libraries; the Level Zero loader and the compute runtime stay the PC's own (see "What you need" below), and the user must be in the `render` group (`strata doctor` says so). The package is built by `packaging/build_sycl_linux.sh`. It was tested on an Arc A750 only. The release zips (the ones `START-HERE.bat` and `setup.sh` use) have no Intel engine; to build one from source, follow the steps below. The Docker route is a ready-made image, `ghcr.io/niko1221/strata:0.2.2-sycl`, which is published only for a release that carries a Linux Intel engine package; with none, [build the image yourself](DOCKER.md#build-it-yourself) from the engine you built (the image needs prepared model files; see [Docker: Intel Arc](DOCKER.md#intel-arc)). The Mac and Windows builds have no Intel engine. ## What has been run, and by whom diff --git a/packaging/ENGINE-COMPONENT.md b/packaging/ENGINE-COMPONENT.md index 3a633e0d..ea76ae39 100644 --- a/packaging/ENGINE-COMPONENT.md +++ b/packaging/ENGINE-COMPONENT.md @@ -104,7 +104,7 @@ the manifest file (which holds every file's hash), used as the package's digest | `linux-x86_64` hip | a box with ROCm (the Python wheels are enough) | `strata`, the HIP runtime, hipBLAS/hipBLASLt/rocBLAS, comgr + libLLVM, `rocblas/library` and `hipblaslt/library` for the listed gfx archs; `packaging/build_hip_linux.sh` builds it with both picture readers | | `linux-x86_64` hip, variant `rx6000` (RX 6000, gfx1030 / gfx1031) | `VARIANT=rx6000 packaging/build_hip_linux.sh` in the jammy chroot, ROCm 7.13.0a20260515 `gfx103X-all` wheels | the same set as the other HIP packages, with `rocblas/library` for gfx1030 / gfx1031; no `hipblaslt/library` kernels exist for them and no `tuning/` table | built, not tested on a real RX 6000 card (the manifest notes say so). `windows-x86_64` hip, variant `rdna2`: the same archs from `tools/hip/build_windows.bat` with `STRATA_HIP_ARCHS=gfx1030;gfx1031`, packaged with `--variant rdna2`. A PC with an RX 7000 / 9000 card beside an RX 6000 one never takes it (`engine_component.hip_preference`) | | `linux-x86_64` hip, gfx1103 (Radeon 780M / Phoenix iGPU) | `packaging/build_hip_gfx1103.sh` on the mini PC (TheRock gfx110X-all SDK) | the same set as the gfx1200/1201 package, with `rocblas/library` and `hipblaslt/library` for gfx1103 (600 MiB) | experimental, unvalidated: the iGPU resets now and then (MES REMOVE_QUEUE); never kill the engine mid-request; run configs set `STRATA_NO_ARENA_THP=1`. `engine_component.resolve` picks a HIP package only when its `archs` list a gfx target the Linux kfd topology reports | -| `linux-x86_64` sycl | a box with oneAPI DPC++ | `strata` (JIT from SPIR-V), libsycl, the Unified Runtime adapters, MKL SYCL libraries | the Level Zero loader and compute runtime are the PC's driver | +| `linux-x86_64` sycl, `archs` `intel-arc` | a Linux box with oneAPI DPC++ 2026.1 and `patchelf`, `packaging/build_sycl_linux.sh` (JIT from SPIR-V; ocloc cannot build the Alchemist FP64 kernels ahead of time, so one JIT package serves A-series and B-series) | `strata`, libsycl, the Unified Runtime adapters, the oneMKL SYCL libraries, libimf / libsvml / libirng / libintlc (about 650 MiB); every ELF file has RUNPATH `$ORIGIN` (Intel's libraries ship without it), so `env -i ./strata --version` runs | the Level Zero loader and compute runtime are the PC's driver; the user must be in the `render` group (`strata doctor` warns). No Windows package: `BACKEND_MATRIX` allows sycl on `linux-x86_64` only | | `macos-arm64` metal | an Apple Silicon Mac | `strata`, `metal/kernels/*.metal`, `metal/engine-msl/*.metal`, `metal/ggml-common.h`, `metal/data/*.bin` | the Metal engine compiles its kernel sources when it starts; since S1 it finds them beside the executable (`metal/src/resource_path.h`: environment variable, then `/metal/`, then the compiled-in source path) | `packaging/collect_libs.py` gathers the Linux libraries (an `ldd` closure with the dlopen'd extras named, kernel data filtered by diff --git a/packaging/README.md b/packaging/README.md index d316ef44..b6e74632 100644 --- a/packaging/README.md +++ b/packaging/README.md @@ -22,7 +22,7 @@ A backend name alone is not a target. Each row is an OS x CPU ABI x backend tupl | `windows-x86_64-hip` | NSIS `.exe` (Tauri) | `tools/hip/build_windows.bat` | **built; never run on a real AMD card.** | | `linux-x86_64-cuda` | AppImage (Tauri) | `setup.py`; built in a glibc 2.35 chroot | **cuda13 built and tested** (RTX 3060 and RTX A4000: app in the browser, a real model, a picture). cuda12 built. | | `linux-x86_64-hip` | AppImage (Tauri) | `packaging/build_hip_linux.sh` | **RX 9000 (gfx1200 / gfx1201) built and tested** on a Radeon AI PRO R9700. **RX 7000 (gfx1100 / 1101 / 1102) built; not run on an RX 7000 card.** **RX 6000 (gfx1030 / 1031, 0.2.2, engine package `rx6000` only) built; not tested on a real RX 6000 card.** | -| `linux-x86_64-sycl` | | `sycl/setup_intel.py` | Documented as experimental ([INTEL.md](../docs/INTEL.md)). | +| `linux-x86_64-sycl` | | `packaging/build_sycl_linux.sh` (one JIT package for Alchemist and Battlemage) | **engine package built; tested on an Arc A750** (Intel Arc is an official platform since 0.1.40.2, docs/INTEL_ARC.md). No B-series card was available for the package. `sycl/setup_intel.py` (Docker) remains the source-build route. | | `windows-x86_64-sycl` | none | none | **gated.** No native Windows SYCL path exists upstream; it needs a separate feasibility gate, not a recipe. | | `macos-x86_64-*` | none | none | **unsupported.** The macOS engine is Apple-Silicon only (`metal/CMakeLists.txt` requires Apple Silicon for the Metal runtime). | diff --git a/packaging/build_sycl_linux.sh b/packaging/build_sycl_linux.sh new file mode 100644 index 00000000..028f0550 --- /dev/null +++ b/packaging/build_sycl_linux.sh @@ -0,0 +1,74 @@ +#!/bin/sh +# Build the Linux Intel Arc (SYCL) engine package for the release feed. +# +# packaging/build_sycl_linux.sh # the release package: GPU code JIT-compiled from SPIR-V (A-series and B-series) +# 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) +# +# Run it on a Linux x86_64 box with Intel oneAPI DPC++ (icx / icpx 2026.1 or newer, oneMKL) installed under $ONEAPI (default +# /opt/intel/oneapi), `patchelf` (apt install patchelf, or pip install patchelf in a venv and put it on PATH) and, for an AOT build, +# `ocloc` (apt: intel-ocloc). The Alchemist cards (A-series, DG2) have no FP64 units and ocloc cannot build the engine's double +# 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 +# kernels, the persistent JIT cache stays off on Xe2, docs/INTEL_ARC.md). +# The level-zero loader and the compute runtime stay the PC's own (the Intel graphics PPA / `apt install libze1 intel-opencl-icd`); +# the oneAPI runtime the engine loads (libsycl, the Unified Runtime adapters, the MKL SYCL libraries) is bundled by collect_libs.py. +# Every ELF file of the package gets RUNPATH $ORIGIN, so the package finds its own libraries with no environment +# (`env -i ./strata --version` runs); Intel's libraries ship without it (libur_loader has $ORIGIN/../lib, libmkl_core none). +# The package lands in $OUT (default ./out-engine-sycl). Nothing is uploaded or signed. +set -eu +repo=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd -P) +aot=${AOT:-} +case "$aot" in + ""|bmg-*|bmg-*,bmg-*) ;; + *) 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 ;; +esac +oneapi=${ONEAPI:-/opt/intel/oneapi} +out=${OUT:-$repo/out-engine-sycl} +build=${BUILD:-$repo/build-sycl} +py=${PYTHON:-python3} +jobs=${JOBS:-$(nproc)} +command -v patchelf >/dev/null || { echo "build_sycl_linux.sh: patchelf is not on PATH" >&2; exit 2; } +# setvars.sh is not written for `set -u` +set +u +# shellcheck disable=SC1091 +. "$oneapi/setvars.sh" >/dev/null 2>&1 || { echo "build_sycl_linux.sh: $oneapi/setvars.sh not found or failed" >&2; exit 2; } +set -u +command -v icpx >/dev/null || { echo "build_sycl_linux.sh: icpx is not on PATH after setvars.sh" >&2; exit 2; } +[ -z "$aot" ] || command -v ocloc >/dev/null || { echo "build_sycl_linux.sh: AOT needs ocloc (apt install intel-ocloc)" >&2; exit 2; } +iccver=$(icpx --version | sed -n 's/.*Compiler \([0-9][0-9.]*\).*/\1/p' | head -1) + +cd "$repo" +ggml="" +if [ -n "${LLAMA_CPP:-}" ]; then ggml="-DFETCHCONTENT_SOURCE_DIR_STRATA_LLAMACPP=$LLAMA_CPP -DFETCHCONTENT_FULLY_DISCONNECTED=ON" +elif [ -d "$repo/third_party/llama.cpp/ggml" ]; then ggml="-DSTRATA_GGML_DIR=$repo/third_party/llama.cpp"; fi +# shellcheck disable=SC2086 +cmake -S sycl -B "$build" -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx \ + -DSTRATA_SYCL_PARITY=OFF ${aot:+"-DSTRATA_SYCL_AOT=$aot"} $ggml +cmake --build "$build" --target strata -j "$jobs" + +ver=$(sed -n 's/^[[:space:]]*project([^)]*VERSION[[:space:]]*\([0-9][0-9.]*\).*/\1/p' CMakeLists.txt | head -1) +commit=${COMMIT:-$(git rev-parse --short=12 HEAD 2>/dev/null || echo unknown)} # a git archive has no .git: pass COMMIT= +stage=$(mktemp -d "${TMPDIR:-/tmp}/strata-sycl-stage.XXXXXX") +trap 'rm -rf "$stage"' EXIT +cp "$build/strata" "$stage/" +code=${aot:+AOT $aot}; code=${code:-JIT from SPIR-V} +echo "{\"version\": \"$ver\", \"source\": \"packaging/build_sycl_linux.sh\", \"sycl\": \"oneAPI DPC++ $iccver ($code)\", \"portable\": false}" > "$stage/BUILD.json" +# libsycl and the MKL SYCL libraries come through ldd; the Unified Runtime adapters (level zero, opencl) are dlopen'd, so they are named +"$py" packaging/collect_libs.py --binary "$build/strata" --search "$oneapi/compiler/latest/lib" --search "$oneapi/mkl/latest/lib" \ + --also 'libur_adapter_level_zero*.so*' --also 'libur_adapter_opencl*.so*' --out "$stage" +# RUNPATH $ORIGIN on the engine and on every bundled library (the same way packaging/build_hip_linux.sh does it) +for f in "$stage/strata" "$stage"/*.so "$stage"/*.so.*; do + [ -f "$f" ] && [ ! -L "$f" ] && patchelf --set-rpath '$ORIGIN' "$f" +done +for f in "$stage/strata" "$stage"/*.so "$stage"/*.so.*; do + [ -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; }; } +done +if [ -n "$aot" ]; then arch_args=$(echo "$aot" | tr ',' '\n' | sed 's/^/--arch /' | tr '\n' ' '); else arch_args="--arch intel-arc"; fi +mkdir -p "$out" +# shellcheck disable=SC2086 +"$py" packaging/package_engine.py --src "$stage" --backend sycl --version "$ver" --out "$out" $arch_args \ + --platform linux-x86_64 --build-id "${commit}-oneapi${iccver}" --include SYSTEM-LIBS.txt +for d in "$out"/*/; do + "$py" packaging/package_engine.py --verify "$d"; "$py" packaging/binary_deps.py "$d" + env -i "$d/strata" --version > /dev/null || { echo "build_sycl_linux.sh: env -i $d/strata --version does not run" >&2; exit 1; } +done +echo "built: $out" diff --git a/strata_control/engine_component.py b/strata_control/engine_component.py index 3d3c09a7..0cddbf4f 100644 --- a/strata_control/engine_component.py +++ b/strata_control/engine_component.py @@ -471,15 +471,15 @@ def detect_backend(environ=None) -> tuple[str | None, str]: return None, "no GPU tool answered" -def _drm_vendor_backend() -> str | None: +def _drm_vendor_backend(root: str = "/sys/class/drm") -> str | None: """Linux without the vendor tools on PATH (a HIP box that runs ROCm from Python wheels has no rocminfo): the PCI vendor of the display adapters decides. NVIDIA 0x10de -> cuda, AMD 0x1002 -> hip, Intel 0x8086 -> sycl, in that order. Read-only sysfs, nothing is run.""" - if not os.path.isdir("/sys/class/drm"): + if not os.path.isdir(root): return None vendors = set() try: - for card in sorted(Path("/sys/class/drm").glob("card[0-9]*")): + for card in sorted(Path(root).glob("card[0-9]*")): if "-" in card.name: continue try: diff --git a/tests/terminal/test_release_matrix.py b/tests/terminal/test_release_matrix.py index a074fbfc..d6aab311 100644 --- a/tests/terminal/test_release_matrix.py +++ b/tests/terminal/test_release_matrix.py @@ -39,6 +39,7 @@ RELEASE = [ pkg("linux-x86_64", "hip", "rx7900", ("gfx1100", "gfx1101", "gfx1102")), pkg("linux-x86_64", "hip", "halo", ("gfx1151",)), pkg("linux-x86_64", "hip", "rx6000", ("gfx1030", "gfx1031")), + pkg("linux-x86_64", "sycl", "", ("intel-arc",)), # the Intel Arc (A and B series) engine, GPU code JIT-compiled pkg("macos-arm64", "metal", "", ("apple-gpu",)), ] @@ -65,6 +66,7 @@ class ReleaseSelection(unittest.TestCase): self.pick(pc("linux-x86_64", "hip", gfx=["gfx1100"]))[0], # RX 7900 XTX self.pick(pc("linux-x86_64", "hip", gfx=["gfx1151"]))[0], # Ryzen AI Max (Strix Halo) self.pick(pc("linux-x86_64", "hip", gfx=["gfx1031"]))[0], # RX 6700 XT + self.pick(pc("linux-x86_64", "sycl"))[0], # Arc A750 / B580 / Pro B70 self.pick(pc("macos-arm64", "metal"))[0], } self.assertEqual(chosen, {(p["platform"], p["backend"], p["variant"]) for p in RELEASE}) diff --git a/tests/terminal/test_sycl_package.py b/tests/terminal/test_sycl_package.py new file mode 100644 index 00000000..be9ac314 --- /dev/null +++ b/tests/terminal/test_sycl_package.py @@ -0,0 +1,127 @@ +"""Intel Arc engine package (owner test round 8, track L3): the stable feed had no `linux-x86_64-sycl` package, so a clean Arc PC got a +Terminal that could not run a model and `strata update` kept saying the feed had no engine for it. The feed is whatever packages the release +builds (packaging/feed_tool.py takes every `*.entry.json`), so the gap was the missing build recipe, not the choice code. These tests keep the +choice honest once the package exists: an Arc PC (found by its PCI vendor, with no oneAPI tools installed) gets it by itself, nobody else does, +and the recipe that makes it carries the checks that a clean PC needs.""" +from __future__ import annotations + +import shutil +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path +from unittest import mock + +from strata_control import engine_component as ec, feed as feedmod, updater + +ROOT = Path(__file__).resolve().parents[2] +sys.path.insert(0, str(ROOT / "packaging")) +import package_engine # noqa: E402 + +LINUX, WIN = "linux-x86_64", "windows-x86_64" + + +def entry(platform, backend, variant, archs, version="0.1.47"): + return {"version": version, "platform": platform, "backend": backend, "variant": variant, "archs": list(archs), "min_driver": {}, + "min_runtime": None, "build_id": f"rel-{platform}-{backend}-{variant}", "format": "tar.gz", + "url": f"strata-engine-{platform}-{backend}-{variant}.tar.gz", "size": 1000, "sha256": "a" * 64, "manifest_sha256": "b" * 64, + "installed_bytes": 2000, "notes": ""} + + +FEED = [feedmod._engine_package(e) for e in ( + entry(LINUX, "cuda", "cuda13", ("sm_75", "sm_86", "sm_89", "sm_120", "compute_120")), + entry(LINUX, "hip", "rx9070", ("gfx1200", "gfx1201")), + entry(WIN, "cuda", "cuda13", ("sm_86",)), + entry(LINUX, "sycl", "", ("intel-arc",)))] + + +def fake_drm(root: Path, *vendors: str) -> str: + """A /sys/class/drm with one card per vendor id (plus a connector entry, which must be skipped).""" + for i, vendor in enumerate(vendors): + dev = root / f"card{i}" / "device" + dev.mkdir(parents=True) + (dev / "vendor").write_text(vendor + "\n") + (root / f"card{i}-HDMI-A-1").mkdir() + return str(root) + + +class ArcChoice(unittest.TestCase): + def detect(self, *vendors, platform=LINUX, environ=None): + """What `updater.detect_hardware` says on a PC with these display vendors and none of the vendor tools installed.""" + with tempfile.TemporaryDirectory() as t: + drm = fake_drm(Path(t), *vendors) + real = ec._drm_vendor_backend + with mock.patch.object(ec.shutil, "which", return_value=None), \ + mock.patch.object(ec, "host_platform", return_value=platform), \ + mock.patch.object(updater, "host_platform", return_value=platform), \ + mock.patch.object(ec, "_drm_vendor_backend", lambda: real(drm)), \ + mock.patch.object(ec, "_windows_vendor_backend", lambda: real(drm)): # the test PC may be Windows: either probe answers + return updater.detect_hardware(environ or {}) + + def pick(self, hardware): + best, reasons = feedmod.select_engine(FEED, hardware) + return best, reasons + + def test_a_clean_arc_pc_without_oneapi_gets_the_sycl_package(self): + hw = self.detect("0x8086") + self.assertEqual((hw["platform"], hw["backend"]), (LINUX, "sycl")) + best, _ = self.pick(hw) + self.assertEqual((best.backend, best.platform, best.archs), ("sycl", LINUX, ("intel-arc",))) + + def test_nvidia_and_amd_pcs_never_get_it_even_with_an_intel_igpu_beside_the_card(self): + for vendors, want in ((("0x10de",), "cuda"), (("0x8086", "0x10de"), "cuda"), (("0x8086", "0x1002"), "hip")): + hw = self.detect(*vendors) + best, _ = self.pick(hw) + self.assertEqual(best.backend, want, vendors) + + def test_windows_has_no_intel_package_and_says_why(self): + hw = self.detect("0x8086", platform=WIN) + best, why = self.pick(hw) + self.assertIsNone(best) + self.assertTrue(any("sycl" in r and WIN in r for r in why), why) + self.assertEqual(ec.backend_supported("sycl", WIN)[0], False) + self.assertEqual(ec.backend_supported("sycl", LINUX)[0], True) + + def test_the_package_is_not_offered_to_a_mac_or_to_a_forced_other_backend(self): + self.assertIsNone(self.pick({"platform": "macos-arm64", "backend": "metal", "runtime": "0.2.2"})[0]) + best, _ = self.pick(self.detect("0x8086", environ={ec.ENV_BACKEND: "cuda"})) + self.assertEqual(best.backend, "cuda") + + def test_an_older_sycl_package_does_not_beat_the_new_one_and_a_newer_one_wins(self): + packages = [feedmod._engine_package(entry(LINUX, "sycl", "", ("intel-arc",), v)) for v in ("0.1.45", "0.1.47", "0.1.46")] + best, _ = feedmod.select_engine(packages, self.detect("0x8086")) + self.assertEqual(best.version, "0.1.47") + + def test_no_package_at_all_gives_the_plain_no_engine_reason(self): + best, why = feedmod.select_engine([p for p in FEED if p.backend != "sycl"], self.detect("0x8086")) + self.assertIsNone(best) + self.assertTrue(any("needs sycl" in r for r in why), why) + + +class Recipe(unittest.TestCase): + SCRIPT = ROOT / "packaging" / "build_sycl_linux.sh" + + def test_the_recipe_exists_and_is_valid_shell(self): + self.assertTrue(self.SCRIPT.is_file()) + sh = shutil.which("sh") + if sh: + self.assertEqual(subprocess.run([sh, "-n", str(self.SCRIPT)], capture_output=True).returncode, 0) + + def test_the_recipe_bundles_the_runtime_and_checks_a_clean_start(self): + text = self.SCRIPT.read_text(encoding="utf-8") + for needed in ("collect_libs.py", "libur_adapter_level_zero", "libur_adapter_opencl", "patchelf --set-rpath", + "package_engine.py --verify", "binary_deps.py", "env -i", "--version", "--backend sycl", "intel-arc"): + self.assertIn(needed, text) + self.assertNotIn("\r", text, "a shell script with CRLF endings does not run on Linux") + + def test_a_sycl_package_needs_an_arch_tag_and_only_linux(self): + with tempfile.TemporaryDirectory() as t: + with self.assertRaises(SystemExit): + package_engine.build(Path(t), "sycl", "0.1.47", LINUX, Path(t) / "out") + self.assertIn(LINUX, ec.BACKEND_MATRIX["sycl"]) + self.assertNotIn(WIN, ec.BACKEND_MATRIX["sycl"]) + + +if __name__ == "__main__": + unittest.main()