diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 63e1f924..5cf0de66 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# CI for CUDA++: the host-only test set (`make test`, no GPU opened, no CUDA toolkit) on a +# CI for CUDA++: the host-only test set (`make test`, no GPU opened, offline nvdisasm oracle) on a # GitHub-hosted arm64 runner, judged by the exit code and the final # `CUDA++ HOST TESTS PASS ( targets)` line as AGENTS.md prescribes. Chip tests need a GB10 # and stay NOT_RUN here. A second job writes an SPDX SBOM of the tree for auditors. @@ -20,11 +20,30 @@ jobs: persist-credentials: false - name: Toolchain record run: gcc --version | head -n 1 && make --version | head -n 1 + - name: Pinned host verification tools + # Disposable hosted runner only. No CUDA driver, runtime or compiler is installed. + # Archive identity: NVIDIA cuda_nvdisasm.linux-sbsa in redistrib_13.0.2.json. + run: | + package=cuda_nvdisasm-linux-sbsa-13.0.85-archive + archive="$RUNNER_TEMP/$package.tar.xz" + curl --fail --location --silent --show-error --proto '=https' --tlsv1.2 \ + "https://developer.download.nvidia.com/compute/cuda/redist/cuda_nvdisasm/linux-sbsa/$package.tar.xz" \ + --output "$archive" + printf '%s %s\n' 77e2ef1494270839829d5608352ba67a278e80fdaf4e3cc3c8ac9cb73e1c463c "$archive" | sha256sum --check --strict + tar -xJf "$archive" -C "$RUNNER_TEMP" "$package/bin/nvdisasm" + sudo install -D -m755 "$RUNNER_TEMP/$package/bin/nvdisasm" /usr/local/cuda/bin/nvdisasm + /usr/local/cuda/bin/nvdisasm --version + printf '%s\n' /usr/local/cuda/bin >> "$GITHUB_PATH" + git clone -q https://github.com/aien-dev/omega-bridge "$RUNNER_TEMP/omega-bridge" + git -C "$RUNNER_TEMP/omega-bridge" checkout -q "$(grep -v '^#' om/omega-bridge.lock)" + git -C "$RUNNER_TEMP/omega-bridge" rev-parse HEAD - name: Host-only tests # The runner's bash uses -e -o pipefail, so make's status is captured with `||`. + env: + OMEGA_BRIDGE: ${{ runner.temp }}/omega-bridge run: | rc=0; make test > "$RUNNER_TEMP/make-test.log" 2>&1 || rc=$? - tail -n 20 "$RUNNER_TEMP/make-test.log" + cat "$RUNNER_TEMP/make-test.log" [ "$rc" -eq 0 ] || exit "$rc" last=$(tail -n 1 "$RUNNER_TEMP/make-test.log") case $last in diff --git a/AGENTS.md b/AGENTS.md index 4e8ef444..c079eb50 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # CUDA++ (GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit) -> CUDA++ is the GPU half of the Omega runtime. It writes sm_121 machine code (SASS) directly, launches it through its own client for NVIDIA's open kernel module ioctls, and ships matrix multiply, attention, elementwise and mixture-of-experts libraries on top. No CUDA toolkit, `nvcc`, PTX, `libcuda` or cuBLAS is used. It builds with `make` and a C compiler; it runs only on the NVIDIA GB10 (DGX Spark, sm_121) with the 580.173.02 open kernel module. The repository on GitHub is `CUDApp`; the project name is written CUDA++. +> CUDA++ is the GPU half of the Omega runtime. It writes sm_121 machine code (SASS) directly, launches it through its own client for NVIDIA's open kernel module ioctls, and ships matrix multiply, attention, elementwise and mixture-of-experts libraries on top. Its build and runtime use no CUDA toolkit, `nvcc`, PTX, `libcuda` or cuBLAS. Host verification uses NVIDIA's offline `nvdisasm` as an independent instruction oracle, never as an implementation dependency. It builds with `make` and a C compiler; it runs only on the NVIDIA GB10 (DGX Spark, sm_121) with the 580.173.02 open kernel module. The repository on GitHub is `CUDApp`; the project name is written CUDA++. Shared rules: read https://www.aienos.com/agents/RULES.md first. This file adds what is specific to this repository; where the two differ, this file wins here. @@ -23,7 +23,7 @@ cd CUDApp make -j8 # build/libomega_gpu.a, copied to build/libcudapp.a ``` -Needs Linux, `git`, `make` and `gcc` (the `Makefile` uses `CC ?= gcc` and builds with `-Wall -Wextra -Werror`). Nothing from the CUDA toolkit is needed. The host build and host tests need no GPU. Running a kernel on the chip needs a DGX Spark (GB10) with NVIDIA's open kernel module 580.173.02 loaded and `/dev/nvidia0` and `/dev/nvidia-uvm` present. +Needs Linux, `git`, `make` and `gcc` (the `Makefile` uses `CC ?= gcc` and builds with `-Wall -Wextra -Werror`). Nothing from the CUDA toolkit is needed to build or run. The complete host test suite additionally requires offline `nvdisasm` for independent encoder operand checks and the pinned Omega verification tools; missing required tools are NOT_RUN, not PASS. The host build and host tests need no GPU. Running a kernel on the chip needs a DGX Spark (GB10) with NVIDIA's open kernel module 580.173.02 loaded and `/dev/nvidia0` and `/dev/nvidia-uvm` present. ## Configuration @@ -70,7 +70,7 @@ make hello-gpu # runs make doctor, then examples/he - Status words in `README.md` and `ROADMAP.md` are PASS (receipt on a named commit), PARTIAL, MISSING, BUILDING. Do not upgrade a status without the receipt. - New source files carry `SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception`. Keep third-party notices (`THIRD_PARTY.md`, `NOTICE`). - Plain English, short sentences, every number with the command that produced it. -- CI on pull requests is GitHub CodeQL (C/C++ and Python). It does not run `make test`; run it yourself and put the result in the pull request, naming every failure in that run. +- Pull request CI runs the host-only `make test` suite, pinned Omega binding regeneration and mutants, SBOM generation and GitHub CodeQL. Its disposable arm64 host-test runner installs only the checksum-verified NVIDIA `nvdisasm` 13.0.85 executable and the bridge source pinned by `om/omega-bridge.lock`. The archive URL and SHA-256 are fixed in `.github/workflows/ci.yml`, from NVIDIA's `redistrib_13.0.2.json` manifest. The oracle is verification-only: no CUDA driver, runtime or compiler is installed, no NVIDIA binary is committed, and no GPU is opened. Provisioning errors and missing-oracle checks remain failures. Put local results in the pull request with their exact source revision; all-green host CI is not physical qualification. ## Safety and approvals diff --git a/README.md b/README.md index 3cd49222..92af280b 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,46 @@ CUDA++ is not affiliated with or endorsed by NVIDIA; CUDA is NVIDIA's trademark. **On this page:** [the stack](#the-stack) · [how I did it](#how-i-did-it) · [the machine code](#what-the-machine-code-looks-like) · [the driver, part by part](#the-driver-part-by-part) · [one launch, start to finish](#one-launch-start-to-finish) · [CUDA, piece by piece](#cuda-piece-by-piece) · [speed](#speed-against-the-ceiling) · [run your first kernel](#run-your-first-kernel) +## TileLab driver checks and replay + +`make test-tilelab-host TILELAB_OMC=/path/to/pinned/omc` runs the driver's +host-only refusals and oracle checks, then the bounded Omega conductor in +`tests/tilelab_host_fault.om`. The compiler must match `tools/c5/omc.pin`. +The separately compiled `gpu_tilelab_host_fault` replaces every GEMM and +configuration entry with nondelegating CPU fault injection; it does not call +GPU or session entry points. Its receipts say `execution: synthetic-host`. +These results are host control-flow evidence, never chip qualification. + +The conductor checks the full shape-list capacity, escaped JSON identifiers, +failed warmup and timed calls, runtime-failed mutants, successfully executed +wrong-result mutants, correct-result negative controls, and buffered receipt +failure on `/dev/full`. A runtime error cannot count as a caught mutant. +Receipt write or close failure returns nonzero before a final PASS. +Arm names must be valid UTF-8. JSON preserves multibyte identifiers exactly, +escapes quotes, backslashes and control characters, and refuses malformed +UTF-8 before any execution or receipt creation. + +Build the current replay with `make tilelab-replay TILELAB_OMC=/path/to/pinned/omc`. +Its interface is: + +```text +build/tilelab_replay DRIVER OUTPUT_PREFIX "M,N,K;..." ROUNDS [NAME:RT,CT,WM,WN,BAND ...] +``` + +It invokes the driver directly, without a shell, and groups at most fifteen +explicit configurations per invocation because the default arm occupies the +remaining slot. Outputs are `OUTPUT_PREFIX.0.json`, `.1.json`, and so on. +Every child must succeed; nonzero child exits, failed execution, and signals +stop replay without printing replay PASS. The host conductor checks failure +propagation and a configuration list spanning three invocations. + +Using the real device driver still requires the operator's current GPU-window +authorization. Neither building replay nor passing host tests grants it. +The scripts and receipts under `evidence/TILELAB-20261028/` are immutable +historical records, not current executable gates. In particular, the archived +sweep scripts can mask child failures and an over-capacity group. Use this +current replay for new runs; do not rewrite the historical scripts or receipts. + ## The stack

