Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/docs/SPIRV.md # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / docs / SPIRV.md` 264 lines ยท 14232 bytes Raw Blame History Rendered 1 # Omega to SPIR-V compute kernels 2 3 `seed/spirv/irspirv.om` translates the seeded compiler's OSC IR v1 scalar units 4 into SPIR-V 1.0 **OpenCL Kernel** modules. It is handwritten Omega, built by 5 `seed/out/omc`; neither LLVM nor a foreign-language generator produces its output. 6 This is the Kernel profile used by the OpenCL/SYCL ecosystem, not Vulkan Shader 7 SPIR-V. The exercised consumer is PoCL on a CPU through `clCreateProgramWithIL`. 8 This does not establish DPC++ integration, Level Zero support, GPU qualification, 9 or general SYCL language support. 10 11 ## Build and demo 12 13 On AArch64 Linux, from the repository root, with the committed compiler: 14 15 ```sh 16 mkdir -p build/seed/spirv 17 seed/out/omc < seed/spirv/irspirv.om > build/seed/spirv/irspirv 18 chmod +x build/seed/spirv/irspirv 19 { printf 'ir\n'; cat seed/spirv/demo.unit.om; } > build/seed/spirv/demo.input 20 seed/out/omc < build/seed/spirv/demo.input > build/seed/spirv/demo.ir 21 build/seed/spirv/irspirv < build/seed/spirv/demo.ir > build/seed/spirv/demo.spv 22 spirv-val --target-env opencl2.1 build/seed/spirv/demo.spv 23 spirv-dis build/seed/spirv/demo.spv -o build/seed/spirv/demo.spvasm 24 export POCL_LIBRARY=/absolute/path/to/libpocl.so.2.16.0 25 cc -std=c11 -O2 -Wall -Wextra \ 26 "-DIRSPIRV_POCL_LIBRARY=\"$POCL_LIBRARY\"" seed/spirv/opencl-host.c \ 27 -o build/seed/spirv/opencl-host -lOpenCL 28 build/seed/spirv/opencl-host build/seed/spirv/demo.spv avgu32 `4294967295` `4294967293` 29 ``` 30 31 Stop immediately if any command fails; never execute a compiler's partial output. 32 For user-space OpenCL headers/libraries, add `-I`, `-L` and the corresponding 33 linker rpath to the host build. The build-time `IRSPIRV_POCL_LIBRARY` pins one 34 absolute PoCL shared-library path. The host overwrites inherited vendor discovery, 35 disables OpenCL layer discovery, forces `POCL_DEVICES=cpu`, and enumerates CPU 36 devices only. No GPU is used. Trust the installed library and its dependency 37 directories; this is not a sandbox for attacker-controlled shared libraries. 38 39 The demo's complete function is: 40 41 ```text 42 fn avgu32 a uint b uint to uint 43 ret add and a b shr xor a b uint 1 44 end 45 ``` 46 47 Observed stdout on PoCL 7.2 (2026-10-26): 48 49 ```text 50 `4294967294` 0 51 ``` 52 53 The first field is the full result bit pattern; the second is the Omega status. 54 Two other exercised demo calls were `avgu32 0 1` -> `0 0` and `avgu32 7 10` -> 55 `8 0`. The host prints runtime/device identity on stderr. It creates an IL 56 program, builds it, creates the named kernel, allocates the input/output buffers, 57 launches one work item, and reads both output words back before printing. 58 59 ## ABI and semantics 60 61 Every IR function is exported as a kernel with its original name and this ABI: 62 63 ```c 64 void kernel_name(__global const ulong *inputs, __global ulong *outputs); 65 ``` 66 67 - Launch exactly one work item. Launching more races on the shared output pair. 68 - Input slots are scalar arguments in source order, at most six. Unsigned values 69 are zero-extended, signed values sign-extended, and booleans are 0 or 1. 70 - `outputs[0]` is the canonical 64-bit result, or zero for void and trapped calls. 71 - `outputs[1]` is zero on success or the exact native Omega status `100 + trap`. 72 A trap is a completed kernel result, not an OpenCL API failure. 73 - Modules declare Addresses, Kernel and Int64 capabilities, Physical64 addressing, 74 and the OpenCL memory model. Internal function values use 64-bit integer bits; 75 private Function-storage variables hold mutable OSC virtual registers. 76 - Signed overflow, divide-by-zero, checked conversions, shift bounds, explicit 77 traps and compiler-emitted loop bounds retain Omega semantics. A callee's trap 78 returns through callers immediately, preserving the first status. Signed 79 minimum divided by minus one traps; the corresponding remainder is zero. 80 - Reachable blocks are emitted in deterministic reverse postorder, so dominators 81 precede dominated blocks even when OSC block numbers are not in that order. 82 Unreachable blocks are validated as IR but not emitted. 83 84 The accepted scalar subset matches `seed/wasm/irwasm.om`: bool and signed/unsigned 85 8/16/32/64-bit integers, constants, moves, arithmetic and bitwise operations, 86 comparisons, checked casts, earlier-function calls, branches, returns and traps. 87 Arrays, memory operations, floating point, host/device words, vectors, atomics, 88 barriers and other OSC versions are not accepted. Contract strings in OSC v1 89 are structurally checked metadata, not runtime pre/postcondition enforcement. 90 There is no shader fallback or silent host-code fallback. 91 92 Limits: 32 nonempty functions per unit, six parameters, 480 registers, 512 blocks, 93 4096 instructions per function, names up to 63 ASCII bytes, input strictly smaller 94 than `2620252` bytes, and an `8388608`-byte output limit. Capacity overflow refuses; 95 these are bounded translator capacities, not claims about the SPIR-V specification. 96 97 | Exit | Named stderr error | Meaning | 98 |---|---|---| 99 | 20 | `irspirv: MAGIC` | Wrong OSC magic | 100 | 21 | `irspirv: VERSION` | Not OSC v1 | 101 | 22 | `irspirv: TRUNCATED` | Incomplete input | 102 | 23 | `irspirv: CAPACITY` | Translator capacity exceeded | 103 | 24 | `irspirv: UNSUPPORTED_OP` | Unsupported instruction | 104 | 25 | `irspirv: UNSUPPORTED_TAG` | Unsupported scalar tag | 105 | 26 | `irspirv: INVALID` | Invalid types, registers, CFG, name, use-before-definition or zero functions | 106 | 27 | `irspirv: TRAILING` | Bytes after the unit | 107 | 28 | `irspirv: IO` | Read/write failure | 108 109 Parsing, validation and emission are buffered: format/semantic/capacity refusals 110 produce no stdout. An I/O failure during final output can leave a partial stream; 111 consumers must check the exit status. Runtime/compiler failures also are not modules. 112 113 ## CPU acceptance gate 114 115 ```sh 116 export SPIRV_VAL=/absolute/path/to/spirv-val 117 export POCL_LIBRARY=/absolute/path/to/libpocl.so.2.16.0 118 # Optional for user-space headers and libraries: 119 # export OPENCL_CFLAGS='-I/absolute/path/include' 120 # export OPENCL_LIBS='-L/absolute/path/lib -Wl,-rpath,/absolute/path/lib -lOpenCL' 121 sh seed/spirv/gate-irspirv.sh 122 ``` 123 124 The gate pins omc sha256 125 ``befb8199db8c4bca188a494dfaac2a6f0ee5c36fcea11188c75666c55fce8a1d``. 126 It compiles the same units as irwasm, preserves the entire original 129-row 127 `seed/wasm/cases.tsv`, and builds a native Omega caller for every row. Comparison 128 uses all eight result bytes and exact native trap statuses, never just process 129 status modulo 256. Every exported kernel must appear in the table. Empty tables, 130 missing files, malformed host responses, timeouts, API failures and skipped 131 kernels fail closed. Missing prerequisite tools are NOT_RUN, not PASS. 132 133 Observed on AArch64 Linux with the toolchain below: 134 135 | Check | Observed | 136 |---|---| 137 | Original irwasm corpus | 129 exact native/PoCL matches, including 29 traps | 138 | Supplemental nested-call corpus | 8 exact matches, including 4 callee traps | 139 | Demo corpus | 3 exact matches | 140 | Reordered CFG `0 -> 2 -> 1` | Validator accepted, CPU returned `0 0` | 141 | Determinism | 16 modules translated twice, byte-identical | 142 | `spirv-val --target-env opencl2.1` | 17 modules accepted, including the valid arithmetic mutant | 143 | Wrong-add-to-sub mutant | Executes successfully with `12 0` instead of baseline `26 0`; parity checker exits 1 | 144 | Validator negative control | Missing final OpFunctionEnd rejected | 145 | Named refusal cases | 16 exact error/status matches, empty stdout | 146 147 148 Host isolation regressions also require inherited vendor/layer settings to be 149 ignored and both an unconfigured host and a nonexistent fixed library to fail 150 without a result or fallback discovery. There is no environment-selected manifest 151 to inspect and then reopen: [ocl-icd 2.3.2](https://github.com/OCL-dev/ocl-icd/blob/v2.3.2/ocl_icd_loader.c) 152 supports loading the build-time selected library directly. `OPENCL_LAYER_PATH` 153 is forced to `/dev/null` so clearing `OPENCL_LAYERS` cannot leave system-layer 154 discovery enabled. 155 The mutant is not a crash control: the gate requires successful OpenCL execution 156 and exactly one result mismatch when substituted into the baseline corpus. 157 The checker uses exit 2 for API/setup faults, distinct from mismatch exit 1. 158 Artifacts include `gate.log`, `case-spirv-parity.tsv`, 159 `regression-case-spirv-parity.tsv`, `demo-case-spirv-parity.tsv`, per-case raw 160 outputs/statuses, validator logs, and the rejected mutant comparison table under 161 `build/seed/spirv`. A gate run replaces this scratch directory; archive receipts 162 before rerunning. Published evidence is retained under `evidence/IRSPIRV/`. 163 164 ## Replay on Intel's CPU OpenCL runtime (x86-64 CI) 165 166 `.github/workflows/irspirv-intel-cpu.yml` replays the gate's modules and AArch64 167 native dumps on an x86-64 runner through `intel-oneapi-runtime-opencl` 168 (`libintelocl.so`, taken from its ICD file). `opencl-host.c` is rebuilt with 169 `IRSPIRV_POCL_LIBRARY`, `IRSPIRV_OCL_LIBRARY_BASE=libintelocl.so` and 170 `IRSPIRV_OCL_PLATFORM`, and rpath-pinned to the distro ocl-icd loader: oneAPI's 171 redist ships a Khronos `libOpenCL.so.1` that the ld.so cache prefers, and that 172 loader ignores a library path in `OCL_ICD_VENDORS`. 173 `seed/spirv/ocl-vendor-matrix.sh BUILD_DIR HOST TABLE PREFIX OUT.tsv [--mutant-baseline]` 174 records built/ran/match and error text per row instead of stopping at the first 175 failure; the mutant substitution must mismatch exactly `mutant.mutadd`. Rows are 176 also replayed under intel/opencl-intercept-layer v3.0.6. Run `40441577102` 177 (runtime 2026.2.0-863, AMD EPYC 7763 runner): cases 129/129, demo 3/3, 178 regression 8/8 matched; mutant 128/129. CPU evidence only, advisory. 179 180 ## External oracle/toolchain ledger 181 182 These are verification/demo dependencies, not translator implementation or 183 production dependencies. The translator build depends only on seeded omc. 184 No DPC++/SYCL package was available in the inspected Ubuntu 24.04 arm64 package 185 catalog, so this demo uses the explicitly requested OpenCL IL route. 186 187 | Tool | Exercised version and role | 188 |---|---| 189 | omc | sha256 above; builds translator, emits OSC IR and native comparison programs | 190 | SPIRV-Tools | v2025.1, Ubuntu `2025.1~rc1-1~ubuntu0.24.04.2`; validator and disassembler | 191 | PoCL | v7.2, source commit ``888c9774b94590fff1afef003154ca2c0ea66605``; CPU OpenCL oracle | 192 | LLVM/clang | 18.1.3; PoCL's CPU compilation dependency, not Omega translation | 193 | SPIRV-LLVM-Translator | 18.1.8; PoCL's SPIR-V reader | 194 | ocl-icd | 2.3.2; test host's OpenCL dispatch loader | 195 | OpenCL headers | `3.0~2023.12.14`; C demo interface declarations | 196 | GCC | 13.3.0; builds only the C demo host | 197 | Python | 3.12.3; read-only parity oracle and malformed-IR test construction | 198 199 Packages were downloaded with apt and extracted with `dpkg-deb -x` into a 200 user-space prefix. Ubuntu PoCL 5.0 did not expose SPIR-V IL and was rejected. 201 PoCL 7.2 was built from its pinned source with `ENABLE_ICD=ON`, 202 `ENABLE_SPIRV=ON`, `HOST_CPU_ENABLE_SPIRV=ON`, LLVM 18 and 203 `LLC_HOST_CPU=cortex-a720` (LLVM 18 did not recognize this host's newer cores). 204 The resulting CPU reports SPIR-V 1.0 through 1.4 and `cl_khr_il_program`. 205 The oracle's SPIR-V reader can abort on malformed IL; validation is mandatory 206 before execution, and a host abort is a failed oracle call, never parity success. 207 208 Binary/semantic authorities: [SPIR-V specification](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html), 209 [OSC wire format](../spec/one-layer-format.md), and the native seeded compiler. 210 The signed multiplication guard uses magnitude division; the Wolfram check 211 `Reduce[a b>l && a<=Quotient[l,b] && a>=0 && b>0 && l>=0,{a,b,l},Integers]` 212 returned `False`. This symbolic check is not the CPU parity receipt. 213 214 ### Reproducing the user-space PoCL oracle 215 216 The following is the exercised Ubuntu arm64 provisioning recipe. It assumes 217 system CMake, Ninja, GCC, Git and apt tools. Run it in a disposable prefix; no 218 root install, ICD system registration, service or GPU change is required. 219 `evidence/IRSPIRV/` retains the exact downloaded package versions/checksums. 220 221 ```sh 222 T=/tmp/spirv-tools-root 223 R=$T/root 224 mkdir -p "$T/debs" "$T/src" "$R" 225 cd "$T/debs" 226 apt-get download spirv-tools=2025.1~rc1-1~ubuntu0.24.04.2 \ 227 opencl-c-headers opencl-clhpp-headers ocl-icd-opencl-dev \ 228 ocl-icd-libopencl1 ocl-icd-dev clinfo llvm-18 llvm-18-dev llvm-18-tools \ 229 llvm-18-runtime llvm-18-linker-tools libllvm18 clang-18 libclang-18-dev \ 230 libclang-cpp18 libclang-cpp18-dev libclang-common-18-dev libclang1-18 \ 231 llvm-spirv-18 libllvmspirvlib-18-dev libllvmspirvlib18.1 \ 232 libpolly-18-dev libclang-rt-18-dev 233 for d in ./*.deb; do dpkg-deb -x "$d" "$R"; done 234 git clone --depth 1 -b v7.2 https://github.com/pocl/pocl.git "$T/src/pocl" 235 test "$(git -C "$T/src/pocl" rev-parse HEAD)" = `888c9774b94590fff1afef003154ca2c0ea66605` 236 export LD_LIBRARY_PATH=$R/usr/lib/aarch64-linux-gnu:$R/usr/lib/llvm-18/lib 237 export PKG_CONFIG_PATH=$R/usr/lib/aarch64-linux-gnu/pkgconfig:$R/usr/share/pkgconfig 238 export PKG_CONFIG_SYSROOT_DIR=$R 239 export PATH=$R/usr/bin:$PATH 240 cmake -S "$T/src/pocl" -B "$T/build/pocl" -G Ninja \ 241 -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="$T/pocl" \ 242 -DWITH_LLVM_CONFIG="$R/usr/lib/llvm-18/bin/llvm-config" \ 243 -DLLC_HOST_CPU=cortex-a720 -DENABLE_ICD=ON -DENABLE_TESTS=OFF \ 244 -DENABLE_EXAMPLES=OFF -DENABLE_HWLOC=OFF -DENABLE_LLVM_FILECHECKS=OFF \ 245 -DENABLE_POCL_BUILDING=OFF \ 246 -DLLVM_SPIRV_INCLUDEDIR="$R/usr/include/LLVMSPIRVLib" \ 247 -DLLVM_SPIRV_LIB="$R/usr/lib/aarch64-linux-gnu/libLLVMSPIRVLib.so" \ 248 -DHOST_LLVM_SPIRV="$R/usr/bin/llvm-spirv-18" \ 249 -DHOST_SPIRV_LINK="$R/usr/bin/spirv-link" \ 250 -DCMAKE_INSTALL_RPATH="$R/usr/lib/aarch64-linux-gnu;$R/usr/lib/llvm-18/lib" 251 nice -n 19 ionice -c3 ninja -C "$T/build/pocl" -j2 252 nice -n 19 ionice -c3 ninja -C "$T/build/pocl" install 253 export SPIRV_VAL=$R/usr/bin/spirv-val 254 export POCL_LIBRARY=$T/pocl/lib/libpocl.so.2.16.0 255 export POCL_DEVICES=cpu 256 export OPENCL_CFLAGS="-I$R/usr/include" 257 export OPENCL_LIBS="-L$R/usr/lib/aarch64-linux-gnu -Wl,-rpath,$R/usr/lib/aarch64-linux-gnu -lOpenCL" 258 # Return to the Omega checkout before running its acceptance gate. 259 ``` 260 261 Confirm CMake reports `ENABLE_SPIRV`, `HOST_CPU_ENABLE_SPIRV`, and `ENABLE_ICD` 262 enabled. In particular, omitting `ocl-icd-dev` can disable ICD support despite 263 the requested option. These are oracle setup checks, not permission to bypass 264 the acceptance gate or use another device.