CUDA and CUDA++ layer by layer. The compiler, maths libraries, runtime and driver library of CUDA are closed and CUDA++ has its own code for their jobs. NVIDIA's open kernel module stays; the signed GSP firmware stays.

diff --git a/docs/SM121_INSTRUCTION_SPEC.md b/docs/SM121_INSTRUCTION_SPEC.md index d51bb428..5398b6fd 100644 --- a/docs/SM121_INSTRUCTION_SPEC.md +++ b/docs/SM121_INSTRUCTION_SPEC.md @@ -42,14 +42,16 @@ The following integer constants represent semantic field roles in `bw_spec_sm121 | 9 | `R_IMM32`| 32-bit Immediate | `o[6]` | Full 32-bit range | | 10 | `R_OFF24`| Signed 24-bit byte offset | `o[6]` | `-8388608 <= v <= 8388607` | | 11 | `R_IMM16`| 16-bit Immediate | `o[6]` | `0 <= v <= 65535` | -| 12 | `R_BAR` | Barrier register (0..15) | `o[7] >> 8` | `0 <= v <= 15` | -| 13 | `R_BSSY_DELTA` | BSSY delta relative PC | `o[6]` | `-8388608 <= v <= 8388607` | -| 14 | `R_BRA_DELTA` | BRA branch offset | `o[6]` | `-8388608 <= v <= 8388607` | -| 15 | `R_SHFL_IMM` | Shuffle mask immediate | `o[6]` | `0 <= v <= 65535` | -| 16 | `R_LDC_IMM` | LDC cbank offset | `o[6]` | `0 <= v <= 65535` | -| 17 | `R_S2R_SR` | Special register index | `o[6]` | `0 <= v <= 255` | -| 18 | `R_LDS128_OFF` | LDS128 offset | `o[6]` | `0 <= v <= 8388607` | -| 19 | `R_FSETP_IMM` | FSETP comparison immediate | `o[6]` | Full 32-bit range | +| 12 | `R_BAR` | Barrier register | `o[11]` | Declared form bounds | +| 13 | `R_BSSY` | Relative instruction delta | `o[6]` | Declared bounds and exact representability of `(v - 1) * 16` | +| 14 | `R_BRA` | Branch delta | `o[6]` | Unsigned 32-bit IR representation | +| 15 | `R_LDC` | Constant-bank offset | `o[6]` | Declared bounds and exact alignment/field representation | +| 16 | `R_SHFL` | Shuffle immediate | `o[6]` | Raw value, no masking before validation | +| 17 | `R_LUT` | LOP3 LUT | `o[6]` | Raw value, no masking before validation | +| 18 | `R_S2R` | Special-register index | `o[6]` | Declared form bounds | +| 19 | `R_LDSW` | Shared-memory offset | `o[6]` | Declared form bounds and exact representation | +| 20 | `R_FSET` | FSETP comparison encoding | `o[6]` | Declared form bounds; zero selects the default encoding | +| 21 | `R_PRED3` | Predicate destination/source | `o[1]` or `o[4]` | Raw value, no masking before validation | ## Specification Table Representation @@ -84,7 +86,7 @@ The encoder refuses invalid input with explicit error codes instead of truncatin - `E_OK = 0`: Successful encoding or decoding. - `E_UNSUP = 1`: Opcode or variant is not supported. -- `E_RANGE = 2`: Operand value exceeds declared `min_v..max_v` bounds. +- `E_RANGE = 2`: Operand exceeds declared bounds or cannot be represented without losing semantic bits. - `E_NOMAT = 3`: Instruction machine words do not match any known form's fixed bits and masks. ## Dual Derivation @@ -92,10 +94,17 @@ The encoder refuses invalid input with explicit error codes instead of truncatin 1. **`sp_enc o w -> err`**: - Matches `o` to an instruction form. - Sets fixed word bits `w0_fix..w2_fix` and control word `w3`. - - Iterates through all fields: validates `min_v <= val <= max_v` (refuses with `E_RANGE` on failure). - - Inserts each field into the destination word: `w[word] |= (val & mask) << shift`. + - Validates the raw semantic operand before inserting masked bits. + - Checks special-layout immediates by decoding their inserted representation and requiring exact equality. 2. **`sp_dec w o -> err`**: + - Initializes its shared table automatically, including standalone cold calls. - Searches `sp_tbl` for a form whose fixed bits match: `(w[k] & mask) == fix`. - Extracts each field: `val = (w[word] >> shift) & mask`. - Populates decoded IR array `o[]`. - - Validates that round-trip `decode(encode(x)) == x` holds for all legal instructions. +3. **Host verification**: + - Compares every active semantic role after decoding, not just the opcode. Inactive IR packing slots are not operands. + - Canonicalizations are explicit: absent source operands for LOP3/SHF/IMAD.HI mean RZ; zero control selects the form default; zero FSETP immediate selects its default encoding. + - IMAD RRU has a GPR destination and a uniform second source. Corpus generation verifies that each intended form actually dispatches. + - Boundary fixtures select representable aligned immediates; separate audit regressions require refusal of raw lossy values. + - `sh tools/test_bw_spec_encoder.sh` checks reference bytes, active operands, cold decode, malformed streams and independent offline nvdisasm operands. Producer failure, truncated records and read errors fail closed. + - All checks are host-only. Physical qualification of the changed encoder remains NOT_RUN until an authorized chip run. Frozen historical receipts are unchanged. diff --git a/mk/c3.mk b/mk/c3.mk index d9eb869e..5ea4fa4e 100644 --- a/mk/c3.mk +++ b/mk/c3.mk @@ -12,10 +12,35 @@ $(GPU_GEMM_TEST): tests/gpu_gemm_test.c tests/bw_warp_sim_tc.h tests/bw_hmma_mod GPU_TILELAB_TEST = $(OUT_DIR)/gpu_tilelab_test $(GPU_TILELAB_TEST): tests/gpu_tilelab_test.c src/omega_gpu_gemm.h src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_tilelab_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm -.PHONY: test-gpu-scan test-gpu-gemm test-tilelab-host +TILELAB_OMC ?= $(OMEGA_MV)/seed/out/omc +TILELAB_HOST_FAULT = $(OUT_DIR)/gpu_tilelab_host_fault +TILELAB_FAULT_GATE = $(OUT_DIR)/tilelab_host_fault +TILELAB_REPLAY = $(OUT_DIR)/tilelab_replay + +# The fault binary compiles out device/session calls; the .om conductor invokes no shell. +$(TILELAB_HOST_FAULT): tests/gpu_tilelab_test.c src/omega_gpu_gemm.h src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a + $(CC) $(CFLAGS) -ffp-contract=off -DTILELAB_HOST_FAULT -Itests -o $@ tests/gpu_tilelab_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +.PHONY: tilelab-compiler-check test-gpu-scan test-gpu-gemm test-tilelab-host tilelab-replay +tilelab-compiler-check: + @test -x "$(TILELAB_OMC)" || { echo "NOT_RUN: set TILELAB_OMC to the tools/c5/omc.pin compiler"; exit 3; } + @read repo rev unit hash < tools/c5/omc.pin; printf '%s %s\n' "$$hash" "$(TILELAB_OMC)" | sha256sum -c - +$(TILELAB_FAULT_GATE): tools/tilelab_process.om tests/tilelab_host_fault.om | tilelab-compiler-check + @mkdir -p $(OUT_DIR) + cat tools/tilelab_process.om tests/tilelab_host_fault.om > $@.om + $(TILELAB_OMC) < $@.om > $@.tmp + chmod +x $@.tmp + mv $@.tmp $@ +$(TILELAB_REPLAY): tools/tilelab_process.om tools/tilelab_replay.om | tilelab-compiler-check + @mkdir -p $(OUT_DIR) + cat tools/tilelab_process.om tools/tilelab_replay.om > $@.om + $(TILELAB_OMC) < $@.om > $@.tmp + chmod +x $@.tmp + mv $@.tmp $@ +tilelab-replay: $(TILELAB_REPLAY) test-gpu-scan: $(GPU_SCAN_TEST) ./$(GPU_SCAN_TEST) --sim test-gpu-gemm: $(GPU_GEMM_TEST) ./$(GPU_GEMM_TEST) --sim -test-tilelab-host: $(GPU_TILELAB_TEST) +test-tilelab-host: $(GPU_TILELAB_TEST) $(TILELAB_HOST_FAULT) $(TILELAB_FAULT_GATE) $(TILELAB_REPLAY) ./$(GPU_TILELAB_TEST) --host-only + ./$(TILELAB_FAULT_GATE) ./$(TILELAB_HOST_FAULT) ./$(TILELAB_REPLAY) "$$(mktemp -u -d $(OUT_DIR)/tilelab-host.XXXXXXXX)" diff --git a/om/encoder/bw_spec_cmp.om b/om/encoder/bw_spec_cmp.om index 250c2167..9e6f94b3 100644 --- a/om/encoder/bw_spec_cmp.om +++ b/om/encoder/bw_spec_cmp.om @@ -4,8 +4,14 @@ fn read_exact fd int buf edit uchar 128 n ulong to long got = ulong 0 while lt got n bound 128 r = read fd buf got sub n got -if le r 0 -ret r +if lt r 0 +ret -1 +end +if eq r 0 +if ne got 0 +ret -1 +end +ret 0 end got = add got ulong r end @@ -29,6 +35,51 @@ put o i unpack_u64 buf off end end +note Compare active semantic roles, not inactive packing slots. Zero control +note and FSET default are documented canonicalizations, absent RA/RB means RZ. +fn same_sem o view ulong 16 dec view ulong 16 to bool +idx = sp_find o +if eq idx 63 +ret false +end +if ne sp_find dec idx +ret false +end +if ne get o 0 get dec 0 +ret false +end +base = mul idx 45 +control = get o 7 +if eq control 0 +control = get sp_tbl add base 8 +if eq get o 0 46 +if and eq get o 6 0 eq get o 9 0 +control = 1032192 +else +control = 1042944 +end +end +end +if ne control get dec 7 +ret false +end +nf = get sp_tbl add base 9 +for f ulong nf +fb = add add base 10 mul f 7 +role = get sp_tbl fb +word = get sp_tbl add fb 1 +a = sp_val role word o +b = sp_val role word dec +if and eq role R_FSET eq a 0 +a = 66084864 +end +if ne a b +ret false +end +end +ret true +end + fn run_check_loop corrupt bool to int buf = new uchar 128 0 o = new ulong 16 0 @@ -39,7 +90,10 @@ count = ulong 0 while lt count 500 bound 500 r = read_exact int 0 buf 128 -if le r 0 +if lt r 0 +ret 2 +end +if eq r 0 break end unpack_case buf o @@ -63,7 +117,7 @@ dst = sp_dec w_spec o_dec if ne dst 0 ret 1 end -if ne get o_dec 0 get o 0 +if not same_sem o o_dec ret 1 end count = add count 1 @@ -147,6 +201,7 @@ fn run_neg_mutant to int o = new ulong 16 0 w_mut = new ulong 4 0 w_ref = new ulong 4 0 +decoded = new ulong 16 0 put o 0 1 put o 1 5 r_ref = enc1 o w_ref @@ -174,6 +229,12 @@ end if same ret 1 end +if ne sp_dec w_mut decoded E_OK +ret 1 +end +if same_sem o decoded +ret 1 +end ret 0 end diff --git a/om/encoder/bw_spec_corpus.om b/om/encoder/bw_spec_corpus.om index 319b6366..32f653b0 100644 --- a/om/encoder/bw_spec_corpus.om +++ b/om/encoder/bw_spec_corpus.om @@ -17,7 +17,7 @@ ret end if eq role 7 put o 5 val -put o 13 1 +put o 14 1 ret end put o 3 val @@ -158,6 +158,16 @@ min_v = get sp_tbl add fbase 5 max_v = get sp_tbl add fbase 6 v_idx = get_v_idx c_i f_i nf val = get_fld_val min_v max_v v_idx +note Fixtures deliberately choose representable special-layout immediates. +note Refusal tests separately retain the raw nonrepresentable boundaries. +if eq role R_LDC +shift = get sp_tbl add fbase 2 +step = shr ulong 256 shift +val = mul div val step step +end +if eq role R_BSSY +val = add and sub val 1 268435455 1 +end set_o_field role word val op o end @@ -170,6 +180,9 @@ emit_one_field fbase c_i f_i nf op o end finalize_o op var o st = write_case o buf +if ne sp_find o div base 45 +ret 2 +end if ne st 0 ret 1 end @@ -186,21 +199,22 @@ nf = get sp_tbl add base 9 if eq nf 0 clear_o o op finalize_o op var o +if ne sp_find o idx +ret 2 +end ret write_case o buf end if eq nf 1 fbase = add base 10 -role = get sp_tbl fbase -word = get sp_tbl add fbase 1 -min_v = get sp_tbl add fbase 5 -max_v = get sp_tbl add fbase 6 for c_i ulong 4 clear_o o op -val = get_fld_val min_v max_v c_i -set_o_field role word val op o +emit_one_field fbase c_i 0 1 op o finalize_o op var o st1 = write_case o buf +if ne sp_find o idx +ret 2 +end if ne st1 0 ret 1 end @@ -221,5 +235,9 @@ if ne st 0 ret 1 end end +note Fault control: a complete valid stream followed by producer failure. +if ge argcnt 2 +ret 7 +end ret 0 end diff --git a/om/encoder/bw_spec_regress.om b/om/encoder/bw_spec_regress.om new file mode 100644 index 00000000..0d6bd3aa --- /dev/null +++ b/om/encoder/bw_spec_regress.om @@ -0,0 +1,118 @@ +note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +note Host audit regressions ENC155-01..07. No device entry points. +fn require yes bool to void +if not yes +exit 80 +end +end +fn reset_o o edit ulong 16 op ulong to void +for i ulong 16 +put o i 0 +end +put o 0 op +end +fn parity o view ulong 16 to void +w = new ulong 4 0 +ref = new ulong 4 0 +dec = new ulong 16 0 +require eq enc1 o ref E_OK +require eq sp_enc o w E_OK +for i ulong 4 +require eq get w i get ref i +end +require eq sp_dec w dec E_OK +require same_sem o dec +end +fn emit_words o view ulong 16 to void +w = new ulong 4 0 +buf = new uchar 16 0 +require eq sp_enc o w E_OK +for i ulong 4 +v = get w i +off = mul i 4 +for b ulong 4 +byte_v = uchar and shr v mul b 8 255 +put buf add off b byte_v +end +end +require eq write 1 buf 0 16 16 +end +fn main to int +w = new ulong 4 4294967295 +dec = new ulong 16 0 +buf128 = new uchar 128 0 +o = new ulong 16 0 +mode = new uchar 16 0 +note Cold decoder must initialize without any prior encoder call. +require eq sp_dec w dec E_NOMAT +note All absent RA/RB operands must encode RZ, independently byte checked. +for j ulong 3 +reset_o o add 51 j +put o 1 4 +put o 4 7 +parity o +end +note RRU destination is a full GPR, not a uniform register. +reset_o o 8 +put o 1 32 +put o 2 1 +put o 5 2 +put o 4 3 +put o 8 1 +put o 12 1 +put o 14 1 +parity o +require eq sp_enc o w E_OK +require eq sp_dec w dec E_OK +put dec 8 0 +require not same_sem o dec +note Optional sample output for offline nvdisasm, no binary listing committed. +if ge argcnt 2 +got = argread 1 mode 0 16 +require gt got 0 +if eq get mode 0 122 +reset_o o add ulong 51 sub ulong get mode 1 48 +put o 1 4 +put o 4 7 +end +emit_words o +ret 0 +end +reset_o o 42 +put o 6 32 +require eq sp_enc o w E_RANGE +reset_o o 51 +put o 6 256 +require eq sp_enc o w E_RANGE +reset_o o 10 +put o 1 8 +require eq sp_enc o w E_RANGE +reset_o o 12 +put o 6 4294967296 +require eq sp_enc o w E_RANGE +reset_o o 4 +put o 6 1 +require eq sp_enc o w E_RANGE +put o 6 262143 +require eq sp_enc o w E_RANGE +reset_o o 54 +put o 6 2147483647 +require eq sp_enc o w E_RANGE +reset_o o 46 +put o 6 4294967296 +require eq sp_enc o w E_RANGE +note A decoded active operand mutation must fail semantically. +reset_o o 8 +put o 13 1 +require eq sp_enc o w E_OK +require eq sp_dec w dec E_OK +require same_sem o dec +put dec 1 add get dec 1 1 +require not same_sem o dec +require eq sp_dec w dec E_OK +put dec 7 xor get dec 7 1 +require not same_sem o dec +note Read errors and partial EOF are distinct from clean EOF. +require eq read_exact int -1 buf128 128 -1 +ret 0 +end diff --git a/om/encoder/bw_spec_sm121.om b/om/encoder/bw_spec_sm121.om index fe3591cb..d2ed1c93 100644 --- a/om/encoder/bw_spec_sm121.om +++ b/om/encoder/bw_spec_sm121.om @@ -175,9 +175,9 @@ set_hdr 9 8 1 2083328 4 set_w0 9 31780 65535 set_w1 9 0 4294967040 set_w2 9 260964864 4294967040 -set_fld 9 0 5 0 16 -set_bnd 9 0 5 0 0 -set_max 9 0 31 +set_fld 9 0 1 0 16 +set_bnd 9 0 8 0 0 +set_max 9 0 255 set_fld 9 1 2 0 24 set_bnd 9 1 8 0 0 set_max 9 1 255 @@ -931,9 +931,21 @@ if or eq role R_RD eq role R_URD ret get o 1 end if or eq role R_RA eq role R_URA +op = get o 0 +if and eq role R_RA or eq op 51 or eq op 52 eq op 53 +if eq get o 12 0 +ret 255 +end +end ret get o 2 end if eq role R_RB +op = get o 0 +if or eq op 51 or eq op 52 eq op 53 +if eq get o 13 0 +ret 255 +end +end ret get o 3 end if eq role R_URB @@ -948,9 +960,9 @@ ret get o 4 end if eq role R_PRED3 if eq word 0 -ret and get o 1 7 +ret get o 1 end -ret and get o 4 7 +ret get o 4 end if eq role R_PRED if eq get o 9 0 @@ -965,16 +977,16 @@ if eq role R_BAR ret get o 11 end if eq role R_SHFL -ret and get o 6 31 +ret get o 6 end if eq role R_LUT -ret and get o 6 255 +ret get o 6 end ret get o 6 end fn sp_off24 imm ulong to bool -ret or lt imm 8388608 ge imm 4286578688 +ret or lt imm 8388608 and ge imm 4286578688 le imm 4294967295 end fn sp_chkr role ulong val ulong min_v ulong max_v ulong to bool @@ -988,7 +1000,7 @@ if eq role R_LDSW ret lt val 8388608 end if eq role R_BRA -ret true +ret le val 4294967295 end ret not or lt val min_v lt max_v val end @@ -1049,6 +1061,19 @@ if not ok ret E_RANGE end sp_fput fbase val w +note Reject values whose special bit layout would discard semantic bits. +probe = new ulong 16 0 +special = sp_dimm role fbase w probe +if special +if eq role R_FSET +if eq val 0 +ret E_OK +end +end +if ne get probe 6 val +ret E_RANGE +end +end ret E_OK end @@ -1172,6 +1197,11 @@ ret end if or eq role R_RB eq role R_URB if eq role R_URB +op = get o 0 +if or eq op 6 eq op 7 +put o 1 raw +ret +end put o 5 raw put o 14 1 else @@ -1216,6 +1246,7 @@ put o 6 raw end fn sp_dec w view ulong 4 o edit ulong 16 to ulong +sp_init idx = sp_dfnd w if eq idx 63 ret E_NOMAT diff --git a/tests/gpu_tilelab_test.c b/tests/gpu_tilelab_test.c index e8af0ea6..f568109b 100644 --- a/tests/gpu_tilelab_test.c +++ b/tests/gpu_tilelab_test.c @@ -51,24 +51,116 @@ static uint64_t oracle(uint32_t M, uint32_t N, uint32_t K, const uint16_t *A, co *checked = ck; return bad; } +/* Consume the entire list, including separators and capacity. Never test a prefix. */ +static int shape_uint(const char **sp, uint32_t *v) { + const unsigned char *p = (const unsigned char *)*sp; uint32_t n = 0; + if (*p < '0' || *p > '9') return -1; + do { + unsigned d = *p++ - '0'; + if (n > UINT32_MAX / 10 || (n == UINT32_MAX / 10 && d > UINT32_MAX % 10)) return -1; + n = n * 10 + d; + } while (*p >= '0' && *p <= '9'); + if (!n) return -1; + *v = n; *sp = (const char *)p; return 0; +} static int parse_shape(const char *s, uint32_t sh[][3], int *n) { *n = 0; - while (*s && *n < MAXSH) { unsigned m, nn, k; int used = 0; if (sscanf(s, "%u,%u,%u%n", &m, &nn, &k, &used) < 3 || !m || !nn || !k) return -1; sh[*n][0] = m; sh[*n][1] = nn; sh[*n][2] = k; (*n)++; s += used; if (*s == ';') s++; } - return *n ? 0 : -1; + for (;;) { + if (*n == MAXSH) return -1; + for (int i = 0; i < 3; i++) { + if (shape_uint(&s, &sh[*n][i])) return -1; + if (i < 2 && *s++ != ',') return -1; + } + (*n)++; + if (!*s) return 0; + if (*s++ != ';' || !*s) return -1; + } } +/* RFC 3629: reject overlong forms, surrogates, truncated sequences and >U+10FFFF. */ +static int valid_utf8(const char *s) { + const unsigned char *p = (const unsigned char *)s; + while (*p) { + unsigned c = *p++, count, lo = 0x80, hi = 0xbf; + if (c < 0x80) continue; + if (c >= 0xc2 && c <= 0xdf) count = 1; + else if (c >= 0xe0 && c <= 0xef) { + count = 2; + if (c == 0xe0) lo = 0xa0; + if (c == 0xed) hi = 0x9f; + } else if (c >= 0xf0 && c <= 0xf4) { + count = 3; + if (c == 0xf0) lo = 0x90; + if (c == 0xf4) hi = 0x8f; + } else return 0; + for (unsigned i = 0; i < count; i++) { + if (*p < lo || *p > hi) return 0; + p++; lo = 0x80; hi = 0xbf; + } + } + return 1; +} + +static void json_string(FILE *f, const char *s) { + fputc('"', f); + for (const unsigned char *p = (const unsigned char *)s; *p; p++) { + if (*p == '"' || *p == '\\') { fputc('\\', f); fputc(*p, f); } + else if (*p < 32) fprintf(f, "\\u%04x", *p); + else fputc(*p, f); + } + fputc('"', f); +} + +#ifdef TILELAB_HOST_FAULT +/* Host regression build only. No delegation to any device or session entry point. */ +static OmegaGemmCfg fault_cfg; +static const char *fault_mode = ""; +static unsigned fault_calls; +static int fault_set_cfg(OmegaGpuGemmType type, const OmegaGemmCfg *cfg) { + if (cfg) fault_cfg = *cfg; else omega_gpu_gemm_default_cfg(type, &fault_cfg); + return 0; +} +static int fault_gemm(OmegaGpuGemmType type, unsigned layout, uint32_t M, uint32_t N, uint32_t K, + const void *va, const void *vb, float *C, OmegaGpuGemmInfo *info) { + (void)type; (void)layout; fault_calls++; + if ((!strcmp(fault_mode, "warm_error") && fault_calls == 2) || + (!strcmp(fault_mode, "timed_error") && fault_calls == 3) || + (!strcmp(fault_mode, "mutant_error") && fault_cfg.mutant)) + return OMEGA_GPU_GEMM_CHIP_FAIL; + const uint16_t *A = va, *B = vb; + for (uint32_t r = 0; r < M; r++) for (uint32_t c = 0; c < N; c++) { + double s = 0; + for (uint32_t k = 0; k < K; k++) s += bf(A[(size_t)r * K + k]) * bf(B[(size_t)k * N + c]); + C[(size_t)r * N + c] = (float)s; + if (fault_cfg.mutant && strcmp(fault_mode, "mutant_good")) C[(size_t)r * N + c] += 10.0f; + } + if (info) { memset(info, 0, sizeof *info); info->main_ns = 1000; info->pack_ns = 1000; } + return 0; +} +#define omega_gpu_gemm_test_set_cfg fault_set_cfg +#define omega_gpu_gemm fault_gemm +#define omega_gpu_session_last_error() "synthetic host fault" +#endif + int main(int argc, char **argv) { +#ifdef TILELAB_HOST_FAULT + puts("TILELAB: synthetic CPU fault build; GPU NOT_RUN"); +#endif const char *out = NULL, *shapes = "1024,1024,1024"; int host = 0, rounds = 7; uint32_t sh[MAXSH][3]; int nsh; omega_gpu_gemm_default_cfg(OMEGA_GPU_GEMM_BF16, &arms[0].c); strcpy(arms[0].name, "default"); narms = 1; for (int i = 1; i < argc; i++) { if (!strcmp(argv[i], "--host-only")) host = 1; +#ifdef TILELAB_HOST_FAULT + else if (!strcmp(argv[i], "--fault") && i + 1 < argc) fault_mode = argv[++i]; +#endif else if (!strcmp(argv[i], "--out") && i + 1 < argc) out = argv[++i]; else if (!strcmp(argv[i], "--shapes") && i + 1 < argc) shapes = argv[++i]; else if (!strcmp(argv[i], "--rounds") && i + 1 < argc) { rounds = atoi(argv[++i]); if (rounds < 1 || rounds > MAXR) { fprintf(stderr, "rounds 1..%d\n", MAXR); return 2; } } else if (!strcmp(argv[i], "--cfg") && i + 1 < argc && narms < MAXCFG) { Arm *a = &arms[narms]; unsigned rt, ct, wm, wn, band; char nm[40]; if (sscanf(argv[++i], "%39[^:]:%u,%u,%u,%u,%u", nm, &rt, &ct, &wm, &wn, &band) != 6) { fprintf(stderr, "bad --cfg\n"); return 2; } + if (!valid_utf8(nm)) { fprintf(stderr, "bad --cfg: arm name must be UTF-8\n"); return 2; } omega_gpu_gemm_default_cfg(OMEGA_GPU_GEMM_BF16, &a->c); a->c.rt = rt; a->c.ct = ct; a->c.wm = wm; a->c.wn = wn; a->c.band = band; strcpy(a->name, nm); narms++; } else { fprintf(stderr, "usage: %s [--host-only] [--shapes S] [--cfg name:rt,ct,wm,wn,band]... [--rounds N] [--out FILE]\n", argv[0]); return 2; } @@ -91,7 +183,14 @@ int main(int argc, char **argv) { int jfd = out ? open(out, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644) : -1; FILE *js = jfd >= 0 ? fdopen(jfd, "w") : NULL; if (out && !js) { perror(out); if (jfd >= 0) close(jfd); return 2; } - if (js) fprintf(js, "{\"tool\":\"gpu_tilelab_test\",\"rounds\":%d,\"cells\":[", rounds); + if (js) { +#ifdef TILELAB_HOST_FAULT + fprintf(js, "{\"execution\":\"synthetic-host\","); +#else + fprintf(js, "{\"execution\":\"device\","); +#endif + fprintf(js, "\"tool\":\"gpu_tilelab_test\",\"rounds\":%d,\"cells\":[", rounds); + } int firstcell = 1; for (int s = 0; s < nsh; s++) { uint32_t M = sh[s][0], N = sh[s][1], K = sh[s][2]; @@ -114,8 +213,17 @@ int main(int argc, char **argv) { for (int j = 0; j < narms; j++) { int a = (j + r) % narms; if (!ok[a] || wrong[a]) continue; omega_gpu_gemm_test_set_cfg(OMEGA_GPU_GEMM_BF16, &arms[a].c); - OmegaGpuGemmInfo info; omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, M, N, K, A, B, C, &info); /* warm: builds the kernels */ - if (omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, M, N, K, A, B, C, &info)) { fails++; continue; } + OmegaGpuGemmInfo info; + int rc = omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, M, N, K, A, B, C, &info); /* warm: builds kernels */ + if (rc) { + printf("%ux%ux%u %s: warmup rc %s: %s\n", M, N, K, arms[a].name, omega_gpu_gemm_rc_name(rc), omega_gpu_session_last_error()); + ok[a] = 0; fails++; continue; + } + rc = omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, M, N, K, A, B, C, &info); + if (rc) { + printf("%ux%ux%u %s: timed rc %s: %s\n", M, N, K, arms[a].name, omega_gpu_gemm_rc_name(rc), omega_gpu_session_last_error()); + ok[a] = 0; fails++; continue; + } samp[a][ns[a]++] = info.main_ns / 1e6; } for (int a = 0; a < narms; a++) { @@ -125,7 +233,9 @@ int main(int argc, char **argv) { double p50 = pct(sc, ns[a], 0.5), p95 = pct(sc, ns[a], 0.95), tf = 2.0 * M * N * K / (p50 * 1e-3) / 1e12; printf("%ux%ux%u %-12s main p50 %.4f ms p95 %.4f ms %.2f TFLOPS gpr %u worst err/bound %.3f (%" PRIu64 " checked)\n", M, N, K, m->name, p50, p95, tf, gpr[a], worst[a], chk[a]); if (js) { - fprintf(js, "%s{\"m\":%u,\"n\":%u,\"k\":%u,\"arm\":\"%s\",\"rt\":%u,\"ct\":%u,\"wm\":%u,\"wn\":%u,\"band\":%u,\"gpr_main\":%u,\"p50_ms\":%.6f,\"p95_ms\":%.6f,\"tflops_p50\":%.4f,\"pack_ms_first\":%.6f,\"worst_err_over_bound\":%.6f,\"checked\":%" PRIu64 ",\"wrong\":%" PRIu64 ",\"samples_ms\":[", firstcell ? "" : ",", M, N, K, m->name, m->c.rt, m->c.ct, m->c.wm, m->c.wn, m->c.band, gpr[a], p50, p95, tf, packms[a], worst[a], chk[a], wrong[a]); + fprintf(js, "%s{\"m\":%u,\"n\":%u,\"k\":%u,\"arm\":", firstcell ? "" : ",", M, N, K); + json_string(js, m->name); + fprintf(js, ",\"rt\":%u,\"ct\":%u,\"wm\":%u,\"wn\":%u,\"band\":%u,\"gpr_main\":%u,\"p50_ms\":%.6f,\"p95_ms\":%.6f,\"tflops_p50\":%.4f,\"pack_ms_first\":%.6f,\"worst_err_over_bound\":%.6f,\"checked\":%" PRIu64 ",\"wrong\":%" PRIu64 ",\"samples_ms\":[", m->c.rt, m->c.ct, m->c.wm, m->c.wn, m->c.band, gpr[a], p50, p95, tf, packms[a], worst[a], chk[a], wrong[a]); for (int i = 0; i < ns[a]; i++) fprintf(js, "%s%.6f", i ? "," : "", samp[a][i]); fprintf(js, "]}"); firstcell = 0; } @@ -140,12 +250,21 @@ int main(int argc, char **argv) { for (int i = 0; i < 65 * 100; i++) A[i] = rbf(); for (int i = 0; i < 100 * 63; i++) B[i] = rbf(); int rc = omega_gpu_gemm(OMEGA_GPU_GEMM_BF16, 0, 65, 63, 100, A, B, C, NULL); - uint64_t bad = rc ? 1 : oracle(65, 63, 100, A, B, C, &w, &ck); + if (rc) { + printf("red: mutant %d RUNTIME ERROR rc %s: %s (oracle NOT_RUN)\n", mut, omega_gpu_gemm_rc_name(rc), omega_gpu_session_last_error()); + fails++; continue; + } + uint64_t bad = oracle(65, 63, 100, A, B, C, &w, &ck); printf("red: mutant %d %s (%" PRIu64 " wrong)\n", mut, bad ? "CAUGHT" : "NOT CAUGHT", bad); caught += bad > 0; } if (caught != 3) fails++; omega_gpu_gemm_test_set_cfg(OMEGA_GPU_GEMM_BF16, NULL); - if (js) { fprintf(js, "],\"red_mutants_caught\":%d,\"fails\":%d}\n", caught, fails); fclose(js); } + if (js) { + fprintf(js, "],\"red_mutants_caught\":%d,\"fails\":%d}\n", caught, fails); + int output_error = ferror(js); + if (fclose(js)) output_error = 1; + if (output_error) { fprintf(stderr, "receipt output failed: %s\n", out); return 2; } + } printf("TILELAB_CHIP: %s\n", fails ? "FAIL" : "PASS"); return fails ? 1 : 0; } diff --git a/tests/tilelab_host_fault.om b/tests/tilelab_host_fault.om new file mode 100644 index 00000000..f00b4308 --- /dev/null +++ b/tests/tilelab_host_fault.om @@ -0,0 +1,223 @@ +note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +note Concatenate after tools/tilelab_process.om. Args: HOST_FAULT_DRIVER REPLAY NEW_SCRATCH_DIR +note All GEMMs are CPU fault injection in an explicitly separate compile-time driver build. +text ttwords "--shapes\n2,2,2\n--rounds\n1\n--out\n--fault\nmutant_error\nwarm_error\ntimed_error\nmutant_good\n--host-only\n--cfg\nbad\"name\\arm\t:2,4,2,4,8\n\"red_mutants_caught\":3\n\"arm\":\"bad\\\"name\\\\arm\\u0009\"\n\"fails\":0\n/dev/full\n/bin/false\n/nonexistent/tilelab-driver\nx:2,4,2,4,8\n\"red_mutants_caught\":0\n\"cells\":[]\n\"arm\"\ncafé € 😀:2,4,2,4,8\n\"arm\":\"café € 😀\"\n" +text ttsuffix "/receipt.json" +text ttshape "2,2,2" +text ttbad "garbage" +text ttpass "TILELAB_HOST_FAULT PASS (synthetic CPU only; GPU NOT_RUN)\n" +global tf uchar 65536 +global tfn ulong 1 +fn tt_check good bool to void +if not good +exit 1 +end +end +fn tt_addword idx ulong to void +tl_word idx +tl_add +end +fn tt_path to void +tl_arg 3 +n = get tn 0 +tt_check le add n len ttsuffix 4095 +for i ulong len ttsuffix +put tb add n i get ttsuffix i +end +put tn 0 add n len ttsuffix +end +fn tt_base to void +tl_clear +tl_arg 1 +tl_add +tt_addword 0 +tt_addword 1 +tt_addword 2 +tt_addword 3 +end +fn tt_out to void +tt_addword 4 +tt_path +tl_add +end +fn tt_read to void +fd = fopen tb 0 get tn 0 0 0 +tt_check ge fd 0 +n = ulong 0 +while lt n len tf bound 65536 +r = read int fd tf n sub len tf n +tt_check ge r 0 +if eq r 0 +break +end +n = add n ulong r +end +tt_check lt n len tf +put tfn 0 n +tt_check eq fclose int fd 0 +end +fn tt_match p ulong n ulong to bool +for i ulong n +if ne get tf add p i get tb i +ret false +end +end +ret true +end +fn tt_count word ulong to ulong +tl_word word +count = ulong 0 +n = get tn 0 +if gt n get tfn 0 +ret 0 +end +for p ulong add sub get tfn 0 n 1 +if tt_match p n +count = add count 1 +end +end +ret count +end +fn tt_receipt to void +tt_path +tt_read +end +fn tt_fault word ulong want int to void +tt_base +tt_out +tt_addword 5 +tt_addword word +tt_check eq tl_run want +tt_receipt +end +fn tt_shapes count ulong bad bool to void +tl_clear +tl_arg 1 +tl_add +tt_addword 10 +tt_addword 0 +p = ulong 0 +for i ulong count +if ne i 0 +put tb p 59 +p = add p 1 +end +for j ulong len ttshape +put tb p get ttshape j +p = add p 1 +end +end +if bad +put tb p 59 +p = add p 1 +for i ulong len ttbad +put tb p get ttbad i +p = add p 1 +end +end +put tn 0 p +tl_add +end +fn tt_replay driver ulong count ulong want int to void +tl_clear +tl_arg 2 +tl_add +if eq driver 0 +tl_arg 1 +else +tl_word driver +end +tl_add +tt_path +tl_add +tt_addword 1 +tt_addword 3 +for i ulong count +tt_addword 19 +end +tt_check eq tl_run want +end +fn tt_chunk digit uchar arms ulong to void +tt_path +p = get tn 0 +put tb p 46 +put tb add p 1 digit +put tb add p 2 46 +put tb add p 3 106 +put tb add p 4 115 +put tb add p 5 111 +put tb add p 6 110 +put tn 0 add p 7 +tt_read +tt_check eq tt_count 22 arms +tt_check eq tt_count 15 1 +end +fn tt_invalid to void +tt_base +tt_addword 11 +tl_word 19 +note A standalone non-UTF8 byte in an otherwise valid configuration must be refused. +put tb 0 255 +tl_add +tt_check eq tl_run 2 +end +fn main to int +tt_check eq argcnt 4 +for i ulong len ttwords +put tw i get ttwords i +end +tl_arg 3 +tt_check eq makedir tb 0 get tn 0 448 0 +tt_shapes 16 false +tt_check eq tl_run 0 +tt_shapes 17 false +tt_check eq tl_run 2 +tt_shapes 16 true +tt_check eq tl_run 2 +tt_shapes 0 true +tt_check eq tl_run 2 +note Baseline successful synthetic executions must catch real wrong-result mutants. +tt_base +tt_out +tt_addword 11 +tt_addword 12 +tt_check eq tl_run 0 +tt_receipt +tt_check eq tt_count 13 1 +tt_check eq tt_count 14 1 +tt_check eq tt_count 15 1 +note Multibyte identifiers preserve their UTF8 bytes, unlike bytewise Unicode escaping. +tt_base +tt_out +tt_addword 11 +tt_addword 23 +tt_check eq tl_run 0 +tt_receipt +tt_check eq tt_count 24 1 +tt_invalid +note Runtime errors are not oracle catches. Failed warmup/timed work has no successful cell. +tt_fault 6 1 +tt_check eq tt_count 20 1 +tt_fault 7 1 +tt_check eq tt_count 21 1 +tt_fault 8 1 +tt_check eq tt_count 21 1 +note Negative control: successfully executed mutants with correct results must fail. +tt_fault 9 1 +tt_check eq tt_count 20 1 +note Opening succeeds but buffered receipt writes fail. +tt_base +tt_addword 4 +tt_addword 16 +tt_check eq tl_run 2 +note Replay propagates child failure and exec failure, and chunks 31 cfgs across three children. +tt_replay 17 0 1 +tt_replay 18 0 127 +tt_replay 0 31 0 +tt_chunk 48 16 +tt_chunk 49 16 +tt_chunk 50 2 +r = write 1 ttpass 0 len ttpass +tt_check eq r long len ttpass +ret 0 +end diff --git a/tools/test_bw_spec_encoder.sh b/tools/test_bw_spec_encoder.sh index d6c6d008..54c4f41a 100755 --- a/tools/test_bw_spec_encoder.sh +++ b/tools/test_bw_spec_encoder.sh @@ -85,8 +85,23 @@ chmod 755 "$WORK/cmp" # 4. Running verification (a): byte-identity on boundary corpus against bw_enc_sm121.om log "4. Running verification (a): byte-identity on boundary corpus against bw_enc_sm121.om..." -"$WORK/corpus" | "$WORK/cmp" || { - echo "FAIL: byte identity or decode verification failed on boundary corpus" >&2 +produce() { + destination=$1 + shift + if "$WORK/corpus" "$@" > "$destination"; then + return 0 + else + producer_rc=$? + echo "FAIL: corpus producer failed ($producer_rc)" >&2 + return "$producer_rc" + fi +} +produce "$WORK/corpus.bin" +rc=0 +produce "$WORK/producer-failed.bin" fault > /dev/null 2>&1 || rc=$? +[ "$rc" -eq 7 ] || { echo "FAIL: terminal producer error expected 7, got $rc" >&2; exit 1; } +"$WORK/cmp" < "$WORK/corpus.bin" || { + echo "FAIL: byte identity or semantic decode verification failed on boundary corpus" >&2 exit 1 } log "PASS: (a) spec-driven encoder matches bw_enc_sm121.om on all 461 boundary cases byte-for-byte!" @@ -169,10 +184,47 @@ log "PASS: out-of-range register 256 refused with declared error E_RANGE (code 2 log "PASS: invalid word pattern refused with declared error E_NOMAT (code 3)" # Negative control 4: corrupted expected byte fails byte-identity comparison (exit 1) -if "$WORK/corpus" | "$WORK/cmp" corrupt > /dev/null 2>&1; then - echo "FAIL: corrupted expected byte did not fail byte-identity comparison!" >&2 +rc=0 +"$WORK/cmp" corrupt < "$WORK/corpus.bin" > /dev/null 2>&1 || rc=$? +if [ "$rc" -ne 1 ]; then + echo "FAIL: corrupt control expected semantic mismatch 1, got $rc" >&2 exit 1 fi log "PASS: corrupted expected byte fails byte-identity comparison (exit 1)" +# Audit controls: build failures are never treated as semantic mutant kills. +sed '/^fn main to int/,$d' "$CMP_OM" > "$WORK/cmp_nomain.om" +cat "$ENC_OM" "$WORK/spec_nomain.om" "$WORK/cmp_nomain.om" om/encoder/bw_spec_regress.om > "$WORK/regress.om" +"$OMC" < "$WORK/regress.om" > "$WORK/regress" 2> "$WORK/regress.err" || { + cat "$WORK/regress.err" >&2 + exit 1 +} +chmod 755 "$WORK/regress" +"$WORK/regress" +for bytes in 1 127; do + cp "$WORK/corpus.bin" "$WORK/partial.bin" + dd if=/dev/zero bs=1 count="$bytes" >> "$WORK/partial.bin" 2>/dev/null + rc=0 + "$WORK/cmp" < "$WORK/partial.bin" || rc=$? + [ "$rc" -eq 2 ] || { echo "FAIL: partial-record expected 2, got $rc" >&2; exit 1; } +done +if [ -x "$NVDISASM" ]; then + "$WORK/regress" sample > "$WORK/rru.bin" + "$NVDISASM" -b SM121 "$WORK/rru.bin" > "$WORK/rru.dis" + grep -Eq 'IMAD[[:space:]]+R32, R1, UR2, R3[[:space:]]*;' "$WORK/rru.dis" || { + echo "FAIL: nvdisasm RRU operand mismatch" >&2; exit 1; + } + for sample in z0 z1 z2; do + "$WORK/regress" "$sample" > "$WORK/$sample.bin" + "$NVDISASM" -b SM121 "$WORK/$sample.bin" > "$WORK/$sample.dis" + grep -Eq 'R4, RZ, RZ, R7' "$WORK/$sample.dis" || { + echo "FAIL: nvdisasm absent-source RZ mismatch ($sample)" >&2; exit 1; + } + done +else + echo "NOT_RUN: required independent operand oracle nvdisasm" >&2 + exit 3 +fi +log "PASS: audit raw ranges, absent RZ parity, cold decode, active-operand mutant, read error and truncated records" + log "ALL SPEC-DRIVEN ENCODER/DECODER VERIFICATIONS PASSED (HOST_TESTED)!" diff --git a/tools/tilelab_process.om b/tools/tilelab_process.om new file mode 100644 index 00000000..63273b67 --- /dev/null +++ b/tools/tilelab_process.om @@ -0,0 +1,77 @@ +note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +note Shared bounded argument packing and direct child execution. No shell or GPU calls. +global ta uchar 4096 +global tb uchar 4096 +global tp ulong 2 +global tw uchar 4096 +global tn ulong 1 +global ts uchar 4 +fn tl_clear to void +put tp 0 2 +put tp 1 0 +end +fn tl_add to void +n = get tn 0 +p = get tp 0 +if or ge get tp 1 64 gt add add p n 2 4096 +exit 90 +end +put ta p uchar and n 255 +put ta add p 1 uchar shr n 8 +for i ulong n +put ta add add p 2 i get tb i +end +put tp 0 add add p 2 n +put tp 1 add get tp 1 1 +end +fn tl_arg idx ulong to void +n = argread idx tb 0 4095 +if lt n 0 +exit 90 +end +put tn 0 ulong n +end +fn tl_word idx ulong to void +note Both scans advance p once per pass through the fixed 4096-byte word pool. +p = ulong 0 +k = ulong 0 +while lt k idx bound 4096 +if ge p len tw +exit 90 +end +if eq get tw p 10 +k = add k 1 +end +p = add p 1 +end +n = ulong 0 +while lt p len tw bound 4096 +if eq get tw p 10 +break +end +put tb n get tw p +n = add n 1 +p = add p 1 +end +put tn 0 n +end +fn tl_run to int +put ta 0 uchar get tp 1 +put ta 1 0 +pid = fork +if lt pid 0 +ret 91 +end +if eq pid 0 +r = execprog ta 0 get tp 0 +exit 127 +end +r = waitpid int pid ts 0 4 0 +if ne r pid +ret 91 +end +if ne get ts 0 0 +ret 92 +end +ret int get ts 1 +end diff --git a/tools/tilelab_replay.om b/tools/tilelab_replay.om new file mode 100644 index 00000000..f14aa346 --- /dev/null +++ b/tools/tilelab_replay.om @@ -0,0 +1,87 @@ +note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +note Concatenate after tools/tilelab_process.om. Usage: DRIVER OUTPUT_PREFIX SHAPES ROUNDS [CFG...] +note Current replay, not a historical evidence script. Device driver requires operator GPU authorization. +text trwords "--shapes\n--rounds\n--out\n--cfg\n" +text trpass "TILELAB_REPLAY PASS\n" +fn tr_output group ulong to void +tl_arg 2 +p = get tn 0 +if gt p 4070 +exit 90 +end +put tb p 46 +p = add p 1 +start = p +v = group +while true bound 20 +put tb p uchar add rem v 10 48 +p = add p 1 +v = div v 10 +if eq v 0 +break +end +end +last = sub p 1 +while lt start last bound 20 +x = get tb start +put tb start get tb last +put tb last x +start = add start 1 +last = sub last 1 +end +put tb p 46 +put tb add p 1 106 +put tb add p 2 115 +put tb add p 3 111 +put tb add p 4 110 +put tn 0 add p 5 +end +fn main to int +if lt argcnt 5 +ret 90 +end +for i ulong len trwords +put tw i get trwords i +end +idx = ulong 5 +group = ulong 0 +while true bound 999999 +tl_clear +tl_arg 1 +tl_add +tl_word 0 +tl_add +tl_arg 3 +tl_add +tl_word 1 +tl_add +tl_arg 4 +tl_add +tl_word 2 +tl_add +tr_output group +tl_add +count = ulong 0 +while and lt idx ulong argcnt lt count 15 bound 15 +tl_word 3 +tl_add +tl_arg idx +tl_add +idx = add idx 1 +count = add count 1 +end +rc = tl_run +if ne rc 0 +ret rc +end +group = add group 1 +if ge idx ulong argcnt +break +end +end +r = write 1 trpass 0 len trpass +if ne r long len trpass +ret 93 +end +ret 0 +end