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/patches/f9dd55189cd8405b # 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 ## GitHub aien-dev/omega-mv#924 (code only) open derived `f9dd55189cd8405b` #924 Imported from GitHub aien-dev/omega-mv#924 (code only) GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed). Base `2638a49bd83d12c1e0c76a4c446d6be1c9a4d4f4` · Head `bf71d5cb678872a1780e9924fd7fc25202ed2ca6` github-advanced-security[bot] commented on `src/omega_blackwell_gates.c` line 600 on 2026-10-28 18:46 UTC ## CodeQL / Uncontrolled data used in path expression This argument to a file access function is derived from user input (an environment variable) and then passed to fopen(__filename). This argument to a file access function is derived from user input (an environment variable) and then passed to fopen(__filename). Show more details github-advanced-security[bot] commented on `src/omega_blackwell_gates.c` line 1220 on 2026-10-28 18:46 UTC ## CodeQL / File created without restricting permissions A file may be created here with mode 0666, which would make it world-writable. Show more details github-advanced-security[bot] commented on `src/omega_blackwell_gates.c` line 1220 on 2026-10-28 18:46 UTC ## CodeQL / Uncontrolled data used in path expression This argument to a file access function is derived from user input (string read by fgets) and then passed to fopen(__filename). Show more details github-advanced-security[bot] commented on `src/omega_blackwell_gates.c` line 1252 on 2026-10-28 18:46 UTC ## CodeQL / Uncontrolled data used in path expression This argument to a file access function is derived from user input (an environment variable) and then passed to compute_file_sha256(path), which calls fopen(__filename). This argument to a file access function is derived from user input (an environment variable) and then passed to compute_file_sha256(path), which calls fopen(__filename). Show more details github-advanced-security[bot] reviewed (COMMENTED) on 2026-10-28 18:46 UTC ### Fetch it A git bundle of the pull request's head, 168195 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/f9dd55189cd8405b.bundle -o f9dd55189cd8405b.bundle git fetch f9dd55189cd8405b.bundle refs/pull/924/head ``` Raw bundle · Diff ### Provenance This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record: ``` github-import 1 aien-dev/omega-mv 924 bf71d5cb678872a1780e9924fd7fc25202ed2ca6 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":924,"url":"https://github.com/aien-dev/omega-mv/pull/924","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:39:22Z","metadata":"unavailable","state_derived":true} ``` ### Changes ``` diff --git a/.crumb b/.crumb index 4c29c6660..4b1f89d5b 100644 --- a/.crumb +++ b/.crumb @@ -47,8 +47,8 @@ "purpose": "Directory calibration. Purpose not yet described by a human." }, { - "digest": "f00281122c0cb3bce9288b99d79cae539f9824faa48ac0bf3e0ce9e3020fed80", - "last_commit": "27997f9ba", + "digest": "5687ce12cd5ab387b3ec020ca7325923acdc085b4ccbfe45913ac38c36e7d296", + "last_commit": "28fbba3e4", "name": "docs", "purpose": "Directory docs. Purpose not yet described by a human." }, @@ -59,8 +59,8 @@ "purpose": "Directory doctrine. Purpose not yet described by a human." }, { - "digest": "c0668c8969cceab0f03ac6ab352ae579c8b473a9ec743d80c89fc187b769c12c", - "last_commit": "22011cbc9", + "digest": "5490f02828f11619c2a427905af48d9d2e3711067e60f72a34ea7b7a69a041b2", + "last_commit": "8e6277d4e", "name": "mk", "purpose": "Directory mk. Purpose not yet described by a human." }, @@ -84,38 +84,38 @@ }, { "digest": "18cd9ce64969204d94b2c93ffa14e83324eebdc71b2c8b468bcaa0b02eee19cf", - "last_commit": "f5c9bd89a", + "last_commit": "0ccdd31d7", "name": "spec", "purpose": "Directory spec. Purpose not yet described by a human." }, { - "digest": "0b45b3b8037fb89222c06563d9cde31caf762b9751994fafa603e1c84d350d91", - "last_commit": "9920aab14", + "digest": "0b8df0bac6a60addd4eb8323b0251db5b55b901a9c965d0d12a2e76bfaae661f", + "last_commit": "28fbba3e4", "name": "src", "purpose": "Directory src. Purpose not yet described by a human." }, { - "digest": "0a1bedfebbcc0e923a70af1b3537bc5af1f45a79c527e517aace0bf4c5287dcf", - "last_commit": "089d63253", + "digest": "42ce588746fbb9982a309142a06639206247d5fada0e859b804eb7e7b17a164a", + "last_commit": "9c340520d", "name": "tests", "purpose": "Directory tests. Purpose not yet described by a human." }, { - "digest": "c9c0eb6fcb03f5be2576714a9b49e2ead49190277059fcbbd253f49db07c047d", - "last_commit": "22011cbc9", + "digest": "d4c5b2b33f12a1d46e845315d1e5ec71c40b7104ecaef4542ceebede179c5f54", + "last_commit": "ef2aba148", "name": "tools", "purpose": "Directory tools. Purpose not yet described by a human." } ], - "children_root": "sha256:7685e485f4351c4a698eaf416894e06aa7d845cbc9269c9ef43f4eb561d2ba6e", - "compiled_at": "2026-10-31T13:29:24Z", + "children_root": "sha256:9906a77f425aebf392693aeed8598ec544e5964676ff83a2c723a46e553844d4", + "compiled_at": "2026-10-31T13:42:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:4e146d21cc7e24b5245ee33654daa0a487eacb5ebb53b0d033d4cff531686259", + "digest": "sha256:712d04319e148c6a5fde5ef766412c43be47d1a863b229ceb24814268e340eaf", "evidence_files": 14989, "evidence_root": "sha256:90148c46bbc2cd096c96064273ac90d63efb54260fe285e18d84429cdf657830", - "files": 23228, - "generated_at_commit": "1840dd869407c96429bab4780b69a7da9b194950", - "source_tree": "sha256:d6c3fb10bc3468b319246f34bd5697741b292c1c42ef4b2370f7aa8eb525ef59" + "files": 23040, + "generated_at_commit": "9c340520d54efa93c955f008e50defaccfae7fb5", + "source_tree": "sha256:1fe2f167afd3a05a8baffc1702720df131c8928c354a21771d6f25ec0cd2a740" }, "owner_lane": "", "provenance": { diff --git a/AGENTS.md b/AGENTS.md index 9085b3de2..7c6f53629 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -31,11 +31,13 @@ Some gates expect sibling checkouts next to this one: `../physics` (physics-mv) ## Configuration -- `physics.lock`, `aienos.lock`, `argus.lock`: commits of the sibling sources the full build and some gates pin. `crumb.lock`: the aien-architecture commit the crumb tool is built from. `om/omega-bridge.lock`: the omega-bridge commit whose `src/native.om` generates `src/omega_om_units.inc`. +- `physics.lock`, `aienos.lock`, `argus.lock`: commits of the sibling sources the full build and some gates pin. `crumb.lock`: the aien-architecture commit the crumb tool is built from. `om/omega-bridge.lock`: the bridge for the retained CPU SHA-256/BLAKE3 binding generated by `om/units.sh`. - `PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0` on `make` builds the host suites without a physics checkout. - `OUT_DIR`: per-step build directory; `tests/gates/run.sh` sets it to `build/step-`. - `.aien/always` lists the gates every commit must pass (`CRUMB-VERIFY`, `OMEGA-EVIDENCE-IMMUTABLE`, `OMEGA-ZERO-DISK-SECRETS`); `.aien/verify.pub` is the Spark judge's public key. - `AIEN_OMEGA_FP8_GROUPED_WAVE=1` and `AIEN_OMEGA_FP8_GROUPED_CTAS=n` change the GB10 FP8 grouped expert launch (off by default; see `README.md`). +- `cudapp.lock`: canonical native GPU source. Set `CUDAPP_DIR` to a checkout at that exact HEAD, `OMEGA_OMC` to the seeded compiler SHA-256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`, and `OMEGA_BRIDGE` to `0c4cb9ff980af278890b231b994eaede4dc7621c`. `check-cudapp` stages and authenticates committed sources, generated units and archive on every native entry, without a lock-check bypass. Canonical headers precede Physics headers; the canonical archive follows retained Omega CPU objects. +- Do not restore duplicate GPU sources or rewrite historical receipts. The 123-path retirement ledger is `tests/cudapp_retirement_sources.json`. Unique Omega gate/resident adapters remain local. Host-only fixtures and source provenance are not GPU or full-model qualification; production native candidate admission remains refused until independently accepted exact-artifact qualification. ## Usage diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 6cc82c7db..34275099a 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -7,6 +7,7 @@ The current development method is [Human-Directed Agentic Engineering (HDAE)](RE | Model | What it did | |---|---| +| Codex (GPT-6.1 Sol) | Canonical CUDApp source staging and native caller integration, graph/session lifecycle binding, preserved full-union GPU source retirement, and independent host refusal controls; GPU and full-model qualification not claimed | | Claude Opus 5.5 (via omp) | OM-2 `scrub` keeps live float registers: since #853 an f32/f64 local name and a held float value live in the V16+j twin of their pool slot, but #875's scrub still zeroed V0-V31, so a live float read back 0 after `scrub` (repro exit 50 on omc `24caacf4…abb7`). scrub now spares exactly the twins of live slots that hold their value there (vsl) and zeroes V0-V15 and every dead twin; s5 fixtures `scrub-flive`/`scrub-femit` and mutants `m-twinall`/`m-twinnone`; OMEGESE 9.13.1; reseed, omc `be8c5130…448a`, pins moved, src units regenerated, size-history row. | | Claude Opus 5.5 (via omp) | #857 merged with main `157bab57` (#848 squash): `omc.om` is main plus only #857's for-bound, IR bound/count range and IR for-guard edits (ir_if/ir_else/ir_doret stay folded as on main); gate16/gate-ir tables and OMEGESE text kept from both sides; reseed, omc `24caacf4…abb7`, pins moved from `90c8884c…3983`, src units regenerated, size-history row. | | Claude Opus 5.5 (via omp) | #857 residual: IR mode refuses a `for` count that is a number or integer constant outside 0..1000000 (a minus sign included) with error 8, the C oracle's count range; before, `for i ulong 1000001` and `const K ulong 1000001` compiled to an unguarded loop checker2 rejects (C2-LOOP-UNBOUNDED) and `for i long -1`/`-0` compiled where the oracle refuses. gate-ir units for both sides; reseed, omc `0d4c722b…a008`. | diff --git a/Makefile b/Makefile index 6011dfa5d..9ebb7d6ab 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ CC ?= gcc .DEFAULT_GOAL := all PHYSICS_DIR ?= ../physics OUT_DIR ?= build +include mk/cudapp-consumer.mk -include mk/*.mk PHYSICS_LOCK_CHECK ?= 1 @@ -11,82 +12,17 @@ CFLAGS ?= -std=gnu11 -Wall -Wextra -Werror -MMD -MP -D_GNU_SOURCE -O2 -Isrc \ -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/kernel-open/common/inc \ -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \ -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include +override CFLAGS := -Isrc $(CUDAPP_HEADER_FLAGS) $(filter-out -Isrc,$(CFLAGS)) -# sm_121 instruction encoder (twin of aien-dev/CUDApp#79): om (default) = om/encoder/bw_enc_sm121.om through the -# generated binding src/omega_om_units.c; c = the migration-pending C encoder, the differential oracle; diff = both on -# every call, abort on any difference (mk/om-encoder.mk). Use a separate OUT_DIR per value. The macro names keep -# CUDApp's spelling so src/omega_blackwell_codegen.c stays the same file in both repositories. -CUDAPP_ENCODER ?= om -CUDAPP_ENCODER_DEFS_om := -CUDAPP_ENCODER_DEFS_c := -DCUDAPP_MIGRATION_PENDING_C_ENCODER -CUDAPP_ENCODER_DEFS_diff := -DCUDAPP_MIGRATION_PENDING_ENCODER_DIFF -CUDAPP_ENCODER_DEFS = $(CUDAPP_ENCODER_DEFS_$(CUDAPP_ENCODER)) -ifeq ($(filter om c diff,$(CUDAPP_ENCODER)),) -$(error CUDAPP_ENCODER must be om, c or diff) -endif - +# Omega owns its CPU substrate and evidence adapters. Native GPU implementation +# and bundled driver objects come only from the pinned canonical CUDApp archive. SRCS = src/omega_om_units.c src/omega_canonical.c src/omega_validate.c src/omega_core.c src/omega_codec.c \ src/aarch64_encoder.c src/aarch64_decoder.c src/omega_realize.c src/omega_exec.c \ src/omega_self_host.c src/omega_verify.c src/omega_program.c src/omega_synthesis.c \ src/omega_library.c src/omega_discovery.c src/omega_machine.c src/omega_realize_synth.c \ src/omega_matvec.c src/omega_accelerator.c src/omega_accelerator_world.c \ - src/omega_vector.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_realize.c src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_gates.c src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_gpu_session.c src/omega_gpu_platform.c src/omega_gpu_platform_linux.c src/omega_gpu_fmt.c src/omega_gpu_matmul_api.c src/omega_gpu_elementwise_api.c src/omega_gpu_attention_api.c src/omega_gpu_serving.c src/omega_world_gates.c src/omega_gpu_wait.c \ - src/omega_evidence.c src/omega_clean_clone.c \ - $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c \ - tools/omegatool.c -# OWN-30B cut 2 (2026-10-13): column windows over a resident bf16 tensor for the MoE path. New file, -# adds exports only (8B decode-speed lane collision rule: no existing GPU source moves). -SRCS += src/omega_gpu_moe_api.c - -# OWN-30B Cut 6 / Cut 5 (2026-10-13): FP8 e4m3 GEMV kernel family, new files only (omega_gpu_fp8_api.h) -SRCS += src/omega_blackwell_codegen_moe.c src/omega_gpu_fp8_pack.c src/omega_gpu_fp8_api.c -# OWN-30B W-L2c (2026-10-14): FP8 GEMV variant 2, row-pipelined (omega_blackwell_codegen_moe2.h), selectable, variant 1 untouched -SRCS += src/omega_blackwell_codegen_moe2.c -# Expert Ribbon P1 (aienix#4 / omega#533, 2026-10-18): versioned replaceable FP8 expert slots, new files only -SRCS += src/omega_fp8_slot_table.c src/omega_gpu_fp8_slots.c -# OWN-30B cut 8 (2026-10-13): one-launch decode attention (omega_gpu_decode_attn_api.h), new files only -SRCS += src/omega_blackwell_codegen_attn.c src/omega_gpu_decode_attn_api.c -# Qwen3.8-27B (omega-mv#544, 2026-10-18): decode attention head_dim 256, new files only -SRCS += src/omega_blackwell_codegen_attn256.c src/omega_gpu_decode_attn256_api.c -# Qwen3.8-27B (omega-mv#545, 2026-10-18): prefill attention head_dim 256 on the decode cache, new files only -SRCS += src/omega_blackwell_codegen_pattn256.c src/omega_gpu_prefill_attn256_api.c -# OWN-30B (2026-10-13): libm-free host math (omega_gpu_hostmath.h) so libomega_gpu.a links without -lm -SRCS += src/omega_gpu_hostmath.c -# OWN-30B cut 8 item 2 (2026-10-13): one-launch MoE router (omega_gpu_router_api.h), new files only -SRCS += src/omega_blackwell_codegen_router.c src/omega_gpu_router_api.c -# Qwen3.8-27B Gated DeltaNet decode step (omega#542, 2026-10-18): one launch per layer (omega_gpu_gdn_api.h), new files only -SRCS += src/omega_blackwell_codegen_gdn.c src/omega_gpu_gdn_api.c -# OWN-30B W-L2 (2026-10-13): decode launch collapse, new files only: command list (N launches, one submit) + glue kernels -SRCS += src/omega_gpu_cmdlist.c src/omega_blackwell_codegen_dec.c -# C3 (docs/OMEGA.md): reductions and prefix sums of any length, bit-exact against the frozen-order host reference. -SRCS += src/omega_gpu_scan.c src/omega_gpu_scan_ref.c -# C3: matrix multiply of any shape, BF16 and FP8, both layouts, on the tensor cores (pack kernels + one multiply kernel). -SRCS += src/omega_gpu_gemm.c -SRCS += src/omega_gpu_mem_cached.c -SRCS += src/omega_gpu_decode_graph.c -# sc #642 (2026-10-18): one Qwen3.8-27B decode token as one command list (GDN + hd256 attention layers, dense MLP) -SRCS += src/omega_gpu_q38_graph.c -SRCS += src/omega_gpu_q36_graph.c -# C6 (L386): Omega's own sm_121 disassembler; the listing checks in tests/ call it instead of nvdisasm -SRCS += src/omega_sm121_disasm.c -# OWN-30B (2026-10-13): bf16 streaming GEMV for the lm_head (omega_gpu_bf16_gemv_api.h), new files only -SRCS += src/omega_blackwell_codegen_bf16.c src/omega_gpu_bf16_gemv_api.c -# OWN-30B prefill (2026-10-13): FP8 grouped GEMM, each expert streamed once per pass (omega_gpu_fp8gemm_api.h), new files only -SRCS += src/omega_blackwell_codegen_gemm.c src/omega_gpu_fp8gemm_api.c -# OWN-30B T3 (2026-10-13): tensor-core prefill kernels (omega_blackwell_codegen_tc.h), new files only -SRCS += src/omega_blackwell_codegen_tc.c -SRCS += src/omega_gpu_tcgemm_api.c -# OWN-30B L1 attention (2026-10-13): tensor-core causal prefill attention (omega_gpu_prefill_attn_api.h), new files only -SRCS += src/omega_blackwell_codegen_pattn.c src/omega_gpu_prefill_attn_api.c -# OWN-30B T3b (2026-10-13): device-resident prefill (omega_gpu_prefill.h), new files only -SRCS += src/omega_blackwell_codegen_pf.c src/omega_gpu_prefill.c src/omega_blackwell_codegen_tc2.c src/omega_gpu_pfgemm.c -# OWN-30B L1 GEMM (W-L1G, 2026-10-14): native FP8 QMMA, new files only -SRCS += src/omega_blackwell_codegen_qmma.c src/omega_blackwell_codegen_qg.c -# OWN-30B W-L1G-D (2026-10-14): router logits + MoE combine for the whole-prompt prefill, new files only -SRCS += src/omega_blackwell_codegen_pfhost.c src/omega_gpu_pfhost.c -# Ternary engine T0 (2026-10-15): KT1, the W2A8 ternary GEMV (omega_gpu_tern_api.h), new files only -SRCS += src/omega_blackwell_codegen_tern.c src/omega_gpu_tern_api.c + src/omega_vector.c src/omega_blackwell_gates.c src/omega_world_gates.c \ + src/omega_evidence.c src/omega_clean_clone.c tools/omegatool.c OBJS = $(patsubst %.c,$(OUT_DIR)/%.o,$(notdir $(SRCS))) DEPS = $(OBJS:.o=.d) -include $(DEPS) @@ -149,12 +85,6 @@ $(PHYSICS_STAMP): check-physics-lock | $(OUT_DIR) if [ "$$(cat $@ 2>/dev/null)" != "$$new" ]; then printf '%s\n' "$$new" > $@; fi $(PHYSICS_OBJS): $(PHYSICS_STAMP) -$(OUT_DIR)/m16_native.o: $(PHYSICS_DIR)/m16/m16_native.c | $(OUT_DIR) - $(CC) $(CFLAGS) -c $< -o $@ - -$(OUT_DIR)/nvrm.o: $(PHYSICS_DIR)/nvrm/nvrm.c | $(OUT_DIR) - $(CC) $(CFLAGS) -c $< -o $@ - $(OUT_DIR)/crumbline/%.o: src/crumbline/%.c | $(OUT_DIR) mkdir -p $(OUT_DIR)/crumbline $(CC) $(CFLAGS) -c $< -o $@ @@ -174,8 +104,8 @@ $(LEARNER): $(LEARNER_OBJS) $(OUT_DIR)/omegatool.o: tools/omegatool.c | $(OUT_DIR) $(CC) $(CFLAGS) -c $< -o $@ -$(TARGET): $(OBJS) | check-physics-lock - $(CC) $(CFLAGS) -o $@.tmp.$$$$ $(OBJS) && mv -f $@.tmp.$$$$ $@ +$(TARGET): $(OBJS) $(CUDAPP_LIB) | check-physics-lock check-cudapp + $(CC) $(CFLAGS) -o $@.tmp.$$$$ $(OBJS) $(CUDAPP_LIB) && mv -f $@.tmp.$$$$ $@ test: $(TARGET) ./$(TARGET) --run-gates @@ -284,9 +214,9 @@ NUMERIC_CPU_SRCS = tests/test_omega_numeric.c src/omega_numeric.c src/omega_nume $(NUMERIC_BW_SRCS) NUMERIC_CPU_HDRS = src/omega_numeric.h src/omega_numeric_provenance.h src/omega_numeric_divsqrt_gb10.h tests/numeric_oracle.h \ $(NUMERIC_BW_HDRS) -build/test_omega_numeric_cpu: $(NUMERIC_CPU_SRCS) $(NUMERIC_CPU_HDRS) +build/test_omega_numeric_cpu: $(NUMERIC_CPU_SRCS) $(NUMERIC_CPU_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ $(NUMERIC_CPU_SRCS) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc $(CUDAPP_HEADER_FLAGS) -DOMEGA_NUMERIC_CPU_ONLY -o $@ $(NUMERIC_CPU_SRCS) $(CUDAPP_LIB) -lpthread # test-numeric-cpu exit status: 0 means no host test failed and the only SKIPs # are the five declared chip-only IDs (CHIP_ONLY_IDS in the test; the last line # prints "Gate 5 Verdict: PASS_EXCEPT_DECLARED_CHIP_ONLY"). Nonzero means a real @@ -324,9 +254,9 @@ test-numeric-e1-exhaustive: build/test_omega_numeric_cpu REDUCE_CPU_SRCS = tests/test_omega_reduce.c src/omega_numeric_reduce.c src/omega_numeric_reduce_gb10.c \ src/omega_numeric.c src/omega_numeric_provenance.c src/omega_numeric_divsqrt_gb10.c \ $(NUMERIC_BW_SRCS) -build/test_omega_reduce_cpu: $(REDUCE_CPU_SRCS) src/omega_numeric_reduce.h $(NUMERIC_CPU_HDRS) +build/test_omega_reduce_cpu: $(REDUCE_CPU_SRCS) src/omega_numeric_reduce.h $(NUMERIC_CPU_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ $(REDUCE_CPU_SRCS) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc $(CUDAPP_HEADER_FLAGS) -DOMEGA_NUMERIC_CPU_ONLY -o $@ $(REDUCE_CPU_SRCS) $(CUDAPP_LIB) -lpthread test-numeric-reduce-cpu: build/test_omega_reduce_cpu ./build/test_omega_reduce_cpu @@ -709,16 +639,13 @@ test-cortex: $(RX_CX_TEST) $(RX_CXJ_TEST) RX_R12_SILICON_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c \ src/runtime/rx_coherent.c src/runtime/rx_native_bind.c \ src/runtime/rx_resident_gpu.c src/omega_om_units.c src/omega_evidence.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_qmd.c src/omega_blackwell_matmul.c \ - $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c \ tests/runtime/rx_r12_silicon.c RX_R12_SILICON = $(OUT_DIR)/rx_r12_silicon_test $(RX_R12_SILICON): $(RX_R12_SILICON_SRCS) src/runtime/rx_world.h \ src/runtime/rx_resident_gpu.h src/runtime/rx_caproot.h src/runtime/aienos_cap.h \ - src/omega_blackwell_codegen.h $(AIENOS_CAP_LIB) | $(OUT_DIR) - $(CC) $(CFLAGS) -pthread -o $@ $(RX_R12_SILICON_SRCS) $(AIENOS_CAP_LIB) -ldl -lm + $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) + $(CC) $(CFLAGS) -pthread -o $@ $(RX_R12_SILICON_SRCS) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm test-r12-silicon: $(RX_R12_SILICON) ./$(RX_R12_SILICON) @@ -778,9 +705,7 @@ RX_R13_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c \ # RX_ERR_AUTHORITY (sovereign-core abi-qualify, 2026-10-12). -include $(RXC_LIB_OBJS:.o=.d) RX_R13_TEST_SRCS = $(RX_R13_SRCS) $(RX_FABRIC_TEST_SRCS) -RX_R13_SILICON_EXTRA = src/runtime/rx_resident_gpu.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c src/omega_blackwell_matmul.c \ - $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c +RX_R13_SILICON_EXTRA = src/runtime/rx_resident_gpu.c # Production program (rules after the ARGUS block below: they link ARGUS). RX_R13_HOST = $(OUT_DIR)/rx_r13_living_host RX_R13_SILICON = $(OUT_DIR)/rx_r13_living_silicon @@ -795,9 +720,9 @@ $(RX_R13_TEST_HOST): $(RX_R13_TEST_SRCS) src/runtime/rx_living.h $(RX_COMPOSE_LI # Lane 17: the Fabric phase runs in the silicon test build too; its Fabric part # is CPU-only loopback. The composition phase stays host-only. $(RX_R13_TEST_SILICON): $(RX_R13_TEST_SRCS) $(RX_R13_SILICON_EXTRA) src/runtime/rx_living.h \ - $(RX_COMPOSE_LIVING_CHECKS) $(RX_R13_TEST_CHECKS) $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(RX_COMPOSE_LIVING_CHECKS) $(RX_R13_TEST_CHECKS) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) $(AIEN_TEST_FLAGS) -DR13_SILICON -pthread -o $@ $(RX_R13_TEST_SRCS) \ - $(RX_R13_SILICON_EXTRA) $(AIENOS_CAP_LIB) -ldl -lm + $(RX_R13_SILICON_EXTRA) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm test-r13-host: $(RX_R13_HOST) ./$(RX_R13_HOST) @@ -848,15 +773,9 @@ $(RX_R14_HOST): $(RX_R14_SRCS) src/runtime/rx_living.h $(RX_COMPOSE_LIVING_CHECK $(CC) $(CFLAGS) -pthread -o $@ $(RX_R14_SRCS) $(AIENOS_CAP_LIB) -lm $(RX_R14_SILICON): $(RX_R14_SRCS) src/runtime/rx_resident_gpu.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_qmd.c src/omega_blackwell_matmul.c \ - $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c \ - $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) -DR14_SILICON -pthread -o $@ $(RX_R14_SRCS) \ - src/runtime/rx_resident_gpu.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_matmul.c $(PHYSICS_DIR)/m16/m16_native.c \ - $(PHYSICS_DIR)/nvrm/nvrm.c $(AIENOS_CAP_LIB) -ldl -lm + src/runtime/rx_resident_gpu.c $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm test-r14-host: $(RX_R14_HOST) ./$(RX_R14_HOST) @@ -884,9 +803,7 @@ RX_R15_RIG_SRCS = $(filter-out tests/runtime/rx_r13_living.c src/runtime/rx_oper src/runtime/rx_seq_reference.c tests/runtime/rx_r15_rig.c RX_R15_RIG_HDRS = src/runtime/rx_living.h src/runtime/rx_seq_reference.h \ src/runtime/rx_world.h tests/runtime/rx_r15_rig.h -RX_R15_GPU_SRCS = src/runtime/rx_resident_gpu.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_matmul.c $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c +RX_R15_GPU_SRCS = src/runtime/rx_resident_gpu.c RX_R15_PARITY_HOST = $(OUT_DIR)/rx_r15_parity_host RX_R15_PARITY_SILICON = $(OUT_DIR)/rx_r15_parity_silicon @@ -896,9 +813,9 @@ $(RX_R15_PARITY_HOST): $(RX_R15_RIG_SRCS) tests/runtime/rx_r15_parity.c $(RX_R15 $(AIENOS_CAP_LIB) -lm $(RX_R15_PARITY_SILICON): $(RX_R15_RIG_SRCS) tests/runtime/rx_r15_parity.c $(RX_R15_RIG_HDRS) \ - $(RX_R15_GPU_SRCS) $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(RX_R15_GPU_SRCS) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) -DR15_SILICON -pthread -o $@ $(RX_R15_RIG_SRCS) \ - tests/runtime/rx_r15_parity.c $(RX_R15_GPU_SRCS) $(AIENOS_CAP_LIB) -ldl -lm + tests/runtime/rx_r15_parity.c $(RX_R15_GPU_SRCS) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm test-r15-parity-host: $(RX_R15_PARITY_HOST) ./$(RX_R15_PARITY_HOST) @@ -920,9 +837,9 @@ R15_GPU_LOAD_SRCS = src/runtime/rx_caproot.c src/runtime/rx_world.c src/runtime/ tests/runtime/r15_gpu_load.c $(R15_GPU_LOAD): $(R15_GPU_LOAD_SRCS) $(RX_R15_GPU_SRCS) src/runtime/rx_world.h \ - $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) -pthread -o $@ $(R15_GPU_LOAD_SRCS) $(RX_R15_GPU_SRCS) \ - $(AIENOS_CAP_LIB) -ldl -lm + $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm r15-gpu-load: $(R15_GPU_LOAD) @@ -949,14 +866,14 @@ $(RX_R15_PERF_HOST_ND): $(RX_R15_PERF_SRCS) $(RX_R15_PERF_HDRS) $(AIENOS_CAP_LIB $(AIENOS_CAP_LIB) -ldl -lm $(RX_R15_PERF_SILICON): $(RX_R15_PERF_SRCS) $(RX_R15_PERF_HDRS) $(RX_R15_GPU_SRCS) \ - $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) -DR15_SILICON -pthread -o $@ $(RX_R15_PERF_SRCS) $(RX_R15_GPU_SRCS) \ - $(AIENOS_CAP_LIB) -ldl -lm + $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm $(RX_R15_PERF_SILICON_ND): $(RX_R15_PERF_SRCS) $(RX_R15_PERF_HDRS) $(RX_R15_GPU_SRCS) \ - $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) -DR15_SILICON -DRX_MEASURE_NO_CAUSAL_DIGEST -pthread -o $@ \ - $(RX_R15_PERF_SRCS) $(RX_R15_GPU_SRCS) $(AIENOS_CAP_LIB) -ldl -lm + $(RX_R15_PERF_SRCS) $(RX_R15_GPU_SRCS) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm $(R15_REDUCE): tools/r15_reduce.c src/omega_om_units.c src/sha256.h | $(OUT_DIR) $(CC) $(CFLAGS) -o $@ tools/r15_reduce.c src/omega_om_units.c -lm @@ -1037,10 +954,7 @@ test-r16-authpath: $(RX_R13_HOST) $(RX_R14_HOST) test-r16-authpath-silicon: $(RX_R13_SILICON) $(RX_R14_SILICON) sh tools/r16_authpath.sh silicon $(RX_R13_SILICON) $(RX_R14_SILICON) \ $(OUT_DIR)/r16/authpath/silicon-$(R16_STAMP) $(RX_R13_SRCS) $(RX_PROD_ARGUS_SRCS) \ - src/runtime/rx_resident_gpu.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_matmul.c $(PHYSICS_DIR)/m16/m16_native.c \ - $(PHYSICS_DIR)/nvrm/nvrm.c $(AIENOS_CAP_LIB) + src/runtime/rx_resident_gpu.c $(AIENOS_CAP_LIB) $(CUDAPP_LIB) # R16-G3 checks 1-3 only (sources, link map, shared libraries, embedded names) # on the current living-system build, for CI runners. Nothing is executed, so @@ -1055,10 +969,7 @@ test-r16-authpath-linkmap: $(RX_R13_HOST) $(RX_R14_HOST) test-r16-authpath-linkmap-silicon: $(RX_R13_SILICON) $(RX_R14_SILICON) R16_G3_STATIC_ONLY=1 sh tools/r16_authpath.sh silicon $(RX_R13_SILICON) $(RX_R14_SILICON) \ $(OUT_DIR)/r16/authpath/linkmap-silicon-$(R16_STAMP) $(RX_R13_SRCS) $(RX_PROD_ARGUS_SRCS) \ - src/runtime/rx_resident_gpu.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_matmul.c $(PHYSICS_DIR)/m16/m16_native.c \ - $(PHYSICS_DIR)/nvrm/nvrm.c $(AIENOS_CAP_LIB) + src/runtime/rx_resident_gpu.c $(AIENOS_CAP_LIB) $(CUDAPP_LIB) # R16-G4: legacy paths cannot bypass authority. The R13 body (R15 rig, RES-4, # host seat) is started; a legacy context tries six acts and each must be @@ -1256,7 +1167,7 @@ $(RX_ROUTE_OBJ): src/runtime/rx_route.c src/runtime/rx_route.h src/runtime/rx_ge $(RX_ROUTE_TEST): $(RX_ROUTE_SRCS) $(RX_ROUTE_OBJ) tests/runtime/rx_cog_engines.h \ src/runtime/aienos_cap.h $(AIENOS_CAP_LIB) | $(OUT_DIR) - $(CC) $(CFLAGS) -Itests -o $@ $(RX_ROUTE_SRCS) $(RX_ROUTE_OBJ) $(AIENOS_CAP_LIB) -lm + $(CC) $(CFLAGS) -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(RX_ROUTE_SRCS) $(RX_ROUTE_OBJ) $(AIENOS_CAP_LIB) -lm test-cognitive-routing: $(RX_ROUTE_TEST) ./$(RX_ROUTE_TEST) @@ -1495,10 +1406,10 @@ test-regulate: $(RX_REGULATE_TEST) ./$(RX_REGULATE_TEST) $(RX_R13_SILICON): $(RX_R13_SRCS) $(RX_R13_SILICON_EXTRA) src/runtime/rx_living.h src/runtime/rx_argus.h \ - $(RX_COMPOSE_LIVING_CHECKS) $(ARGUS_STAMP) $(AIENOS_CAP_LIB) | $(OUT_DIR) + $(RX_COMPOSE_LIVING_CHECKS) $(ARGUS_STAMP) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) | check-cudapp $(OUT_DIR) $(RX_PROD_REFUSE_TEST) $(CC) $(CFLAGS) $(RX_PROD_ARGUS_FLAGS) -DR13_SILICON -pthread -o $@ $(RX_R13_SRCS) \ - $(RX_PROD_ARGUS_SRCS) $(RX_R13_SILICON_EXTRA) $(AIENOS_CAP_LIB) -ldl -lm + $(RX_PROD_ARGUS_SRCS) $(RX_R13_SILICON_EXTRA) $(AIENOS_CAP_LIB) $(CUDAPP_LIB) -ldl -lm # Production hygiene (link map + strings + ARGUS present; host run of the # ARGUS probe where the binary can run) and the negative build test: compiling @@ -1942,15 +1853,12 @@ print-c4-requal-bin: # tests/runtime/rx_compose_gpu_skill.h. A chip run: take the quiet flag and # use tools/composition_gate.sh --gpu (clean tree, content-addressed receipt). RX_COMPOSE_GATE_GPU = $(OUT_DIR)/rx_composition_gate_gpu -RX_COMPOSE_GPU_SRCS = src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c src/omega_blackwell_matmul.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_realize.c src/omega_vector.c src/omega_validate.c src/omega_gpu_wait.c \ - $(PHYSICS_DIR)/m16/m16_native.c $(PHYSICS_DIR)/nvrm/nvrm.c +RX_COMPOSE_GPU_SRCS = src/omega_vector.c src/omega_validate.c $(RX_COMPOSE_GATE_GPU): $(RX_COMPOSE_DEPS) $(RX_COMPOSE_GPU_SRCS) tests/runtime/rx_composition_gate.c \ - tests/runtime/rx_compose_gpu_skill.h | check-physics-lock $(OUT_DIR) + tests/runtime/rx_compose_gpu_skill.h $(CUDAPP_LIB) | check-physics-lock check-cudapp $(OUT_DIR) $(CC) $(CFLAGS) -DRXC_GATE_GPU -Itests/runtime -pthread -o $@ $(RX_COMPOSE_SRCS) \ - $(RX_COMPOSE_GPU_SRCS) tests/runtime/rx_composition_gate.c $(RX_COMPOSE_LINK) -ldl + $(RX_COMPOSE_GPU_SRCS) tests/runtime/rx_composition_gate.c $(RX_COMPOSE_LINK) $(CUDAPP_LIB) -ldl test-composition-gate-gpu: $(RX_COMPOSE_GATE_GPU) ./$(RX_COMPOSE_GATE_GPU) "$$(git rev-parse HEAD)" $(OUT_DIR)/composition_gate_gpu_receipt.json @@ -1968,12 +1876,11 @@ print-composition-gate-gpu-bin: # tools/run_divsqrt_gate.sh only (quiet flag, detached, receipt). DIVSQRT_SRCS = tests/test_omega_divsqrt_gb10.c src/omega_numeric_divsqrt_gb10.c src/omega_numeric.c \ src/omega_numeric_provenance.c $(NUMERIC_BW_SRCS) -DIVSQRT_HDRS = src/omega_numeric_divsqrt_gb10.h src/omega_numeric.h src/omega_blackwell_encoder.h \ - src/omega_blackwell_qmd.h src/sha256.h +DIVSQRT_HDRS = src/omega_numeric_divsqrt_gb10.h src/omega_numeric.h $(NUMERIC_BW_HDRS) .PHONY: test-divsqrt-host test-divsqrt-nvdisasm test-divsqrt-sweep -build/test_omega_divsqrt_gb10_cpu: $(DIVSQRT_SRCS) $(DIVSQRT_HDRS) +build/test_omega_divsqrt_gb10_cpu: $(DIVSQRT_SRCS) $(DIVSQRT_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(DIVSQRT_SRCS) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc $(CUDAPP_HEADER_FLAGS) -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(DIVSQRT_SRCS) $(CUDAPP_LIB) test-divsqrt-host: build/test_omega_divsqrt_gb10_cpu ./build/test_omega_divsqrt_gb10_cpu test-divsqrt-nvdisasm: @@ -1990,9 +1897,9 @@ TRANSC_GB10_SRCS = tests/test_omega_numeric_transc_gb10.c src/omega_numeric_divs src/omega_numeric_transc.c src/omega_numeric.c src/omega_numeric_provenance.c \ $(NUMERIC_BW_SRCS) .PHONY: test-numeric-transc-gb10-host -build/test_omega_numeric_transc_gb10_cpu: $(TRANSC_GB10_SRCS) $(DIVSQRT_HDRS) src/omega_numeric_transc.h +build/test_omega_numeric_transc_gb10_cpu: $(TRANSC_GB10_SRCS) $(DIVSQRT_HDRS) src/omega_numeric_transc.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -Isrc -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(TRANSC_GB10_SRCS) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -Isrc $(CUDAPP_HEADER_FLAGS) -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(TRANSC_GB10_SRCS) $(CUDAPP_LIB) test-numeric-transc-gb10-host: build/test_omega_numeric_transc_gb10_cpu ./build/test_omega_numeric_transc_gb10_cpu @@ -2011,14 +1918,12 @@ test-unwritten-trap-host: build/test_omega_unwritten_trap # docs/numeric/E1_LDST_GB10.md). test-ldst-host needs no device; test-ldst-nvdisasm # decodes every table kernel offline; the chip run is tools/run_numeric_ldst_chip.sh. LDST_SRCS = tests/test_omega_ldst_gb10.c src/omega_numeric_ldst_gb10.c src/omega_numeric_divsqrt_gb10.c src/omega_numeric.c \ - src/omega_numeric_provenance.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c -LDST_HDRS = src/omega_numeric_ldst_gb10.h src/omega_numeric_divsqrt_gb10.h src/omega_numeric.h src/omega_blackwell_encoder.h \ - src/omega_blackwell_qmd.h src/sha256.h + src/omega_numeric_provenance.c $(NUMERIC_BW_SRCS) +LDST_HDRS = src/omega_numeric_ldst_gb10.h src/omega_numeric_divsqrt_gb10.h src/omega_numeric.h $(NUMERIC_BW_HDRS) .PHONY: test-ldst-host test-ldst-nvdisasm -build/test_omega_ldst_gb10_cpu: $(LDST_SRCS) $(LDST_HDRS) +build/test_omega_ldst_gb10_cpu: $(LDST_SRCS) $(LDST_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(LDST_SRCS) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -Isrc $(CUDAPP_HEADER_FLAGS) -DOMEGA_NUMERIC_CPU_ONLY -pthread -o $@ $(LDST_SRCS) $(CUDAPP_LIB) test-ldst-host: build/test_omega_ldst_gb10_cpu ./build/test_omega_ldst_gb10_cpu test-ldst-nvdisasm: @@ -2321,7 +2226,7 @@ RESOLVE_HDRS += src/omega_genesis.h src/omega_vcstore_priv.h src/omega_program_i .PHONY: test-genesis GENESIS_DIR = $(OUT_DIR)/genesis-test GENESIS_STACK = src/omega_receipt.c src/omega_blake3.c src/omega_om_units.c $(RESOLVE_PROGRAM_STACK) -GENESIS_CFLAGS = $(RESOLVE_FLAGS) -I$(GENESIS_DIR) -Itests +GENESIS_CFLAGS = $(RESOLVE_FLAGS) -I$(GENESIS_DIR) -I$(CUDAPP_SOURCE)/tests -Itests test-genesis: tests/test_omega_genesis_set.c tests/genesis_variant/member.inc src/omega_vcstore.c src/omega_resolve.c src/omega_genesis.h $(RESOLVE_HDRS) @set -eu; mkdir -p $(GENESIS_DIR)/genesis_variant; \ sed -e 's|^#define OMEGA_GENESIS_1_COUNT 0u|#define OMEGA_GENESIS_1_COUNT 1u|' -e 's|^#define OMEGA_GENESIS_SET_NAME "VC-GENESIS-1"|#define OMEGA_GENESIS_SET_NAME "VC-GENESIS-1-TEST-VARIANT"|' src/omega_genesis.h \ @@ -2500,9 +2405,9 @@ test-vc-bridge: tests/test_omega_vc_bridge.c src/omega_vc_bridge.c src/omega_vc_ @echo "test-vc-bridge: PASS (bridge verifies and recomputes the id, bridge records refused in build, ASan/UBSan clean, 4 mutants killed)" # FB-1 cut 1: native (no CUDA) matmul entry point for the inference stack. -# libomega_gpu.a = everything the tool links except its main; the Rust FFI crate -# (cut 2) links it. test-gpu-matmul-api runs the host-only refusals; the chip -# sweep is `./build/gpu_matmul_api_test --out receipt.json` through the heavy queue. +# libomega_gpu.a is the Omega CPU/evidence adapter companion, not a +# second GPU implementation. Consumers link it FIRST and the pinned canonical +# CUDApp archive LAST. Host-only API refusals do not qualify the chip path. .PHONY: libomega_gpu test-gpu-matmul-api # The two gate-runner objects (omegatool's M17/M18/M19 and World gates) are NOT part of the # library: nothing in the library or in the Rust FFI crate calls them (checked with nm), and @@ -2510,22 +2415,25 @@ test-vc-bridge: tests/test_omega_vc_bridge.c src/omega_vc_bridge.c src/omega_vc_ # archive digest depend on where physics was checked out. Without them libomega_gpu.a is # byte-identical for any PHYSICS_DIR and any omega checkout directory. GPU_API_OBJS = $(filter-out $(OUT_DIR)/omegatool.o $(OUT_DIR)/omega_blackwell_gates.o $(OUT_DIR)/omega_world_gates.o $(OUT_DIR)/omega_clean_clone.o,$(OBJS)) +GPU_LINK_LIBS = $(OUT_DIR)/libomega_gpu.a $(CUDAPP_LIB) GPU_API_TEST = $(OUT_DIR)/gpu_matmul_api_test GPU_R4_RECEIPT = $(OUT_DIR)/gpu_matmul_r4_receipt -$(OUT_DIR)/libomega_gpu.a: $(GPU_API_OBJS) | check-physics-lock - ar rcs $@ $(GPU_API_OBJS) -libomega_gpu: $(OUT_DIR)/libomega_gpu.a +$(OUT_DIR)/libomega_gpu.a: $(GPU_API_OBJS) | check-physics-lock check-cudapp + ar rcs $@.tmp.$$$$ $(GPU_API_OBJS) && mv -f $@.tmp.$$$$ $@ +libomega_gpu: $(GPU_LINK_LIBS) # omega-mv#471: the archive must link without -lm (omegatool, the Rust FFI crate and AIENOS link it bare). Fails if any symbol # the archive leaves undefined is one libm exports (the export list is read from this toolchain's libm.so.6). .PHONY: test-gpu-libm-free -test-gpu-libm-free: $(OUT_DIR)/libomega_gpu.a +test-gpu-libm-free: $(GPU_LINK_LIBS) @export LC_ALL=C; libm="$$($(CC) -print-file-name=libm.so.6)"; test -f "$$libm" || { echo "libm-free: no libm.so.6 from $(CC)"; exit 1; }; \ - nm -D --defined-only "$$libm" | awk '{print $$3}' | sed 's/@.*//' | sort -u > $(OUT_DIR)/libm.syms; \ - nm -u $(OUT_DIR)/libomega_gpu.a | awk '{print $$2}' | sort -u | comm -12 - $(OUT_DIR)/libm.syms > $(OUT_DIR)/libm-refs.txt; \ - n=$$(wc -l < $(OUT_DIR)/libm-refs.txt); echo "libm-free: $$n libm symbols referenced by libomega_gpu.a ($$(wc -l < $(OUT_DIR)/libm.syms) libm exports checked)"; \ - if [ "$$n" -ne 0 ]; then sed 's/^/ /' $(OUT_DIR)/libm-refs.txt; echo "FAIL: libomega_gpu.a is not libm-free"; exit 1; fi; echo "PASS: libomega_gpu.a is libm-free" -$(GPU_API_TEST): tests/gpu_matmul_api_test.c src/omega_gpu_matmul_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/gpu_matmul_api_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm + nm -D --defined-only "$$libm" > $(OUT_DIR)/libm-exports.raw || exit $$?; \ + awk '{print $$3}' $(OUT_DIR)/libm-exports.raw | sed 's/@.*//' | sort -u > $(OUT_DIR)/libm.syms; \ + nm -u $(GPU_LINK_LIBS) > $(OUT_DIR)/gpu-undefined.raw || exit $$?; \ + awk '{print $$2}' $(OUT_DIR)/gpu-undefined.raw | sort -u | comm -12 - $(OUT_DIR)/libm.syms > $(OUT_DIR)/libm-refs.txt; \ + n=$$(wc -l < $(OUT_DIR)/libm-refs.txt); echo "libm-free: $$n libm symbols referenced by the adapter plus canonical GPU archives ($$(wc -l < $(OUT_DIR)/libm.syms) libm exports checked)"; \ + if [ "$$n" -ne 0 ]; then sed 's/^/ /' $(OUT_DIR)/libm-refs.txt; echo "FAIL: adapter plus canonical GPU archives are not libm-free"; exit 1; fi; echo "PASS: adapter plus canonical GPU archives are libm-free" +$(GPU_API_TEST): $(CUDAPP_SOURCE)/tests/gpu_matmul_api_test.c $(CUDAPP_SOURCE)/src/omega_gpu_matmul_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/gpu_matmul_api_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-matmul-api: $(GPU_API_TEST) $(GPU_R4_RECEIPT) ./$(GPU_API_TEST) --host-only ./$(GPU_R4_RECEIPT) --host-only @@ -2533,8 +2441,8 @@ test-gpu-matmul-api: $(GPU_API_TEST) $(GPU_R4_RECEIPT) # omega #473 R4: the sealed CTA-budget receipt (full-output comparison at the training shapes, # every budget, repeats, I42 stale-output check, negative controls). Host-only self-test above; the # chip receipt is `quietlock run -- ./build/gpu_matmul_r4_receipt --out receipt.json`. -$(GPU_R4_RECEIPT): tests/gpu_matmul_r4_receipt.c src/omega_gpu_matmul_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/gpu_matmul_r4_receipt.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_R4_RECEIPT): $(CUDAPP_SOURCE)/tests/gpu_matmul_r4_receipt.c $(CUDAPP_SOURCE)/src/omega_gpu_matmul_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/gpu_matmul_r4_receipt.c $(GPU_LINK_LIBS) -lpthread -lm # FB-1 cut 4: native rmsnorm / rope / swiglu (+ EX2 and shared-exchange probes). # test-gpu-elementwise is host-only (refusals, codegen, word fixtures, nvdisasm @@ -2542,8 +2450,8 @@ $(GPU_R4_RECEIPT): tests/gpu_matmul_r4_receipt.c src/omega_gpu_matmul_api.h $(OU # through the heavy queue. -ffp-contract=off keeps the f32 oracle free of FMA. .PHONY: test-gpu-elementwise GPU_EW_TEST = $(OUT_DIR)/gpu_elementwise_test -$(GPU_EW_TEST): tests/gpu_elementwise_test.c src/omega_gpu_elementwise_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_elementwise_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_EW_TEST): $(CUDAPP_SOURCE)/tests/gpu_elementwise_test.c $(CUDAPP_SOURCE)/src/omega_gpu_elementwise_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_elementwise_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-elementwise: $(GPU_EW_TEST) ./$(GPU_EW_TEST) --host-only @@ -2551,19 +2459,19 @@ test-gpu-elementwise: $(GPU_EW_TEST) # into instruction word 3. Host only; the golden-word checks compare words 0..2, so this is the check for word 3. .PHONY: test-bw-encode-control BW_ENCODE_CONTROL_TEST = $(OUT_DIR)/bw_encode_control_test -$(BW_ENCODE_CONTROL_TEST): tests/bw_encode_control_test.c src/omega_blackwell_codegen.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/bw_encode_control_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(BW_ENCODE_CONTROL_TEST): $(CUDAPP_SOURCE)/tests/bw_encode_control_test.c $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/bw_encode_control_test.c $(GPU_LINK_LIBS) -lpthread -lm test-bw-encode-control: $(BW_ENCODE_CONTROL_TEST) ./$(BW_ENCODE_CONTROL_TEST) # omega #308: structured warp reconvergence (BSSY/BSYNC regions). test-gpu-reconv is # host-only (encoder goldens, region bookkeeping, refusals, nvdisasm listing, every probe -# kernel through the SIMT warp simulator tests/bw_warp_sim.h against the oracle, mutation +# kernel through the SIMT warp simulator $(CUDAPP_SOURCE)/tests/bw_warp_sim.h against the oracle, mutation # controls); the chip gate is tools/run_gpu_reconv_chip.sh. .PHONY: test-gpu-reconv GPU_RECONV_TEST = $(OUT_DIR)/gpu_reconv_test -$(GPU_RECONV_TEST): tests/gpu_reconv_test.c tests/bw_warp_sim.h src/omega_gpu_elementwise_api.h src/omega_bw_reconv.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -Itests -o $@ tests/gpu_reconv_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_RECONV_TEST): $(CUDAPP_SOURCE)/tests/gpu_reconv_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_SOURCE)/src/omega_gpu_elementwise_api.h $(CUDAPP_SOURCE)/src/omega_bw_reconv.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_reconv_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-reconv: $(GPU_RECONV_TEST) ./$(GPU_RECONV_TEST) --host-only @@ -2574,8 +2482,8 @@ test-gpu-reconv: $(GPU_RECONV_TEST) .PHONY: test-gpu-imadhi-rc GPU_IMADHI_SIMS = bw_warp_sim bw_warp_sim_tc bw_warp_sim_k bw_warp_sim_pa GPU_IMADHI_TESTS = $(GPU_IMADHI_SIMS:%=$(OUT_DIR)/gpu_imadhi_rc_test_%) -$(OUT_DIR)/gpu_imadhi_rc_test_%: tests/gpu_imadhi_rc_test.c tests/%.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -Itests -DSIM_HEADER='"$*.h"' -o $@ tests/gpu_imadhi_rc_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(OUT_DIR)/gpu_imadhi_rc_test_%: $(CUDAPP_SOURCE)/tests/gpu_imadhi_rc_test.c tests/%.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -I$(CUDAPP_SOURCE)/tests -Itests -DSIM_HEADER='"$*.h"' -o $@ $(CUDAPP_SOURCE)/tests/gpu_imadhi_rc_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-imadhi-rc: $(GPU_IMADHI_TESTS) @for t in $(GPU_IMADHI_TESTS); do ./$$t || exit 1; done @@ -2588,8 +2496,8 @@ test-gpu-imadhi-rc: $(GPU_IMADHI_TESTS) # (tools/run_gpu_attention_chip.sh). -ffp-contract=off keeps the oracle free of FMA. .PHONY: test-gpu-attention GPU_ATTN_TEST = $(OUT_DIR)/gpu_attention_test -$(GPU_ATTN_TEST): tests/gpu_attention_test.c tests/bw_warp_sim.h src/omega_gpu_attention_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_attention_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_ATTN_TEST): $(CUDAPP_SOURCE)/tests/gpu_attention_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_SOURCE)/src/omega_gpu_attention_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_attention_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-attention: $(GPU_ATTN_TEST) ./$(GPU_ATTN_TEST) --host-only ./$(GPU_ATTN_TEST) --sim @@ -2599,15 +2507,15 @@ test-gpu-attention: $(GPU_ATTN_TEST) ./$(GPU_ATTN_TEST) --hd 128 --divergent --sim # FB-1 cut 4b: fresh-process device-open probe (flake investigation, tools/probe_gpu_open.sh) -$(OUT_DIR)/gpu_session_probe: tests/gpu_session_probe.c src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/gpu_session_probe.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(OUT_DIR)/gpu_session_probe: $(CUDAPP_SOURCE)/tests/gpu_session_probe.c $(CUDAPP_SOURCE)/src/omega_gpu_session.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/gpu_session_probe.c $(GPU_LINK_LIBS) -lpthread -lm -# OWN-30B cut 2: window matmul gate (tests/gpu_moe_window_test.c). test-gpu-moe-window runs the host-only +# OWN-30B cut 2: window matmul gate ($(CUDAPP_SOURCE)/tests/gpu_moe_window_test.c). test-gpu-moe-window runs the host-only # refusals and the packed-window byte rule; the chip gate is `./build/gpu_moe_window_test --out r.json` # under /tmp/aien-gb10.lock (equivalence to the whole-tensor columns, mutants, window timing). GPU_MOE_TEST = $(OUT_DIR)/gpu_moe_window_test -$(GPU_MOE_TEST): tests/gpu_moe_window_test.c src/omega_gpu_moe_api.h src/omega_gpu_matmul_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/gpu_moe_window_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_MOE_TEST): $(CUDAPP_SOURCE)/tests/gpu_moe_window_test.c $(CUDAPP_SOURCE)/src/omega_gpu_moe_api.h $(CUDAPP_SOURCE)/src/omega_gpu_matmul_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/gpu_moe_window_test.c $(GPU_LINK_LIBS) -lpthread -lm .PHONY: test-gpu-moe-window test-gpu-moe-window: $(GPU_MOE_TEST) ./$(GPU_MOE_TEST) --host-only @@ -2618,8 +2526,8 @@ test-gpu-moe-window: $(GPU_MOE_TEST) # -ffp-contract=off keeps the double oracle free of FMA. .PHONY: test-gpu-fp8 GPU_FP8_TEST = $(OUT_DIR)/gpu_fp8_api_test -$(GPU_FP8_TEST): tests/gpu_fp8_api_test.c tests/bw_warp_sim.h src/omega_gpu_fp8_api.h src/omega_blackwell_codegen_moe.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_fp8_api_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_FP8_TEST): $(CUDAPP_SOURCE)/tests/gpu_fp8_api_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_moe.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_fp8_api_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-fp8: $(GPU_FP8_TEST) ./$(GPU_FP8_TEST) --host-only AIEN_OMEGA_FP8_COAL=0 ./$(GPU_FP8_TEST) --coal-default @@ -2629,39 +2537,39 @@ test-gpu-fp8: $(GPU_FP8_TEST) # omega #457 (2026-10-15): host rewrite of a GPU-cached buffer must be visible to the next launch. Chip only; the gate # is tools/run_gpu_l2_stale_chip.sh. GPU_L2_STALE_TEST = $(OUT_DIR)/gpu_l2_stale_test -$(GPU_L2_STALE_TEST): tests/gpu_l2_stale_test.c src/omega_gpu_fp8_api.h src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_l2_stale_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_L2_STALE_TEST): $(CUDAPP_SOURCE)/tests/gpu_l2_stale_test.c $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(CUDAPP_SOURCE)/src/omega_gpu_session.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_l2_stale_test.c $(GPU_LINK_LIBS) -lpthread -lm # OWN-30B cut 8 (2026-10-13): one-launch decode attention (omega_gpu_decode_attn_api.h). test-gpu-decode-attn is # host-only + simulator; the chip gate is tools/run_gpu_decode_attn_chip.sh. .PHONY: test-gpu-decode-attn GPU_DATTN_TEST = $(OUT_DIR)/gpu_decode_attn_test -$(GPU_DATTN_TEST): tests/gpu_decode_attn_test.c tests/bw_warp_sim_k.h src/omega_gpu_decode_attn_api.h src/omega_blackwell_codegen_attn.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_decode_attn_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_DATTN_TEST): $(CUDAPP_SOURCE)/tests/gpu_decode_attn_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_attn.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_decode_attn_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-decode-attn: $(GPU_DATTN_TEST) test-gpu-decode-attn-maxpos $(GPU_DATTN_TEST) --host-only $(GPU_DATTN_TEST) --sim # omega #535: the 128k position bound (OMEGA_GPU_DATTN_MAX_POS 131072) on a fake platform, no device. A sanitized copy -# of src/omega_gpu_decode_attn_api.c is linked ahead of the library, so cache writes, the RoPE fill and launch staging +# of $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.c is linked ahead of the library, so cache writes, the RoPE fill and launch staging # are ASan/UBSan checked against the fake's exact-size buffers. Each mutant breaks one bound in a copy of that file; # the test must FAIL on it. .PHONY: test-gpu-decode-attn-maxpos GPU_DATTN_MAXPOS_TEST = $(OUT_DIR)/test_omega_gpu_decode_attn_maxpos GPU_DATTN_MAXPOS_MUT = $(OUT_DIR)/dattn_maxpos_mut GPU_DATTN_MAXPOS_SAN = -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -$(GPU_DATTN_MAXPOS_TEST): tests/test_omega_gpu_decode_attn_maxpos.c src/omega_gpu_decode_attn_api.c src/omega_gpu_decode_attn_api.h src/omega_blackwell_codegen_attn.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(filter-out -MMD -MP -O2,$(CFLAGS)) $(GPU_DATTN_MAXPOS_SAN) -o $@ tests/test_omega_gpu_decode_attn_maxpos.c \ - src/omega_gpu_decode_attn_api.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_DATTN_MAXPOS_TEST): $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_attn_maxpos.c $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.c $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_attn.h $(GPU_LINK_LIBS) + $(CC) $(filter-out -MMD -MP -O2,$(CFLAGS)) $(GPU_DATTN_MAXPOS_SAN) -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_attn_maxpos.c \ + $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-decode-attn-maxpos: $(GPU_DATTN_MAXPOS_TEST) $(GPU_DATTN_MAXPOS_TEST) @mkdir -p $(GPU_DATTN_MAXPOS_MUT) @set -e; \ tmut() { name=$$1; script=$$2; \ - sed -e "$$script" src/omega_gpu_decode_attn_api.c > $(GPU_DATTN_MAXPOS_MUT)/$$name.c; \ - if cmp -s src/omega_gpu_decode_attn_api.c $(GPU_DATTN_MAXPOS_MUT)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ + sed -e "$$script" $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.c > $(GPU_DATTN_MAXPOS_MUT)/$$name.c; \ + if cmp -s $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn_api.c $(GPU_DATTN_MAXPOS_MUT)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ $(CC) $(filter-out -MMD -MP -O2,$(CFLAGS)) $(GPU_DATTN_MAXPOS_SAN) -o $(GPU_DATTN_MAXPOS_MUT)/$$name \ - tests/test_omega_gpu_decode_attn_maxpos.c $(GPU_DATTN_MAXPOS_MUT)/$$name.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm; \ + $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_attn_maxpos.c $(GPU_DATTN_MAXPOS_MUT)/$$name.c $(GPU_LINK_LIBS) -lpthread -lm; \ if $(GPU_DATTN_MAXPOS_MUT)/$$name > $(GPU_DATTN_MAXPOS_MUT)/$$name.log 2>&1; then echo "mutant $$name SURVIVED"; exit 1; fi; \ if ! grep -q '^FAIL ' $(GPU_DATTN_MAXPOS_MUT)/$$name.log; then \ echo "mutant $$name: no FAIL case (did not run?)"; cat $(GPU_DATTN_MAXPOS_MUT)/$$name.log; exit 1; fi; \ @@ -2680,8 +2588,8 @@ test-gpu-decode-attn-maxpos: $(GPU_DATTN_MAXPOS_TEST) # tools/run_gpu_decode_attn256_chip.sh. .PHONY: test-gpu-decode-attn256 GPU_DATTN256_TEST = $(OUT_DIR)/gpu_decode_attn256_test -$(GPU_DATTN256_TEST): tests/gpu_decode_attn256_test.c tests/bw_warp_sim_k.h src/omega_gpu_decode_attn256_api.h src/omega_blackwell_codegen_attn256.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_decode_attn256_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_DATTN256_TEST): $(CUDAPP_SOURCE)/tests/gpu_decode_attn256_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn256_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_attn256.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_decode_attn256_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-decode-attn256: $(GPU_DATTN256_TEST) $(GPU_DATTN256_TEST) --host-only $(GPU_DATTN256_TEST) --sim @@ -2690,8 +2598,8 @@ test-gpu-decode-attn256: $(GPU_DATTN256_TEST) # (oracle, budgets) plus the warp simulator; the chip gate is tools/run_gpu_router_chip.sh under the GB10 lock. .PHONY: test-gpu-router GPU_ROUTER_TEST = $(OUT_DIR)/gpu_router_test -$(GPU_ROUTER_TEST): tests/gpu_router_test.c tests/bw_warp_sim_k.h src/omega_gpu_router_api.h src/omega_blackwell_codegen_router.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_router_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_ROUTER_TEST): $(CUDAPP_SOURCE)/tests/gpu_router_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_router_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_router.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_router_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-router: $(GPU_ROUTER_TEST) ./$(GPU_ROUTER_TEST) --host-only ./$(GPU_ROUTER_TEST) --sim @@ -2700,15 +2608,15 @@ test-gpu-router: $(GPU_ROUTER_TEST) # test-gpu-gdn is host-only plus the warp simulator over the whole grid; the chip run is ./build/gpu_gdn_test under the GB10 lock. .PHONY: test-gpu-gdn GPU_GDN_TEST = $(OUT_DIR)/gpu_gdn_test -$(GPU_GDN_TEST): tests/gpu_gdn_test.c tests/bw_warp_sim_k.h src/omega_gpu_gdn_api.h src/omega_blackwell_codegen_gdn.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_gdn_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_GDN_TEST): $(CUDAPP_SOURCE)/tests/gpu_gdn_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_gdn_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_gdn.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_gdn_test.c $(GPU_LINK_LIBS) -lpthread -lm # L369: the multi-token GDN decode == T decode steps bit for bit (--sim: simulator; default: the chip, under the GB10 lock) GPU_GDN_MULTI_TEST = $(OUT_DIR)/gpu_gdn_multi_test -$(GPU_GDN_MULTI_TEST): tests/gpu_gdn_multi_test.c tests/bw_warp_sim_k.h src/omega_gpu_gdn_api.h src/omega_blackwell_codegen_gdn.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_gdn_multi_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_GDN_MULTI_TEST): $(CUDAPP_SOURCE)/tests/gpu_gdn_multi_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_gdn_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_gdn.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_gdn_multi_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_DATTN256_MULTI_TEST = $(OUT_DIR)/gpu_dattn256_multi_test -$(GPU_DATTN256_MULTI_TEST): tests/gpu_dattn256_multi_test.c src/omega_gpu_decode_attn256_api.h src/omega_blackwell_codegen_attn256.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -Itests -o $@ tests/gpu_dattn256_multi_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_DATTN256_MULTI_TEST): $(CUDAPP_SOURCE)/tests/gpu_dattn256_multi_test.c $(CUDAPP_SOURCE)/src/omega_gpu_decode_attn256_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_attn256.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_dattn256_multi_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-gdn: $(GPU_GDN_TEST) ./$(GPU_GDN_TEST) --host-only ./$(GPU_GDN_TEST) --sim @@ -2718,8 +2626,8 @@ test-gpu-gdn: $(GPU_GDN_TEST) # gate is tools/run_gpu_bf16_gemv_chip.sh under the GB10 lock. .PHONY: test-gpu-bf16-gemv GPU_BF16_TEST = $(OUT_DIR)/gpu_bf16_gemv_test -$(GPU_BF16_TEST): tests/gpu_bf16_gemv_test.c tests/bw_warp_sim_k.h src/omega_gpu_bf16_gemv_api.h src/omega_blackwell_codegen_bf16.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_bf16_gemv_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_BF16_TEST): $(CUDAPP_SOURCE)/tests/gpu_bf16_gemv_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_bf16_gemv_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_bf16.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_bf16_gemv_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-bf16-gemv: $(GPU_BF16_TEST) $(GPU_BF16_TEST) --host-only $(GPU_BF16_TEST) --sim @@ -2729,30 +2637,30 @@ test-gpu-bf16-gemv: $(GPU_BF16_TEST) # epilogue, mutants 1-3 caught); the chip gate is tools/run_gpu_tern_chip.sh with the quiet flag held. .PHONY: test-gpu-tern GPU_TERN_TEST = $(OUT_DIR)/gpu_tern_test -$(GPU_TERN_TEST): tests/gpu_tern_test.c tests/bw_warp_sim_k.h src/omega_gpu_tern_api.h src/omega_blackwell_codegen_tern.h $(OMA_RZ_SRCS) $(OMA_RZ_HDRS) $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off $(OMA_RZ_ARCH) -Itests -o $@ tests/gpu_tern_test.c $(OMA_RZ_SRCS) $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_TERN_TEST): tests/gpu_tern_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_tern_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_tern.h $(OMA_RZ_SRCS) $(OMA_RZ_HDRS) $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off $(OMA_RZ_ARCH) -I$(CUDAPP_SOURCE)/tests -Itests -o $@ tests/gpu_tern_test.c $(OMA_RZ_SRCS) $(GPU_LINK_LIBS) -lpthread -lm test-gpu-tern: $(GPU_TERN_TEST) $(GPU_TERN_TEST) --host-only $(GPU_TERN_TEST) --sim # OWN-30B (2026-10-13): report-only lm_head study, fp8 vs bf16 argmax agreement on the real checkpoint (chip, GB10 lock). -$(OUT_DIR)/gpu_lmhead_fp8_study: tests/gpu_lmhead_fp8_study.c src/omega_gpu_bf16_gemv_api.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -O2 -o $@ tests/gpu_lmhead_fp8_study.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(OUT_DIR)/gpu_lmhead_fp8_study: $(CUDAPP_SOURCE)/tests/gpu_lmhead_fp8_study.c $(CUDAPP_SOURCE)/src/omega_gpu_bf16_gemv_api.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -O2 -o $@ $(CUDAPP_SOURCE)/tests/gpu_lmhead_fp8_study.c $(GPU_LINK_LIBS) -lpthread -lm # OWN-30B prefill (2026-10-13): FP8 grouped GEMM (omega_gpu_fp8gemm_api.h). test-gpu-fp8gemm is host-only (emulation, # permutation, budgets) plus the warp simulator (512 threads); the chip gate is tools/run_gpu_fp8gemm_chip.sh under the GB10 lock. .PHONY: test-gpu-fp8gemm GPU_FP8GEMM_TEST = $(OUT_DIR)/gpu_fp8gemm_test -$(GPU_FP8GEMM_TEST): tests/gpu_fp8gemm_test.c tests/bw_warp_sim_k.h src/omega_gpu_fp8gemm_api.h src/omega_blackwell_codegen_gemm.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_fp8gemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_FP8GEMM_TEST): $(CUDAPP_SOURCE)/tests/gpu_fp8gemm_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8gemm_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_gemm.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_fp8gemm_test.c $(GPU_LINK_LIBS) -lpthread -lm # Qwen3.6-35B (sc L306 / L312) host-only simulator checks of the decode glue kernels, and the codegen hash pin Q36_DEC_SIM_TEST = $(OUT_DIR)/q36_dec_sim_test -$(Q36_DEC_SIM_TEST): tests/q36_dec_sim_test.c tests/bw_warp_sim_k.h src/omega_blackwell_codegen_dec.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/q36_dec_sim_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(Q36_DEC_SIM_TEST): tests/q36_dec_sim_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_dec.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ tests/q36_dec_sim_test.c $(GPU_LINK_LIBS) -lpthread -lm Q36_CODEGEN_HASH = $(OUT_DIR)/q36_codegen_hash -$(Q36_CODEGEN_HASH): tests/q36_codegen_hash.c $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -Itests -o $@ tests/q36_codegen_hash.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(Q36_CODEGEN_HASH): tests/q36_codegen_hash.c $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -I$(CUDAPP_SOURCE)/tests -Itests -o $@ tests/q36_codegen_hash.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST) $(GPU_FP8GEMM_TEST) --host-only $(GPU_FP8GEMM_TEST) --sim @@ -2760,8 +2668,8 @@ test-gpu-fp8gemm: $(GPU_FP8GEMM_TEST) # OWN-30B (2026-10-13): host-only audit that every launcher declares peak + 2 registers (the chip hung at peak + 1). .PHONY: test-gpu-gpr-boundary GPU_GPR_BOUNDARY_TEST = $(OUT_DIR)/gpu_gpr_boundary_test -$(GPU_GPR_BOUNDARY_TEST): tests/gpu_gpr_boundary_test.c src/omega_blackwell_codegen.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/gpu_gpr_boundary_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_GPR_BOUNDARY_TEST): $(CUDAPP_SOURCE)/tests/gpu_gpr_boundary_test.c $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/gpu_gpr_boundary_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-gpr-boundary: $(GPU_GPR_BOUNDARY_TEST) $(GPU_GPR_BOUNDARY_TEST) @@ -2772,8 +2680,8 @@ test-gpu-gpr-boundary: $(GPU_GPR_BOUNDARY_TEST) # kernel (bar C6: every check that called nvdisasm calls ours; test-sm121dis checks that disassembler against the oracle). .PHONY: test-bw-hazard test-bw-hazard-nvdisasm BW_HAZARD_TEST = $(OUT_DIR)/bw_hazard_test -$(BW_HAZARD_TEST): tests/bw_hazard_test.c src/omega_bw_hazard.c src/omega_bw_hazard.h src/omega_sm121_disasm.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/bw_hazard_test.c src/omega_bw_hazard.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(BW_HAZARD_TEST): $(CUDAPP_SOURCE)/tests/bw_hazard_test.c $(CUDAPP_SOURCE)/src/omega_bw_hazard.c $(CUDAPP_SOURCE)/src/omega_bw_hazard.h $(CUDAPP_SOURCE)/src/omega_sm121_disasm.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/bw_hazard_test.c $(CUDAPP_SOURCE)/src/omega_bw_hazard.c $(GPU_LINK_LIBS) -lpthread -lm test-bw-hazard: $(BW_HAZARD_TEST) $(BW_HAZARD_TEST) test-bw-hazard-nvdisasm: $(BW_HAZARD_TEST) @@ -2781,43 +2689,43 @@ test-bw-hazard-nvdisasm: $(BW_HAZARD_TEST) # OWN-30B T3 (2026-10-13): HMMA arithmetic probe (host model self-checks; chip run under the GB10 lock). GPU_TC_PROBE_TEST = $(OUT_DIR)/gpu_tc_probe_test -$(GPU_TC_PROBE_TEST): tests/gpu_tc_probe_test.c tests/bw_hmma_model.h src/omega_blackwell_codegen_tc.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_tc_probe_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_TC_PROBE_TEST): $(CUDAPP_SOURCE)/tests/gpu_tc_probe_test.c $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_tc.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_tc_probe_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_TCGEMM_TEST = $(OUT_DIR)/gpu_tcgemm_test -$(GPU_TCGEMM_TEST): tests/gpu_tcgemm_test.c tests/bw_hmma_model.h tests/bw_warp_sim_tc.h src/omega_blackwell_codegen_tc.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_tcgemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_TCGEMM_TEST): $(CUDAPP_SOURCE)/tests/gpu_tcgemm_test.c $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_tc.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_tcgemm_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_TC_PEAK_TEST = $(OUT_DIR)/gpu_tc_peak_test -$(GPU_TC_PEAK_TEST): tests/gpu_tc_peak_test.c tests/bw_hmma_model.h tests/bw_warp_sim_tc.h src/omega_blackwell_codegen_tc.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_tc_peak_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_TC_PEAK_TEST): $(CUDAPP_SOURCE)/tests/gpu_tc_peak_test.c $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_tc.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_tc_peak_test.c $(GPU_LINK_LIBS) -lpthread -lm # OWN-30B L1 attention (2026-10-13): tensor-core causal prefill attention. --host-only and --sim are host proofs; # the chip gate is tools/run_gpu_prefill_attn_chip.sh. GPU_PATTN_TEST = $(OUT_DIR)/gpu_prefill_attn_test -$(GPU_PATTN_TEST): tests/gpu_prefill_attn_test.c tests/bw_hmma_model.h tests/bw_warp_sim_pa.h src/omega_gpu_prefill_attn_api.h src/omega_blackwell_codegen_pattn.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=256 -Itests -o $@ tests/gpu_prefill_attn_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_PATTN_TEST): $(CUDAPP_SOURCE)/tests/gpu_prefill_attn_test.c $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/tests/bw_warp_sim_pa.h $(CUDAPP_SOURCE)/src/omega_gpu_prefill_attn_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_pattn.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=256 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_prefill_attn_test.c $(GPU_LINK_LIBS) -lpthread -lm # Qwen3.8-27B (omega-mv#545, 2026-10-18): head_dim 256 prefill attention on the decode cache. --host-only and --sim # are host proofs; the chip run is the default mode (under the GB10 lock). GPU_PATTN256_TEST = $(OUT_DIR)/gpu_prefill_attn256_test -$(GPU_PATTN256_TEST): tests/gpu_prefill_attn256_test.c tests/bw_hmma_model.h tests/bw_warp_sim_pa.h src/omega_gpu_prefill_attn256_api.h src/omega_blackwell_codegen_pattn256.h src/omega_blackwell_codegen_attn256.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=256 -Itests -o $@ tests/gpu_prefill_attn256_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_PATTN256_TEST): $(CUDAPP_SOURCE)/tests/gpu_prefill_attn256_test.c $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/tests/bw_warp_sim_pa.h $(CUDAPP_SOURCE)/src/omega_gpu_prefill_attn256_api.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_pattn256.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_attn256.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=256 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_prefill_attn256_test.c $(GPU_LINK_LIBS) -lpthread -lm # OWN-30B T3b (2026-10-13): device-resident prefill module tests (host sim first; chip parts under the GB10 lock) GPU_PF_MEM_TEST = $(OUT_DIR)/gpu_pf_mem_test -$(GPU_PF_MEM_TEST): tests/gpu_pf_mem_test.c tests/bw_warp_sim_tc.h src/omega_gpu_prefill.h src/omega_blackwell_codegen_pf.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_pf_mem_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_PF_MEM_TEST): $(CUDAPP_SOURCE)/tests/gpu_pf_mem_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/src/omega_gpu_prefill.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_pf.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_pf_mem_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_PFGEMM_TEST = $(OUT_DIR)/gpu_pfgemm_test -$(GPU_PFGEMM_TEST): tests/gpu_pfgemm_test.c tests/bw_hmma_model.h tests/bw_warp_sim_tc.h src/omega_gpu_prefill.h src/omega_blackwell_codegen_tc2.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -Itests -o $@ tests/gpu_pfgemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_PFGEMM_TEST): $(CUDAPP_SOURCE)/tests/gpu_pfgemm_test.c $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/src/omega_gpu_prefill.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_tc2.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=512 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_pfgemm_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_QMMA_PROBE_TEST = $(OUT_DIR)/gpu_qmma_probe_test -$(GPU_QMMA_PROBE_TEST): tests/gpu_qmma_probe_test.c tests/bw_qmma_model.h src/omega_blackwell_codegen_qmma.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_qmma_probe_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_QMMA_PROBE_TEST): $(CUDAPP_SOURCE)/tests/gpu_qmma_probe_test.c $(CUDAPP_SOURCE)/tests/bw_qmma_model.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_qmma.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_qmma_probe_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_QGEMM_TEST = $(OUT_DIR)/gpu_qgemm_test -$(GPU_QGEMM_TEST): tests/gpu_qgemm_test.c tests/bw_qmma_model.h tests/bw_warp_sim_tc.h src/omega_gpu_prefill.h src/omega_blackwell_codegen_qg.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=1024 -Itests -o $@ tests/gpu_qgemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_QGEMM_TEST): $(CUDAPP_SOURCE)/tests/gpu_qgemm_test.c $(CUDAPP_SOURCE)/tests/bw_qmma_model.h $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/src/omega_gpu_prefill.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_qg.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=1024 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_qgemm_test.c $(GPU_LINK_LIBS) -lpthread -lm GPU_PFHOST_TEST = $(OUT_DIR)/gpu_pfhost_test -$(GPU_PFHOST_TEST): tests/gpu_pfhost_test.c tests/bw_warp_sim_tc.h src/omega_gpu_pfhost.h src/omega_blackwell_codegen_pfhost.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=1024 -Itests -o $@ tests/gpu_pfhost_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_PFHOST_TEST): $(CUDAPP_SOURCE)/tests/gpu_pfhost_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/src/omega_gpu_pfhost.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_pfhost.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -DWS_MAX_THREADS=1024 -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_pfhost_test.c $(GPU_LINK_LIBS) -lpthread -lm # omega#456: the prefill tests above, host model and warp simulator only. Every run names --host-only or --sim, the two # modes that never open the device (each test's main returns before its chip part); chip runs stay under the GB10 lock. .PHONY: test-gpu-prefill-host @@ -2840,7 +2748,7 @@ test-gpu-prefill-host: $(GPU_TC_PROBE_TEST) $(GPU_TCGEMM_TEST) $(GPU_PATTN_TEST) # omega#456: tools/own30b_decode_profile.c is a link-only recorder built by hand on the Spark; compile it with the # project's -Werror flags so a warning cannot land unseen. .PHONY: check-own30b-decode-profile -check-own30b-decode-profile: tools/own30b_decode_profile.c +check-own30b-decode-profile: tools/own30b_decode_profile.c | check-cudapp @mkdir -p $(OUT_DIR) $(CC) $(CFLAGS) -c -o $(OUT_DIR)/own30b_decode_profile.o tools/own30b_decode_profile.c @echo "check-own30b-decode-profile: PASS (compiles with -Werror)" @@ -2848,8 +2756,8 @@ check-own30b-decode-profile: tools/own30b_decode_profile.c # host-only + warp simulator; the chip gate is tools/run_gpu_cmdlist_chip.sh under the GB10 lock. .PHONY: test-gpu-cmdlist GPU_CMDLIST_TEST = $(OUT_DIR)/gpu_cmdlist_test -$(GPU_CMDLIST_TEST): tests/gpu_cmdlist_test.c tests/bw_warp_sim_k.h src/omega_gpu_cmdlist.h src/omega_blackwell_codegen_dec.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_cmdlist_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_CMDLIST_TEST): $(CUDAPP_SOURCE)/tests/gpu_cmdlist_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_gpu_cmdlist.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_dec.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_cmdlist_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-cmdlist: $(GPU_CMDLIST_TEST) ./$(GPU_CMDLIST_TEST) --host-only ./$(GPU_CMDLIST_TEST) --sim @@ -2859,8 +2767,8 @@ test-gpu-cmdlist: $(GPU_CMDLIST_TEST) # with no flag, under the GB10 lock (timings need an exclusive window). .PHONY: test-gpu-streams GPU_STREAMS_TEST = $(OUT_DIR)/gpu_streams_test -$(GPU_STREAMS_TEST): tests/gpu_streams_test.c tests/bw_warp_sim.h src/omega_gpu_cmdlist.h src/omega_bw_em.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_streams_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_STREAMS_TEST): $(CUDAPP_SOURCE)/tests/gpu_streams_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_SOURCE)/src/omega_gpu_cmdlist.h $(CUDAPP_SOURCE)/src/omega_bw_em.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_streams_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-streams: $(GPU_STREAMS_TEST) ./$(GPU_STREAMS_TEST) --sim @@ -2869,8 +2777,8 @@ test-gpu-streams: $(GPU_STREAMS_TEST) # the chip tier is "$(GPU_ISOLATION_TEST)" with no flag, under the GB10 lock. .PHONY: test-gpu-isolation GPU_ISOLATION_TEST = $(OUT_DIR)/gpu_isolation_test -$(GPU_ISOLATION_TEST): tests/gpu_isolation_test.c tests/bw_warp_sim.h src/omega_gpu_session.h src/omega_bw_em.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_isolation_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_ISOLATION_TEST): $(CUDAPP_SOURCE)/tests/gpu_isolation_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_SOURCE)/src/omega_gpu_session.h $(CUDAPP_SOURCE)/src/omega_bw_em.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_isolation_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-isolation: $(GPU_ISOLATION_TEST) ./$(GPU_ISOLATION_TEST) --host-only @@ -2879,8 +2787,8 @@ test-gpu-isolation: $(GPU_ISOLATION_TEST) .PHONY: test-gpu-decode-graph GPU_DECODE_GRAPH_TEST = $(OUT_DIR)/gpu_decode_graph_test GPU_DGRAPH_ABORT_TEST = $(OUT_DIR)/test_omega_gpu_decode_graph_abort -$(GPU_DECODE_GRAPH_TEST): tests/gpu_decode_graph_test.c src/omega_gpu_decode_graph.h src/omega_gpu_cmdlist.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_decode_graph_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_DECODE_GRAPH_TEST): $(CUDAPP_SOURCE)/tests/gpu_decode_graph_test.c $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.h $(CUDAPP_SOURCE)/src/omega_gpu_cmdlist.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_decode_graph_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-decode-graph: $(GPU_DECODE_GRAPH_TEST) $(GPU_DGRAPH_ABORT_TEST) test-gpu-decode-graph-abort-mutants test-gpu-decode-graph-timeline ./$(GPU_DECODE_GRAPH_TEST) --host-only ./$(GPU_DGRAPH_ABORT_TEST) @@ -2890,17 +2798,17 @@ test-gpu-decode-graph: $(GPU_DECODE_GRAPH_TEST) $(GPU_DGRAPH_ABORT_TEST) test-gp # Each mutant breaks one rule in a copy of omega_gpu_decode_graph.c linked ahead of the library; the test must FAIL on it. .PHONY: test-gpu-decode-graph-abort-mutants GPU_DGRAPH_MUT_DIR = $(OUT_DIR)/dgraph_mut -$(GPU_DGRAPH_ABORT_TEST): tests/test_omega_gpu_decode_graph_abort.c src/omega_gpu_decode_graph.h src/omega_gpu_platform.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/test_omega_gpu_decode_graph_abort.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm -test-gpu-decode-graph-abort-mutants: $(OUT_DIR)/libomega_gpu.a +$(GPU_DGRAPH_ABORT_TEST): $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_graph_abort.c $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.h $(CUDAPP_SOURCE)/src/omega_gpu_platform.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_graph_abort.c $(GPU_LINK_LIBS) -lpthread -lm +test-gpu-decode-graph-abort-mutants: $(GPU_LINK_LIBS) @mkdir -p $(GPU_DGRAPH_MUT_DIR) @set -e; killed=0; \ dmut() { name=$$1; script=$$2; \ - sed -e "$$script" src/omega_gpu_decode_graph.c > $(GPU_DGRAPH_MUT_DIR)/$$name.c; \ - if cmp -s src/omega_gpu_decode_graph.c $(GPU_DGRAPH_MUT_DIR)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ + sed -e "$$script" $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.c > $(GPU_DGRAPH_MUT_DIR)/$$name.c; \ + if cmp -s $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.c $(GPU_DGRAPH_MUT_DIR)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ $(CC) $(filter-out -MMD -MP,$(CFLAGS)) -c -o $(GPU_DGRAPH_MUT_DIR)/$$name.o $(GPU_DGRAPH_MUT_DIR)/$$name.c; \ - $(CC) $(filter-out -MMD -MP,$(CFLAGS)) -o $(GPU_DGRAPH_MUT_DIR)/$$name tests/test_omega_gpu_decode_graph_abort.c \ - $(GPU_DGRAPH_MUT_DIR)/$$name.o $(OUT_DIR)/libomega_gpu.a -lpthread -lm; \ + $(CC) $(filter-out -MMD -MP,$(CFLAGS)) -o $(GPU_DGRAPH_MUT_DIR)/$$name $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_graph_abort.c \ + $(GPU_DGRAPH_MUT_DIR)/$$name.o $(GPU_LINK_LIBS) -lpthread -lm; \ if ./$(GPU_DGRAPH_MUT_DIR)/$$name > $(GPU_DGRAPH_MUT_DIR)/$$name.log 2>&1; then echo "mutant $$name SURVIVED"; exit 1; fi; \ nfail=$$(grep -c '^FAIL' $(GPU_DGRAPH_MUT_DIR)/$$name.log || true); \ if [ "$$nfail" -eq 0 ]; then echo "mutant $$name: nonzero exit but no FAIL case (did not run?)"; cat $(GPU_DGRAPH_MUT_DIR)/$$name.log; exit 1; fi; \ @@ -2919,17 +2827,17 @@ test-gpu-decode-graph-abort-mutants: $(OUT_DIR)/libomega_gpu.a .PHONY: test-gpu-decode-graph-timeline GPU_DGRAPH_TL_TEST = $(OUT_DIR)/test_omega_gpu_decode_graph_timeline GPU_DGRAPH_TL_MUT = $(OUT_DIR)/dgraph_tl_mut -$(GPU_DGRAPH_TL_TEST): tests/test_omega_gpu_decode_graph_timeline.c src/omega_gpu_decode_graph.h src/omega_gpu_platform.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -o $@ tests/test_omega_gpu_decode_graph_timeline.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_DGRAPH_TL_TEST): $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_graph_timeline.c $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.h $(CUDAPP_SOURCE)/src/omega_gpu_platform.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_graph_timeline.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-decode-graph-timeline: $(GPU_DGRAPH_TL_TEST) ./$(GPU_DGRAPH_TL_TEST) @mkdir -p $(GPU_DGRAPH_TL_MUT) @set -e; \ tmut() { name=$$1; script=$$2; \ - sed -e "$$script" src/omega_gpu_decode_graph.c > $(GPU_DGRAPH_TL_MUT)/$$name.c; \ - if cmp -s src/omega_gpu_decode_graph.c $(GPU_DGRAPH_TL_MUT)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ - $(CC) $(filter-out -MMD -MP,$(CFLAGS)) -o $(GPU_DGRAPH_TL_MUT)/$$name tests/test_omega_gpu_decode_graph_timeline.c \ - $(GPU_DGRAPH_TL_MUT)/$$name.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm; \ + sed -e "$$script" $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.c > $(GPU_DGRAPH_TL_MUT)/$$name.c; \ + if cmp -s $(CUDAPP_SOURCE)/src/omega_gpu_decode_graph.c $(GPU_DGRAPH_TL_MUT)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ + $(CC) $(filter-out -MMD -MP,$(CFLAGS)) -o $(GPU_DGRAPH_TL_MUT)/$$name $(CUDAPP_SOURCE)/tests/test_omega_gpu_decode_graph_timeline.c \ + $(GPU_DGRAPH_TL_MUT)/$$name.c $(GPU_LINK_LIBS) -lpthread -lm; \ if ./$(GPU_DGRAPH_TL_MUT)/$$name > $(GPU_DGRAPH_TL_MUT)/$$name.log 2>&1; then echo "mutant $$name SURVIVED"; exit 1; fi; \ if ! grep -q '^FAIL one launch past the timeline' $(GPU_DGRAPH_TL_MUT)/$$name.log; then \ echo "mutant $$name: no FAIL case (did not run?)"; cat $(GPU_DGRAPH_TL_MUT)/$$name.log; exit 1; fi; \ @@ -2938,34 +2846,34 @@ test-gpu-decode-graph-timeline: $(GPU_DGRAPH_TL_TEST) tmut timeline-after-failure 's#if (!g->stamps || g->failed || #if (!g->stamps || #'; \ echo "test-gpu-decode-graph-timeline: 2 of 2 mutants killed" -# OWN-30B W-L2c (2026-10-14): per-launch fixed cost inside a command list (tests/gpu_launch_cost_test.c, chip only, GB10 lock). +# OWN-30B W-L2c (2026-10-14): per-launch fixed cost inside a command list ($(CUDAPP_SOURCE)/tests/gpu_launch_cost_test.c, chip only, GB10 lock). GPU_LAUNCH_COST_TEST = $(OUT_DIR)/gpu_launch_cost_test -$(GPU_LAUNCH_COST_TEST): tests/gpu_launch_cost_test.c src/omega_gpu_fp8_api.h src/omega_gpu_cmdlist.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_launch_cost_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_LAUNCH_COST_TEST): $(CUDAPP_SOURCE)/tests/gpu_launch_cost_test.c $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(CUDAPP_SOURCE)/src/omega_gpu_cmdlist.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_launch_cost_test.c $(GPU_LINK_LIBS) -lpthread -lm -# OWN-30B W-L2d (2026-10-14): L2 reuse of FP8 GEMV weights between two launches of one list (tests/gpu_l2_reuse_test.c, chip only, GB10 lock). +# OWN-30B W-L2d (2026-10-14): L2 reuse of FP8 GEMV weights between two launches of one list ($(CUDAPP_SOURCE)/tests/gpu_l2_reuse_test.c, chip only, GB10 lock). GPU_L2_REUSE_TEST = $(OUT_DIR)/gpu_l2_reuse_test -$(GPU_L2_REUSE_TEST): tests/gpu_l2_reuse_test.c src/omega_gpu_fp8_api.h src/omega_gpu_cmdlist.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_l2_reuse_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_L2_REUSE_TEST): $(CUDAPP_SOURCE)/tests/gpu_l2_reuse_test.c $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(CUDAPP_SOURCE)/src/omega_gpu_cmdlist.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_l2_reuse_test.c $(GPU_LINK_LIBS) -lpthread -lm # sc #642 (2026-10-18): Qwen3.8-27B decode graph (one token = one command list), chip test vs the APIs one call at a time .PHONY: test-gpu-q38-graph-host GPU_Q38_GRAPH_TEST = $(OUT_DIR)/gpu_q38_graph_test -$(GPU_Q38_GRAPH_TEST): tests/gpu_q38_graph_test.c src/omega_gpu_q38_graph.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_q38_graph_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_Q38_GRAPH_TEST): $(CUDAPP_SOURCE)/tests/gpu_q38_graph_test.c $(CUDAPP_SOURCE)/src/omega_gpu_q38_graph.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_q38_graph_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-q38-graph-host: $(GPU_Q38_GRAPH_TEST) ./$(GPU_Q38_GRAPH_TEST) --host-only # HUM L314 exact two-pass lm_head (XBOUND simulator proofs; the chip run comes with the export) GPU_EXACT_HEAD_TEST = $(OUT_DIR)/gpu_exact_head_test -$(GPU_EXACT_HEAD_TEST): tests/gpu_exact_head_test.c tests/bw_warp_sim_k.h src/omega_blackwell_codegen_dec.h src/omega_gpu_bf16_gemv_api.h src/omega_gpu_fp8_api.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_exact_head_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_EXACT_HEAD_TEST): $(CUDAPP_SOURCE)/tests/gpu_exact_head_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_k.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen_dec.h $(CUDAPP_SOURCE)/src/omega_gpu_bf16_gemv_api.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_exact_head_test.c $(GPU_LINK_LIBS) -lpthread -lm # C3 (docs/OMEGA.md): sum, max, min and prefix sum of any length 1..2^28, bit-exact against the frozen order. # test-gpu-scan: host refusals, codegen, references vs exact sums and vs the E1 reference, then the warp simulator # (both orders, mutants caught). The chip tier is "$(GPU_SCAN_TEST)" with no flag, under the GB10 lock. GPU_SCAN_TEST = $(OUT_DIR)/gpu_scan_test -$(GPU_SCAN_TEST): tests/gpu_scan_test.c tests/bw_warp_sim.h src/omega_gpu_scan.h src/omega_numeric_reduce.c src/omega_numeric.c $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_scan_test.c src/omega_numeric_reduce.c src/omega_numeric.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_SCAN_TEST): $(CUDAPP_SOURCE)/tests/gpu_scan_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_SOURCE)/src/omega_gpu_scan.h src/omega_numeric_reduce.c src/omega_numeric.c $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(CUDAPP_SOURCE)/tests/gpu_scan_test.c src/omega_numeric_reduce.c src/omega_numeric.c $(GPU_LINK_LIBS) -lpthread -lm .PHONY: test-gpu-scan test-gpu-scan: $(GPU_SCAN_TEST) ./$(GPU_SCAN_TEST) --sim @@ -2973,9 +2881,11 @@ test-gpu-scan: $(GPU_SCAN_TEST) # C3 (docs/OMEGA.md): matrix multiply of any shape, BF16 and FP8 (e4m3), both layouts, on the tensor cores; bit-exact # against the chip-measured tensor-core model. test-gpu-gemm: host refusals and codegen, then the warp simulator. # The chip tier is "$(GPU_GEMM_TEST)" with no flag (>= 200 shapes up to 8192, speed vs the measured ceiling), under the GB10 lock. +# The test and its tensor-core models are CUDApp's ($(CUDAPP_SOURCE)/tests), the owner of omega_gpu_gemm.h. GPU_GEMM_TEST = $(OUT_DIR)/gpu_gemm_test -$(GPU_GEMM_TEST): tests/gpu_gemm_test.c tests/bw_warp_sim_tc.h tests/bw_hmma_model.h tests/bw_qmma_model.h src/omega_gpu_gemm.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -Itests -o $@ tests/gpu_gemm_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_GEMM_TEST): $(CUDAPP_SOURCE)/tests/gpu_gemm_test.c $(CUDAPP_SOURCE)/tests/bw_warp_sim_tc.h $(CUDAPP_SOURCE)/tests/bw_hmma_model.h \ + $(CUDAPP_SOURCE)/tests/bw_qmma_model.h $(CUDAPP_SOURCE)/src/omega_gpu_gemm.h $(GPU_LINK_LIBS) | check-cudapp + $(CC) $(CFLAGS) -ffp-contract=off -I"$(CUDAPP_SOURCE)/tests" -o $@ $(CUDAPP_SOURCE)/tests/gpu_gemm_test.c $(GPU_LINK_LIBS) -lpthread -lm .PHONY: test-gpu-gemm test-gpu-gemm: $(GPU_GEMM_TEST) ./$(GPU_GEMM_TEST) --sim @@ -2985,7 +2895,7 @@ test-gpu-gemm: $(GPU_GEMM_TEST) # tools/run_gpu_fp8_slots_chip.sh under the GB10 lock (parity vs resident, churn, reader fence via a command list, negative control). .PHONY: test-gpu-fp8-slots GPU_FP8_SLOTS_TEST = $(OUT_DIR)/gpu_fp8_slots_test -$(GPU_FP8_SLOTS_TEST): tests/gpu_fp8_slots_test.c src/omega_gpu_fp8_slots.h src/omega_fp8_slot_table.h src/omega_gpu_fp8_api.h src/omega_gpu_cmdlist.h $(OUT_DIR)/libomega_gpu.a - $(CC) $(CFLAGS) -ffp-contract=off -o $@ tests/gpu_fp8_slots_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm +$(GPU_FP8_SLOTS_TEST): $(CUDAPP_SOURCE)/tests/gpu_fp8_slots_test.c $(CUDAPP_SOURCE)/src/omega_gpu_fp8_slots.h $(CUDAPP_SOURCE)/src/omega_fp8_slot_table.h $(CUDAPP_SOURCE)/src/omega_gpu_fp8_api.h $(CUDAPP_SOURCE)/src/omega_gpu_cmdlist.h $(GPU_LINK_LIBS) + $(CC) $(CFLAGS) -ffp-contract=off -o $@ $(CUDAPP_SOURCE)/tests/gpu_fp8_slots_test.c $(GPU_LINK_LIBS) -lpthread -lm test-gpu-fp8-slots: $(GPU_FP8_SLOTS_TEST) ./$(GPU_FP8_SLOTS_TEST) --host-only diff --git a/README.md b/README.md index 8664459b4..71e7a4153 100644 --- a/README.md +++ b/README.md @@ -60,6 +60,65 @@ Not yet true on main: the GPU C under `src/omega_blackwell_*`, `src/omega_gpu_*` [aienux](https://github.com/aien-dev/aienux) holds Aienux, the kernel of AienOS, which Omega is meant to run on. [physics-mv](https://github.com/aien-dev/physics-mv) provides FORGE machine realization and the GB10 native path (pinned in `physics.lock`). [aien-architecture-mv](https://github.com/aien-dev/aien-architecture-mv) owns status and sequencing. ARGUS-0/1 (a defensive plane) is implemented in aienux (`native/argus`, pinned by `argus.lock`); Omega only carries the opt-in `RX_ARGUS` hooks (`src/runtime/rx_argus.c`) and receipts in `evidence/ARGUS/`. Physics Zero exists here as a host benchmark apparatus and learner (`src/physics0/`, `tests/physics0/`, `mk/physics0-learner.mk`, `docs/physics0/`, receipts in `evidence/physics0/`), with its specifications in the physics repository. DIRAC-0 is a specification in aien-architecture-mv plus an oracle source in `research/dirac-oracle/` that has never been built or run. The Evolution Arena is a plan only. +### Canonical native GPU sources + +`cudapp.lock` pins the CUDApp source consumed by this tree. Native GPU implementation, driver closure, generated native GPU units and their public headers come from that revision, not from a second Omega copy. `tools/cudapp-stage.sh` authenticates the checkout, materializes its committed tree, checks native-unit regeneration, builds the canonical archive and publishes an immutable stage under `OUT_DIR/cudapp`. Every native build authenticates that stage again, including a build without `make clean`. A missing or different pin, missing source, changed source or changed archive refuses the build. There is no lock-check bypass. + +Set `CUDAPP_DIR` to a checkout whose HEAD is exactly `cudapp.lock`, `OMEGA_OMC` to the seeded compiler with SHA-256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f` (Omega `e5b32567a7aff3ce594e3254a622a846a6cd190b`), and `OMEGA_BRIDGE` to omega-bridge `0c4cb9ff980af278890b231b994eaede4dc7621c`. The canonical library is linked after Omega's retained CPU objects. Omega's CPU SHA-256/BLAKE3 binding retains its separately recorded compiler and bridge pins in `om/units.sh` and `om/omega-bridge.lock`; those are not the native GPU binding. + +`tests/cudapp_retirement_sources.json` records all 123 removed source/header paths, their exact historical and canonical object identities, and the SHA-256 of the preserved original-source archive. Omega retains its unique Blackwell qualification adapter and resident runtime adapter. Historical receipts and unmerged branches, including #618, are not rewritten or represented as newly qualified. The remaining CPU implementation overlap is explicit: Omega's CPU companion objects precede the canonical archive; native GPU implementation comes only from CUDApp. + +Visor and program host callers also link the canonical archive after retained CPU +objects; they do not require retired local Blackwell object rules. Tensor mutation +and GB10-host controls authenticate/stage before invoking their standalone runner, +including parallel builds. `test-numeric-cpu`, `test-program-fp32`, +`test-program-realize`, `test-program-id`, `test-tensor`, `test-tensor-store` and +`test-tensor-mutations` exercise host behavior only. + +Standalone chip collectors use the same authenticated stage or disposable canonical overlay and retain their existing device-authorization requirements. Their `canonical_source` field embeds the existing `.om` stage-verifier object unchanged; it is source provenance, not qualification authority. M17 reruns refuse an existing receipt or corpus manifest: set `M17_EVIDENCE_DIR` to a fresh evidence directory rather than replacing historical evidence. A build-only check of a chip collector is not a chip run. + +This ownership cutover does not activate new native candidates. Existing artifact admission remains authoritative; new candidates have no production qualification record and remain refused. Host fixtures use explicitly synthetic handles. GPU execution, exact-artifact independent hardware qualification and full-model parity/performance are separate authorized gates, not consequences of staging, compilation or host tests. + +#### Existing 35B candidate acceptance boundary + +The first whole-model target is the existing Q36 35B inference path on Spark, +not a new operator, adapter or hardware backend. Before an authorized device run, +freeze one manifest containing the Core source and executable hashes, this Omega +source, `cudapp.lock`, staged source/archive hashes, all generated-unit identities, +compiler and bridge pins, model/config/tokenizer/weight/scale content identities, +exact command/environment, admission records and workload inputs. The pinned +CUDApp revision `6bfd376` contains the LDG MMIO repair (#172, `27bce88`), the +capacity repair (#173, landed as `a25fb9f`) and the command-list lifetime and +grouped host-acceptance repairs (#174/#175, landed as `8717565`). Merged source +and historical component receipts are not qualification of that manifest. + +Build the canonical archive through `check-cudapp`, then build the existing Core +35B consumer against that exact archive without an alternate GPU implementation. +Retain the link map and verify the consumed archive and generated-unit identities. +Run host/refusal controls first, including wrong pin, changed source/archive, +shape/grouped-MoE admission, capacity exhaustion, command disposal and recovery. +Production resolver `NULL` and record count zero remain unchanged; a build-only +candidate does not acquire production admission. + +Actual inference requires a current authorized GPU reservation and an isolated +endpoint, never an unapproved replacement or second large model beside the resident +service. Compare the candidate with the saved qualified incumbent using identical +model bytes, prompts, decoding settings, context and slot configuration. Record +correctness and numerical/model-quality results, complete prefill/decode timings, +peak and steady memory, repeated-run reliability, timeout/refusal and recovery +behavior, and effects on neighboring processes. Cover one-user and existing +multi-user workloads, ragged/large-M prefill and grouped experts; bind every actual +recorded code/launch occurrence before submission. A partial run, a mismatched +artifact or any unaccepted qualification refuses activation. GPU, full-model, +memory, speed, recovery and neighboring-process outcomes remain NOT_RUN until +measured against the frozen candidate; publish new receipts without changing old ones. + +This path still depends on Linux and NVIDIA's kernel driver/firmware; the vendored +driver interface headers are version `580.173.02`. Record the actual running driver +and firmware versions in the candidate manifest. Removing CUDA userspace imports +does not establish an independent driver, generic CUDA compatibility or a drop-in +replacement for arbitrary applications. + ## Standing rules Language rule: `.om` is the only forward first-party implementation language. Implement and qualify each replacement, switch its actual consumers, then remove the superseded first-party source and obsolete build/runtime dependencies from the active tree. This includes compiler/runtime code, services, tools, automation and project-owned tests; C/Rust/shell remaining today are unfinished migration, not permanent exemptions. Preserve Git history and immutable evidence. External protocol formats, generated machine code, device firmware and independently sourced qualification oracles have separately declared roles; they must not conceal a foreign implementation of Omega. See the [replacement/deletion contract](https://github.com/aien-dev/aien-architecture-mv/issues/300). diff --git a/cudapp.lock b/cudapp.lock new file mode 100644 index 000000000..c8d0215cc --- /dev/null +++ b/cudapp.lock @@ -0,0 +1 @@ +c944ee82fcfb536f44edef3697b081319039b6ca diff --git a/docs/.crumb b/docs/.crumb index 21e93ea0a..13a530336 100644 --- a/docs/.crumb +++ b/docs/.crumb @@ -124,14 +124,14 @@ } ], "children_root": "sha256:c81d43c0c392dfec2b6ed5b38ba95ea7c592782b283950e32b777e7b9cfd9d61", - "compiled_at": "2026-10-31T11:59:10Z", + "compiled_at": "2026-10-31T13:42:24Z", "compiler": "crumb-compile/1", - "digest": "sha256:f00281122c0cb3bce9288b99d79cae539f9824faa48ac0bf3e0ce9e3020fed80", + "digest": "sha256:5687ce12cd5ab387b3ec020ca7325923acdc085b4ccbfe45913ac38c36e7d296", "evidence_files": 34, "evidence_root": "sha256:589d8b3706e6d7a202ab20b278dac5fc5bafc973f1c2a867b2668aa7210b65cc", - "files": 147, - "generated_at_commit": "474197e4fa0207e0e2fb3c0494594a975f5031fa", - "source_tree": "sha256:29540f872c6ce1408cb626bc0ed03fb20190295bae8f139baef650dd94727c2d" + "files": 145, + "generated_at_commit": "9c340520d54efa93c955f008e50defaccfae7fb5", + "source_tree": "sha256:2bfb2a14a62503ba6ec3961c4a6676a257dfe52d3fcdeb67886eb8de53e24f39" }, "owner_lane": "", "provenance": { diff --git a/docs/runtime/API.md b/docs/runtime/API.md deleted file mode 100644 index 9f5f34321..000000000 --- a/docs/runtime/API.md +++ /dev/null @@ -1,577 +0,0 @@ -# Omega Runtime API v0 - -Omega Runtime API version: 0.1 - -Status: first written version, 2026-10-19 (slice R1, omega-mv#594, tracking #593). Source of truth is the C headers in -`src/`. This file describes them; `docs/runtime/omega_runtime_api.manifest` lists them; `make test-runtime-api` checks the -list against the headers (a host check, no GPU). Review state: the first version was reviewed by Opus 5.5 on 2026-10-22 (L386). -The sections changed for main 62d1d0d6 (head 2908f13a) were reviewed again by a separate review lane (ApiReview594); its -findings F1-F7 and N1-N5 are fixed in this version. Those fixes were reviewed at head 7be2c6f7 (Rev955), and its six -findings are fixed too; `docs/runtime/API-REVIEW.md` records both reviews. The fixes of the second review have not been -reviewed again. The check proves the list and every quoted C signature match the headers; prose is checked by review. - -The version number lives in one header, `src/omega_runtime_api.h` (`OMEGA_RUNTIME_API_VERSION_MAJOR`, `_MINOR`). - -## 1. What this is - -Omega is a GPU compute runtime that does not use CUDA. This file is the written contract for the part a program calls -directly: find and open the GPU, get memory, copy data in and out, run a kernel, run many kernels in one submission, run a -packaged job, and read errors. It covers what exists on the main branch today, on one machine type (GB10, the DGX Spark), -through the Linux open-driver backend. Nothing here claims more than that. - -How to read an entry: - -| Tier | Meaning | -| --- | --- | -| **STABLE** | Used by other code in the project, covered by chip results, and kept compatible under the rule in section 2. Has its own `####` section below. | -| **EXPERIMENTAL** | Works and is listed, but may change in any minor version, because the design is still moving or only one use of it exists. Listed in tables with the reason. | -| **INTERNAL** | Exists in a header for the project's own libraries or tests. Not part of the API; not in the manifest; may change or disappear any time. Every one declared in a manifest header is named in section 10, so nobody builds on it by accident (the check enforces that list). | - -Every C signature in this file is copied from the header it names. `tools/runtime_api_check.sh` re-checks every quoted -signature against the headers on every run. - -## 2. Version and compatibility rule - -The version is MAJOR.MINOR, currently **0.1**. It is a property of the list of entries and their behaviour, not of the -library build. - -**A MINOR bump (0.1 to 0.2) is allowed to:** -- add a function, a constant, an enum value at the end of an existing enum, or a new struct; -- add an EXPERIMENTAL entry, change or remove an EXPERIMENTAL entry, or move an entry from EXPERIMENTAL to STABLE; -- fix a STABLE function that did not do what this file says (the fix makes it match); -- add a new failure name for the same call to report (callers must treat an unknown failure code or stage text as a failure). - -**It needs a MAJOR bump (0.x to 1.0, then 1.x to 2.0) to:** -- remove or rename a STABLE function, struct, field or constant; -- change a STABLE function's argument or return types, a STABLE struct's size, field order or field offsets, or the value - of a STABLE constant or enum value; -- change documented behaviour of a STABLE entry: what the lock covers, what a latch does, which buffers get parked, what - a return value means; -- move a STABLE entry down to EXPERIMENTAL or INTERNAL; -- raise the platform contract's major number (section 9.2). - -MAJOR 0 means "the first written version", not "anything goes": the rule above already binds STABLE entries in 0.x. What -0 adds is a warning: the project may promote entries to STABLE freely until 1.0 (moving a STABLE entry down still needs a -MAJOR bump, as above), and the first 1.0 will be cut only when -section 8 (what v0 does not have) has been looked at again. - -How it is enforced: a header change that moves any listed entry fails `make test-runtime-api` until the manifest line is -edited on purpose (`tools/runtime_api_check.sh --bless` refreshes the numbers; the diff is reviewed). A reviewer then decides -MINOR or MAJOR using the rule above and edits the version macros and the `Omega Runtime API version:` line in this file; -the check fails if the three disagree. The check cannot tell whether the bump was the right size. That is a review duty. - -The platform contract has its own number (`OMEGA_GPU_PLATFORM_ABI_MAJOR` 1, `OMEGA_GPU_PLATFORM_ABI_MINOR` 2, set in -`src/omega_gpu_platform.h`). A platform minor bump needs at least a runtime MINOR bump; a platform major bump needs a runtime MAJOR bump. - -## 3. How the pieces fit (plain English) - -**Device and platform.** Omega talks to the GPU through a small "platform" layer: a table of services (a clock, a lock, -device-visible memory, a submission queue, a way to poll for completion). Today one platform exists, the Linux reference -(`src/omega_gpu_platform_linux.c`), which uses NVIDIA's open kernel driver. The contract is written so a second backend -(WSL2 on Windows, or AIENOS with no Linux driver) can fill the same table. A program normally never touches the platform: -the first call that needs the GPU installs the Linux reference by itself. There is **one device, one channel per process**. -There is no call to ask the device its name, SM count or memory size yet (section 8). - -**Memory.** You ask the session for a buffer and get an `OmegaGpuMem`: a handle, a CPU pointer, a GPU address and a size. -Every ordinary buffer is GPU-uncached, because the CPU writes inputs the chip reads and polls markers the chip writes. -You make CPU writes visible to the GPU with `omega_gpu_session_sync_to_gpu` and GPU writes visible to the CPU with -`omega_gpu_session_sync_to_cpu`. Code (the machine code of a kernel) lives in a separate kind of buffer -(`omega_gpu_session_alloc_code`): the CPU writes it once, the GPU only executes it. Handles carry a generation number, so a -handle from a closed device or an already freed buffer is refused instead of silently reused. A buffer you mean to reuse and -grow, such as staging space, can be an `OmegaGpuScratch`. For read-only weights there is a GPU-cached allocation -(`omega_gpu_session_alloc_cached`, EXPERIMENTAL). There is no async copy and no unified memory in v0. - -**Launch.** One kernel launch is an `OmegaGpuLaunch`: where the code is, how many registers, the block and grid size, the -argument words, shared memory, and a timeout. `omega_gpu_session_launch` submits it and waits for the chip to finish (it -is synchronous). The wait is by polling a completion word, never by an interrupt. - -**Command lists.** `omega_gpu_cmdlist_*` records many launches and submits them as one unit with one completion wait. By -default each launch is preceded by a barrier so dependent launches cannot overlap; a launch can be marked independent. -EXPERIMENTAL: streams, events and dependency-ordered execution are being built on top of it (omega-mv#580), so its options -and statistics will grow. - -**Job engine.** `omega_gpu_execute` runs one already-built job (today only a 1-D vector job: two inputs, one output) through -named states and returns success or exactly one named failure. EXPERIMENTAL. - -**Errors, the latch and parked buffers.** -- A failing call returns a non-zero value and names its stage in text: `omega_gpu_session_last_error()`. A device-open failure - carries the driver's own text. Do not read a bare return code as the cause. -- If the chip's completion cannot be confirmed (a completion wait ran out of time, the completion poll was refused, or a launch was cancelled after submit), - the work may still be running and still be reading or writing your buffers. The process then **latches**: - `omega_gpu_session_is_blocked()` returns 1 for the rest of the process, every later launch is refused, close and reopen are - refused, and nothing is returned to the platform. -- After the latch, every buffer freed through `omega_gpu_session_free` is **parked**: kept allocated, counted by - `omega_gpu_session_parked`, never released. Handles stay valid for inspection (`omega_gpu_session_is_parked`). -- Recovery in the same process is EXPERIMENTAL (section 9.1; cut C5, `evidence/C5-ISOLATION/`): `omega_gpu_session_recover` - runs the on-close hooks while still latched, closes the device through the platform, and only then lifts the latch. If - the close is refused or reports a driver teardown fault, the process stays latched for good and must exit (header). - That ordering is checked on the host with a fake platform (`evidence/C5-ISOLATION/02-session-platform.log`). What the - Linux reference's close does on the chip is intended, not shown: its RM client close is meant to destroy this process's - channels, and with them any grid still running, and to release the driver objects. The chip run of this path has not - been done (`evidence/C5-ISOLATION/README.md`: NO RESULT, then NOT RUN). The reference does not unmap buffers the caller - did not free (`src/omega_gpu_platform_linux.c:198-199`), so whether each recovery leaks CPU mappings is not known. - Every handle and command list of the old device is stale afterwards. A latch held only by the command lists also - counts: `omega_gpu_session_is_blocked()` is then 0 while `omega_gpu_cmdlist_is_latched()` is 1, so check both. - -**Threads.** One process-wide lock (the platform LOCK service, lock id `OMEGA_GPU_SESSION_LOCK_ID`, which is 0). A call -sequence that touches the device (open, alloc, launch, readback) is done between `omega_gpu_session_lock()` and -`omega_gpu_session_unlock()`. Threads therefore take turns on the one channel. The Linux reference lock is a plain -(non-recursive) pthread mutex (`locks[id]`, `src/omega_gpu_platform_linux.c:45` and `:141`), so taking it twice from one thread -deadlocks. These take the lock themselves and must be called without it: `omega_gpu_session_close`, `omega_gpu_session_recover`, -`omega_gpu_cmdlist_create`, `omega_gpu_cmdlist_free`, and the section 9.5 calls that touch the device or a library cache -(the compute and upload calls, `omega_gpu_tensor_free`, `omega_gpu_matmul_cache_clear`, `omega_gpu_matmul_set_cta_budget`, -`omega_gpu_matmul_prepare`, `omega_gpu_attention_pool_alloc`, `omega_gpu_attention_pool_free`, the serving reserve, seal and -release calls, and `omega_gpu_device_close` through `omega_gpu_session_close`). The section 9.5 accessors do not take the lock: -`omega_gpu_matmul_cta_budget`, `omega_gpu_tensor_shape`, `omega_gpu_matmul_rc_name`, `omega_gpu_matmul_last_error`, -`omega_gpu_elementwise_rc_name`, `omega_gpu_attention_rc_name`, `omega_gpu_attention_last_error` and -`omega_gpu_matmul_is_blocked` (an atomic read); neither does the INTERNAL `omega_gpu_elementwise_last_error` (section 10). -`omega_gpu_matmul_cta_budget` reads without the lock the value that -`omega_gpu_matmul_set_cta_budget` writes under it (`src/omega_gpu_matmul_api.c:146-153`), so calling the two from different -threads at once is a data race. -`omega_gpu_session_cancel` may be called from any thread without the lock (header). `omega_gpu_session_is_blocked` reads the latch with an atomic load (`src/omega_gpu_session.c:173`), so it is safe without the lock too. -`omega_gpu_session_last_error` returns a pointer into one process-wide text buffer: read it under the lock, before the next call. - -### 3.1 A minimal sequence (sketch) - -```c example -omega_gpu_session_lock(); -OmegaGpuSession *s = omega_gpu_session_open(); /* NULL: see omega_gpu_session_last_error() */ -OmegaGpuMem in, code; -omega_gpu_session_alloc(bytes, &in); /* GPU-uncached data buffer */ -omega_gpu_session_alloc_code(code_size, &code); /* write the machine code to code.cpu */ -omega_gpu_session_sync_to_gpu(&in); -OmegaGpuLaunch L = { .code_va = code.va, .timeout_ms = 1000, /* gpr_count, threads_*, grid_*, args, n_args ... */ }; -uint64_t elapsed_ns = 0; uint32_t marker = 0; /* launch adds to elapsed_ns: start it at 0 */ -int rc = omega_gpu_session_launch(&L, &elapsed_ns, &marker); -omega_gpu_session_sync_to_cpu(&in); -omega_gpu_session_free(&in); -omega_gpu_session_unlock(); -``` - -This is a shape sketch, not a worked example (the worked example is slice R2). - -## 4. Session: device, lock and state - -#### `omega_gpu_session_lock` -STABLE: used by every library API and chip-proven; the lock model is the documented one. -```c -void omega_gpu_session_lock(void); -``` -Takes the process-wide session lock (platform LOCK service, id `OMEGA_GPU_SESSION_LOCK_ID`). Does not touch the device. -In the hosted build the first call installs the Linux reference platform (`pthread_once`, `src/omega_gpu_session.c:109-115`), -so it takes a real mutex. Freestanding build only: with no platform installed it does nothing, and the open that follows refuses. - -#### `omega_gpu_session_unlock` -STABLE: pairs with the lock. -```c -void omega_gpu_session_unlock(void); -``` - -#### `omega_gpu_session_open` -STABLE: used by every library API and chip-proven. Treat the returned pointer as "the device is open"; the fields of -`OmegaGpuSession` are EXPERIMENTAL (the session's own launch buffers) and a caller needs none of them. -```c -OmegaGpuSession *omega_gpu_session_open(void); -``` -Caller holds the lock. Opens the device on first use. Returns NULL when the process is latched, no platform is installed or the -open failed; the stage is in `omega_gpu_session_last_error()`. - -#### `omega_gpu_session_is_open` -STABLE: simple state query. -```c -bool omega_gpu_session_is_open(void); -``` - -#### `omega_gpu_session_is_blocked` -STABLE: the latch query that every caller needs. -```c -int omega_gpu_session_is_blocked(void); -``` -Returns 1 once an uncertain completion has latched this process, else 0. Any thread. - -#### `omega_gpu_session_close` -STABLE: the only way to close the device; its refusal after a latch is part of the error model. -```c -void omega_gpu_session_close(void); -``` -Closes the device and frees every session buffer. **Takes the lock itself.** Refused (a no-op) after an uncertain completion. -The next open reopens; every handle of the closed device is stale from then on. - -#### `omega_gpu_session_open_count` -STABLE: diagnostic with a fixed meaning. -```c -uint32_t omega_gpu_session_open_count(void); -``` -Device opens so far in this process (a persistent session shows 1). - -#### `omega_gpu_session_set_spin_us` -STABLE: used by sovereign-core's binding; fixed meaning and limit. -```c -int omega_gpu_session_set_spin_us(uint32_t us); -``` -Process-wide marker-poll spin window, used by every launch whose own `spin_us` is 0. 0 (the default) keeps the platform's -sleep-poll. Returns 0 on success, -1 above `OMEGA_GPU_SESSION_MAX_SPIN_US` (setting unchanged). - -#### `omega_gpu_session_spin_us` -STABLE: reads the setting above. -```c -uint32_t omega_gpu_session_spin_us(void); -``` - -## 5. Session: memory - -All allocation calls need the caller to hold the lock with the device open. - -#### `OmegaGpuMem` -STABLE: the buffer type every API passes around. -A device buffer: a typed handle, its kind, the CPU view, the GPU virtual address and the size. A `cpu` of NULL means there is no CPU view. - -| Field | Meaning (from `src/omega_gpu_session.h`) | -| --- | --- | -| `handle` | `OmegaGpuBufferHandle`: index and generation | -| `kind` | `OMEGA_GPU_HANDLE_BUF_DATA`, `_BUF_CODE` or `_BUF_QUEUE` | -| `cpu` | CPU view | -| `va` | GPU virtual address | -| `size` | bytes of both views | - -#### `OmegaGpuBufferHandle` -STABLE: a field of `OmegaGpuMem`, so its layout is part of it. -`{ uint32_t index; uint32_t generation; }`. Generation 0 is never issued, so a zeroed handle means "none". -A handle is valid only while its slot generation matches; a closed handle is refused. - -#### `OmegaGpuDeviceHandle` -STABLE: same shape and rule as the buffer handle; named in the platform contract. -`{ uint32_t index; uint32_t generation; }`. - -#### `OmegaGpuQueueHandle` -STABLE: same shape and rule as the buffer handle; named in the platform contract. -`{ uint32_t index; uint32_t generation; }`. - -#### `omega_gpu_session_alloc` -STABLE: the ordinary buffer call, used by every library. -```c -int omega_gpu_session_alloc(size_t bytes, OmegaGpuMem *out); -``` -A GPU-uncached DATA buffer, CPU and GPU read/write, rounded up to a page. Returns 0 on success; non-zero with the stage named on -failure (the driver can refuse, for example with no memory; the refusal is counted in `OmegaGpuAllocStats.alloc_failures`). - -#### `omega_gpu_session_alloc_code` -STABLE: the only way to place kernel code; chip-proven. -```c -int omega_gpu_session_alloc_code(size_t code_size, OmegaGpuMem *out); -``` -A CODE buffer (CPU writes, GPU executes, GPU never writes) for `code_size` bytes plus the 2 KB instruction-prefetch tail -(`src/omega_gpu_code_alloc.h`), the tail zero-filled. The caller writes the code to `out->cpu`. A size of 0 still gets one page (`omega_gpu_code_alloc_bytes` rounds up to at least one page). - -#### `omega_gpu_session_free` -STABLE: the release call; its latch behaviour is part of the error model. -```c -void omega_gpu_session_free(OmegaGpuMem *m); -``` -Releases `m` to the platform and zeroes `*m`. **Latched: `m` is parked instead (never released).** A stale handle (from a -closed device) or a closed session is refused: nothing is released, the refusal is counted -(`OmegaGpuAllocStats.stale_refusals`) and `*m` is zeroed. - -#### `omega_gpu_session_sync_to_gpu` -STABLE: the visibility rule for CPU writes. -```c -int omega_gpu_session_sync_to_gpu(const OmegaGpuMem *m); -``` -Makes CPU writes to the whole buffer visible to the device (platform SYNC). Returns 0, also for a buffer with no CPU view; --1 with the stage named when refused or when there is no device. - -#### `omega_gpu_session_sync_to_cpu` -STABLE: the visibility rule for GPU writes. -```c -int omega_gpu_session_sync_to_cpu(const OmegaGpuMem *m); -``` -Makes device writes to the whole buffer visible to the CPU. Same return values as `sync_to_gpu`. - -#### `OmegaGpuScratch` -STABLE: the staging-buffer type the library APIs use. -A caller-owned staging buffer that grows to its high-water mark: `mem` (an `OmegaGpuMem`), `cap` (usable bytes), `high_water` -(largest request so far) and `reserved` (a serving reservation is active, see `omega_gpu_session_scratch_reserve`). -Zero-initialise it before first use. This is required: `omega_gpu_session_scratch` reads `reserved`, `cap`, `mem.cpu` and -`high_water` before it writes them (`src/omega_gpu_session.c:315-321`). - -#### `omega_gpu_session_scratch` -STABLE: used by every library API. -```c -int omega_gpu_session_scratch(OmegaGpuScratch *s, size_t bytes); -``` -Makes `s->mem` at least `bytes` long (reallocated when it grows; **contents are not kept**). Returns 0 or -1; with a -reservation active, a request past the reserved size returns `OMEGA_GPU_SESSION_SCRATCH_RESERVED` (-2) and allocates nothing. - -#### `omega_gpu_session_scratch_free` -STABLE: the matching release. -```c -void omega_gpu_session_scratch_free(OmegaGpuScratch *s); -``` - -#### `OmegaGpuAllocStats` -STABLE: used by sovereign-core's binding to show that serving asks the driver for nothing. -Counters of driver allocations made through `omega_gpu_session_alloc` since the process started: `allocs`, `alloc_bytes` -(page-rounded), `alloc_failures`, `frees`, `stale_refusals`. Covers the session layer only. - -#### `omega_gpu_session_alloc_stats` -STABLE: reads the counters above. -```c -void omega_gpu_session_alloc_stats(OmegaGpuAllocStats *out); -``` - -## 6. Session: launch - -#### `OmegaGpuLaunch` -STABLE: the launch descriptor; chip-proven by every library. -One launch: a kernel already resident at `code_va`, argument words for constant bank 0 at 0x380 (buffer addresses, then -parameters), and the grid. - -Argument layout and the checks `omega_gpu_session_launch` makes (`src/omega_gpu_session.c:525-537`): -- a 64-bit GPU address takes two words, the low word first, then the high word; -- `L` is not NULL, `n_args` is 1 to `OMEGA_GPU_SESSION_MAX_ARGS`, `args` is not NULL, `threads_x`, `grid_x` and `grid_y` - are not 0 (a `threads_y` of 0 means 1), and `spin_us` is at most `OMEGA_GPU_SESSION_MAX_SPIN_US` (1000000); otherwise the - launch is refused with "launch arguments" and nothing runs; -- `gpr_count` is rounded up to a multiple of 8, and to at least 64; -- `elapsed_ns` is added to, not set: start it at 0. -What the kernel itself may read in constant bank 0 besides these words, and where GB10 machine code comes from, is slice -R2 (`examples/hello_gpu`, README "Run your first kernel"). - -| Field | Meaning (from `src/omega_gpu_session.h`) | -| --- | --- | -| `code_va` | GPU address of the kernel code | -| `gpr_count` | registers the QMD (the launch descriptor the hardware reads) declares; multiple of 8, at least 64 in practice | -| `threads_x`, `threads_y` | block size | -| `grid_x`, `grid_y` | grid size | -| `num_elements` | QMD config num_elements (kept per API for identical words) | -| `args`, `n_args` | `n_args` words written at constant bank + 0x380; `n_args` at most `OMEGA_GPU_SESSION_MAX_ARGS` (32) | -| `timeout_ms` | completion poll limit, applied to each of the launch's two markers in turn (so a launch can wait up to twice this); past it the completion is uncertain and **the process latches**. Do not pass 0: the marker is then polled once (after the spin window, if any) and the launch latches unless the grid had already finished | -| `shared_bytes` | shared memory per block; 0 = the default (1024) | -| `spin_us` | spin-poll window before the platform's sleep-poll; 0 = the process-wide setting; at most `OMEGA_GPU_SESSION_MAX_SPIN_US` | - -#### `omega_gpu_session_launch` -STABLE: the single-kernel launch; chip-proven. -```c -int omega_gpu_session_launch(const OmegaGpuLaunch *L, uint64_t *elapsed_ns, uint32_t *marker_out); -``` -Caller holds the lock, device open, not latched. Submits one launch and polls for both completion markers, so it returns when -the chip is done. 0 on success; -1 with the stage named on failure; `OMEGA_GPU_SESSION_CANCELLED` (-3) when a cancel request -was seen. A marker timeout latches the process. `elapsed_ns` (submit to second marker) is added to when the pointer is given; -`marker_out` receives the first marker word observed. - -## 7. Session: errors, the latch, parked buffers - -#### `omega_gpu_session_last_error` -STABLE: the error-model entry point. -```c -const char *omega_gpu_session_last_error(void); -``` -The stage of the most recent failure, `""` if none. Shared by every API. Points into one process-wide buffer: read it under -the lock, before the next call. - -#### `OmegaGpuParkStats` -STABLE: the parked-buffer report. -`buffers` (parked, listed plus untracked), `untracked` (parked past the listed `OMEGA_GPU_SESSION_PARK_MAX` = 512) and -`bytes`. - -#### `omega_gpu_session_parked` -STABLE: how a caller sees what the latch kept. -```c -void omega_gpu_session_parked(OmegaGpuParkStats *out); -``` -Buffers parked after an uncertain completion: kept allocated, never returned to the platform. The session's own launch -buffers (ring, constant bank, marker, QMD page) are parked at the latch and every later free parks too. - -#### `omega_gpu_session_is_parked` -STABLE: per-handle form of the above. -```c -int omega_gpu_session_is_parked(OmegaGpuBufferHandle h); -``` -1 if this handle is parked and listed. - -## 8. Not in v0 (so nobody assumes it) - -Each line is a gap named in `docs/runtime/ROADMAP.md` section 1 (on branch `runtime/roadmap`, not yet merged); the gaps themselves are not in the manifest. -- A device query (name, SM count, memory): there is no API call for it. -- More than one device in a process; sharing the GPU between processes (a second channel failed under load: omega-mv#523). - Extra queues on the one device (`omega_gpu_session_extra_queue`, `omega_gpu_cmdlist_submit_pair`) are EXPERIMENTAL (9.1, 9.3). -- A STABLE recovery contract: `omega_gpu_session_recover` is EXPERIMENTAL in v0 (section 9.1). -- Async copy, streams, events, host callbacks (omega-mv#580 is building ordering on command lists). -- Cached read-write buffers; unified memory. -- Launches with more than the 32 argument words, or an asynchronous single launch. -- A second real backend (WSL2 `/dev/dxg` is on branch `rig/gb20x`; native AIENOS is planned), so the platform contract has only been exercised by one. -- A runtime function that reports the version of the linked library (the version is a compile-time macro only). - -## 9. EXPERIMENTAL entries - -Listed in the manifest, may change in any minor version. Signatures are in the manifest and the headers; the names are -checked there. The reason is why each is not STABLE yet. - -### 9.1 Session extras (`src/omega_gpu_session.h`, `src/omega_gpu_mem_cached.h`) - -| Entry | Reason it is EXPERIMENTAL | -| --- | --- | -| `omega_gpu_session_alloc_cached` | GPU-cached memory is correct only for write-once, never-polled, GPU-read-only weights; the API cannot enforce that (the caller must). | -| `omega_gpu_session_scratch_reserve`, `omega_gpu_session_scratch_unreserve` | Serving-daemon feature (no driver call after warm-up); one user. | -| `omega_gpu_session_cancel` | A cancel after submit cannot stop the chip: it latches the process. Semantics may tighten as recovery matures. | -| `omega_gpu_session_recover`, `omega_gpu_session_recoveries` | C5 recovery after a latch (`evidence/C5-ISOLATION/`): new on main after this API was first drafted; its device-close path is one backend's (Linux RM client close) behaviour and has no chip run yet (section 3). `recover` returns 0 when the latch is lifted, -1 with the reason named when nothing was latched (neither the process nor the command lists), no device is open, or the close was refused (then the process stays latched). | -| `omega_gpu_session_extra_queue` | Queues 1..3 past the session queue, each with its own 64 KB ring; granted only when the device was opened with `AIEN_OMEGA_GPU_CHANNELS` > i. Work on different queues is not ordered. One backend, one user (the command-list pair). | -| `omega_gpu_session_set_platform`, `omega_gpu_session_platform`, `omega_gpu_session_submit_prefix_words`, `omega_gpu_session_completion_mode`, `omega_gpu_session_now_ns` | Tied to the platform contract, which has one real backend. | -| `omega_gpu_host_alloc`, `omega_gpu_host_calloc`, `omega_gpu_host_free` | CPU-only memory from the platform HOST_MEM service; the freestanding build needs them, hosted code can use malloc. | -| `OmegaGpuSession` | The session's own launch buffers; a caller needs none of its fields. | - -### 9.2 Platform contract (`src/omega_gpu_platform.h`, ABI 1.2) - -Types: `OmegaGpuPlatform` (the service table), `OmegaGpuPlatformCaps`, `OmegaGpuBufferDesc`, `OmegaCpuView`, `OmegaGpuVa`, -`OmegaGpuBusAddr`, `OmegaGpuHandleTable`. Functions: `omega_gpu_platform_refusal_name`, `omega_gpu_platform_negotiate`, -`omega_gpu_platform_check`, `omega_gpu_platform_check_for`, `omega_gpu_platform_check_buffer`, `omega_gpu_handles_init`, -`omega_gpu_handles_open`, `omega_gpu_handles_check`, `omega_gpu_handles_close`. Enums and constants: the handle kinds, -rights (`OMEGA_GPU_RIGHT_*`), cache policy, services (`OMEGA_GPU_SVC_*`) and refusal names (`OMEGA_GPU_PLAT_*`). - -Reason: the contract is written for three backends but only the Linux reference has run; the second backend (`rig/gb20x`) and -the native one will likely force changes. What it already promises (from the header): resources are typed handles with a -generation; every byte range carries a length and rights; anything the CPU polls is `OMEGA_GPU_RIGHT_HOST_POLLED` and must be -GPU-uncached; polling a word is never claimed as interrupt support; a missing service is refused, never emulated. - -### 9.3 Command lists (`src/omega_gpu_cmdlist.h`) - -Types: `OmegaGpuCmdListOpts`, `OmegaGpuCmdListStats`, the opaque `OmegaGpuCmdList`. Functions: `omega_gpu_cmdlist_create` -(takes the lock itself), `omega_gpu_cmdlist_free`, `omega_gpu_cmdlist_reset`, `omega_gpu_cmdlist_count`, -`omega_gpu_cmdlist_add`, `omega_gpu_cmdlist_mark_independent`, `omega_gpu_cmdlist_submit`, `omega_gpu_cmdlist_is_latched`, -`omega_gpu_cmdlist_stamps`, `omega_gpu_cmdlist_barrier_name`, `omega_gpu_cmdlist_submit_pair` (list a on the session queue -and list b on extra queue 1, both submitted before either is waited; caller holds the lock), `omega_gpu_cmdlist_wait_for` -(C4 event: the next launch added waits on the chip for a launch of the other list of the pair). Up to -`OMEGA_GPU_CMDLIST_MAX_LAUNCHES` (4096) launches per list. A list made before `omega_gpu_session_recover` is refused after it. - -Reason: omega-mv#580 is building pipelined and dependency-ordered execution on this module, so the options, statistics -and barrier modes will grow. The measured extra cost of each launch in a list is about 30 us with a wait-for-idle barrier -(`evidence/OWN30B-LAUNCH-COST-20261014T0120Z/r1/receipt.json`, verdict FAIL on 4 of 11 checks). A timeout latches the list; -the session latches as well only if the 1 ms check launch queued behind the list also times out -(`src/omega_gpu_cmdlist.c:233-240`, section 3). The `OMEGA_GPU_CMDLIST_BARRIER_NONE` mode and `skip_launch` option are test-only. -`OmegaGpuCmdListOpts.first_barrier_none` (C4 streams) drops the WAIT_FOR_IDLE and the shader-cache invalidate before launch 0 -of a list. The caller must make sure the code, constant banks and QMDs that launch 0 reads are not in a stale cache line -(fresh slots or unchanged contents), or launch 0 may read old bytes (`src/omega_gpu_cmdlist.h:85-87`). 0 keeps the barrier. - -### 9.4 Job engine (`src/omega_gpu_engine.h`) - -Types: `OmegaGpuJob`, `OmegaGpuResult`, `OmegaGpuTimeouts`, `OmegaGpuBackend`, `OmegaGpuBackendDiag`. Functions: -`omega_gpu_execute`, `omega_gpu_engine_set_backend`, `omega_gpu_engine_is_blocked`, `omega_gpu_engine_set_clock`, -`omega_gpu_engine_failure_name`, `omega_gpu_engine_state_name`, `omega_gpu_engine_wait_name`, `omega_gpu_engine_step_name`. One failure name per run -(`OMEGA_GPU_ENGINE_*`), states `INITIAL` to `SUCCESS`, the failed step recorded, and an uncertain completion blocks every -later `omega_gpu_execute` in the process with `UNCERTAIN_COMPLETION_BLOCKED`. - -Reason: accepts one job shape (`OMEGA_GPU_LAYOUT_VECTOR_1D`); #580 widens it; the chip receipt for the vector-add job is on an -unmerged branch (`hive/DEEP2-A3-gpu-engine-impl`). Note: the status paragraph at the top of `omega_gpu_engine.h` says only a -fake backend exists; `src/omega_blackwell_engine.c` is on main and `src/omega_blackwell_submit.c` installs it, so that -paragraph is out of date (whether it is chip-qualified on main is UNVERIFIED here). - -### 9.5 Libraries (matmul, elementwise, attention, serving) - -The entries carried over from aien-sovereign-core's manifest: `src/omega_gpu_matmul_api.h`, `omega_gpu_elementwise_api.h`, -`omega_gpu_attention_api.h`, `omega_gpu_serving.h` (the functions and structs after the `libraries` comment in the -manifest). Reason: shapes and formats follow one model (Qwen3-30B); there is no general any-shape GEMM yet -(`docs/runtime/ROADMAP.md` 1.3, branch `runtime/roadmap`). They are the surface sovereign-core's Rust binding uses today. They are not described entry by entry in v0; -their headers are the description. One value differs from sovereign-core's pinned copy: `OMEGA_GPU_MATMUL_MAX_CTAS` is 1024 in -the header (changed by omega #473, commit 98cecadc), 64 in their manifest. Omega's manifest is canonical; R12 brings theirs level. - - -### 9.6 Library entries (manifest spelling) - -Types are the manifest's Rust spelling (`*const`, `*mut`, `u32`, ...); the headers hold the C. Every entry here is EXPERIMENTAL. - -| Entry | Signature | -| --- | --- | -| `OmegaGpuMatmulInfo` | struct, 160 bytes (fields in the manifest) | -| `OmegaGpuServingBounds` | struct, 44 bytes (fields in the manifest) | -| `OmegaGpuEwInfo` | struct, 120 bytes (fields in the manifest) | -| `OmegaGpuAttnInfo` | struct, 176 bytes (fields in the manifest) | -| `OmegaGpuKvLayout` | struct, 64 bytes (fields in the manifest) | -| `omega_gpu_matmul_bf16` | `fn(u32, u32, u32, *const u16, *const u16, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | -| `omega_gpu_matmul_f32` | `fn(u32, u32, u32, *const f32, *const f32, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | -| `omega_gpu_matmul_rc_name` | `fn(i32) -> *const c_char` | -| `omega_gpu_matmul_cache_clear` | `fn() -> ()` | -| `omega_gpu_tensor_upload_bf16` | `fn(u32, u32, *const u16, *mut *mut OmegaGpuTensor) -> i32` | -| `omega_gpu_tensor_upload_f32` | `fn(u32, u32, *const f32, *mut *mut OmegaGpuTensor) -> i32` | -| `omega_gpu_tensor_free` | `fn(*mut OmegaGpuTensor) -> ()` | -| `omega_gpu_tensor_shape` | `fn(*const OmegaGpuTensor, *mut u32, *mut u32) -> ()` | -| `omega_gpu_matmul_resident_bf16` | `fn(u32, *const u16, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | -| `omega_gpu_matmul_resident_f32` | `fn(u32, *const f32, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32` | -| `omega_gpu_matmul_last_error` | `fn() -> *const c_char` | -| `omega_gpu_matmul_is_blocked` | `fn() -> i32` | -| `omega_gpu_device_close` | `fn() -> ()` | -| `omega_gpu_matmul_set_cta_budget` | `fn(u32) -> ()` | -| `omega_gpu_matmul_cta_budget` | `fn() -> u32` | -| `omega_gpu_reserve_serving` | `fn(*const OmegaGpuServingBounds) -> i32` | -| `omega_gpu_serving_release` | `fn() -> ()` | -| `omega_gpu_matmul_prepare` | `fn(u32, u32, u32) -> i32` | -| `omega_gpu_serving_seal` | `fn() -> ()` | -| `omega_gpu_rmsnorm_f32` | `fn(u32, u32, *const f32, *const f32, f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` | -| `omega_gpu_rope_f32` | `fn(u32, u32, *const f32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` | -| `omega_gpu_swiglu_f32` | `fn(u32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32` | -| `omega_gpu_elementwise_rc_name` | `fn(i32) -> *const c_char` | -| `omega_gpu_gqa_attention_f32` | `fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` | -| `omega_gpu_gqa_attention_rows_f32` | `fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` | -| `omega_gpu_attention_pool_alloc` | `fn(usize, *mut *mut c_void) -> i32` | -| `omega_gpu_attention_pool_free` | `fn() -> ()` | -| `omega_gpu_paged_attention_bf16` | `fn(*const f32, *const c_void, *const OmegaGpuKvLayout, *const u32, u32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` | -| `omega_gpu_paged_attention_batch_bf16` | `fn(*const f32, *const c_void, *const OmegaGpuKvLayout, *const i32, *const i32, u32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32` | -| `omega_gpu_attention_rc_name` | `fn(i32) -> *const c_char` | -| `omega_gpu_attention_last_error` | `fn() -> *const c_char` | - -## 10. INTERNAL (not part of the API) - -Not in the manifest; may change or vanish without notice. Every external function a manifest header declares is either -a manifest `fn` or named below as one of the leading names of a bullet (the names before any other text; names in the -prose after them do not count); `make test-runtime-api` fails on any other, and on a name that is both (section 11). - -Session (`src/omega_gpu_session.h`): -- `omega_gpu_session_set_error` (library code names its failure stage through it). -- `omega_gpu_session_on_close` (lets a library drop its resident kernels before the session closes; up to 8 hooks). -- `omega_gpu_session_latch_uncertain`, `omega_gpu_session_note_module_latch` (a module such as the command lists tells the session it latched). - -Job engine (`src/omega_gpu_engine.h`): -- `omega_gpu_engine_test_reset_block`, `omega_gpu_engine_test_force_block`, `omega_gpu_engine_test_set_clock`: TEST ONLY. A blocked process must stay blocked because the GPU may still be running. - -Matmul (`src/omega_gpu_matmul_api.h`): -- `omega_gpu_matmul_reserve`, `omega_gpu_matmul_unreserve`, `omega_gpu_matmul_seal` (the serving reservation; callers use `omega_gpu_reserve_serving`, `omega_gpu_serving_seal` and `omega_gpu_serving_release`). -- `omega_gpu_tensor_update_bf16`, `omega_gpu_tensor_update_f32` (rewrite a resident B in place). -- `omega_gpu_matmul_last_stages`, `omega_gpu_matmul_set_oracle` (per-stage timing of the last call; host oracle on the non-resident calls). -- `omega_gpu_matmul_test_set_mutant`, `omega_gpu_matmul_test_set_unroll`, `omega_gpu_matmul_test_a_row0_hits`: TEST ONLY. - -Elementwise (`src/omega_gpu_elementwise_api.h`): -- `omega_gpu_elementwise_cache_clear`, `omega_gpu_elementwise_last_error`. -- `omega_gpu_elementwise_codegen`, `omega_gpu_elementwise_codegen_ir` (build a kernel without launching it, for offline disassembly and the host IR simulator). -- `omega_gpu_ex2_f32`, `omega_gpu_shared_xchg_u32`, `omega_gpu_reconv_probe_u32` (chip probes). -- `omega_gpu_elementwise_test_set_mutant`, `omega_gpu_elementwise_test_set_mutant_level`: TEST ONLY. - -Attention (`src/omega_gpu_attention_api.h`): -- `omega_gpu_attention_cache_clear`, `omega_gpu_attention_heads_per_cta`, `omega_gpu_attention_mutant_name`. -- `omega_gpu_attention_reserve`, `omega_gpu_attention_reserve_rows`, `omega_gpu_attention_unreserve` (the serving reservation; callers use `omega_gpu_reserve_serving`). -- `omega_gpu_attention_codegen`, `omega_gpu_attention_codegen_hd` (build a kernel without launching it). -- `omega_gpu_attention_test_set_mutant`, `omega_gpu_attention_test_set_divergent`, `omega_gpu_attention_test_set_dedupe`, `omega_gpu_attention_test_set_split`, `omega_gpu_attention_test_set_simulator`, `omega_gpu_attention_test_shared_bytes`, `omega_gpu_attention_test_resident_fits`: TEST ONLY. - -Everything else under `src/omega_gpu_*` and `src/omega_blackwell_*` in headers the manifest does not list (kernel builder, encoder, per-model APIs, launch helpers). - -## 11. Checking this file - -`make test-runtime-api` runs `tools/runtime_api_check.sh` on the real headers and then `tools/runtime_api_negative.sh`, which breaks a -copy of the headers, the manifest or this file in sixteen ways and requires the check to fail each time: a removed function (twice: a STABLE one and the EXPERIMENTAL `omega_gpu_session_recover`), a missing version macro, a -changed function signature, a changed struct, a changed constant, a version line in this file that disagrees with the macro, a quoted signature in this file that no header has, a quoted -signature that only appears inside a longer one (`int32_t` inside `uint32_t`), a STABLE entry with no section here, a removed -struct field the manifest lists (`OmegaGpuCmdListOpts.first_barrier_none`), a new function in a manifest header with no -manifest line, the same for a function that returns a function pointer, an INTERNAL function dropped from section 10, a -manifest `fn` dropped from the manifest while section 10's prose still mentions it (`omega_gpu_serving_seal`), and a -manifest `fn` also listed as INTERNAL. It needs no GPU and no physics checkout. It checks: every manifest function against its header -with exact types; sizes, offsets and constants against a compiled probe; the version macros against the manifest and this file; -that every STABLE entry has a `####` section here and every EXPERIMENTAL one is named here; that every C signature quoted -in this file appears verbatim in a header; and, with gcc's `-aux-info`, that every external function a manifest header -declares is either a manifest `fn` or a leading name of a section-10 bullet, never both, and every such name is still -declared (another compiler fails -the check with "needs a compiler with -aux-info"). It does not check that the prose is true. Not seen: a new struct or -constant (nothing to compare it with), a field added inside padding that the manifest does not list, a field that changes -type but keeps its size, and a constant value quoted in prose. - -Where it runs: the gate `OMEGA-RUNTIME-API` (`tests/gates/omega-runtime-api.gate`, requires `portable`) runs -`make test-runtime-api` through `tests/gates/run.sh runtime-api`. The Spark judge runs it on a pull request that touches -its inputs. The hosted AIEN Checks job runs the portable gates it finds on main (`.github/workflows/aien-verification.yml`), -so it runs there from the first pull request after the gate file is on main. It needs gcc (for `-aux-info`), make, perl, -sed and a POSIX awk. diff --git a/docs/runtime/PORTABILITY.md b/docs/runtime/PORTABILITY.md index 7b923a91e..d1c505f39 100644 --- a/docs/runtime/PORTABILITY.md +++ b/docs/runtime/PORTABILITY.md @@ -8,6 +8,11 @@ UNVERIFIED. Nothing here was run on a GPU; this slice is read-only analysis plus Companion documents, not repeated here: `docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md` (which driver call each part makes today and which cut removes it) and `docs/numeric/OMEGA_GPU_ENGINE.md` (the engine contract). +Since omega-mv#924 the GPU sources this document describes are CUDApp's, consumed from the exact revision in +`cudapp.lock`; their table is `docs/runtime/portability_table.tsv` of that revision, and `make test-runtime-portability` +checks it in the staged source (`$(CUDAPP_SOURCE)`). This repository's table keeps only the rows of the GPU-named files +Omega still carries (`src/omega_blackwell_gates.{c,h}`). The totals below are the historical review of omega-mv main. + ## 1. Two separate questions Porting Omega means answering two questions that are easy to mix up: diff --git a/docs/runtime/omega_runtime_api.manifest b/docs/runtime/omega_runtime_api.manifest deleted file mode 100644 index d02c0ebe0..000000000 --- a/docs/runtime/omega_runtime_api.manifest +++ /dev/null @@ -1,553 +0,0 @@ -# Omega Runtime API manifest: the canonical list of the C entries that docs/runtime/API.md describes. -# Canonical from R1 (2026-10-19): Omega's copy leads; aien-sovereign-core's crates/aien-omega-gpu/abi/omega_gpu.manifest -# must match it (R12 checks that). The part from "libraries" down to the end of the `fn` lines of those headers was -# copied from that file at aien-sovereign-core origin/main (see the "carried over" comment below) and kept unchanged. -# Line format = aien-abi-conformance src/manifest.rs (header, struct, field, const, fn); `#` starts a comment. -# Additions to that format, all inside comments or in the free `kind` column, so its parser still reads the file: -# - every `struct` and `fn` line ends with a tier comment: `# STABLE` or `# EXPERIMENTAL` (INTERNAL entries are not listed); -# - field kinds beyond its list: `ptr` (any pointer, 8 bytes), `enum` (4 bytes), `struct:Name` (a struct by value); -# `usize`/size_t fields are written `u64` (LP64), as it does. -# Checked by tools/runtime_api_check.sh (make test-runtime-api): every `fn` against its header with the exact types, -# every size, offset and constant against a compiled probe, the version macros against src/omega_runtime_api.h. -# After a deliberate header change: edit the line here, run `tools/runtime_api_check.sh --bless` to refresh numbers, review the diff. -abi omega_runtime 0.1 -header src/omega_runtime_api.h -header src/omega_gpu_platform.h -header src/omega_gpu_session.h -header src/omega_gpu_mem_cached.h -header src/omega_gpu_cmdlist.h -header src/omega_gpu_engine.h -header src/omega_gpu_matmul_api.h -header src/omega_gpu_serving.h -header src/omega_gpu_elementwise_api.h -header src/omega_gpu_attention_api.h -# ---- version ---- -const OMEGA_RUNTIME_API_VERSION_MAJOR 0 -const OMEGA_RUNTIME_API_VERSION_MINOR 1 -# ---- platform contract (src/omega_gpu_platform.h, ABI 1.2) ---- -struct OmegaGpuDeviceHandle 8 4 # STABLE -field OmegaGpuDeviceHandle index 0 4 u32 1 -field OmegaGpuDeviceHandle generation 4 4 u32 1 -struct OmegaGpuBufferHandle 8 4 # STABLE -field OmegaGpuBufferHandle index 0 4 u32 1 -field OmegaGpuBufferHandle generation 4 4 u32 1 -struct OmegaGpuQueueHandle 8 4 # STABLE -field OmegaGpuQueueHandle index 0 4 u32 1 -field OmegaGpuQueueHandle generation 4 4 u32 1 -struct OmegaCpuView 16 8 # EXPERIMENTAL -field OmegaCpuView ptr 0 8 ptr 1 -field OmegaCpuView len 8 8 u64 1 -struct OmegaGpuVa 8 8 # EXPERIMENTAL -field OmegaGpuVa va 0 8 u64 1 -struct OmegaGpuBusAddr 8 8 # EXPERIMENTAL -field OmegaGpuBusAddr iova 0 8 u64 1 -struct OmegaGpuBufferDesc 24 8 # EXPERIMENTAL -field OmegaGpuBufferDesc kind 0 4 u32 1 -field OmegaGpuBufferDesc rights 4 4 u32 1 -field OmegaGpuBufferDesc gpu_cache 8 4 u32 1 -field OmegaGpuBufferDesc align 12 4 u32 1 -field OmegaGpuBufferDesc bytes 16 8 u64 1 -struct OmegaGpuPlatformCaps 56 8 # EXPERIMENTAL -field OmegaGpuPlatformCaps abi_major 0 4 u32 1 -field OmegaGpuPlatformCaps abi_minor 4 4 u32 1 -field OmegaGpuPlatformCaps services 8 4 u32 1 -field OmegaGpuPlatformCaps max_devices 12 4 u32 1 -field OmegaGpuPlatformCaps max_buffers 16 4 u32 1 -field OmegaGpuPlatformCaps max_queues 20 4 u32 1 -field OmegaGpuPlatformCaps max_inflight 24 4 u32 1 -field OmegaGpuPlatformCaps max_buffer_bytes 32 8 u64 1 -field OmegaGpuPlatformCaps max_total_bytes 40 8 u64 1 -field OmegaGpuPlatformCaps submit_prefix_words 48 4 u32 1 -struct OmegaGpuPlatform 184 8 # EXPERIMENTAL -field OmegaGpuPlatform ctx 0 8 ptr 1 -field OmegaGpuPlatform time_now_ms 8 8 ptr 1 -field OmegaGpuPlatform wait_ms 16 8 ptr 1 -field OmegaGpuPlatform lock 24 8 ptr 1 -field OmegaGpuPlatform unlock 32 8 ptr 1 -field OmegaGpuPlatform mmio_read32 40 8 ptr 1 -field OmegaGpuPlatform mmio_write32 48 8 ptr 1 -field OmegaGpuPlatform dma_alloc 56 8 ptr 1 -field OmegaGpuPlatform dma_free 64 8 ptr 1 -field OmegaGpuPlatform sync_cpu_to_gpu 72 8 ptr 1 -field OmegaGpuPlatform sync_gpu_to_cpu 80 8 ptr 1 -field OmegaGpuPlatform poll_word 88 8 ptr 1 -field OmegaGpuPlatform irq_wait 96 8 ptr 1 -field OmegaGpuPlatform device_open 104 8 ptr 1 -field OmegaGpuPlatform device_close 112 8 ptr 1 -field OmegaGpuPlatform diag_text 120 8 ptr 1 -field OmegaGpuPlatform queue_open 128 8 ptr 1 -field OmegaGpuPlatform queue_close 136 8 ptr 1 -field OmegaGpuPlatform queue_submit 144 8 ptr 1 -field OmegaGpuPlatform queue_retire 152 8 ptr 1 -field OmegaGpuPlatform time_now_ns 160 8 ptr 1 -field OmegaGpuPlatform host_alloc 168 8 ptr 1 -field OmegaGpuPlatform host_free 176 8 ptr 1 -struct OmegaGpuHandleTable 69648 8 # EXPERIMENTAL -field OmegaGpuHandleTable generation 0 16384 u32 4096 -field OmegaGpuHandleTable kind 16384 16384 u32 4096 -field OmegaGpuHandleTable bytes 32768 32768 u64 4096 -field OmegaGpuHandleTable live 65536 4096 u8 4096 -field OmegaGpuHandleTable nlive 69632 4 u32 1 -field OmegaGpuHandleTable total_bytes 69640 8 u64 1 -fn omega_gpu_platform_refusal_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_platform_negotiate fn(*const OmegaGpuPlatformCaps, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL -fn omega_gpu_platform_check fn(*const OmegaGpuPlatform, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL -fn omega_gpu_platform_check_for fn(*const OmegaGpuPlatform, *const OmegaGpuPlatformCaps, u32) -> i32 # EXPERIMENTAL -fn omega_gpu_platform_check_buffer fn(*const OmegaGpuBufferDesc, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL -fn omega_gpu_handles_init fn(*mut OmegaGpuHandleTable) -> () # EXPERIMENTAL -fn omega_gpu_handles_open fn(*mut OmegaGpuHandleTable, u32, u64, u32, u64, *mut u32, *mut u32) -> i32 # EXPERIMENTAL -fn omega_gpu_handles_check fn(*const OmegaGpuHandleTable, u32, u32, u32) -> i32 # EXPERIMENTAL -fn omega_gpu_handles_close fn(*mut OmegaGpuHandleTable, u32, u32, u32) -> i32 # EXPERIMENTAL -# ---- session: device, memory, launch, errors (src/omega_gpu_session.h, src/omega_gpu_mem_cached.h) ---- -struct OmegaGpuMem 40 8 # STABLE -field OmegaGpuMem handle 0 8 struct:OmegaGpuBufferHandle 1 -field OmegaGpuMem kind 8 4 u32 1 -field OmegaGpuMem cpu 16 8 ptr 1 -field OmegaGpuMem va 24 8 u64 1 -field OmegaGpuMem size 32 8 u64 1 -struct OmegaGpuSession 192 8 # EXPERIMENTAL -field OmegaGpuSession dev 0 8 struct:OmegaGpuDeviceHandle 1 -field OmegaGpuSession queue 8 8 struct:OmegaGpuQueueHandle 1 -field OmegaGpuSession pb 16 40 struct:OmegaGpuMem 1 -field OmegaGpuSession cbank 56 40 struct:OmegaGpuMem 1 -field OmegaGpuSession marker 96 40 struct:OmegaGpuMem 1 -field OmegaGpuSession qmd 136 40 struct:OmegaGpuMem 1 -field OmegaGpuSession opens 176 4 u32 1 -field OmegaGpuSession last_open_ns 184 8 u64 1 -struct OmegaGpuScratch 64 8 # STABLE -field OmegaGpuScratch mem 0 40 struct:OmegaGpuMem 1 -field OmegaGpuScratch cap 40 8 u64 1 -field OmegaGpuScratch high_water 48 8 u64 1 -field OmegaGpuScratch reserved 56 1 bool 1 -struct OmegaGpuLaunch 72 8 # STABLE -field OmegaGpuLaunch code_va 0 8 u64 1 -field OmegaGpuLaunch gpr_count 8 4 u32 1 -field OmegaGpuLaunch threads_x 12 4 u32 1 -field OmegaGpuLaunch threads_y 16 4 u32 1 -field OmegaGpuLaunch grid_x 20 4 u32 1 -field OmegaGpuLaunch grid_y 24 4 u32 1 -field OmegaGpuLaunch num_elements 32 8 u64 1 -field OmegaGpuLaunch args 40 8 ptr 1 -field OmegaGpuLaunch n_args 48 4 u32 1 -field OmegaGpuLaunch timeout_ms 56 8 u64 1 -field OmegaGpuLaunch shared_bytes 64 4 u32 1 -field OmegaGpuLaunch spin_us 68 4 u32 1 -struct OmegaGpuParkStats 16 8 # STABLE -field OmegaGpuParkStats buffers 0 4 u32 1 -field OmegaGpuParkStats untracked 4 4 u32 1 -field OmegaGpuParkStats bytes 8 8 u64 1 -fn omega_gpu_session_lock fn() -> () # STABLE -fn omega_gpu_session_unlock fn() -> () # STABLE -fn omega_gpu_session_open fn() -> *mut OmegaGpuSession # STABLE -fn omega_gpu_session_is_open fn() -> bool # STABLE -fn omega_gpu_session_is_blocked fn() -> i32 # STABLE -fn omega_gpu_session_close fn() -> () # STABLE -fn omega_gpu_session_open_count fn() -> u32 # STABLE -fn omega_gpu_session_alloc fn(usize, *mut OmegaGpuMem) -> i32 # STABLE -fn omega_gpu_session_alloc_code fn(usize, *mut OmegaGpuMem) -> i32 # STABLE -fn omega_gpu_session_free fn(*mut OmegaGpuMem) -> () # STABLE -fn omega_gpu_session_sync_to_gpu fn(*const OmegaGpuMem) -> i32 # STABLE -fn omega_gpu_session_sync_to_cpu fn(*const OmegaGpuMem) -> i32 # STABLE -fn omega_gpu_session_scratch fn(*mut OmegaGpuScratch, usize) -> i32 # STABLE -fn omega_gpu_session_scratch_free fn(*mut OmegaGpuScratch) -> () # STABLE -fn omega_gpu_session_launch fn(*const OmegaGpuLaunch, *mut u64, *mut u32) -> i32 # STABLE -fn omega_gpu_session_last_error fn() -> *const c_char # STABLE -fn omega_gpu_session_parked fn(*mut OmegaGpuParkStats) -> () # STABLE -fn omega_gpu_session_is_parked fn(OmegaGpuBufferHandle) -> i32 # STABLE -fn omega_gpu_session_alloc_cached fn(usize, *mut OmegaGpuMem) -> i32 # EXPERIMENTAL -fn omega_gpu_session_scratch_reserve fn(*mut OmegaGpuScratch, usize) -> i32 # EXPERIMENTAL -fn omega_gpu_session_scratch_unreserve fn(*mut OmegaGpuScratch) -> () # EXPERIMENTAL -fn omega_gpu_session_cancel fn() -> () # EXPERIMENTAL -fn omega_gpu_session_recover fn() -> i32 # EXPERIMENTAL -fn omega_gpu_session_recoveries fn() -> u32 # EXPERIMENTAL -fn omega_gpu_session_extra_queue fn(u32, *mut OmegaGpuQueueHandle) -> i32 # EXPERIMENTAL -fn omega_gpu_session_set_platform fn(*const OmegaGpuPlatform, *const OmegaGpuPlatformCaps) -> i32 # EXPERIMENTAL -fn omega_gpu_session_platform fn() -> *const OmegaGpuPlatform # EXPERIMENTAL -fn omega_gpu_session_submit_prefix_words fn() -> u32 # EXPERIMENTAL -fn omega_gpu_session_completion_mode fn() -> OmegaGpuCompletionMode # EXPERIMENTAL -fn omega_gpu_session_now_ns fn() -> u64 # EXPERIMENTAL -fn omega_gpu_host_alloc fn(usize) -> *mut c_void # EXPERIMENTAL -fn omega_gpu_host_calloc fn(usize, usize) -> *mut c_void # EXPERIMENTAL -fn omega_gpu_host_free fn(*mut c_void) -> () # EXPERIMENTAL -# ---- command lists (src/omega_gpu_cmdlist.h) ---- -struct OmegaGpuCmdListOpts 32 8 # EXPERIMENTAL -field OmegaGpuCmdListOpts mode 0 4 enum 1 -field OmegaGpuCmdListOpts barrier 4 4 enum 1 -field OmegaGpuCmdListOpts timeout_ms 8 8 u64 1 -field OmegaGpuCmdListOpts spin_us 16 4 u32 1 -field OmegaGpuCmdListOpts stamps 20 4 i32 1 -field OmegaGpuCmdListOpts skip_launch 24 4 i32 1 -field OmegaGpuCmdListOpts first_barrier_none 28 4 i32 1 -struct OmegaGpuCmdListStats 40 8 # EXPERIMENTAL -field OmegaGpuCmdListStats launches 0 4 u32 1 -field OmegaGpuCmdListStats submits 4 4 u32 1 -field OmegaGpuCmdListStats words 8 4 u32 1 -field OmegaGpuCmdListStats elapsed_ns 16 8 u64 1 -field OmegaGpuCmdListStats host_ns 24 8 u64 1 -field OmegaGpuCmdListStats sems_done 32 4 u32 1 -field OmegaGpuCmdListStats first_missing 36 4 i32 1 -fn omega_gpu_cmdlist_barrier_name fn(OmegaGpuCmdListBarrier) -> *const c_char # EXPERIMENTAL -fn omega_gpu_cmdlist_create fn(u32, *mut *mut OmegaGpuCmdList) -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_free fn(*mut OmegaGpuCmdList) -> () # EXPERIMENTAL -fn omega_gpu_cmdlist_reset fn(*mut OmegaGpuCmdList) -> () # EXPERIMENTAL -fn omega_gpu_cmdlist_count fn(*const OmegaGpuCmdList) -> u32 # EXPERIMENTAL -fn omega_gpu_cmdlist_mark_independent fn(*mut OmegaGpuCmdList) -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_add fn(*mut OmegaGpuCmdList, *const OmegaGpuLaunch) -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_submit fn(*mut OmegaGpuCmdList, *const OmegaGpuCmdListOpts, *mut OmegaGpuCmdListStats) -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_is_latched fn() -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_stamps fn(*const OmegaGpuCmdList, *mut u64, u32) -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_submit_pair fn(*mut OmegaGpuCmdList, *mut OmegaGpuCmdList, *const OmegaGpuCmdListOpts, *mut OmegaGpuCmdListStats, *mut OmegaGpuCmdListStats) -> i32 # EXPERIMENTAL -fn omega_gpu_cmdlist_wait_for fn(*mut OmegaGpuCmdList, *const OmegaGpuCmdList, u32) -> i32 # EXPERIMENTAL -# ---- job engine (src/omega_gpu_engine.h) ---- -struct OmegaGpuTimeouts 32 8 # EXPERIMENTAL -field OmegaGpuTimeouts marker_ms 0 8 u64 1 -field OmegaGpuTimeouts release_semaphore_ms 8 8 u64 1 -field OmegaGpuTimeouts marker2_ms 16 8 u64 1 -field OmegaGpuTimeouts visibility_ms 24 8 u64 1 -struct OmegaGpuJob 128 8 # EXPERIMENTAL -field OmegaGpuJob program 0 8 ptr 1 -field OmegaGpuJob program_len 8 8 u64 1 -field OmegaGpuJob layout 16 4 i32 1 -field OmegaGpuJob element_count 20 4 u32 1 -field OmegaGpuJob input_a 24 8 ptr 1 -field OmegaGpuJob input_a_len 32 8 u64 1 -field OmegaGpuJob input_b 40 8 ptr 1 -field OmegaGpuJob input_b_len 48 8 u64 1 -field OmegaGpuJob output 56 8 ptr 1 -field OmegaGpuJob output_len 64 8 u64 1 -field OmegaGpuJob poison 72 8 ptr 1 -field OmegaGpuJob poison_count 80 8 u64 1 -field OmegaGpuJob timeouts 88 32 struct:OmegaGpuTimeouts 1 -field OmegaGpuJob flags 120 4 u32 1 -struct OmegaGpuResult 208 8 # EXPERIMENTAL -field OmegaGpuResult failure 0 4 i32 1 -field OmegaGpuResult last_state 4 4 i32 1 -field OmegaGpuResult failed_step 8 4 i32 1 -field OmegaGpuResult wait 12 4 i32 1 -field OmegaGpuResult wait_timeout_ms 16 8 u64 1 -field OmegaGpuResult waited_ms 24 8 u64 1 -field OmegaGpuResult drv_rc 32 4 i32 1 -field OmegaGpuResult err_no 36 4 i32 1 -field OmegaGpuResult drv_text 40 128 c_char 128 -field OmegaGpuResult sync_valid 168 4 u32 1 -field OmegaGpuResult marker 172 4 u32 1 -field OmegaGpuResult marker2 176 4 u32 1 -field OmegaGpuResult semaphore 180 4 u32 1 -field OmegaGpuResult retained 184 4 i32 1 -field OmegaGpuResult cleanup_failed 188 4 i32 1 -field OmegaGpuResult n_outputs 192 8 u64 1 -field OmegaGpuResult output_unchanged_words 200 8 u64 1 -struct OmegaGpuBackendDiag 148 4 # EXPERIMENTAL -field OmegaGpuBackendDiag drv_rc 0 4 i32 1 -field OmegaGpuBackendDiag drv_text 4 128 c_char 128 -field OmegaGpuBackendDiag sync_valid 132 4 u32 1 -field OmegaGpuBackendDiag marker 136 4 u32 1 -field OmegaGpuBackendDiag marker2 140 4 u32 1 -field OmegaGpuBackendDiag semaphore 144 4 u32 1 -struct OmegaGpuBackend 128 8 # EXPERIMENTAL -field OmegaGpuBackend ctx 0 8 ptr 1 -field OmegaGpuBackend open_device 8 8 ptr 1 -field OmegaGpuBackend create_channel 16 8 ptr 1 -field OmegaGpuBackend alloc 24 8 ptr 1 -field OmegaGpuBackend copy_in 32 8 ptr 1 -field OmegaGpuBackend fill_poison 40 8 ptr 1 -field OmegaGpuBackend build 48 8 ptr 1 -field OmegaGpuBackend submit 56 8 ptr 1 -field OmegaGpuBackend wait_marker 64 8 ptr 1 -field OmegaGpuBackend wait_marker2 72 8 ptr 1 -field OmegaGpuBackend wait_release_semaphore 80 8 ptr 1 -field OmegaGpuBackend barrier 88 8 ptr 1 -field OmegaGpuBackend copy_out 96 8 ptr 1 -field OmegaGpuBackend diagnostics 104 8 ptr 1 -field OmegaGpuBackend free_buf 112 8 ptr 1 -field OmegaGpuBackend close 120 8 ptr 1 -fn omega_gpu_execute fn(*const OmegaGpuJob, *mut OmegaGpuResult) -> i32 # EXPERIMENTAL -fn omega_gpu_engine_set_backend fn(*const OmegaGpuBackend) -> () # EXPERIMENTAL -fn omega_gpu_engine_is_blocked fn() -> i32 # EXPERIMENTAL -fn omega_gpu_engine_set_clock fn(fn() -> u64) -> () # EXPERIMENTAL -fn omega_gpu_engine_failure_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_engine_state_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_engine_wait_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_engine_step_name fn(i32) -> *const c_char # EXPERIMENTAL -# ---- libraries: carried over unchanged from aien-sovereign-core origin/main 10b4f851d6b082df6c2c477fbab700b551b854be crates/aien-omega-gpu/abi/omega_gpu.manifest ---- -# (matmul, elementwise, attention, serving; all EXPERIMENTAL: shapes follow one model, see docs/runtime/ROADMAP.md 1.3). -# ONE DIFFERENCE from that file: OMEGA_GPU_MATMUL_MAX_CTAS is 1024 here, 64 there (omega 98cecadc, #473, changed the header; sovereign-core pin is older). R12 must bring theirs to match. -# (omega_gpu_session_set_spin_us / _spin_us / _alloc_stats are STABLE session entries; they live in the session section of API.md) -struct OmegaGpuMatmulInfo 160 8 # EXPERIMENTAL -field OmegaGpuMatmulInfo m 0 4 u32 1 -field OmegaGpuMatmulInfo k 4 4 u32 1 -field OmegaGpuMatmulInfo n 8 4 u32 1 -field OmegaGpuMatmulInfo padded_m 12 4 u32 1 -field OmegaGpuMatmulInfo padded_n 16 4 u32 1 -field OmegaGpuMatmulInfo k_slices 20 4 u32 1 -field OmegaGpuMatmulInfo chip_calls 24 4 u32 1 -field OmegaGpuMatmulInfo rows_per_call 28 4 u32 1 -field OmegaGpuMatmulInfo elapsed_ns 32 8 u64 1 -field OmegaGpuMatmulInfo max_abs_err 40 4 f32 1 -field OmegaGpuMatmulInfo max_rel_err 44 4 f32 1 -field OmegaGpuMatmulInfo mismatch_count 48 8 u64 1 -field OmegaGpuMatmulInfo parity_verified 56 1 bool 1 -field OmegaGpuMatmulInfo completion_marker 60 4 u32 1 -field OmegaGpuMatmulInfo kernel_cache_hit 64 1 bool 1 -field OmegaGpuMatmulInfo target_chip 65 64 c_char 64 -field OmegaGpuMatmulInfo sm_architecture 132 4 u32 1 -field OmegaGpuMatmulInfo grid_x 136 4 u32 1 -field OmegaGpuMatmulInfo grid_y 140 4 u32 1 -field OmegaGpuMatmulInfo padded_k 144 4 u32 1 -field OmegaGpuMatmulInfo resident 148 1 bool 1 -field OmegaGpuMatmulInfo oracle_ran 149 1 bool 1 -field OmegaGpuMatmulInfo call_ns 152 8 u64 1 -struct OmegaGpuAllocStats 40 8 # STABLE -field OmegaGpuAllocStats allocs 0 8 u64 1 -field OmegaGpuAllocStats alloc_bytes 8 8 u64 1 -field OmegaGpuAllocStats alloc_failures 16 8 u64 1 -field OmegaGpuAllocStats frees 24 8 u64 1 -field OmegaGpuAllocStats stale_refusals 32 8 u64 1 -struct OmegaGpuServingBounds 44 4 # EXPERIMENTAL -field OmegaGpuServingBounds max_context 0 4 u32 1 -field OmegaGpuServingBounds max_seqs 4 4 u32 1 -field OmegaGpuServingBounds num_q_heads 8 4 u32 1 -field OmegaGpuServingBounds num_kv_heads 12 4 u32 1 -field OmegaGpuServingBounds head_dim 16 4 u32 1 -field OmegaGpuServingBounds kv_block_size 20 4 u32 1 -field OmegaGpuServingBounds max_rows 24 4 u32 1 -field OmegaGpuServingBounds max_k 28 4 u32 1 -field OmegaGpuServingBounds max_n 32 4 u32 1 -field OmegaGpuServingBounds max_n_one_row 36 4 u32 1 -field OmegaGpuServingBounds kernel_slots 40 4 u32 1 -struct OmegaGpuEwInfo 120 8 # EXPERIMENTAL -field OmegaGpuEwInfo chip_calls 0 4 u32 1 -field OmegaGpuEwInfo elapsed_ns 8 8 u64 1 -field OmegaGpuEwInfo completion_marker 16 4 u32 1 -field OmegaGpuEwInfo unwritten_words 20 4 u32 1 -field OmegaGpuEwInfo kernel_cache_hit 24 1 bool 1 -field OmegaGpuEwInfo gpr_count 28 4 u32 1 -field OmegaGpuEwInfo insn_count 32 4 u32 1 -field OmegaGpuEwInfo threads_per_cta 36 4 u32 1 -field OmegaGpuEwInfo ctas_last_launch 40 4 u32 1 -field OmegaGpuEwInfo target_chip 44 64 c_char 64 -field OmegaGpuEwInfo sm_architecture 108 4 u32 1 -field OmegaGpuEwInfo call_ns 112 8 u64 1 -struct OmegaGpuAttnInfo 176 8 # EXPERIMENTAL -field OmegaGpuAttnInfo chip_calls 0 4 u32 1 -field OmegaGpuAttnInfo elapsed_ns 8 8 u64 1 -field OmegaGpuAttnInfo call_ns 16 8 u64 1 -field OmegaGpuAttnInfo completion_marker 24 4 u32 1 -field OmegaGpuAttnInfo unwritten_words 28 4 u32 1 -field OmegaGpuAttnInfo gpr_count 32 4 u32 1 -field OmegaGpuAttnInfo insn_count 36 4 u32 1 -field OmegaGpuAttnInfo kernel_cache_hit 40 1 bool 1 -field OmegaGpuAttnInfo ctas_last_launch 44 4 u32 1 -field OmegaGpuAttnInfo threads_per_cta 48 4 u32 1 -field OmegaGpuAttnInfo target_chip 52 64 c_char 64 -field OmegaGpuAttnInfo sm_architecture 116 4 u32 1 -field OmegaGpuAttnInfo kv_bytes_staged 120 8 u64 1 -field OmegaGpuAttnInfo kv_bytes_naive 128 8 u64 1 -field OmegaGpuAttnInfo kv_blocks_logical 136 4 u32 1 -field OmegaGpuAttnInfo kv_blocks_unique 140 4 u32 1 -field OmegaGpuAttnInfo q_bytes 144 8 u64 1 -field OmegaGpuAttnInfo tab_bytes 152 8 u64 1 -field OmegaGpuAttnInfo out_bytes 160 8 u64 1 -field OmegaGpuAttnInfo kv_source 168 4 u32 1 -struct OmegaGpuKvLayout 64 8 # EXPERIMENTAL -field OmegaGpuKvLayout block_stride_bytes 0 8 u64 1 -field OmegaGpuKvLayout layer_stride_bytes 8 8 u64 1 -field OmegaGpuKvLayout kv_plane_stride_bytes 16 8 u64 1 -field OmegaGpuKvLayout token_stride_bytes 24 8 u64 1 -field OmegaGpuKvLayout head_stride_bytes 32 8 u64 1 -field OmegaGpuKvLayout pool_bytes 40 8 u64 1 -field OmegaGpuKvLayout num_blocks 48 4 u32 1 -field OmegaGpuKvLayout num_layers 52 4 u32 1 -field OmegaGpuKvLayout block_size 56 4 u32 1 -const OMEGA_GPU_MATMUL_OK 0 -const OMEGA_GPU_MATMUL_BAD_ARGS -1 -const OMEGA_GPU_MATMUL_TOO_LARGE -2 -const OMEGA_GPU_MATMUL_CODEGEN_FAIL -3 -const OMEGA_GPU_MATMUL_CHIP_FAIL -4 -const OMEGA_GPU_MATMUL_PARITY_FAIL -5 -const OMEGA_GPU_MATMUL_TILE_M 16 -const OMEGA_GPU_MATMUL_TILE_N 8 -const OMEGA_GPU_MATMUL_TILE_K 16 -const OMEGA_GPU_MATMUL_MAX_CTAS 1024 -const OMEGA_GPU_EW_OK 0 -const OMEGA_GPU_EW_BAD_ARGS -1 -const OMEGA_GPU_EW_TOO_LARGE -2 -const OMEGA_GPU_EW_CODEGEN_FAIL -3 -const OMEGA_GPU_EW_CHIP_FAIL -4 -const OMEGA_GPU_EW_UNWRITTEN -5 -const OMEGA_GPU_ATTN_OK 0 -const OMEGA_GPU_ATTN_BAD_ARGS -1 -const OMEGA_GPU_ATTN_TOO_LARGE -2 -const OMEGA_GPU_ATTN_CODEGEN_FAIL -3 -const OMEGA_GPU_ATTN_CHIP_FAIL -4 -const OMEGA_GPU_ATTN_UNWRITTEN -5 -const OMEGA_GPU_ATTN_KV_STAGED 0 -fn omega_gpu_matmul_bf16 fn(u32, u32, u32, *const u16, *const u16, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_matmul_f32 fn(u32, u32, u32, *const f32, *const f32, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_matmul_rc_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_matmul_cache_clear fn() -> () # EXPERIMENTAL -fn omega_gpu_tensor_upload_bf16 fn(u32, u32, *const u16, *mut *mut OmegaGpuTensor) -> i32 # EXPERIMENTAL -fn omega_gpu_tensor_upload_f32 fn(u32, u32, *const f32, *mut *mut OmegaGpuTensor) -> i32 # EXPERIMENTAL -fn omega_gpu_tensor_free fn(*mut OmegaGpuTensor) -> () # EXPERIMENTAL -fn omega_gpu_tensor_shape fn(*const OmegaGpuTensor, *mut u32, *mut u32) -> () # EXPERIMENTAL -fn omega_gpu_matmul_resident_bf16 fn(u32, *const u16, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_matmul_resident_f32 fn(u32, *const f32, *const OmegaGpuTensor, *mut f32, *mut OmegaGpuMatmulInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_matmul_last_error fn() -> *const c_char # EXPERIMENTAL -fn omega_gpu_matmul_is_blocked fn() -> i32 # EXPERIMENTAL -fn omega_gpu_device_close fn() -> () # EXPERIMENTAL -fn omega_gpu_matmul_set_cta_budget fn(u32) -> () # EXPERIMENTAL -fn omega_gpu_matmul_cta_budget fn() -> u32 # EXPERIMENTAL -fn omega_gpu_session_set_spin_us fn(u32) -> i32 # STABLE -fn omega_gpu_session_spin_us fn() -> u32 # STABLE -fn omega_gpu_reserve_serving fn(*const OmegaGpuServingBounds) -> i32 # EXPERIMENTAL -fn omega_gpu_serving_release fn() -> () # EXPERIMENTAL -fn omega_gpu_matmul_prepare fn(u32, u32, u32) -> i32 # EXPERIMENTAL -fn omega_gpu_serving_seal fn() -> () # EXPERIMENTAL -fn omega_gpu_session_alloc_stats fn(*mut OmegaGpuAllocStats) -> () # STABLE -fn omega_gpu_rmsnorm_f32 fn(u32, u32, *const f32, *const f32, f32, *mut f32, *mut OmegaGpuEwInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_rope_f32 fn(u32, u32, *const f32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_swiglu_f32 fn(u32, *const f32, *const f32, *mut f32, *mut OmegaGpuEwInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_elementwise_rc_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_gqa_attention_f32 fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_gqa_attention_rows_f32 fn(*const f32, *const f32, *const f32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_attention_pool_alloc fn(usize, *mut *mut c_void) -> i32 # EXPERIMENTAL -fn omega_gpu_attention_pool_free fn() -> () # EXPERIMENTAL -fn omega_gpu_paged_attention_bf16 fn(*const f32, *const c_void, *const OmegaGpuKvLayout, *const u32, u32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_paged_attention_batch_bf16 fn(*const f32, *const c_void, *const OmegaGpuKvLayout, *const i32, *const i32, u32, u32, u32, u32, u32, u32, *mut f32, *mut OmegaGpuAttnInfo) -> i32 # EXPERIMENTAL -fn omega_gpu_attention_rc_name fn(i32) -> *const c_char # EXPERIMENTAL -fn omega_gpu_attention_last_error fn() -> *const c_char # EXPERIMENTAL -# ---- constants of the runtime headers (values blessed from the headers) ---- -const OMEGA_GPU_PLATFORM_ABI_MAJOR 1 -const OMEGA_GPU_PLATFORM_ABI_MINOR 2 -const OMEGA_GPU_POLL_TIMED_OUT 100 -const OMEGA_GPU_HANDLE_SLOTS 4096 -const OMEGA_GPU_HANDLE_DEVICE 1 -const OMEGA_GPU_HANDLE_BUF_DATA 2 -const OMEGA_GPU_HANDLE_BUF_CODE 3 -const OMEGA_GPU_HANDLE_BUF_QUEUE 4 -const OMEGA_GPU_HANDLE_QUEUE 5 -const OMEGA_GPU_HANDLE_KIND_COUNT 6 -const OMEGA_GPU_RIGHT_CPU_READ 1 -const OMEGA_GPU_RIGHT_CPU_WRITE 2 -const OMEGA_GPU_RIGHT_GPU_READ 4 -const OMEGA_GPU_RIGHT_GPU_WRITE 8 -const OMEGA_GPU_RIGHT_GPU_EXEC 16 -const OMEGA_GPU_RIGHT_HOST_POLLED 32 -const OMEGA_GPU_RIGHT_ALL 63 -const OMEGA_GPU_CACHE_GPU_UNCACHED 0 -const OMEGA_GPU_CACHE_GPU_CACHED 1 -const OMEGA_GPU_SVC_TIME 1 -const OMEGA_GPU_SVC_WAIT 2 -const OMEGA_GPU_SVC_LOCK 4 -const OMEGA_GPU_SVC_MMIO 8 -const OMEGA_GPU_SVC_DMA 16 -const OMEGA_GPU_SVC_SYNC 32 -const OMEGA_GPU_SVC_COMPLETION 64 -const OMEGA_GPU_SVC_IRQ 128 -const OMEGA_GPU_SVC_REQUIRED_V1 127 -const OMEGA_GPU_SVC_DEVICE 256 -const OMEGA_GPU_SVC_QUEUE 512 -const OMEGA_GPU_SVC_CLOCK_NS 1024 -const OMEGA_GPU_SVC_HOST_MEM 2048 -const OMEGA_GPU_SVC_REQUIRED_SESSION 3959 -const OMEGA_GPU_SVC_ALL 4095 -const OMEGA_GPU_PLAT_OK 0 -const OMEGA_GPU_PLAT_REFUSED_ARGS 1 -const OMEGA_GPU_PLAT_REFUSED_ABI 2 -const OMEGA_GPU_PLAT_REFUSED_MISSING_SERVICE 3 -const OMEGA_GPU_PLAT_REFUSED_NULL_SERVICE 4 -const OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE 5 -const OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE 6 -const OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH 7 -const OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS 8 -const OMEGA_GPU_PLAT_REFUSED_BAD_KIND 9 -const OMEGA_GPU_PLAT_REFUSED_CACHE_POLICY 10 -const OMEGA_GPU_PLAT_REFUSED_LIMIT 11 -const OMEGA_GPU_PLAT_REFUSED_BUSY 12 -const OMEGA_GPU_PLAT_REFUSED_DEVICE 13 -const OMEGA_GPU_PLAT_REFUSAL_COUNT 14 -const OMEGA_GPU_SESSION_MAX_SPIN_US 1000000 -const OMEGA_GPU_SESSION_MAX_ARGS 32 -const OMEGA_GPU_SESSION_POLL_SLICE_MS 1 -const OMEGA_GPU_SESSION_LOCK_ID 0 -const OMEGA_GPU_SESSION_SCRATCH_RESERVED -2 -const OMEGA_GPU_SESSION_CANCELLED -3 -const OMEGA_GPU_SESSION_PARK_MAX 512 -const OMEGA_GPU_COMPLETION_POLLING 1 -const OMEGA_GPU_CMDLIST_MAX_LAUNCHES 4096 -const OMEGA_GPU_CMDLIST_BANK_BYTES 1024 -const OMEGA_GPU_CMDLIST_QMD_BYTES 1024 -const OMEGA_GPU_CMDLIST_PCAS 0 -const OMEGA_GPU_CMDLIST_INLINE 1 -const OMEGA_GPU_CMDLIST_BARRIER_WFI 0 -const OMEGA_GPU_CMDLIST_BARRIER_NONE 1 -const OMEGA_GPU_CMDLIST_BARRIER_WFI_ONLY 2 -const OMEGA_GPU_CMDLIST_BARRIER_WFI_DATA 3 -const OMEGA_GPU_CMDLIST_BARRIER_FLUSH_DATA 4 -const OMEGA_GPU_ENGINE_FLAG_NO_C3 1 -const OMEGA_GPU_ENGINE_JOB_OUTPUTS 1 -const OMEGA_GPU_ENGINE_SEMAPHORE_WORDS 1 -const OMEGA_GPU_ENGINE_DRV_TEXT_BYTES 128 -const OMEGA_GPU_SYNC_MARKER 1 -const OMEGA_GPU_SYNC_MARKER2 2 -const OMEGA_GPU_SYNC_SEMAPHORE 4 -const OMEGA_GPU_BACKEND_TIMEOUT 1 -const OMEGA_GPU_BACKEND_UNKNOWN_STATE 2 -const OMEGA_GPU_ENGINE_OK 0 -const OMEGA_GPU_ENGINE_DEVICE_OPEN 1 -const OMEGA_GPU_ENGINE_CHANNEL_CREATE 2 -const OMEGA_GPU_ENGINE_ALLOC 3 -const OMEGA_GPU_ENGINE_PREPARE 4 -const OMEGA_GPU_ENGINE_SUBMIT 5 -const OMEGA_GPU_ENGINE_COMPLETION_WAIT 6 -const OMEGA_GPU_ENGINE_RELEASE_WAIT 7 -const OMEGA_GPU_ENGINE_VISIBILITY_WAIT 8 -const OMEGA_GPU_ENGINE_OUTPUT_UNCHANGED 9 -const OMEGA_GPU_ENGINE_INVALID_ARGS 10 -const OMEGA_GPU_ENGINE_INTERNAL_INVARIANT 11 -const OMEGA_GPU_ENGINE_CLEANUP 12 -const OMEGA_GPU_ENGINE_UNCERTAIN_COMPLETION_BLOCKED 13 -const OMEGA_GPU_ENGINE_FAILURE_COUNT 14 -const OMEGA_GPU_ENGINE_STATE_INITIAL 0 -const OMEGA_GPU_ENGINE_STATE_PREPARED 1 -const OMEGA_GPU_ENGINE_STATE_SUBMITTED 2 -const OMEGA_GPU_ENGINE_STATE_GPU_COMPLETE 3 -const OMEGA_GPU_ENGINE_STATE_OUTPUT_VISIBLE 4 -const OMEGA_GPU_ENGINE_STATE_OUTPUT_PRODUCED 5 -const OMEGA_GPU_ENGINE_STATE_SUCCESS 6 -const OMEGA_GPU_ENGINE_STATE_COUNT 7 -const OMEGA_GPU_ENGINE_WAIT_NONE 0 -const OMEGA_GPU_ENGINE_WAIT_MARKER 1 -const OMEGA_GPU_ENGINE_WAIT_RELEASE_SEMAPHORE 2 -const OMEGA_GPU_ENGINE_WAIT_MARKER2 3 -const OMEGA_GPU_ENGINE_WAIT_COUNT 4 -const OMEGA_GPU_ENGINE_STEP_NONE 0 -const OMEGA_GPU_ENGINE_STEP_VALIDATE 1 -const OMEGA_GPU_ENGINE_STEP_BACKEND_CHECK 2 -const OMEGA_GPU_ENGINE_STEP_BLOCKED 3 -const OMEGA_GPU_ENGINE_STEP_NOT_IMPLEMENTED 4 -const OMEGA_GPU_ENGINE_STEP_OPEN_DEVICE 5 -const OMEGA_GPU_ENGINE_STEP_CREATE_CHANNEL 6 -const OMEGA_GPU_ENGINE_STEP_ALLOC 7 -const OMEGA_GPU_ENGINE_STEP_COPY_IN 8 -const OMEGA_GPU_ENGINE_STEP_FILL_POISON 9 -const OMEGA_GPU_ENGINE_STEP_BUILD 10 -const OMEGA_GPU_ENGINE_STEP_SUBMIT 11 -const OMEGA_GPU_ENGINE_STEP_WAIT_MARKER 12 -const OMEGA_GPU_ENGINE_STEP_WAIT_MARKER2 13 -const OMEGA_GPU_ENGINE_STEP_WAIT_RELEASE_SEMAPHORE 14 -const OMEGA_GPU_ENGINE_STEP_BARRIER 15 -const OMEGA_GPU_ENGINE_STEP_COPY_OUT 16 -const OMEGA_GPU_ENGINE_STEP_SCAN 17 -const OMEGA_GPU_ENGINE_STEP_FREE 18 -const OMEGA_GPU_ENGINE_STEP_CLOSE 19 -const OMEGA_GPU_ENGINE_STEP_CLOCK_CHECK 20 -const OMEGA_GPU_ENGINE_STEP_COUNT 21 -const OMEGA_GPU_LAYOUT_VECTOR_1D 0 -const OMEGA_GPU_LAYOUT_COUNT 1 -const OMEGA_GPU_BUF_SCRATCH 0 -const OMEGA_GPU_BUF_PROGRAM 1 -const OMEGA_GPU_BUF_INPUT_A 2 -const OMEGA_GPU_BUF_INPUT_B 3 -const OMEGA_GPU_BUF_OUTPUT 4 -const OMEGA_GPU_BUF_ROLE_COUNT 5 diff --git a/docs/runtime/portability_table.tsv b/docs/runtime/portability_table.tsv index 7d927220d..8cd739d2b 100644 --- a/docs/runtime/portability_table.tsv +++ b/docs/runtime/portability_table.tsv @@ -1,133 +1,8 @@ -# Omega portability table (omega-mv#596, slice R3). Checked by: make test-runtime-portability (tools/runtime_portability_check.sh). +# Omega portability table (omega-mv#596, slice R3): the rows of the GPU-named files Omega still carries. Every other GPU source, +# and its row, is CUDApp's ($(CUDAPP_SOURCE)/docs/runtime/portability_table.tsv). Checked by: make test-runtime-portability-check. # Columns, tab separated: file, class, reason, os_binding. Explained in docs/runtime/PORTABILITY.md. # class: CHIP_SPECIFIC carries knowledge of the GB10 / Blackwell chip or of the driver interface that exposes it; PORTABLE carries neither. # os_binding: FREESTANDING_PROVEN (a .c file in GPU_FS_SRCS, mk/omega-gpu-engine.mk, built by make gpu-engine-freestanding), NO_HOSTED_INCLUDE (no hosted header by include scan only; not linked freestanding), HOSTED_LIBC (includes stdio, stdlib, time, errno, math or pthread), LINUX_DRIVER (includes nvrm.h, m16_native.h or omega_gpu_platform_linux.h). file class reason os_binding -src/omega_blackwell_codegen.c CHIP_SPECIFIC Instruction generators for the sm_121 kernels (vector add, matmul, the Qwen decode set); emits Blackwell machine code through the encoder. In the freestanding closure; the allocating generators and the printing self-test are hosted-only (docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md section 3). FREESTANDING_PROVEN -src/omega_blackwell_codegen.h CHIP_SPECIFIC Blackwell IR opcodes and kernel-generator API; includes omega_blackwell_matmul.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_attn.c CHIP_SPECIFIC Generates the single-launch decode attention kernel (sm_121 machine code, 8 query heads per KV head, head_dim 128). NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_attn.h CHIP_SPECIFIC Interface of the decode attention kernel generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_attn256.c CHIP_SPECIFIC Generates the one-launch decode attention kernel for head_dim 256 (Qwen3.8-27B: 24 query heads over 4 KV heads, KV append inside the kernel) as sm_121 machine code; reuses the emitter helpers of omega_blackwell_codegen_attn.c. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_attn256.h CHIP_SPECIFIC Interface of the head_dim 256 decode attention generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_bf16.c CHIP_SPECIFIC Generates the bf16 streaming GEMV (lm_head) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_bf16.h CHIP_SPECIFIC Interface of the bf16 GEMV generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_dec.c CHIP_SPECIFIC Generates the decode glue kernels (residual add, RMSNorm, SwiGLU, expert combine, argmax) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_dec.h CHIP_SPECIFIC Interface of the decode glue kernel generators; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_gdn.c CHIP_SPECIFIC Generates the one-launch Gated DeltaNet decode step as sm_121 machine code (control words, read barriers, held-scoreboard prefetch of omega_bw_em.h). NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_gdn.h CHIP_SPECIFIC Interface of the Gated DeltaNet generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_gemm.c CHIP_SPECIFIC Generates the FP8 block-scaled grouped GEMM for prefill as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_gemm.h CHIP_SPECIFIC Interface of the FP8 prefill GEMM generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_moe.c CHIP_SPECIFIC Generates the FP8 GEMV kernel family (MoE) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_moe.h CHIP_SPECIFIC Interface of the FP8 GEMV generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_moe2.c CHIP_SPECIFIC Generates FP8 GEMV variant 2 (row-pipelined) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_moe2.h CHIP_SPECIFIC Interface of FP8 GEMV variant 2; includes omega_blackwell_codegen_moe.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pattn.c CHIP_SPECIFIC Generates the causal prefill attention kernel on tensor cores (HMMA, SHFL) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pattn.h CHIP_SPECIFIC Interface of the prefill attention generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pattn256.c CHIP_SPECIFIC Generates the head_dim 256 causal prefill attention attend kernel on tensor cores (HMMA spacing, SHFL.BFLY / F2FP placeholders) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pattn256.h CHIP_SPECIFIC Interface of the head_dim 256 prefill attention generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pf.c CHIP_SPECIFIC Generates the small device-resident prefill kernels (copy and friends) as sm_121 machine code through the omega_bw_em.h emitters. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pf.h CHIP_SPECIFIC Interface of the prefill helper kernels; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pfhost.c CHIP_SPECIFIC Generates the on-chip router-logits and MoE-combine kernels as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_pfhost.h CHIP_SPECIFIC Interface of the on-chip router and combine generators; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_qg.c CHIP_SPECIFIC Generates the native FP8 prefill kernels (activation quantiser, QMMA GEMM) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_qg.h CHIP_SPECIFIC Interface of the native FP8 prefill generators; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_qmma.c CHIP_SPECIFIC Encodes the FP8 tensor-core op QMMA.16832, patched in after the shared encoder (which lacks it); values come from an nvcc sm_121 oracle. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_qmma.h CHIP_SPECIFIC Describes the QMMA.16832.F32.E4M3.E4M3 encoding for sm_121. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_router.c CHIP_SPECIFIC Generates the MoE router kernel (RMSNorm, logits, softmax, top-8) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_router.h CHIP_SPECIFIC Interface of the router kernel generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_tc2.c CHIP_SPECIFIC Generates the tensor-core grouped FP8 GEMM v2 as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_tc2.h CHIP_SPECIFIC Interface of the tensor-core GEMM v2 generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_tc.c CHIP_SPECIFIC Generates tensor-core kernels (HMMA.16816 fragment layout) as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_tc.h CHIP_SPECIFIC Interface of the tensor-core kernel generators; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_tern.c CHIP_SPECIFIC Generates the ternary W2A8 GEMV as sm_121 machine code. NO_HOSTED_INCLUDE -src/omega_blackwell_codegen_tern.h CHIP_SPECIFIC Interface of the ternary GEMV generator; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_blackwell_encoder.c CHIP_SPECIFIC The sm_121 machine-code encoder: packs instructions into 16-byte words. OS-free (in the freestanding closure) but the words it writes are Blackwell's. FREESTANDING_PROVEN -src/omega_blackwell_encoder.h CHIP_SPECIFIC Encoder interface; OMEGA_BW_INSTRUCTION_BYTES is 16, the Blackwell instruction size. NO_HOSTED_INCLUDE -src/omega_blackwell_engine.c CHIP_SPECIFIC The Linux backend of OmegaGpuBackend: calls m16_native_* and carries the GB10 compute-class setup words (class 0xcec0). LINUX_DRIVER -src/omega_blackwell_engine.h CHIP_SPECIFIC Declares the Blackwell GB10 backend function table for the engine core. NO_HOSTED_INCLUDE src/omega_blackwell_gates.c CHIP_SPECIFIC Milestone 17 and 18 qualification gates and a silicon vector-add demonstration on GB10; host tooling. HOSTED_LIBC src/omega_blackwell_gates.h CHIP_SPECIFIC Entry points of the M17 and M18 GB10 qualification gates. NO_HOSTED_INCLUDE -src/omega_blackwell_matmul.c CHIP_SPECIFIC Plans the Blackwell matmul kernels; in the freestanding closure, but the kernel shapes are sm_121 tensor-core shapes. FREESTANDING_PROVEN -src/omega_blackwell_matmul.h CHIP_SPECIFIC Types of the Blackwell matmul kernel (OmegaBlackwellKernel) and its size limits. NO_HOSTED_INCLUDE -src/omega_blackwell_qmd.c CHIP_SPECIFIC Builds the 384-byte QMD launch descriptor (96 words) for Blackwell compute class 0xcec0. In the freestanding closure. FREESTANDING_PROVEN -src/omega_blackwell_qmd.h CHIP_SPECIFIC QMD layout: OMEGA_BW_QMD_BYTES 384, field evidence tiers (documented, observed, reverse engineered), shared-memory field per clcec0qmd.h. NO_HOSTED_INCLUDE -src/omega_blackwell_realize.c CHIP_SPECIFIC Turns an Omega vector program into Blackwell code plus QMD plus constant bank. In the freestanding closure. FREESTANDING_PROVEN -src/omega_blackwell_realize.h CHIP_SPECIFIC Realization interface; includes omega_blackwell_qmd.h and omega_blackwell_encoder.h. NO_HOSTED_INCLUDE -src/omega_blackwell_submit.c CHIP_SPECIFIC The vector executor: allocates and submits through m16_native_* on the Linux driver; its setup words and launch methods are GB10's. Pinned by the M17 and M18 gates. LINUX_DRIVER -src/omega_blackwell_submit.h CHIP_SPECIFIC Launch constants and executor interface for GB10; includes the realize and matmul headers. NO_HOSTED_INCLUDE -src/omega_bw_em.h CHIP_SPECIFIC Private IR emitter helpers for the sm_121 tensor-core generators (scheduling rules proven on the chip). NO_HOSTED_INCLUDE -src/omega_bw_em_q.h CHIP_SPECIFIC Private emitters for the FP8 QMMA placeholders (sm_121). NO_HOSTED_INCLUDE -src/omega_bw_hazard.c CHIP_SPECIFIC Static scoreboard hazard checker over encoded sm_121 kernel bytes (RAW, WAR, WAW against the Blackwell write and read barriers); decodes the operand positions the encoder writes. Includes stdlib.h. HOSTED_LIBC -src/omega_bw_hazard.h CHIP_SPECIFIC Interface of the sm_121 scoreboard hazard checker; includes only stddef.h and stdint.h. NO_HOSTED_INCLUDE -src/omega_bw_reconv.h CHIP_SPECIFIC Warp reconvergence regions (BSSY, BSYNC) for the Blackwell IR emitters. NO_HOSTED_INCLUDE -src/omega_gpu_attention_api.c CHIP_SPECIFIC Builds and launches its own sm_121 attention kernels (stall counts as nvcc writes them for sm_121) through the session. In the freestanding closure. FREESTANDING_PROVEN -src/omega_gpu_attention_api.h CHIP_SPECIFIC Attention API; its kernel type OmegaBlackwellKernel comes from omega_blackwell_matmul.h. NO_HOSTED_INCLUDE -src/omega_gpu_bf16_gemv_api.c CHIP_SPECIFIC Launches the bf16 GEMV through a command list; uses the Blackwell bf16 generator. NO_HOSTED_INCLUDE -src/omega_gpu_bf16_gemv_api.h CHIP_SPECIFIC bf16 GEMV API; includes omega_blackwell_codegen_bf16.h. NO_HOSTED_INCLUDE -src/omega_gpu_cmdlist.c CHIP_SPECIFIC Records launches into one method stream using clcec0 method numbers (WAIT_FOR_IDLE 0x0110, SEND_PCAS_A 0x02b4), the compute-class setup words, and the completion tail with an L2 flush. NO_HOSTED_INCLUDE -src/omega_gpu_cmdlist.h CHIP_SPECIFIC Command-list interface; documents the uncached marker page and the L2_FLUSH_DIRTY tail. NO_HOSTED_INCLUDE -src/omega_gpu_code_alloc.h CHIP_SPECIFIC Code buffers keep a 2 KB tail after the last instruction because the SM instruction cache prefetches past it (omega#323; the cause on GB10 is INFERRED). NO_HOSTED_INCLUDE -src/omega_gpu_decode_attn256_api.c CHIP_SPECIFIC Resident KV cache, RoPE table and launch of the head_dim 256 decode attention kernel on the session and command list. NO_HOSTED_INCLUDE -src/omega_gpu_decode_attn256_api.h CHIP_SPECIFIC head_dim 256 decode attention API; includes omega_blackwell_codegen_attn256.h. NO_HOSTED_INCLUDE -src/omega_gpu_decode_attn_api.c CHIP_SPECIFIC Launches the decode attention kernel from the Blackwell generator through a command list. NO_HOSTED_INCLUDE -src/omega_gpu_decode_attn_api.h CHIP_SPECIFIC Decode attention API; includes omega_blackwell_codegen_attn.h. NO_HOSTED_INCLUDE -src/omega_gpu_decode_graph.c CHIP_SPECIFIC Chains a whole decode token into one command list from Blackwell kernels. HOSTED_LIBC -src/omega_gpu_decode_graph.h CHIP_SPECIFIC Decode graph interface over the FP8, router, attention and bf16 GEMV APIs. NO_HOSTED_INCLUDE -src/omega_gpu_elementwise_api.c CHIP_SPECIFIC Generates and launches its own elementwise sm_121 kernels; still hosted (stdio, stdlib, time), outside the freestanding closure (boundary doc section 6). HOSTED_LIBC -src/omega_gpu_elementwise_api.h CHIP_SPECIFIC Elementwise API; kernel type OmegaBlackwellKernel comes from omega_blackwell_matmul.h. NO_HOSTED_INCLUDE -src/omega_gpu_engine.c PORTABLE The engine state machine (open, validate, submit, verify, close, named failure steps). Builds in make gpu-engine-freestanding; errno and the default clock exist only in the hosted build. FREESTANDING_PROVEN -src/omega_gpu_engine.h PORTABLE Engine contract and OmegaGpuBackend function table; includes only stddef.h and stdint.h. NO_HOSTED_INCLUDE -src/omega_gpu_fmt.c PORTABLE Bounded text formatter that replaces snprintf in the session. Builds in make gpu-engine-freestanding. FREESTANDING_PROVEN -src/omega_gpu_fmt.h PORTABLE Formatter interface; includes only stddef.h. NO_HOSTED_INCLUDE -src/omega_gpu_fp8_api.c CHIP_SPECIFIC Launches the FP8 GEMV through Blackwell generators and command lists, with GPU-cached weight buffers. HOSTED_LIBC -src/omega_gpu_fp8_api.h CHIP_SPECIFIC FP8 GEMV API; includes omega_blackwell_codegen_moe.h. NO_HOSTED_INCLUDE -src/omega_gpu_fp8gemm_api.c CHIP_SPECIFIC Launches the FP8 prefill GEMM through the session. HOSTED_LIBC -src/omega_gpu_fp8gemm_api.h CHIP_SPECIFIC FP8 GEMM API; includes omega_blackwell_codegen_gemm.h. NO_HOSTED_INCLUDE -src/omega_gpu_fp8_pack.c CHIP_SPECIFIC Packs FP8 weights into the layout the sm_121 GEMV kernels read; host side. HOSTED_LIBC -src/omega_gpu_fp8_internal.h CHIP_SPECIFIC Library-internal helpers of omega_gpu_fp8_api.c for the slot pool (GPU-UNCACHED FP8 tensor allocation, CPU views of one expert); includes omega_gpu_fp8_api.h. NO_HOSTED_INCLUDE -src/omega_gpu_fp8_slots.c CHIP_SPECIFIC Versioned replaceable FP8 expert slots backed by one OmegaGpuFp8Tensor; uses the session's platform SYNC and the grouped FP8 GEMV launch. Includes stdlib.h. HOSTED_LIBC -src/omega_gpu_fp8_slots.h CHIP_SPECIFIC FP8 expert slot pool API (load, pin, entry, evict, grouped GEMV); includes omega_gpu_fp8_api.h. NO_HOSTED_INCLUDE -src/omega_gpu_gdn_api.c CHIP_SPECIFIC Resident Gated DeltaNet parameters, GPU-cached tails and states (omega_gpu_mem_cached.h) and the one-launch decode step from the Blackwell generator. HOSTED_LIBC -src/omega_gpu_gdn_api.h CHIP_SPECIFIC Gated DeltaNet API; includes omega_blackwell_codegen_gdn.h. NO_HOSTED_INCLUDE -src/omega_gpu_gemm.c CHIP_SPECIFIC Matrix multiply of any shape on the GB10 tensor cores (HMMA.16816 BF16, QMMA.16832 E4M3) through the omega_bw_em emitters. HOSTED_LIBC -src/omega_gpu_gemm.h CHIP_SPECIFIC GEMM API whose arithmetic order is fixed by the GB10 tensor-core step shapes; includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_gpu_hostmath.c PORTABLE libm-free double-precision log, exp and pow for host-side tables; plain arithmetic, no chip or OS call. NO_HOSTED_INCLUDE -src/omega_gpu_hostmath.h PORTABLE Interface of the libm-free host math; no includes. NO_HOSTED_INCLUDE -src/omega_gpu_matmul_api.c CHIP_SPECIFIC Builds Blackwell matmul kernels, fills the QMD and launches; reports target_chip GB10. In the freestanding closure. FREESTANDING_PROVEN -src/omega_gpu_matmul_api.h CHIP_SPECIFIC Public contract exposes Blackwell tile macros TILE_M=16, TILE_N=8, TILE_K=16, chip CTA envelope and GPU-uncached resident storage; plain C types do not make these semantics chip-neutral. NO_HOSTED_INCLUDE -src/omega_gpu_mem_cached.c CHIP_SPECIFIC Allocates GPU-cached weight buffers; relies on the GB10 rule that a write-once buffer the CPU never reads cannot hold a stale L2 line. NO_HOSTED_INCLUDE -src/omega_gpu_mem_cached.h CHIP_SPECIFIC Documents the GPU-cached read-only weight invariant (nvos.h GPU_CACHEABLE: not coherent with CPU mappings). NO_HOSTED_INCLUDE -src/omega_gpu_moe_api.c CHIP_SPECIFIC Launches MoE matmul kernels from the Blackwell generators and the QMD builder. NO_HOSTED_INCLUDE -src/omega_gpu_moe_api.h CHIP_SPECIFIC Public packing contract is Blackwell tile-major B with col0 modulo 8 alignment and OMEGA_BW_MATMUL_MAX limits; includes omega_gpu_matmul_api.h. NO_HOSTED_INCLUDE -src/omega_gpu_pfgemm.c CHIP_SPECIFIC Prefill GEMM driver over the Blackwell tensor-core generators. HOSTED_LIBC -src/omega_gpu_pfhost.c CHIP_SPECIFIC Prefill router and combine launcher over the Blackwell pfhost generators. NO_HOSTED_INCLUDE -src/omega_gpu_pfhost.h CHIP_SPECIFIC Prefill router and combine API; documents bit-exact sm_121 kernel semantics. NO_HOSTED_INCLUDE -src/omega_gpu_platform.c PORTABLE Platform contract checks, negotiation and handle table. Builds in make gpu-engine-freestanding. FREESTANDING_PROVEN -src/omega_gpu_platform.h CHIP_SPECIFIC ABI 1.2 has reusable typed handles but its current queue_submit contract specifies one GPFIFO entry and its HOST_POLLED rights require the NVIDIA GPU-uncached visibility policy. Device ordinal 0 is documented as the GB10; review this contract on another chip. NO_HOSTED_INCLUDE -src/omega_gpu_platform_linux.c CHIP_SPECIFIC The Linux reference platform: nvrm_open and m16_native_create_channel on the NVIDIA open driver. Hosted only, outside the freestanding closure. LINUX_DRIVER -src/omega_gpu_platform_linux.h CHIP_SPECIFIC Declares the Linux driver platform; the implementation behind it is the Linux binding. NO_HOSTED_INCLUDE -src/omega_gpu_prefill_attn256_api.c CHIP_SPECIFIC Launches the two head_dim 256 prefill attention kernels and patches the tensor-core placeholders of omega_blackwell_codegen_tc.h. NO_HOSTED_INCLUDE -src/omega_gpu_prefill_attn256_api.h CHIP_SPECIFIC head_dim 256 prefill attention API; includes omega_blackwell_codegen_pattn256.h. NO_HOSTED_INCLUDE -src/omega_gpu_prefill_attn_api.c CHIP_SPECIFIC Launches the prefill attention kernel from the Blackwell generator on the session. NO_HOSTED_INCLUDE -src/omega_gpu_prefill_attn_api.h CHIP_SPECIFIC Prefill attention API; includes omega_blackwell_codegen_pattn.h. NO_HOSTED_INCLUDE -src/omega_gpu_prefill.c CHIP_SPECIFIC Device-resident prefill: GPU-cached device buffers and a copy kernel, with the stale-L2 rules for GB10. NO_HOSTED_INCLUDE -src/omega_gpu_prefill.h CHIP_SPECIFIC Documents the prefill memory policy: GPU-cached device-private buffers and L2_FLUSH_DIRTY. NO_HOSTED_INCLUDE -src/omega_gpu_q36_graph.c CHIP_SPECIFIC One Qwen3.6-35B-A3B decode token as one command list of Blackwell kernels with GPU-cached intermediates (omega_gpu_mem_cached.h). HOSTED_LIBC -src/omega_gpu_q36_graph.h CHIP_SPECIFIC Qwen3.6-35B-A3B decode graph interface over the decode graph, hd256 attention, GDN and router APIs. NO_HOSTED_INCLUDE -src/omega_gpu_q38_graph.c CHIP_SPECIFIC One Qwen3.8-27B decode token as one command list of Blackwell kernels with GPU-cached intermediates (omega_gpu_mem_cached.h). HOSTED_LIBC -src/omega_gpu_q38_graph.h CHIP_SPECIFIC Qwen3.8-27B decode graph interface over the decode graph, hd256 attention and GDN APIs. NO_HOSTED_INCLUDE -src/omega_gpu_router_api.c CHIP_SPECIFIC Launches the router kernel through a command list. NO_HOSTED_INCLUDE -src/omega_gpu_router_api.h CHIP_SPECIFIC Router API; includes omega_blackwell_codegen_router.h. NO_HOSTED_INCLUDE -src/omega_gpu_scan.c CHIP_SPECIFIC Reduction and prefix-sum kernels from the omega_bw_em emitters (SHFL.DOWN warp trees) and the chip launch driver. HOSTED_LIBC -src/omega_gpu_scan.h CHIP_SPECIFIC Reduction and prefix-sum API; the chip calls take Blackwell kernels and the header includes omega_blackwell_codegen.h. NO_HOSTED_INCLUDE -src/omega_gpu_scan_ref.c PORTABLE Host references of the frozen reduction and prefix-sum order, which depends only on n and the element index (docs/numeric/E1_REDUCTION_CONTRACT.md); plain C additions, no chip or OS call. Its own header omega_gpu_scan.h still pulls in omega_blackwell_codegen.h, so reusing it off this tree needs the declarations split out. HOSTED_LIBC -src/omega_gpu_serving.c CHIP_SPECIFIC Thin wrapper calls omega_gpu_matmul_reserve and the current attention reservation APIs with their chip-specific contracts; it does not implement an independent generic accounting layer. OS-free in make gpu-engine-freestanding. FREESTANDING_PROVEN -src/omega_gpu_serving.h CHIP_SPECIFIC Current GB10 serving contract delegates to chip-specific matmul/attention reservations and documents at-most-16-row handling and fixed kernel-cache defaults/limits; absence of hosted includes is not a chip-neutral contract. NO_HOSTED_INCLUDE -src/omega_gpu_session.c CHIP_SPECIFIC The persistent session over OmegaGpuPlatform. OS-free (in the freestanding closure) but carries GB10 constants: the compute-class setup words (class 0xcec0), the cache-invalidate method 0x021c, launch constants from omega_blackwell_submit.h. FREESTANDING_PROVEN -src/omega_gpu_session.h CHIP_SPECIFIC Session exposes QMD scratch, register-count rules and QMD shared-memory default 1024, plus the GB10 two-marker/L2 flush launch protocol; platform handles remove OS types, not chip assumptions. NO_HOSTED_INCLUDE -src/omega_gpu_tcgemm_api.c CHIP_SPECIFIC Launches the tensor-core GEMM through the session. HOSTED_LIBC -src/omega_gpu_tcgemm_api.h CHIP_SPECIFIC Tensor-core GEMM API; includes omega_blackwell_codegen_tc.h. NO_HOSTED_INCLUDE -src/omega_gpu_tern_api.c CHIP_SPECIFIC Launches the ternary GEMV with GPU-cached weights through a command list. HOSTED_LIBC -src/omega_gpu_tern_api.h CHIP_SPECIFIC Ternary GEMV API; includes omega_blackwell_codegen_tern.h. NO_HOSTED_INCLUDE -src/omega_gpu_wait.c PORTABLE Bounded wait with a caller-supplied clock and hooks; no default clock in the freestanding build. Builds in make gpu-engine-freestanding. FREESTANDING_PROVEN -src/omega_gpu_wait.h PORTABLE Bounded wait interface; includes only stdbool.h and stdint.h. NO_HOSTED_INCLUDE diff --git a/mk/.crumb b/mk/.crumb index e7c066246..5a802c107 100644 --- a/mk/.crumb +++ b/mk/.crumb @@ -7,14 +7,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-31T02:35:18Z", + "compiled_at": "2026-10-31T10:38:06Z", "compiler": "crumb-compile/1", - "digest": "sha256:c0668c8969cceab0f03ac6ab352ae579c8b473a9ec743d80c89fc187b769c12c", + "digest": "sha256:5490f02828f11619c2a427905af48d9d2e3711067e60f72a34ea7b7a69a041b2", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 97, - "generated_at_commit": "6d7b883844a0f17a7a3ceb427108be7e01e4c677", - "source_tree": "sha256:bca5f08744bd80629e47ac0c27aaeda59e174ed0a3e0cc1d55378862bae21e78" + "generated_at_commit": "a84088331cab756df49419eb03049d7b9a70eb2c", + "source_tree": "sha256:ef1eb39feb05c1ac78a55cb4cfac4d22f7a05a197cc5d2c6e5d64c44a141455c" }, "owner_lane": "", "provenance": { diff --git a/mk/00-visor-core.mk b/mk/00-visor-core.mk index d5e243a92..b30a7dcd7 100644 --- a/mk/00-visor-core.mk +++ b/mk/00-visor-core.mk @@ -3,7 +3,7 @@ # from a clean checkout with PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0. VISOR_CORE = omega_om_units omega_canonical omega_validate omega_core omega_codec aarch64_encoder aarch64_decoder \ omega_realize omega_realize_synth omega_machine omega_exec omega_verify omega_program omega_synthesis omega_library \ - omega_vector omega_blackwell_qmd omega_blackwell_encoder omega_blackwell_realize + omega_vector VISOR_CORE_OBJS = $(addprefix $(OUT_DIR)/,$(addsuffix .o,$(VISOR_CORE))) VISOR_CFLAGS = -std=gnu11 -Wall -Wextra -Werror -MMD -MP -D_GNU_SOURCE -O2 -Isrc -Isrc/visor -Isrc/language VISOR_SRCS = $(wildcard src/visor/*.c) @@ -26,7 +26,7 @@ $(OUT_DIR)/language/%.o: src/language/%.c | $(OUT_DIR)/language $(OUT_DIR)/omega_main.o: tools/omega.c | $(OUT_DIR) $(CC) $(VISOR_CFLAGS) -c $< -o $@ -$(OMEGA_BIN): $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(OUT_DIR)/omega_main.o +$(OMEGA_BIN): $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(OUT_DIR)/omega_main.o $(CUDAPP_LIB) | check-cudapp $(CC) $(VISOR_CFLAGS) -o $@ $^ .PHONY: omega @@ -34,11 +34,11 @@ omega: $(OMEGA_BIN) cp $(OMEGA_BIN) ./omega # Generic rule for lane tests: tests/visor/test_X.c -> build/tests-visor/test_X -$(OUT_DIR)/tests-visor/%: tests/visor/%.c $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) | $(OUT_DIR)/tests-visor - $(CC) $(VISOR_CFLAGS) -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) +$(OUT_DIR)/tests-visor/%: tests/visor/%.c $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(CUDAPP_LIB) | $(OUT_DIR)/tests-visor check-cudapp + $(CC) $(VISOR_CFLAGS) -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(CUDAPP_LIB) -$(OUT_DIR)/tests-language/%: tests/language/%.c $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) | $(OUT_DIR)/tests-language - $(CC) $(VISOR_CFLAGS) -Itests/language -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) +$(OUT_DIR)/tests-language/%: tests/language/%.c $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(CUDAPP_LIB) | $(OUT_DIR)/tests-language check-cudapp + $(CC) $(VISOR_CFLAGS) -Itests/language -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(CUDAPP_LIB) # ---- aggregate Visor gates (lead-owned) -------------------------------------- # Physics-free lane tests (no PHYSICS_DIR needed): diff --git a/mk/autodiff.mk b/mk/autodiff.mk index 1ef131765..9f727d75a 100644 --- a/mk/autodiff.mk +++ b/mk/autodiff.mk @@ -14,26 +14,25 @@ ifndef AUTODIFF_MK AUTODIFF_MK := 1 .PHONY: test-autodiff test-autodiff-mutations autodiff-mutants AUTODIFF_CFLAGS = -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -Isrc/tensor \ - -Isrc/autodiff -DOMEGA_NUMERIC_CPU_ONLY + -Isrc/autodiff -DOMEGA_NUMERIC_CPU_ONLY $(CUDAPP_HEADER_FLAGS) AUTODIFF_SRCS = src/autodiff/omega_autodiff.c AUTODIFF_TENSOR_SRCS = src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c \ src/tensor/omega_tensor_reduce_seam.c src/omega_numeric_reduce.c src/omega_numeric_transc.c -AUTODIFF_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c +AUTODIFF_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_om_units.c AUTODIFF_HDRS = src/autodiff/omega_autodiff.h src/tensor/omega_tensor.h src/tensor/omega_tensor_reduce_seam.h \ src/omega_numeric_reduce.h src/omega_numeric.h src/sha256.h src/omega_numeric_transc.h $(OUT_DIR)/test_omega_autodiff: tests/test_omega_autodiff.c $(AUTODIFF_SRCS) $(AUTODIFF_TENSOR_SRCS) \ - $(AUTODIFF_DEPS) $(AUTODIFF_HDRS) + $(AUTODIFF_DEPS) $(AUTODIFF_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) gcc $(AUTODIFF_CFLAGS) -O2 -o $@ tests/test_omega_autodiff.c $(AUTODIFF_SRCS) $(AUTODIFF_TENSOR_SRCS) \ - $(AUTODIFF_DEPS) + $(AUTODIFF_DEPS) $(CUDAPP_LIB) $(OUT_DIR)/test_omega_autodiff_asan: tests/test_omega_autodiff.c $(AUTODIFF_SRCS) $(AUTODIFF_TENSOR_SRCS) \ - $(AUTODIFF_DEPS) $(AUTODIFF_HDRS) + $(AUTODIFF_DEPS) $(AUTODIFF_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) gcc $(AUTODIFF_CFLAGS) -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all \ - -o $@ tests/test_omega_autodiff.c $(AUTODIFF_SRCS) $(AUTODIFF_TENSOR_SRCS) $(AUTODIFF_DEPS) + -o $@ tests/test_omega_autodiff.c $(AUTODIFF_SRCS) $(AUTODIFF_TENSOR_SRCS) $(AUTODIFF_DEPS) $(CUDAPP_LIB) test-autodiff: $(OUT_DIR)/test_omega_autodiff $(OUT_DIR)/test_omega_autodiff_asan ./$(OUT_DIR)/test_omega_autodiff diff --git a/mk/cudapp-consumer.mk b/mk/cudapp-consumer.mk new file mode 100644 index 000000000..3a6e6ee25 --- /dev/null +++ b/mk/cudapp-consumer.mk @@ -0,0 +1,34 @@ +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# Source identity is checked on every native entry, including stale-output builds. +ifndef OMEGA_CUDAPP_CONSUMER_MK +OMEGA_CUDAPP_CONSUMER_MK := 1 +CUDAPP_DIR ?= ../CUDApp +CUDAPP_STAGE = $(OUT_DIR)/cudapp +CUDAPP_SOURCE = $(CUDAPP_STAGE)/source +CUDAPP_LIB = $(CUDAPP_STAGE)/build/libcudapp.a +CUDAPP_HEADER_FLAGS = -I"$(CUDAPP_SOURCE)/src" -I"$(CUDAPP_SOURCE)/m16" -I"$(CUDAPP_SOURCE)/nvrm" \ + -I"$(CUDAPP_SOURCE)/third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc" \ + -I"$(CUDAPP_SOURCE)/third_party/nvidia-open-580.173.02/kernel-open/common/inc" \ + -I"$(CUDAPP_SOURCE)/third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm" \ + -I"$(CUDAPP_SOURCE)/third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include" \ + -DOMEGA_CUDAPP_SOURCE='"$(abspath $(CUDAPP_SOURCE))"' +.PHONY: check-cudapp test-cudapp-stage-hermetic +check-cudapp: + sh tools/cudapp-stage.sh cudapp.lock "$(CUDAPP_DIR)" "$(CUDAPP_STAGE)" + +test-cudapp-stage-hermetic: + sh tests/cudapp_stage_hermetic.sh "$(CUDAPP_DIR)" + +$(CUDAPP_LIB): cudapp.lock | check-cudapp + @test -f "$@" + +# Required canonical source/header prerequisites may not exist until staging. +# A missing member is an error; it is never silently dropped from a read set. +$(CUDAPP_SOURCE)/%: | check-cudapp + @test -f "$@" + +$(OUT_DIR)/omegatool.o $(OUT_DIR)/omega_blackwell_gates.o $(OUT_DIR)/omega_world_gates.o \ +$(OUT_DIR)/omega_vector.o $(OUT_DIR)/omega_accelerator.o $(OUT_DIR)/omega_accelerator_world.o \ +$(OUT_DIR)/rx_resident_gpu.o: cudapp.lock $(CUDAPP_SOURCE)/src/cudapp_native.h | check-cudapp + +endif diff --git a/mk/numeric-slices.mk b/mk/numeric-slices.mk index ff2125f03..7d8ea79db 100644 --- a/mk/numeric-slices.mk +++ b/mk/numeric-slices.mk @@ -1,4 +1,3 @@ -# Numeric Blackwell source slice, declared once. The numeric CPU/host test -# source lists in Makefile end with this run, in this order. -NUMERIC_BW_SRCS = src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c -NUMERIC_BW_HDRS = src/omega_blackwell_qmd.h src/omega_blackwell_codegen.h src/omega_blackwell_encoder.h src/sha256.h +# Hosted numerics retain Omega CPU/provenance units; GPU code comes from CUDA++. +NUMERIC_BW_SRCS = src/omega_om_units.c +NUMERIC_BW_HDRS = $(CUDAPP_SOURCE)/src/omega_blackwell_qmd.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(CUDAPP_SOURCE)/src/omega_blackwell_encoder.h src/sha256.h diff --git a/mk/om-encoder.mk b/mk/om-encoder.mk deleted file mode 100644 index 16de2e0d0..000000000 --- a/mk/om-encoder.mk +++ /dev/null @@ -1,83 +0,0 @@ -# The sm_121 instruction encoder in seeded Omega (om/encoder/bw_enc_sm121.om, twin of aien-dev/CUDApp#79), linked -# through the omega-bridge native binding src/omega_om_units.c that om/units.sh generates. The C encoder in -# src/omega_blackwell_codegen.c is migration-pending: the freestanding build and the oracle builds only. -# make test-om-encoder (no Omega tools needed) -# 1. the golden-word fixture verifiers (nvcc/nvdisasm oracles) through the .om encoder; -# 2. a build with CUDAPP_MIGRATION_PENDING_ENCODER_DIFF encodes every codegen fixture both ways and must log -# only SAME lines; 3. its red check: the same build with one flipped output bit must abort. -# make test-om-encoder-corpus every kernel of the sm121dis corpus (tools/sm121dis/corpus.sh) built three ways: -# .om (OUT_DIR), C oracle ($(OUT_DIR)-enc-c), diff ($(OUT_DIR)-enc-diff); the .om and C kernel sets must be -# identical file for file, and the diff build must log no DIFFER line. The num_*.bin kernels come from the -# numeric encoder (build/test_omega_{divsqrt,ldst}_gb10_cpu, shared by all three runs), not from this one. -# make test-om-encoder-mutants three mutant .om encoders, each compiled by the pinned omc, must go red -# The binding itself regenerates byte for byte in tests/gates/run.sh om-units (om/units.sh --check). The mutants need -# OMEGA_OMC (default seed/out/omc, born from the seed by seed/omega-from-seed.sh) and OMEGA_BRIDGE_DIR (an -# aien-dev/omega-bridge checkout at om/omega-bridge.lock); without them they exit 3 (NOT_RUN), never PASS. -OMEGA_OMC ?= seed/out/omc -OMEGA_BRIDGE_DIR ?= ../omega-bridge -OM_ENC_DIR = $(OUT_DIR)/om-encoder -OM_ENC_TEST_DEPS = tests/test_omega_codegen_freestanding.c src/omega_blackwell_codegen.h src/omega_blackwell_matmul.h -OM_ENC_SRCS = src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c -OM_ENC_BUILD = gcc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -Isrc -# The mutant bindings keep the other units, so sha256_* (src/omega_api_decl.h) still resolves; only the encoder changes. -OM_ENC_OTHER_UNITS = om/sha256/sha256-om2.om om/blake3/b3unit.om - -.PHONY: test-om-encoder test-om-encoder-corpus test-om-encoder-mutants -$(OM_ENC_DIR)/codegen_om: $(OM_ENC_TEST_DEPS) $(OM_ENC_SRCS) src/omega_om_units.c src/omega_native.h - @mkdir -p $(OM_ENC_DIR) - $(OM_ENC_BUILD) -o $@ tests/test_omega_codegen_freestanding.c $(OM_ENC_SRCS) src/omega_om_units.c -$(OM_ENC_DIR)/codegen_diff: $(OM_ENC_TEST_DEPS) $(OM_ENC_SRCS) src/omega_om_units.c src/omega_native.h - @mkdir -p $(OM_ENC_DIR) - $(OM_ENC_BUILD) -DCUDAPP_MIGRATION_PENDING_ENCODER_DIFF -o $@ tests/test_omega_codegen_freestanding.c \ - $(OM_ENC_SRCS) src/omega_om_units.c -$(OM_ENC_DIR)/codegen_diff_red: $(OM_ENC_TEST_DEPS) $(OM_ENC_SRCS) src/omega_om_units.c src/omega_native.h - @mkdir -p $(OM_ENC_DIR) - $(OM_ENC_BUILD) -DCUDAPP_MIGRATION_PENDING_ENCODER_DIFF -DCUDAPP_ENCODER_DIFF_SELFTEST -o $@ \ - tests/test_omega_codegen_freestanding.c $(OM_ENC_SRCS) src/omega_om_units.c - -test-om-encoder: $(OM_ENC_DIR)/codegen_om $(OM_ENC_DIR)/codegen_diff $(OM_ENC_DIR)/codegen_diff_red - $(OM_ENC_DIR)/codegen_om --golden - rm -f $(OM_ENC_DIR)/diff.log - CUDAPP_ENCODER_DIFF_LOG=$(OM_ENC_DIR)/diff.log $(OM_ENC_DIR)/codegen_diff --golden - CUDAPP_ENCODER_DIFF_LOG=$(OM_ENC_DIR)/diff.log $(OM_ENC_DIR)/codegen_diff --dump > $(OM_ENC_DIR)/dump_diff.txt - @same=$$(grep -c ' SAME$$' $(OM_ENC_DIR)/diff.log); other=$$(grep -vc ' SAME$$' $(OM_ENC_DIR)/diff.log); \ - if [ "$$same" -eq 0 ] || [ "$$other" -ne 0 ]; then echo "FAIL encoder diff: $$same SAME, $$other other lines"; exit 1; fi; \ - echo "encoder diff: .om and C byte-identical on $$(grep -c '^insn ' $(OM_ENC_DIR)/diff.log) golden instructions and $$(grep -c '^program ' $(OM_ENC_DIR)/diff.log) fixture programs" - @if CUDAPP_ENCODER_DIFF_LOG=$(OM_ENC_DIR)/diff_red.log $(OM_ENC_DIR)/codegen_diff_red --dump > /dev/null 2>&1; then \ - echo "RED CHECK BROKEN: a flipped bit passed the encoder diff"; exit 1; \ - else echo "red check: one flipped bit aborts the encoder diff, as it must"; fi - -test-om-encoder-corpus: - $(MAKE) OUT_DIR=$(OUT_DIR) CUDAPP_ENCODER=om sm121dis-corpus-bins - $(MAKE) OUT_DIR=$(OUT_DIR)-enc-c CUDAPP_ENCODER=c sm121dis-corpus-bins - $(MAKE) OUT_DIR=$(OUT_DIR)-enc-diff CUDAPP_ENCODER=diff sm121dis-corpus-bins - rm -rf $(OM_ENC_DIR)/k-om $(OM_ENC_DIR)/k-c $(OM_ENC_DIR)/k-diff $(OM_ENC_DIR)/corpus-diff.log - @mkdir -p $(OM_ENC_DIR) - sh tools/sm121dis/corpus.sh $(OUT_DIR) $(OM_ENC_DIR)/k-om - sh tools/sm121dis/corpus.sh $(OUT_DIR)-enc-c $(OM_ENC_DIR)/k-c - CUDAPP_ENCODER_DIFF_LOG=$(abspath $(OM_ENC_DIR))/corpus-diff.log sh tools/sm121dis/corpus.sh $(OUT_DIR)-enc-diff $(OM_ENC_DIR)/k-diff - diff -r $(OM_ENC_DIR)/k-om $(OM_ENC_DIR)/k-c - diff -r $(OM_ENC_DIR)/k-om $(OM_ENC_DIR)/k-diff - @if grep -v ' SAME$$' $(OM_ENC_DIR)/corpus-diff.log; then echo "FAIL corpus encoder diff"; exit 1; fi - @echo "encoder corpus: $$(ls $(OM_ENC_DIR)/k-om/*.bin | grep -vc '/num_') distinct codegen kernels identical .om vs C (plus $$(ls $(OM_ENC_DIR)/k-om/num_*.bin | wc -l) numeric-encoder kernels); diff build $$(grep -c '^program ' $(OM_ENC_DIR)/corpus-diff.log) program encodes and $$(grep -c '^insn ' $(OM_ENC_DIR)/corpus-diff.log) single-instruction encodes, all SAME" - -# Each mutant is one edit of the .om source, compiled by the pinned omc into its own binding; the hosted -# fixture test linked with it must fail the golden words or differ from the C-encoded freestanding dump. -OM_ENC_MUTANTS = 's/^ret or base shl rb o 1 16$$/ret or base shl rb o 1 17/' \ - 's/^p = 262144$$/p = 0/' \ - 's/^const NOPC ulong 1032192$$/const NOPC ulong 1032193/' -test-om-encoder-mutants: build/test_codegen_freestanding - @[ -x $(OMEGA_OMC) ] && [ -f $(OMEGA_BRIDGE_DIR)/src/native.om ] || { echo "NOT_RUN: set OMEGA_OMC and OMEGA_BRIDGE_DIR"; exit 3; } - @mkdir -p $(OM_ENC_DIR) - ./build/test_codegen_freestanding --dump > $(OM_ENC_DIR)/c-dump.txt - @n=0; for m in $(OM_ENC_MUTANTS); do n=$$((n+1)); d=$(OM_ENC_DIR)/mutant$$n; rm -rf $$d; mkdir -p $$d; \ - sed "$$m" om/encoder/bw_enc_sm121.om > $$d/bw_enc_sm121.om; \ - if cmp -s $$d/bw_enc_sm121.om om/encoder/bw_enc_sm121.om; then echo "MUTANT $$n BROKEN: '$$m' changed nothing"; exit 1; fi; \ - OMEGA_UNITS="$(OM_ENC_OTHER_UNITS) $$(pwd)/$$d/bw_enc_sm121.om" OMEGA_UNITS_DEST=$$d OMEGA_OMC=$(abspath $(OMEGA_OMC)) \ - OMEGA_BRIDGE=$(OMEGA_BRIDGE_DIR) sh om/units.sh > /dev/null || exit 1; \ - $(OM_ENC_BUILD) -o $$d/codegen tests/test_omega_codegen_freestanding.c $(OM_ENC_SRCS) $$d/omega_om_units.c || exit 1; \ - g=0; $$d/codegen --golden > $$d/golden.log 2>&1 || g=1; \ - c=0; $$d/codegen --dump > $$d/dump.txt 2>&1; cmp -s $$d/dump.txt $(OM_ENC_DIR)/c-dump.txt || c=1; \ - if [ $$g = 0 ] && [ $$c = 0 ]; then echo "MUTANT $$n SURVIVED: '$$m'"; exit 1; fi; \ - echo "mutant $$n red ('$$m'): golden words $$( [ $$g = 1 ] && echo FAIL || echo pass ), dump vs C $$( [ $$c = 1 ] && echo DIFFERS || echo same )"; \ - done diff --git a/mk/omega-gpu-code-alloc.mk b/mk/omega-gpu-code-alloc.mk index 3b217c32d..0de14ea51 100644 --- a/mk/omega-gpu-code-alloc.mk +++ b/mk/omega-gpu-code-alloc.mk @@ -1,18 +1,34 @@ -# GPU code buffer sizing (src/omega_gpu_code_alloc.h): the 2 KB instruction prefetch tail after every +# Canonical GPU code buffer sizing: the 2 KB instruction prefetch tail after every # kernel (omega#323). Host only: no device, no physics headers. Three parts: the size rule, a NO_TAIL # mutant that must fail it, and a source scan that refuses the page-only code sizing idioms the six # variable-size upload sites and five fixed-size sites used before. -CODE_ALLOC_SCAN_SRC := src/*.c src/runtime/*.c +CODE_ALLOC_SCAN_SRC = $(wildcard $(CUDAPP_SOURCE)/src/*.c src/runtime/*.c) CODE_ALLOC_SCAN_RE := code_size \+ 0x[fF]{3}|session_alloc\([^,]*code_size|alloc[a-z_]*\([^,]*, *(0x[0-9a-fA-F]+|OMEGA_DS_MAX_CODE_BYTES), *&[a-z_>.-]*code_mem\) -.PHONY: test-gpu-code-alloc -build/test_omega_gpu_code_alloc: tests/test_omega_gpu_code_alloc.c src/omega_gpu_code_alloc.h +.PHONY: test-gpu-code-alloc test-gpu-code-alloc-scan +build/test_omega_gpu_code_alloc: $(CUDAPP_SOURCE)/tests/test_omega_gpu_code_alloc.c $(CUDAPP_SOURCE)/src/omega_gpu_code_alloc.h | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -o $@ tests/test_omega_gpu_code_alloc.c + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_code_alloc.c test-gpu-code-alloc: build/test_omega_gpu_code_alloc ./build/test_omega_gpu_code_alloc - @gcc -std=gnu11 -O2 -Wall -Wextra -Werror -DOMEGA_GPU_CODE_ALLOC_MUTANT_NO_TAIL -Isrc -o build/test_omega_gpu_code_alloc_no_tail tests/test_omega_gpu_code_alloc.c + @gcc -std=gnu11 -O2 -Wall -Wextra -Werror -DOMEGA_GPU_CODE_ALLOC_MUTANT_NO_TAIL $(CUDAPP_HEADER_FLAGS) -Isrc -o build/test_omega_gpu_code_alloc_no_tail $(CUDAPP_SOURCE)/tests/test_omega_gpu_code_alloc.c @if ./build/test_omega_gpu_code_alloc_no_tail >build/test_omega_gpu_code_alloc_no_tail.log 2>&1; then echo "MUTANT SURVIVED: NO_TAIL"; exit 1; fi @echo "NO_TAIL mutant: killed ($$(grep -c '^FAIL:' build/test_omega_gpu_code_alloc_no_tail.log) failing checks)" - @if grep -nE '$(CODE_ALLOC_SCAN_RE)' $(CODE_ALLOC_SCAN_SRC); then echo "code buffer sized without the prefetch tail (use omega_gpu_code_alloc_bytes)"; exit 1; fi - @echo "source scan: no page-only code sizing" + @$(MAKE) --no-print-directory test-gpu-code-alloc-scan + @if $(MAKE) --no-print-directory test-gpu-code-alloc-scan CODE_ALLOC_SCAN_SRC=build/code-alloc-missing-input.c >build/code-alloc-missing.log 2>&1; then echo "source scan accepted a missing input"; exit 1; fi + @grep -q '^source scan failed (grep exit 2)' build/code-alloc-missing.log + @if $(MAKE) --no-print-directory test-gpu-code-alloc-scan CODE_ALLOC_SCAN_SRC= >build/code-alloc-empty.log 2>&1; then echo "source scan accepted an empty readset"; exit 1; fi + @grep -q '^source scan has no inputs' build/code-alloc-empty.log + @printf '%s\n' 'code_size + 0xfff' >build/code-alloc-forbidden.c + @if $(MAKE) --no-print-directory test-gpu-code-alloc-scan CODE_ALLOC_SCAN_SRC=build/code-alloc-forbidden.c >build/code-alloc-forbidden.log 2>&1; then echo "source scan accepted forbidden sizing"; exit 1; fi + @grep -q '^code buffer sized without the prefetch tail' build/code-alloc-forbidden.log @echo "OMEGA_GPU_CODE_ALLOC_GATE PASS" + +# A canonical stage must exist before expanding the default optional source globs. +test-gpu-code-alloc-scan: | check-cudapp + @test -n "$(strip $(CODE_ALLOC_SCAN_SRC))" || { echo "source scan has no inputs"; exit 2; } + @rc=0; grep -nE '$(CODE_ALLOC_SCAN_RE)' $(CODE_ALLOC_SCAN_SRC) || rc=$$?; \ + case $$rc in \ + 1) echo "source scan: no page-only code sizing" ;; \ + 0) echo "code buffer sized without the prefetch tail (use omega_gpu_code_alloc_bytes)"; exit 1 ;; \ + *) echo "source scan failed (grep exit $$rc)"; exit 2 ;; \ + esac diff --git a/mk/omega-gpu-engine.mk b/mk/omega-gpu-engine.mk index f3f5dd632..5a647fd4e 100644 --- a/mk/omega-gpu-engine.mk +++ b/mk/omega-gpu-engine.mk @@ -3,46 +3,41 @@ # part of `all` or `test`. # test-gpu-engine-compile header + core compile, enum names, refusals, no-op backend (A2/A3a) # test-gpu-engine the engine core against a fake backend (every state and failure) -# test-gpu-engine-backend-compile syntax-checks src/omega_blackwell_engine.c (A3b1): -c only, no link, no device +# test-gpu-engine-backend-compile syntax-checks $(CUDAPP_SOURCE)/src/omega_blackwell_engine.c (A3b1): -c only, no link, no device # test-gpu-engine-prod-build production build of build/omegatool at the physics pin: links only, opens no device -# test-gpu-engine-mutants removes each protection from src/omega_gpu_engine.c in a scratch +# test-gpu-engine-mutants removes each protection from $(CUDAPP_SOURCE)/src/omega_gpu_engine.c in a scratch # copy; the host test must fail each one (exit nonzero on a survivor) # test-gpu-engine-sim (A3b2) the REAL engine core + Blackwell backend + vector wrapper against a simulated driver -# (tests/fake_m16_native.c); host only, no device, no physics C sources +# ($(CUDAPP_SOURCE)/tests/fake_m16_native.c); host only, no device, no physics C sources # test-gpu-engine-backend-mutants (A3b2) one mutant per protection in the backend and the vector wrapper -# test-gpu-engine-gb10-compile (A3b2) compile-only check of tests/test_omega_gpu_engine_gb10.c (Phase B chip test, never run here) +# test-gpu-engine-gb10-compile (A3b2) compile-only check of $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine_gb10.c (Phase B chip test, never run here) # gpu-engine-freestanding (native v1 P07 cut A) the portable GPU files built -ffreestanding with # OMEGA_GPU_NO_POSIX: no Linux header, no errno, no clock, no libc beyond mem*/str* # test-codegen-freestanding (cut A.2) codegen hosted vs freestanding byte-identical, bounded code buffers # test-gpu-engine-freestanding the engine contract test and the platform contract test linked against # those freestanding objects (host runner, opens no device) .PHONY: test-gpu-engine-compile test-gpu-engine test-gpu-engine-mutants test-gpu-engine-backend-compile test-gpu-engine-prod-build test-gpu-engine-sim test-gpu-engine-backend-mutants test-gpu-engine-gb10-compile gpu-engine-freestanding test-gpu-engine-freestanding -build/test_omega_gpu_engine_compile: tests/test_omega_gpu_engine_compile.c src/omega_gpu_engine.c src/omega_gpu_engine.h +build/test_omega_gpu_engine_compile: $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine_compile.c $(CUDAPP_SOURCE)/src/omega_gpu_engine.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ tests/test_omega_gpu_engine_compile.c src/omega_gpu_engine.c + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine_compile.c $(CUDAPP_LIB) test-gpu-engine-compile: build/test_omega_gpu_engine_compile ./build/test_omega_gpu_engine_compile -build/test_omega_gpu_engine: tests/test_omega_gpu_engine.c src/omega_gpu_engine.c src/omega_gpu_engine.h +build/test_omega_gpu_engine: $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine.c $(CUDAPP_SOURCE)/src/omega_gpu_engine.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ tests/test_omega_gpu_engine.c src/omega_gpu_engine.c + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -DOMEGA_NUMERIC_CPU_ONLY -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine.c $(CUDAPP_LIB) test-gpu-engine: build/test_omega_gpu_engine ./build/test_omega_gpu_engine test-gpu-engine-mutants: sh tools/gpu_engine_mutations.sh -# A3b1: the Blackwell backend includes physics headers (m16_native.h, nvrm.h), so it -# uses the same physics -I paths as the top-level Makefile CFLAGS (Makefile lines 9-14). -GPU_ENGINE_PHYS_INC = -I$(PHYSICS_DIR)/m16 -I$(PHYSICS_DIR)/nvrm \ - -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc \ - -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/kernel-open/common/inc \ - -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm \ - -I$(PHYSICS_DIR)/third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include +# Syntax-check the canonical backend, using its bundled driver headers. +GPU_ENGINE_PHYS_INC = $(CUDAPP_HEADER_FLAGS) -build/omega_blackwell_engine_syntax.o: src/omega_blackwell_engine.c src/omega_blackwell_engine.h src/omega_gpu_engine.h +build/omega_blackwell_engine_syntax.o: $(CUDAPP_SOURCE)/src/omega_blackwell_engine.c $(CUDAPP_SOURCE)/src/omega_blackwell_engine.h $(CUDAPP_SOURCE)/src/omega_gpu_engine.h | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -Isrc $(GPU_ENGINE_PHYS_INC) -c -o $@ src/omega_blackwell_engine.c + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE $(GPU_ENGINE_PHYS_INC) -Isrc -c -o $@ $(CUDAPP_SOURCE)/src/omega_blackwell_engine.c test-gpu-engine-backend-compile: build/omega_blackwell_engine_syntax.o # Links only, opens no device. Uses the real m16_native and nvrm sources at the physics pin. @@ -50,19 +45,17 @@ test-gpu-engine-prod-build: $(MAKE) build/omegatool # A3b2: simulated-driver host test. Links the sources of the Makefile RX_COMPOSE_GPU_SRCS list (plus the -# three core files the vector builder needs) with tests/fake_m16_native.c in place of the physics +# three core files the vector builder needs) with $(CUDAPP_SOURCE)/tests/fake_m16_native.c in place of the physics # m16_native.c and nvrm.c. Opens no device. -GPU_ENGINE_SIM_SRCS = src/omega_blackwell_submit.c src/omega_blackwell_engine.c src/omega_gpu_engine.c \ - src/omega_blackwell_matmul.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_qmd.c src/omega_blackwell_realize.c src/omega_vector.c src/omega_validate.c \ +GPU_ENGINE_SIM_SRCS = src/omega_vector.c src/omega_validate.c \ src/omega_core.c src/omega_canonical.c src/omega_om_units.c -build/test_omega_blackwell_engine: tests/test_omega_blackwell_engine.c tests/fake_m16_native.c tests/fake_m16_native.h \ - $(GPU_ENGINE_SIM_SRCS) src/omega_gpu_engine.h src/omega_blackwell_engine.h +build/test_omega_blackwell_engine: $(CUDAPP_SOURCE)/tests/test_omega_blackwell_engine.c $(CUDAPP_SOURCE)/tests/fake_m16_native.c $(CUDAPP_SOURCE)/tests/fake_m16_native.h \ + $(GPU_ENGINE_SIM_SRCS) $(CUDAPP_SOURCE)/src/omega_gpu_engine.h $(CUDAPP_SOURCE)/src/omega_blackwell_engine.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -ffunction-sections -fdata-sections \ - -Isrc -Itests $(GPU_ENGINE_PHYS_INC) -o $@ tests/test_omega_blackwell_engine.c tests/fake_m16_native.c \ - $(GPU_ENGINE_SIM_SRCS) -Wl,--gc-sections -lm + -Isrc -I$(CUDAPP_SOURCE)/tests -Itests $(GPU_ENGINE_PHYS_INC) -o $@ $(CUDAPP_SOURCE)/tests/test_omega_blackwell_engine.c $(CUDAPP_SOURCE)/tests/fake_m16_native.c \ + $(GPU_ENGINE_SIM_SRCS) -Wl,--gc-sections -lm $(CUDAPP_LIB) test-gpu-engine-sim: build/test_omega_blackwell_engine ./build/test_omega_blackwell_engine @@ -71,21 +64,19 @@ test-gpu-engine-backend-mutants: PHYSICS_DIR="$(PHYSICS_DIR)" sh tools/gpu_engine_backend_mutations.sh # Phase B chip test, compile only here. Never run in Phase A. -build/test_omega_gpu_engine_gb10.o: tests/test_omega_gpu_engine_gb10.c src/omega_gpu_engine.h src/omega_blackwell_engine.h src/omega_blackwell_submit.h +build/test_omega_gpu_engine_gb10.o: $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine_gb10.c $(CUDAPP_SOURCE)/src/omega_gpu_engine.h $(CUDAPP_SOURCE)/src/omega_blackwell_engine.h $(CUDAPP_SOURCE)/src/omega_blackwell_submit.h | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread -Isrc $(GPU_ENGINE_PHYS_INC) -c -o $@ tests/test_omega_gpu_engine_gb10.c + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -ffp-contract=off -fno-fast-math -pthread -Isrc $(GPU_ENGINE_PHYS_INC) -c -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine_gb10.c test-gpu-engine-gb10-compile: build/test_omega_gpu_engine_gb10.o # Measurement (sc#277): driver allocations and frees made by the REAL session + matmul + attention # APIs while serving a Qwen3-4B-shaped sequence, against the simulated driver. Host only, no device. # Prints MEASURE lines; asserts only bookkeeping. Links no physics C sources, only its headers. -GPU_SERVE_ALLOC_SRCS = src/omega_gpu_session.c src/omega_gpu_platform.c src/omega_gpu_platform_linux.c src/omega_gpu_fmt.c src/omega_gpu_matmul_api.c src/omega_gpu_attention_api.c src/omega_gpu_serving.c \ - src/omega_gpu_wait.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c src/omega_blackwell_qmd.c \ - src/omega_blackwell_matmul.c src/omega_om_units.c -build/gpu_serving_alloc_count_test: tests/gpu_serving_alloc_count_test.c tests/fake_m16_native.c tests/fake_m16_native.h $(GPU_SERVE_ALLOC_SRCS) +GPU_SERVE_ALLOC_SRCS = src/omega_om_units.c +build/gpu_serving_alloc_count_test: $(CUDAPP_SOURCE)/tests/gpu_serving_alloc_count_test.c $(CUDAPP_SOURCE)/tests/fake_m16_native.c $(CUDAPP_SOURCE)/tests/fake_m16_native.h $(GPU_SERVE_ALLOC_SRCS) $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -ffp-contract=off -Isrc -Itests $(GPU_ENGINE_PHYS_INC) \ - -o $@ tests/gpu_serving_alloc_count_test.c tests/fake_m16_native.c $(GPU_SERVE_ALLOC_SRCS) -lm + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -ffp-contract=off -Isrc -I$(CUDAPP_SOURCE)/tests -Itests $(GPU_ENGINE_PHYS_INC) \ + -o $@ $(CUDAPP_SOURCE)/tests/gpu_serving_alloc_count_test.c $(CUDAPP_SOURCE)/tests/fake_m16_native.c $(GPU_SERVE_ALLOC_SRCS) -lm $(CUDAPP_LIB) .PHONY: test-gpu-serving-alloc test-gpu-serving-alloc: build/gpu_serving_alloc_count_test ./build/gpu_serving_alloc_count_test plain @@ -112,26 +103,30 @@ test-gpu-serving-alloc: build/gpu_serving_alloc_count_test # runtime symbols; it proves nothing about device ownership (NOT_RUN until cut B runs on the Spark). GPU_FS_DIR = build/gpu_fs GPU_FS_CFLAGS = -std=gnu11 -O2 -Wall -Wextra -Werror -ffreestanding -fno-builtin -fno-stack-protector \ - -U_FORTIFY_SOURCE -DOMEGA_GPU_NO_POSIX -DOMEGA_NUMERIC_CPU_ONLY -Isrc + -U_FORTIFY_SOURCE -DOMEGA_GPU_NO_POSIX -DOMEGA_NUMERIC_CPU_ONLY $(CUDAPP_HEADER_FLAGS) -Isrc # P07 cut C (session part): the persistent session, the matmul and attention APIs, the serving reservation and the # bounded wait join the link. Their machine comes from an installed OmegaGpuPlatform; the Linux reference -# (src/omega_gpu_platform_linux.c) is deliberately NOT in this list. Still outside it: the elementwise API, the +# ($(CUDAPP_SOURCE)/src/omega_gpu_platform_linux.c) is deliberately NOT in this list. Still outside it: the elementwise API, the # numeric launchers, the vector executor, the resident runtime (docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md). # SHA-256 here is the migration-pending C of src/omega_sha256_fs.c, not the Omega unit: the omega-bridge binding in # src/omega_om_units.c needs pthread, mmap, mprotect and abort (outside GPU_FS_ALLOWED). test-sha256-fs-parity # holds the two equal; successor: a freestanding bridge binding with a caller-supplied stack. -GPU_FS_SRCS = src/omega_gpu_engine.c src/omega_gpu_platform.c src/omega_blackwell_encoder.c src/omega_blackwell_codegen.c \ - src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_blackwell_realize.c src/omega_sha256_fs.c \ - src/omega_gpu_session.c src/omega_gpu_fmt.c src/omega_gpu_matmul_api.c src/omega_gpu_attention_api.c \ - src/omega_gpu_serving.c src/omega_gpu_wait.c -GPU_FS_HDRS = src/omega_gpu_engine.h src/omega_gpu_platform.h src/omega_blackwell_codegen.h src/omega_blackwell_matmul.h \ - src/omega_gpu_session.h src/omega_gpu_fmt.h src/omega_gpu_matmul_api.h src/omega_gpu_attention_api.h \ - src/omega_gpu_serving.h src/omega_gpu_wait.h -GPU_FS_OBJS = $(patsubst src/%.c,$(GPU_FS_DIR)/%.o,$(GPU_FS_SRCS)) +GPU_FS_NAMES = omega_gpu_engine omega_gpu_platform omega_blackwell_encoder omega_blackwell_codegen \ + omega_blackwell_matmul omega_blackwell_qmd omega_blackwell_realize \ + omega_gpu_session omega_gpu_fmt omega_gpu_matmul_api omega_gpu_attention_api \ + omega_gpu_serving omega_gpu_wait cudapp_freest_units +GPU_FS_SRCS = $(addprefix $(CUDAPP_SOURCE)/src/,$(addsuffix .c,$(GPU_FS_NAMES))) src/omega_sha256_fs.c +GPU_FS_HDRS = $(addprefix $(CUDAPP_SOURCE)/src/,omega_gpu_engine.h omega_gpu_platform.h omega_blackwell_codegen.h omega_blackwell_matmul.h \ + omega_gpu_session.h omega_gpu_fmt.h omega_gpu_matmul_api.h omega_gpu_attention_api.h omega_gpu_serving.h omega_gpu_wait.h) +GPU_FS_OBJS = $(addprefix $(GPU_FS_DIR)/,$(addsuffix .o,$(GPU_FS_NAMES))) $(GPU_FS_DIR)/omega_sha256_fs.o GPU_FS_LINK = $(GPU_FS_DIR)/omega_gpu_freestanding.o GPU_FS_ALLOWED = memcpy|memmove|memset|memcmp|strlen|strcmp -$(GPU_FS_DIR)/%.o: src/%.c $(GPU_FS_HDRS) +$(GPU_FS_DIR)/%.o: $(CUDAPP_SOURCE)/src/%.c $(GPU_FS_HDRS) | check-cudapp + @mkdir -p $(GPU_FS_DIR) + gcc $(GPU_FS_CFLAGS) -c -o $@ $< + +$(GPU_FS_DIR)/omega_sha256_fs.o: src/omega_sha256_fs.c src/sha256.h $(GPU_FS_HDRS) | check-cudapp @mkdir -p $(GPU_FS_DIR) gcc $(GPU_FS_CFLAGS) -c -o $@ $< @@ -142,13 +137,13 @@ $(GPU_FS_LINK): $(GPU_FS_OBJS) @echo "freestanding GPU link ($(words $(GPU_FS_SRCS)) files): only $$(nm -u $@ | awk '{print $$NF}' | grep -Ev '^_GLOBAL_OFFSET_TABLE_$$' | sort -u | tr '\n' ' ')undefined" gpu-engine-freestanding: $(GPU_FS_LINK) -build/test_omega_gpu_engine_freestanding: tests/test_omega_gpu_engine.c $(GPU_FS_DIR)/omega_gpu_engine.o src/omega_gpu_engine.h +build/test_omega_gpu_engine_freestanding: $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine.c $(GPU_FS_LINK) $(CUDAPP_SOURCE)/src/omega_gpu_engine.h | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_NUMERIC_CPU_ONLY -DOMEGA_GPU_NO_POSIX \ - -o $@ tests/test_omega_gpu_engine.c $(GPU_FS_DIR)/omega_gpu_engine.o -build/test_omega_gpu_platform: tests/test_omega_gpu_platform.c $(GPU_FS_DIR)/omega_gpu_platform.o src/omega_gpu_platform.h + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -DOMEGA_NUMERIC_CPU_ONLY -DOMEGA_GPU_NO_POSIX \ + -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_engine.c $(GPU_FS_LINK) +build/test_omega_gpu_platform: $(CUDAPP_SOURCE)/tests/test_omega_gpu_platform.c $(GPU_FS_LINK) $(CUDAPP_SOURCE)/src/omega_gpu_platform.h | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -o $@ tests/test_omega_gpu_platform.c $(GPU_FS_DIR)/omega_gpu_platform.o + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_platform.c $(GPU_FS_LINK) test-gpu-engine-freestanding: $(GPU_FS_LINK) build/test_omega_gpu_engine_freestanding build/test_omega_gpu_platform ./build/test_omega_gpu_engine_freestanding ./build/test_omega_gpu_platform @@ -161,18 +156,18 @@ test-gpu-engine-freestanding: $(GPU_FS_LINK) build/test_omega_gpu_engine_freesta # all 2^32 inputs. The allowlist control links a malloc caller into the freestanding object and requires the # nm -u check to refuse it (a check that can never fail proves nothing). .PHONY: test-codegen-freestanding test-gpu-fs-allowlist-control -CODEGEN_FS_TEST_DEPS = tests/test_omega_codegen_freestanding.c src/omega_blackwell_codegen.h src/omega_blackwell_matmul.h -# The hosted side encodes through the .om encoder (om/encoder/bw_enc_sm121.om via src/omega_om_units.c), the -# freestanding side through the migration-pending C encoder, so the cmp below is also an .om-vs-C differential. -build/test_codegen_hosted: $(CODEGEN_FS_TEST_DEPS) src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_om_units.c \ - src/omega_native.h +CODEGEN_FS_TEST_DEPS = $(CUDAPP_SOURCE)/tests/test_omega_codegen_freestanding.c $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(CUDAPP_SOURCE)/src/omega_blackwell_matmul.h +# The hosted side encodes through CUDApp's canonical .om encoder (om/encoder/bw_enc_sm121.om of the pinned stage, +# bound in libcudapp.a by cudapp_om_units.c; omega_om_units.c carries only SHA-256 and BLAKE3), the freestanding +# side through the migration-pending C encoder, so the cmp below is also an .om-vs-C differential. +build/test_codegen_hosted: $(CODEGEN_FS_TEST_DEPS) src/omega_om_units.c src/omega_native.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -o $@ tests/test_omega_codegen_freestanding.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_om_units.c -build/test_codegen_freestanding: $(CODEGEN_FS_TEST_DEPS) $(GPU_FS_LINK) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ $(CUDAPP_SOURCE)/tests/test_omega_codegen_freestanding.c \ + src/omega_om_units.c $(CUDAPP_LIB) +build/test_codegen_freestanding: $(CODEGEN_FS_TEST_DEPS) $(GPU_FS_LINK) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_GPU_NO_POSIX -o $@ tests/test_omega_codegen_freestanding.c \ - $(GPU_FS_DIR)/omega_blackwell_codegen.o $(GPU_FS_DIR)/omega_blackwell_matmul.o $(GPU_FS_DIR)/omega_sha256_fs.o + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -DOMEGA_GPU_NO_POSIX -o $@ $(CUDAPP_SOURCE)/tests/test_omega_codegen_freestanding.c \ + $(GPU_FS_LINK) test-codegen-freestanding: build/test_codegen_hosted build/test_codegen_freestanding test-gpu-fs-allowlist-control ./build/test_codegen_hosted --dump > build/codegen_dump_hosted.txt ./build/test_codegen_freestanding --dump > build/codegen_dump_freestanding.txt @@ -210,7 +205,7 @@ test-sha256-fs-parity: build/test_codegen_hosted echo "control: hosted compile of src/omega_sha256_fs.c refused; hosted codegen test links $$n omega2_sha256_* functions" sed 's/0x428a2f98/0x428a2f99/' src/omega_sha256_fs.c > $(SHA_FS_DIR)/red.c @! cmp -s $(SHA_FS_DIR)/red.c src/omega_sha256_fs.c || { echo "RED MUTANT BROKEN: sed changed nothing"; exit 1; } - gcc $(GPU_FS_CFLAGS) $(SHA_FS_RENAME) -c -o $(SHA_FS_DIR)/red.o $(SHA_FS_DIR)/red.c + gcc $(GPU_FS_CFLAGS) -iquote src $(SHA_FS_RENAME) -c -o $(SHA_FS_DIR)/red.o $(SHA_FS_DIR)/red.c gcc -std=gnu11 -O2 -Wall -Wextra -Werror -pthread -Isrc -o $(SHA_FS_DIR)/parity_red tests/test_sha256_fs_parity.c \ $(SHA_FS_DIR)/red.o src/omega_om_units.c @if ./$(SHA_FS_DIR)/parity_red > $(SHA_FS_DIR)/red.log; then echo "RED CHECK BROKEN: a wrong round constant passed"; exit 1; \ @@ -225,19 +220,14 @@ test-sha256-fs-parity: build/test_codegen_hosted # - the mutants prove the session test can fail: each one breaks one rule in a copy of the session and the test # must report FAIL for it. .PHONY: test-gpu-session-platform test-gpu-session-mutants -build/test_omega_gpu_session_platform: tests/test_omega_gpu_session_platform.c $(GPU_FS_LINK) +build/test_omega_gpu_session_platform: $(CUDAPP_SOURCE)/tests/test_omega_gpu_session_platform.c $(GPU_FS_LINK) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_GPU_NO_POSIX -o $@ tests/test_omega_gpu_session_platform.c $(GPU_FS_LINK) -GPU_LINUX_REF_SRCS = src/omega_gpu_session.c src/omega_gpu_platform.c src/omega_gpu_platform_linux.c src/omega_gpu_fmt.c src/omega_blackwell_qmd.c -# omega #459: the command list over the reference (near-full ring with the #457 L2 invalidate prefix pending) needs the -# cached allocation, the command list and the codegen behind its nop kernel. -GPU_LINUX_REF_CMDLIST_SRCS = src/omega_gpu_mem_cached.c src/omega_gpu_cmdlist.c src/omega_blackwell_codegen.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_matmul.c src/omega_blackwell_realize.c src/omega_om_units.c -build/test_omega_gpu_platform_linux: tests/test_omega_gpu_platform_linux.c tests/fake_m16_native.c tests/fake_m16_native.h $(GPU_LINUX_REF_SRCS) $(GPU_FS_HDRS) src/omega_gpu_platform_linux.h \ - src/omega_gpu_cmdlist.h src/omega_gpu_mem_cached.h $(GPU_LINUX_REF_CMDLIST_SRCS) + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -DOMEGA_GPU_NO_POSIX -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_session_platform.c $(GPU_FS_LINK) +GPU_LINUX_REF_SRCS = src/omega_om_units.c +build/test_omega_gpu_platform_linux: $(CUDAPP_SOURCE)/tests/test_omega_gpu_platform_linux.c $(CUDAPP_SOURCE)/tests/fake_m16_native.c $(CUDAPP_SOURCE)/tests/fake_m16_native.h $(GPU_LINUX_REF_SRCS) $(GPU_FS_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -Isrc -Itests $(GPU_ENGINE_PHYS_INC) \ - -o $@ tests/test_omega_gpu_platform_linux.c tests/fake_m16_native.c $(GPU_LINUX_REF_SRCS) $(GPU_LINUX_REF_CMDLIST_SRCS) -lm + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -pthread -Isrc -I$(CUDAPP_SOURCE)/tests -Itests $(GPU_ENGINE_PHYS_INC) \ + -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_platform_linux.c $(CUDAPP_SOURCE)/tests/fake_m16_native.c $(GPU_LINUX_REF_SRCS) -lm $(CUDAPP_LIB) test-gpu-session-platform: build/test_omega_gpu_session_platform build/test_omega_gpu_platform_linux test-gpu-session-mutants ./build/test_omega_gpu_session_platform ./build/test_omega_gpu_platform_linux @@ -247,12 +237,12 @@ test-gpu-session-mutants: $(GPU_FS_LINK) @mkdir -p $(GPU_SESSION_MUT_DIR) @set -e; killed=0; \ smut() { name=$$1; script=$$2; \ - sed -e "$$script" src/omega_gpu_session.c > $(GPU_SESSION_MUT_DIR)/$$name.c; \ - if cmp -s src/omega_gpu_session.c $(GPU_SESSION_MUT_DIR)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ + sed -e "$$script" $(CUDAPP_SOURCE)/src/omega_gpu_session.c > $(GPU_SESSION_MUT_DIR)/$$name.c; \ + if cmp -s $(CUDAPP_SOURCE)/src/omega_gpu_session.c $(GPU_SESSION_MUT_DIR)/$$name.c; then echo "mutant $$name: pattern not found"; exit 1; fi; \ gcc $(GPU_FS_CFLAGS) -c -o $(GPU_SESSION_MUT_DIR)/$$name.o $(GPU_SESSION_MUT_DIR)/$$name.c; \ objs=$$(echo $(GPU_FS_OBJS) | tr ' ' '\n' | grep -v '/omega_gpu_session.o$$' | tr '\n' ' '); \ - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -Isrc -DOMEGA_GPU_NO_POSIX -o $(GPU_SESSION_MUT_DIR)/$$name \ - tests/test_omega_gpu_session_platform.c $$objs $(GPU_SESSION_MUT_DIR)/$$name.o; \ + gcc -std=gnu11 -O2 -Wall -Wextra -Werror $(CUDAPP_HEADER_FLAGS) -Isrc -DOMEGA_GPU_NO_POSIX -o $(GPU_SESSION_MUT_DIR)/$$name \ + $(CUDAPP_SOURCE)/tests/test_omega_gpu_session_platform.c $$objs $(GPU_SESSION_MUT_DIR)/$$name.o; \ if ./$(GPU_SESSION_MUT_DIR)/$$name > $(GPU_SESSION_MUT_DIR)/$$name.log 2>&1; then echo "mutant $$name SURVIVED"; exit 1; fi; \ echo "mutant $$name killed: $$(grep -c '^FAIL' $(GPU_SESSION_MUT_DIR)/$$name.log) case(s) failed"; killed=$$((killed+1)); }; \ smut release-when-latched 's|if (LOAD(g_blocked)) {$$|if (0) {|'; \ diff --git a/mk/omega-gpu-wait.mk b/mk/omega-gpu-wait.mk index 42e5ed25b..237dc0e8b 100644 --- a/mk/omega-gpu-wait.mk +++ b/mk/omega-gpu-wait.mk @@ -1,15 +1,15 @@ -# Shared GPU completion wait primitive (src/omega_gpu_wait.c): host unit test with +# Shared canonical GPU completion wait primitive: host unit test with # fake memory and a fake clock, plus a naive wall-clock mutant that must be # caught. Picked up by `-include mk/*.mk`. Host only: opens no device, needs no # physics headers, takes no chip lock. .PHONY: test-gpu-wait -build/test_omega_gpu_wait: tests/test_omega_gpu_wait.c src/omega_gpu_wait.c src/omega_gpu_wait.h +build/test_omega_gpu_wait: $(CUDAPP_SOURCE)/tests/test_omega_gpu_wait.c $(CUDAPP_SOURCE)/src/omega_gpu_wait.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -Isrc -o $@ tests/test_omega_gpu_wait.c src/omega_gpu_wait.c + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ $(CUDAPP_SOURCE)/tests/test_omega_gpu_wait.c $(CUDAPP_LIB) test-gpu-wait: build/test_omega_gpu_wait ./build/test_omega_gpu_wait -# Real-code mutants: src/omega_gpu_wait.c carries one-line compile-flag mutants. +# Real-code mutants: the canonical omega_gpu_wait.c carries compile-flag mutants. # Each flagged build of the real primitive must FAIL the suite; the unflagged # build must PASS. A mutant that does not compile is an error, not a kill. GPU_WAIT_MUTANTS := OMEGA_GPU_WAIT_MUTANT_STALL_NO_RESET OMEGA_GPU_WAIT_MUTANT_PROGRESS_EXTENDS_HARD OMEGA_GPU_WAIT_MUTANT_NO_READ_BARRIER @@ -18,7 +18,7 @@ test-gpu-wait-mutants: build/test_omega_gpu_wait @./build/test_omega_gpu_wait >/dev/null || { echo "unflagged build FAILED"; exit 1; } @echo "unflagged: PASS" @set -e; for m in $(GPU_WAIT_MUTANTS); do \ - gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -D$$m -Isrc -o build/test_omega_gpu_wait_$$m tests/test_omega_gpu_wait.c src/omega_gpu_wait.c; \ + gcc -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -D$$m $(CUDAPP_HEADER_FLAGS) -Isrc -o build/test_omega_gpu_wait_$$m $(CUDAPP_SOURCE)/tests/test_omega_gpu_wait.c $(CUDAPP_SOURCE)/src/omega_gpu_wait.c; \ if ./build/test_omega_gpu_wait_$$m >build/test_omega_gpu_wait_$$m.log 2>&1; then echo "MUTANT SURVIVED: $$m"; exit 1; fi; \ echo "$$m: killed ($$(grep -c 'FAIL' build/test_omega_gpu_wait_$$m.log) failing checks)"; \ done diff --git a/mk/omega-mufu-ftz.mk b/mk/omega-mufu-ftz.mk index 00ebb48d3..8c31fe1e5 100644 --- a/mk/omega-mufu-ftz.mk +++ b/mk/omega-mufu-ftz.mk @@ -1,18 +1,18 @@ # MUFU flush rule (omega #462): the GB10 MUFU unit (EX2 / RCP / RSQ) flushes a subnormal input or result to a -# sign-preserving zero. tests/bw_mufu_ftz.h is the one host model of it; every warp simulator and SwiGLU host reference +# sign-preserving zero. $(CUDAPP_SOURCE)/tests/bw_mufu_ftz.h is the one host model of it; every warp simulator and SwiGLU host reference # routes through it. test-mufu-ftz runs the helper unit test, then one MUFU instruction through each simulator's # ws_lane_exec (bw_warp_sim.h, _k, _pa, _tc). Picked up by `-include mk/*.mk`. Host only: opens no device, needs no # physics headers, takes no chip lock. The attention test's own per-thread simulator is checked by # `gpu_attention_test --host-only` (test-gpu-attention). MUFU_FTZ_SIMS := bw_warp_sim bw_warp_sim_k bw_warp_sim_pa bw_warp_sim_tc -MUFU_FTZ_CFLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -Itests +MUFU_FTZ_CFLAGS := -std=gnu11 -O2 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -I$(CUDAPP_SOURCE)/tests -Itests .PHONY: test-mufu-ftz -$(OUT_DIR)/test_mufu_ftz_helper: tests/bw_mufu_ftz_test.c tests/bw_mufu_ftz.h +$(OUT_DIR)/test_mufu_ftz_helper: $(CUDAPP_SOURCE)/tests/bw_mufu_ftz_test.c $(CUDAPP_SOURCE)/tests/bw_mufu_ftz.h @mkdir -p $(OUT_DIR) - gcc $(MUFU_FTZ_CFLAGS) -o $@ tests/bw_mufu_ftz_test.c -lm -$(OUT_DIR)/test_mufu_ftz_%: tests/bw_mufu_ftz_test.c tests/bw_mufu_ftz.h tests/%.h tests/bw_hmma_model.h tests/bw_qmma_model.h src/omega_blackwell_codegen.h + gcc $(MUFU_FTZ_CFLAGS) -o $@ $(CUDAPP_SOURCE)/tests/bw_mufu_ftz_test.c -lm +$(OUT_DIR)/test_mufu_ftz_%: $(CUDAPP_SOURCE)/tests/bw_mufu_ftz_test.c $(CUDAPP_SOURCE)/tests/bw_mufu_ftz.h tests/%.h $(CUDAPP_SOURCE)/tests/bw_hmma_model.h $(CUDAPP_SOURCE)/tests/bw_qmma_model.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h @mkdir -p $(OUT_DIR) - gcc $(MUFU_FTZ_CFLAGS) -DWS_SIM_HDR='"$*.h"' -o $@ tests/bw_mufu_ftz_test.c -lm + gcc $(MUFU_FTZ_CFLAGS) -DWS_SIM_HDR='"$*.h"' -o $@ $(CUDAPP_SOURCE)/tests/bw_mufu_ftz_test.c -lm test-mufu-ftz: $(OUT_DIR)/test_mufu_ftz_helper $(addprefix $(OUT_DIR)/test_mufu_ftz_,$(MUFU_FTZ_SIMS)) $(OUT_DIR)/test_mufu_ftz_helper @for s in $(MUFU_FTZ_SIMS); do $(OUT_DIR)/test_mufu_ftz_$$s || exit 1; done diff --git a/mk/prime_race_gb10.mk b/mk/prime_race_gb10.mk index 67634702a..9fcf65520 100644 --- a/mk/prime_race_gb10.mk +++ b/mk/prime_race_gb10.mk @@ -1,6 +1,6 @@ -# AIEN Prime Drag Race: native GB10 implementation (bench/prime_race/gb10_native.c) on Omega's -# own Blackwell codegen + session (libomega_gpu.a, no CUDA). Picked up by `-include mk/*.mk`; -# not part of `all` or `test`. Needs PHYSICS_DIR at the physics.lock commit (libomega_gpu). +# AIEN Prime Drag Race: native GB10 implementation (bench/prime_race/gb10_native.c) +# linked to the pinned canonical CUDA++ archive. No CUDA runtime; chip execution +# remains separate from the host build and simulation checks. # # prime-race-gb10 build bench/prime_race/build/gb10_native (+ _mutant, the chip test's # negative control) and refuse them if nm finds a CUDA symbol @@ -20,33 +20,33 @@ GB_OPT = -O3 -mcpu=native GB_SRC_COMMIT := $(shell git rev-parse HEAD 2>/dev/null || echo unknown)$(shell git status --porcelain -- src bench/prime_race mk 2>/dev/null | head -c1 | sed 's/.\+/+dirty/') GB_LABEL_STAMP = $(GB_BUILD)/.gb_source_label GB_DEFS = -DPR_SOURCE_COMMIT='"$(GB_SRC_COMMIT)"' -DPR_CC='"$(CC)"' \ - -DPR_CFLAGS='"$(GB_OPT) -I$(GB_DIR) + omega CFLAGS; libomega_gpu.a built with omega CFLAGS"' + -DPR_CFLAGS='"$(GB_OPT) -I$(GB_DIR) + omega CFLAGS; pinned canonical libcudapp.a"' GB_DEPS = $(GB_DIR)/gb10_native.c $(GB_LABEL_STAMP) $(GB_DIR)/prime_race_impl.c $(GB_DIR)/prime_race_impl.h \ - src/omega_gpu_elementwise_api.h src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a + $(CUDAPP_SOURCE)/src/omega_gpu_elementwise_api.h $(CUDAPP_SOURCE)/src/omega_gpu_session.h $(CUDAPP_LIB) # Same pattern as tools/chip_run.sh REFUSAL:cuda GB_NM_CHECK = if nm -u $@ | grep -Eiq 'cuda|cuInit|cuLaunch|nvrtc|cublas'; then echo "CUDA symbols in $@"; rm -f $@; exit 1; fi -$(GB_BUILD)/gb10_native: $(GB_DEPS) +$(GB_BUILD)/gb10_native: $(GB_DEPS) | check-cudapp @mkdir -p $(GB_BUILD) - $(CC) $(CFLAGS) $(GB_OPT) -I$(GB_DIR) $(GB_DEFS) -o $@ $(GB_DIR)/gb10_native.c $(GB_DIR)/prime_race_impl.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm + $(CC) $(CFLAGS) $(GB_OPT) -I$(GB_DIR) $(GB_DEFS) -o $@ $(GB_DIR)/gb10_native.c $(GB_DIR)/prime_race_impl.c -lpthread -lm $(CUDAPP_LIB) @$(GB_NM_CHECK) -$(GB_BUILD)/gb10_native_mutant: $(GB_DEPS) +$(GB_BUILD)/gb10_native_mutant: $(GB_DEPS) | check-cudapp @mkdir -p $(GB_BUILD) - $(CC) $(CFLAGS) $(GB_OPT) -I$(GB_DIR) $(GB_DEFS) -DPR_GB10_MUTANT=1 -o $@ $(GB_DIR)/gb10_native.c $(GB_DIR)/prime_race_impl.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm + $(CC) $(CFLAGS) $(GB_OPT) -I$(GB_DIR) $(GB_DEFS) -DPR_GB10_MUTANT=1 -o $@ $(GB_DIR)/gb10_native.c $(GB_DIR)/prime_race_impl.c -lpthread -lm $(CUDAPP_LIB) @$(GB_NM_CHECK) prime-race-gb10: $(GB_BUILD)/gb10_native $(GB_BUILD)/gb10_native_mutant $(GB_LABEL_STAMP): PRIME_RACE_FORCE @mkdir -p $(GB_BUILD) @echo '$(GB_SRC_COMMIT)' > $@.tmp; cmp -s $@.tmp $@ && rm $@.tmp || mv $@.tmp $@ -$(GB_BUILD)/gb10_sieve_host_test: $(GB_DIR)/tests/gb10_sieve_host_test.c $(GB_DIR)/prime_race_impl.h src/omega_blackwell_codegen.h src/omega_gpu_elementwise_api.h tests/bw_warp_sim.h $(OUT_DIR)/libomega_gpu.a +$(GB_BUILD)/gb10_sieve_host_test: $(GB_DIR)/tests/gb10_sieve_host_test.c $(GB_DIR)/prime_race_impl.h $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(CUDAPP_SOURCE)/src/omega_gpu_elementwise_api.h $(CUDAPP_SOURCE)/tests/bw_warp_sim.h $(CUDAPP_LIB) | check-cudapp @mkdir -p $(GB_BUILD) - $(CC) $(CFLAGS) -I$(GB_DIR) -Itests -o $@ $(GB_DIR)/tests/gb10_sieve_host_test.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm + $(CC) $(CFLAGS) -I$(GB_DIR) -I$(CUDAPP_SOURCE)/tests -Itests -o $@ $(GB_DIR)/tests/gb10_sieve_host_test.c -lpthread -lm $(CUDAPP_LIB) prime-race-gb10-host-test: $(GB_BUILD)/gb10_sieve_host_test ./$(GB_BUILD)/gb10_sieve_host_test -$(GB_BUILD)/gb10_launch_cost: $(GB_DIR)/tests/gb10_launch_cost.c src/omega_blackwell_codegen.h src/omega_gpu_elementwise_api.h src/omega_gpu_session.h $(OUT_DIR)/libomega_gpu.a +$(GB_BUILD)/gb10_launch_cost: $(GB_DIR)/tests/gb10_launch_cost.c $(CUDAPP_SOURCE)/src/omega_blackwell_codegen.h $(CUDAPP_SOURCE)/src/omega_gpu_elementwise_api.h $(CUDAPP_SOURCE)/src/omega_gpu_session.h $(CUDAPP_LIB) | check-cudapp @mkdir -p $(GB_BUILD) - $(CC) $(CFLAGS) $(GB_OPT) -o $@ $(GB_DIR)/tests/gb10_launch_cost.c $(OUT_DIR)/libomega_gpu.a -lpthread -lm + $(CC) $(CFLAGS) $(GB_OPT) -o $@ $(GB_DIR)/tests/gb10_launch_cost.c -lpthread -lm $(CUDAPP_LIB) @$(GB_NM_CHECK) prime-race-gb10-launch-cost: $(GB_BUILD)/gb10_launch_cost endif diff --git a/mk/program-fp32.mk b/mk/program-fp32.mk index 41dacb2e1..bc943bcfc 100644 --- a/mk/program-fp32.mk +++ b/mk/program-fp32.mk @@ -1,11 +1,10 @@ # FP32 in the program IR (spec/program-fp32.md, E1 gap row 12). Physics-free, host-only. PROGRAM_FP32_TEST = $(OUT_DIR)/tests-realize/test_program_fp32 -PROGRAM_FP32_NUM = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_numeric_divsqrt_gb10.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c +PROGRAM_FP32_NUM = src/omega_numeric.c src/omega_numeric_provenance.c -$(PROGRAM_FP32_TEST): tests/realize/test_program_fp32.c src/omega_program_fp32.c src/omega_program_fp32.h $(VISOR_CORE_OBJS) $(PROGRAM_FP32_NUM) +$(PROGRAM_FP32_TEST): tests/realize/test_program_fp32.c src/omega_program_fp32.c src/omega_program_fp32.h $(VISOR_CORE_OBJS) $(PROGRAM_FP32_NUM) $(CUDAPP_LIB) | check-cudapp mkdir -p $(dir $@) - $(CC) $(VISOR_CFLAGS) -ffp-contract=off -DOMEGA_NUMERIC_CPU_ONLY -o $@ tests/realize/test_program_fp32.c src/omega_program_fp32.c $(PROGRAM_FP32_NUM) $(VISOR_CORE_OBJS) + $(CC) $(VISOR_CFLAGS) $(CUDAPP_HEADER_FLAGS) -ffp-contract=off -DOMEGA_NUMERIC_CPU_ONLY -o $@ tests/realize/test_program_fp32.c src/omega_program_fp32.c $(PROGRAM_FP32_NUM) $(VISOR_CORE_OBJS) $(CUDAPP_LIB) .PHONY: test-program-fp32 test-program-fp32: $(PROGRAM_FP32_TEST) diff --git a/mk/program-id.mk b/mk/program-id.mk index 1a28bbf6b..0526d4c5e 100644 --- a/mk/program-id.mk +++ b/mk/program-id.mk @@ -6,9 +6,9 @@ PROGRAM_ID_TEST = $(OUT_DIR)/tests-program/test_program_id PROGRAM_ID_BRIDGE_OBJS = $(addprefix $(OUT_DIR)/,$(addsuffix .o,omega_program_ir omega_vc_bridge omega_resolve omega_receipt omega_blake3 omega_vcstore)) $(PROGRAM_ID_TEST): tests/program/test_program_id.c $(VISOR_CORE_OBJS) $(OUT_DIR)/omega_discovery.o \ - $(VISOR_OBJS) $(LANG_OBJS) $(PROGRAM_ID_BRIDGE_OBJS) + $(VISOR_OBJS) $(LANG_OBJS) $(PROGRAM_ID_BRIDGE_OBJS) $(CUDAPP_LIB) | check-cudapp mkdir -p $(dir $@) - $(CC) $(VISOR_CFLAGS) -o $@ $< $(VISOR_CORE_OBJS) $(OUT_DIR)/omega_discovery.o $(VISOR_OBJS) $(LANG_OBJS) $(PROGRAM_ID_BRIDGE_OBJS) + $(CC) $(VISOR_CFLAGS) -o $@ $< $(VISOR_CORE_OBJS) $(OUT_DIR)/omega_discovery.o $(VISOR_OBJS) $(LANG_OBJS) $(PROGRAM_ID_BRIDGE_OBJS) $(CUDAPP_LIB) .PHONY: test-program-id test-program-id: $(PROGRAM_ID_TEST) diff --git a/mk/program-realize.mk b/mk/program-realize.mk index 64a5dfeeb..c0e1eacc4 100644 --- a/mk/program-realize.mk +++ b/mk/program-realize.mk @@ -2,9 +2,9 @@ # Visor core object set. Executes generated code natively: run on an AArch64 host. PROGRAM_REALIZE_TEST = $(OUT_DIR)/tests-realize/test_program_realize -$(PROGRAM_REALIZE_TEST): tests/realize/test_program_realize.c $(VISOR_CORE_OBJS) +$(PROGRAM_REALIZE_TEST): tests/realize/test_program_realize.c $(VISOR_CORE_OBJS) $(CUDAPP_LIB) | check-cudapp mkdir -p $(dir $@) - $(CC) $(VISOR_CFLAGS) -o $@ $< $(VISOR_CORE_OBJS) + $(CC) $(VISOR_CFLAGS) -o $@ $< $(VISOR_CORE_OBJS) $(CUDAPP_LIB) .PHONY: test-program-realize test-program-realize: $(PROGRAM_REALIZE_TEST) diff --git a/mk/reservoir.mk b/mk/reservoir.mk index 5063f3dc8..8088f1090 100644 --- a/mk/reservoir.mk +++ b/mk/reservoir.mk @@ -24,13 +24,12 @@ ifndef RESERVOIR_MK RESERVOIR_MK := 1 .PHONY: test-reservoir reservoir-purity qualify-reservoir RES_CFLAGS = -std=gnu11 -Wall -Wextra -Werror -O2 -Isrc -Isrc/reservoir -Itests/reservoir \ - -ffp-contract=off -fno-fast-math -fno-math-errno -DOMEGA_NUMERIC_CPU_ONLY + -ffp-contract=off -fno-fast-math -fno-math-errno -DOMEGA_NUMERIC_CPU_ONLY $(CUDAPP_HEADER_FLAGS) RES_ASAN = -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all -DRES_QUICK RES_SRCS = src/reservoir/omega_reservoir.c src/reservoir/omega_reservoir_readout.c RES_HDRS = src/reservoir/omega_reservoir.h src/reservoir/omega_reservoir_readout.h src/omega_numeric.h src/sha256.h -# omega_numeric.c pulls in the provenance and encoder objects at link time. -RES_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c +# CPU numerics retain provenance and Omega units; GPU definitions are canonical. +RES_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_om_units.c RES_TEST_SRCS = tests/reservoir/test_reservoir.c tests/reservoir/res_oracle64.c RES_TEST_HDRS = tests/reservoir/res_fixtures.h tests/reservoir/res_oracle64.h RES_DIR = $(OUT_DIR)/tests-reservoir @@ -42,7 +41,7 @@ RES_TOOL_CFLAGS = $(RES_CFLAGS) -Itools/reservoir -pthread RES_MAT_SRCS = tools/reservoir/res_mat.c tools/reservoir/res_inflate.c src/omega_om_units.c RES_MAT_TEST = tests/reservoir/test_res_mat.c -$(RES_DIR)/%.o: src/reservoir/%.c $(RES_HDRS) +$(RES_DIR)/%.o: src/reservoir/%.c $(RES_HDRS) | check-cudapp @mkdir -p $(RES_DIR) $(CC) $(RES_CFLAGS) -pedantic -c -o $@ $< @@ -51,20 +50,20 @@ reservoir-purity: $(RES_DIR)/omega_reservoir.o $(RES_DIR)/omega_reservoir_readou echo "reservoir object references an allocator, libm or an I/O or process operation"; exit 1; fi @echo "reservoir-purity: omega_reservoir.o and omega_reservoir_readout.o reference no forbidden symbol" -$(RES_DIR)/test_reservoir: $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) $(RES_HDRS) $(RES_TEST_HDRS) +$(RES_DIR)/test_reservoir: $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) $(RES_HDRS) $(RES_TEST_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(RES_DIR) - $(CC) $(RES_CFLAGS) -o $@ $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) -lm -$(RES_DIR)/test_reservoir_asan: $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) $(RES_HDRS) $(RES_TEST_HDRS) + $(CC) $(RES_CFLAGS) -o $@ $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) -lm $(CUDAPP_LIB) +$(RES_DIR)/test_reservoir_asan: $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) $(RES_HDRS) $(RES_TEST_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(RES_DIR) - $(CC) $(RES_CFLAGS) $(RES_ASAN) -o $@ $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) -lm + $(CC) $(RES_CFLAGS) $(RES_ASAN) -o $@ $(RES_TEST_SRCS) $(RES_SRCS) $(RES_DEPS) -lm $(CUDAPP_LIB) -$(RES_DIR)/res_qualify: $(RES_TOOL_SRCS) $(RES_TOOL_HDRS) $(RES_SRCS) $(RES_DEPS) $(RES_HDRS) $(RES_TEST_HDRS) +$(RES_DIR)/res_qualify: $(RES_TOOL_SRCS) $(RES_TOOL_HDRS) $(RES_SRCS) $(RES_DEPS) $(RES_HDRS) $(RES_TEST_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(RES_DIR) - $(CC) $(RES_TOOL_CFLAGS) -DRES_BUILD_FLAGS='"$(strip $(RES_TOOL_CFLAGS))"' -o $@ $(RES_TOOL_SRCS) $(RES_SRCS) $(RES_DEPS) -lm -$(RES_DIR)/test_res_mat: $(RES_MAT_TEST) $(RES_MAT_SRCS) $(RES_TOOL_HDRS) $(RES_TEST_HDRS) + $(CC) $(RES_TOOL_CFLAGS) -DRES_BUILD_FLAGS='"$(strip $(RES_TOOL_CFLAGS))"' -o $@ $(RES_TOOL_SRCS) $(RES_SRCS) $(RES_DEPS) -lm $(CUDAPP_LIB) +$(RES_DIR)/test_res_mat: $(RES_MAT_TEST) $(RES_MAT_SRCS) $(RES_TOOL_HDRS) $(RES_TEST_HDRS) | check-cudapp @mkdir -p $(RES_DIR) $(CC) $(RES_TOOL_CFLAGS) -o $@ $(RES_MAT_TEST) $(RES_MAT_SRCS) -$(RES_DIR)/test_res_mat_asan: $(RES_MAT_TEST) $(RES_MAT_SRCS) $(RES_TOOL_HDRS) $(RES_TEST_HDRS) +$(RES_DIR)/test_res_mat_asan: $(RES_MAT_TEST) $(RES_MAT_SRCS) $(RES_TOOL_HDRS) $(RES_TEST_HDRS) | check-cudapp @mkdir -p $(RES_DIR) $(CC) $(RES_TOOL_CFLAGS) $(RES_ASAN) -o $@ $(RES_MAT_TEST) $(RES_MAT_SRCS) diff --git a/mk/runtime-r1.mk b/mk/runtime-r1.mk index a6cc401cf..b95d43e57 100644 --- a/mk/runtime-r1.mk +++ b/mk/runtime-r1.mk @@ -1,9 +1,11 @@ # Omega runtime R1 (omega-mv#594): the Runtime API manifest checked against the headers. Host only, no GPU, no physics checkout. # Picked up by `-include mk/*.mk` at the top of the Makefile, so no extra include line is needed. -RUNTIME_API_MANIFEST ?= docs/runtime/omega_runtime_api.manifest -RUNTIME_API_MD ?= docs/runtime/API.md +# The Runtime API headers, manifest, API.md and both checkers are CUDApp's: the staged source of the exact revision in +# cudapp.lock ($(CUDAPP_SOURCE), check-cudapp). Without a stage the target fails; it never falls back to a local copy. +RUNTIME_API_MANIFEST ?= $(CUDAPP_SOURCE)/docs/runtime/omega_runtime_api.manifest +RUNTIME_API_MD ?= $(CUDAPP_SOURCE)/docs/runtime/API.md RUNTIME_API_WORK ?= $(OUT_DIR)/runtime-api .PHONY: test-runtime-api -test-runtime-api: - CC="$(CC)" tools/runtime_api_check.sh $(RUNTIME_API_MANIFEST) . $(RUNTIME_API_WORK)/real $(RUNTIME_API_MD) - CC="$(CC)" tools/runtime_api_negative.sh $(RUNTIME_API_MANIFEST) . $(RUNTIME_API_WORK) $(RUNTIME_API_MD) +test-runtime-api: | check-cudapp + CC="$(CC)" sh $(CUDAPP_SOURCE)/tools/runtime_api_check.sh $(RUNTIME_API_MANIFEST) $(CUDAPP_SOURCE) $(RUNTIME_API_WORK)/real $(RUNTIME_API_MD) + CC="$(CC)" sh $(CUDAPP_SOURCE)/tools/runtime_api_negative.sh $(RUNTIME_API_MANIFEST) $(CUDAPP_SOURCE) $(RUNTIME_API_WORK) $(RUNTIME_API_MD) diff --git a/mk/runtime-r3.mk b/mk/runtime-r3.mk index 9c541fbb2..d37d7bf05 100644 --- a/mk/runtime-r3.mk +++ b/mk/runtime-r3.mk @@ -1,14 +1,22 @@ -# Omega runtime R3 (omega-mv#596): the portability table (docs/runtime/portability_table.tsv) must match src/. +# Omega runtime R3 (omega-mv#596): the portability table must match the source tree. # Picked up by `-include mk/*.mk`. Host only: no compiler, no device, no physics headers. -# test-runtime-portability-check every src/omega_gpu_*, omega_blackwell_*, omega_bw_* file has a row, every row names a -# file, a PORTABLE row's file includes no Linux/NVRM or Blackwell header, and the -# os_binding column agrees with the include scan and the freestanding file list -# test-runtime-portability-controls breaks one thing at a time in scratch copies; the check must FAIL each (and PASS the -# guarded-include control) +# The GPU sources, their table (docs/runtime/portability_table.tsv), the freestanding list (mk/omega-gpu-engine.mk) and +# both scripts are CUDApp's: the staged source of the exact revision in cudapp.lock ($(CUDAPP_SOURCE), check-cudapp). +# Omega's own docs/runtime/portability_table.tsv holds only the rows of the GPU-named files Omega still carries +# (src/omega_blackwell_gates.*), checked by the same canonical script against this tree and this mk/omega-gpu-engine.mk. +# test-runtime-portability-check the canonical tree against the canonical table, then Omega's tree against Omega's +# table: every src/omega_gpu_*, omega_blackwell_*, omega_bw_* file has a row, every +# row names a file, a PORTABLE row's file includes no Linux/NVRM or Blackwell header, +# and the os_binding column agrees with the include scan and the freestanding list +# test-runtime-portability-controls breaks one thing at a time in scratch copies of the canonical tree; the check must +# FAIL each (and PASS the guarded-include control) # test-runtime-portability both .PHONY: test-runtime-portability test-runtime-portability-check test-runtime-portability-controls -test-runtime-portability-check: - sh tools/runtime_portability_check.sh . docs/runtime/portability_table.tsv mk/omega-gpu-engine.mk -test-runtime-portability-controls: - sh tools/runtime_portability_controls.sh build/runtime_r3_controls docs/runtime/portability_table.tsv mk/omega-gpu-engine.mk +test-runtime-portability-check: | check-cudapp + sh $(CUDAPP_SOURCE)/tools/runtime_portability_check.sh $(CUDAPP_SOURCE) $(CUDAPP_SOURCE)/docs/runtime/portability_table.tsv \ + $(CUDAPP_SOURCE)/mk/omega-gpu-engine.mk + sh $(CUDAPP_SOURCE)/tools/runtime_portability_check.sh . docs/runtime/portability_table.tsv mk/omega-gpu-engine.mk +test-runtime-portability-controls: | check-cudapp + cd $(CUDAPP_SOURCE) && sh tools/runtime_portability_controls.sh $(abspath $(OUT_DIR)/runtime_r3_controls) \ + docs/runtime/portability_table.tsv mk/omega-gpu-engine.mk test-runtime-portability: test-runtime-portability-check test-runtime-portability-controls diff --git a/mk/sm121dis.mk b/mk/sm121dis.mk index c9440caa7..6a8f9cd85 100644 --- a/mk/sm121dis.mk +++ b/mk/sm121dis.mk @@ -1,4 +1,4 @@ -# C6 of docs/OMEGA.md: Omega's own sm_121 disassembler (src/omega_sm121_disasm.c, tools/sm121dis/). +# C6 of docs/OMEGA.md: Omega's own sm_121 disassembler ($(CUDAPP_SOURCE)/src/omega_sm121_disasm.c, tools/sm121dis/). # make test-sm121dis collect every kernel the library builds (no GPU), compare our text with nvdisasm's, word by word; # then the red check: a decoder built with one deliberate fault must FAIL the same comparison. # Picked up by the `-include mk/*.mk` line of the Makefile. The test binaries are named as files, not through the @@ -7,12 +7,12 @@ SM121DIS = $(OUT_DIR)/sm121dis SM121DIS_RED = $(OUT_DIR)/sm121dis_red SM121DIS_K = $(OUT_DIR)/sm121dis-kernels -$(SM121DIS): tools/sm121dis/sm121dis.c src/omega_sm121_disasm.c src/omega_sm121_disasm.h +$(SM121DIS): tools/sm121dis/sm121dis.c $(CUDAPP_SOURCE)/src/omega_sm121_disasm.h $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) - $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 -Isrc -o $@ tools/sm121dis/sm121dis.c src/omega_sm121_disasm.c -$(SM121DIS_RED): tools/sm121dis/sm121dis.c src/omega_sm121_disasm.c src/omega_sm121_disasm.h + $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ tools/sm121dis/sm121dis.c $(CUDAPP_LIB) +$(SM121DIS_RED): tools/sm121dis/sm121dis.c $(CUDAPP_SOURCE)/src/omega_sm121_disasm.c $(CUDAPP_SOURCE)/src/omega_sm121_disasm.h | check-cudapp @mkdir -p $(OUT_DIR) - $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 -DSM121DIS_MUTANT=1 -Isrc -o $@ tools/sm121dis/sm121dis.c src/omega_sm121_disasm.c + $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 -DSM121DIS_MUTANT=1 $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ tools/sm121dis/sm121dis.c $(CUDAPP_SOURCE)/src/omega_sm121_disasm.c sm121dis-corpus-bins: $(addprefix $(OUT_DIR)/,gpu_matmul_api_test gpu_elementwise_test gpu_reconv_test gpu_attention_test \ gpu_moe_window_test gpu_fp8_api_test gpu_decode_attn_test gpu_router_test gpu_bf16_gemv_test gpu_tern_test gpu_fp8gemm_test \ @@ -40,9 +40,9 @@ test-sm121dis: $(SM121DIS) $(SM121DIS_RED) sm121dis-corpus-bins test-sm121dis-co # The provenance checks (tools/divsqrt_nvdisasm_check.sh, tools/ldst_nvdisasm_check.sh, test-numeric-reduce-nvdisasm) # call build/sm121dis by that name, whatever OUT_DIR is. ifneq ($(OUT_DIR),build) -build/sm121dis: tools/sm121dis/sm121dis.c src/omega_sm121_disasm.c src/omega_sm121_disasm.h +build/sm121dis: tools/sm121dis/sm121dis.c $(CUDAPP_SOURCE)/src/omega_sm121_disasm.h $(CUDAPP_LIB) | check-cudapp @mkdir -p build - $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 -Isrc -o $@ tools/sm121dis/sm121dis.c src/omega_sm121_disasm.c + $(CC) -std=gnu11 -Wall -Wextra -Werror -O2 $(CUDAPP_HEADER_FLAGS) -Isrc -o $@ tools/sm121dis/sm121dis.c $(CUDAPP_LIB) endif # ZERO-NVDISASM (bar C6, second half: nothing calls nvdisasm). tools/sm121dis/zero_nvdisasm.sh runs every listing and diff --git a/mk/tensor.mk b/mk/tensor.mk index d257cc2a3..e66fbaa11 100644 --- a/mk/tensor.mk +++ b/mk/tensor.mk @@ -22,11 +22,10 @@ ifndef TENSOR_MK TENSOR_MK := 1 .PHONY: test-tensor test-tensor-no-hooks test-tensor-mutations test-tensor-e1-reduce test-tensor-store TENSOR_CFLAGS = -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -ffp-contract=off -Isrc -Isrc/tensor \ - -DOMEGA_NUMERIC_CPU_ONLY + -DOMEGA_NUMERIC_CPU_ONLY $(CUDAPP_HEADER_FLAGS) TENSOR_SRCS = src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c \ src/omega_numeric_reduce.c src/omega_numeric_transc.c -TENSOR_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_blackwell_encoder.c \ - src/omega_blackwell_codegen.c src/omega_blackwell_matmul.c src/omega_blackwell_qmd.c src/omega_om_units.c +TENSOR_DEPS = src/omega_numeric.c src/omega_numeric_provenance.c src/omega_om_units.c TENSOR_HDRS = src/tensor/omega_tensor.h src/tensor/omega_tensor_reduce_seam.h src/omega_numeric_reduce.h src/omega_numeric.h src/sha256.h src/omega_numeric_transc.h # CR-5 tests are #included by tests/test_omega_tensor.c: rebuild when they change. TENSOR_HDRS += tests/tensor_reduce_multi_tests.inc @@ -37,14 +36,14 @@ TENSOR_HOOK_SYMS = omega_tensor_test_set_storage_generation omega_tensor_store_t TENSOR_STORE_SRCS = src/tensor/omega_tensor_store.c TENSOR_STORE_HDRS = src/tensor/omega_tensor_store.h -$(OUT_DIR)/test_omega_tensor: tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) $(TENSOR_HDRS) +$(OUT_DIR)/test_omega_tensor: tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) $(TENSOR_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) - gcc $(TENSOR_CFLAGS) $(TENSOR_TEST_FLAGS) -O2 -o $@ tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) + gcc $(TENSOR_CFLAGS) $(TENSOR_TEST_FLAGS) -O2 -o $@ tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) $(CUDAPP_LIB) -$(OUT_DIR)/test_omega_tensor_asan: tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) $(TENSOR_HDRS) +$(OUT_DIR)/test_omega_tensor_asan: tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) $(TENSOR_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) gcc $(TENSOR_CFLAGS) $(TENSOR_TEST_FLAGS) -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all \ - -o $@ tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) + -o $@ tests/test_omega_tensor.c $(TENSOR_SRCS) $(TENSOR_DEPS) $(CUDAPP_LIB) test-tensor: $(OUT_DIR)/test_omega_tensor $(OUT_DIR)/test_omega_tensor_asan ./$(OUT_DIR)/test_omega_tensor @@ -54,7 +53,7 @@ test-tensor: $(OUT_DIR)/test_omega_tensor $(OUT_DIR)/test_omega_tensor_asan # Default (library) build of the tensor sources: no OMEGA_TENSOR_TEST_HOOKS. # Fails if any test-only hook symbol is defined or referenced in the objects. test-tensor-no-hooks: src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c src/tensor/omega_tensor_reduce_seam.c $(TENSOR_HDRS) \ - $(TENSOR_STORE_SRCS) $(TENSOR_STORE_HDRS) + $(TENSOR_STORE_SRCS) $(TENSOR_STORE_HDRS) | check-cudapp @mkdir -p $(OUT_DIR)/tensor-lib gcc $(TENSOR_CFLAGS) -O2 -c -o $(OUT_DIR)/tensor-lib/omega_tensor.o src/tensor/omega_tensor.c gcc $(TENSOR_CFLAGS) -O2 -c -o $(OUT_DIR)/tensor-lib/omega_tensor_cpu.o src/tensor/omega_tensor_cpu.c @@ -69,7 +68,7 @@ test-tensor-no-hooks: src/tensor/omega_tensor.c src/tensor/omega_tensor_cpu.c sr echo "test-tensor-no-hooks: FAIL ($$s present in default build)"; exit 1; fi; \ done; echo "test-tensor-no-hooks: PASS (test-only hook absent from default build)" -test-tensor-mutations: +test-tensor-mutations: | check-cudapp tools/tensor_mutations.sh # Kept as an alias: the seam now always calls omega_reduce_cpu (E1 WP-D, #134 merged). @@ -85,16 +84,16 @@ test-m20-receipt: # only under $TMPDIR (default /tmp). Its mutants run in test-tensor-mutations. $(OUT_DIR)/test_omega_tensor_store: tests/test_omega_tensor_store.c $(TENSOR_STORE_SRCS) $(TENSOR_SRCS) $(TENSOR_DEPS) \ - $(TENSOR_HDRS) $(TENSOR_STORE_HDRS) + $(TENSOR_HDRS) $(TENSOR_STORE_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) gcc $(TENSOR_CFLAGS) $(TENSOR_TEST_FLAGS) -O2 -o $@ tests/test_omega_tensor_store.c $(TENSOR_STORE_SRCS) \ - $(TENSOR_SRCS) $(TENSOR_DEPS) + $(TENSOR_SRCS) $(TENSOR_DEPS) $(CUDAPP_LIB) $(OUT_DIR)/test_omega_tensor_store_asan: tests/test_omega_tensor_store.c $(TENSOR_STORE_SRCS) $(TENSOR_SRCS) \ - $(TENSOR_DEPS) $(TENSOR_HDRS) $(TENSOR_STORE_HDRS) + $(TENSOR_DEPS) $(TENSOR_HDRS) $(TENSOR_STORE_HDRS) $(CUDAPP_LIB) | check-cudapp @mkdir -p $(OUT_DIR) gcc $(TENSOR_CFLAGS) $(TENSOR_TEST_FLAGS) -O1 -g -fsanitize=address,undefined -fno-sanitize-recover=all \ - -o $@ tests/test_omega_tensor_store.c $(TENSOR_STORE_SRCS) $(TENSOR_SRCS) $(TENSOR_DEPS) + -o $@ tests/test_omega_tensor_store.c $(TENSOR_STORE_SRCS) $(TENSOR_SRCS) $(TENSOR_DEPS) $(CUDAPP_LIB) test-tensor-store: $(OUT_DIR)/test_omega_tensor_store $(OUT_DIR)/test_omega_tensor_store_asan ./$(OUT_DIR)/test_omega_tensor_store @@ -112,7 +111,7 @@ test-tensor-store: $(OUT_DIR)/test_omega_tensor_store $(OUT_DIR)/test_omega_tens # unless GB10_CHIP_RUN=1 is set, so it never runs by # accident. Never pass a quiet flag. .PHONY: test-tensor-gb10-host test-tensor-gb10-chip -test-tensor-gb10-host: +test-tensor-gb10-host: | check-cudapp @test -n "$(PHYSICS_DIR)" && test -d "$(PHYSICS_DIR)" \ || { echo "test-tensor-gb10-host: set PHYSICS_DIR to the physics checkout"; exit 2; } tools/tensor_mutations.sh --gb10 "$(PHYSICS_DIR)" diff --git a/mk/visor-authority.mk b/mk/visor-authority.mk index 946e6cdb0..dec0c45bd 100644 --- a/mk/visor-authority.mk +++ b/mk/visor-authority.mk @@ -30,10 +30,10 @@ $(OUT_DIR)/tests-visor-authority: $(VISOR_AUTH_TEST): tests/visor/test_visor_authority.c $(VISOR_AUTH_RX_SRCS) \ $(OUT_DIR)/visor/visor_effect_request.o $(VISOR_CORE_OBJS) src/visor/visor_effect_request.h \ src/runtime/rx_aegis.h src/runtime/rx_caproot.h src/runtime/rx_world.h \ - src/runtime/rx_generation.h $(VISOR_AUTH_CAP_LIB) | $(OUT_DIR)/tests-visor-authority + src/runtime/rx_generation.h $(VISOR_AUTH_CAP_LIB) $(CUDAPP_LIB) | $(OUT_DIR)/tests-visor-authority check-cudapp @test -f "$(VISOR_AUTH_CAP_LIB)" || { echo "error: VISOR_AUTH_CAP_LIB=$(VISOR_AUTH_CAP_LIB) not found (needed by rx_aegis.c); pass VISOR_AUTH_CAP_LIB=" >&2; exit 1; } $(CC) $(CFLAGS) -Isrc/visor -pthread -o $@ tests/visor/test_visor_authority.c $(VISOR_AUTH_RX_SRCS) \ - $(OUT_DIR)/visor/visor_effect_request.o $(VISOR_CORE_OBJS) $(VISOR_AUTH_CAP_LIB) -lm + $(OUT_DIR)/visor/visor_effect_request.o $(VISOR_CORE_OBJS) $(VISOR_AUTH_CAP_LIB) $(CUDAPP_LIB) -lm .PHONY: test-visor-authority visor-authority-check test-visor-authority: $(VISOR_AUTH_TEST) diff --git a/mk/visor-console.mk b/mk/visor-console.mk index d849520e7..f7dd59c2c 100644 --- a/mk/visor-console.mk +++ b/mk/visor-console.mk @@ -11,8 +11,8 @@ VISOR_CONSOLE_OBJS = $(OUT_DIR)/visor/visor.o $(OUT_DIR)/visor/visor_console.o $ $(OUT_DIR)/lane2: mkdir -p $@ -$(OUT_DIR)/lane2/test_visor_console: tests/visor/test_visor_console.c $(VISOR_CORE_OBJS) $(VISOR_CONSOLE_OBJS) | $(OUT_DIR)/lane2 - $(CC) $(VISOR_CFLAGS) -DVISOR_CONSOLE_LANE_ONLY -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_CONSOLE_OBJS) +$(OUT_DIR)/lane2/test_visor_console: tests/visor/test_visor_console.c $(VISOR_CORE_OBJS) $(VISOR_CONSOLE_OBJS) $(CUDAPP_LIB) | $(OUT_DIR)/lane2 check-cudapp + $(CC) $(VISOR_CFLAGS) -DVISOR_CONSOLE_LANE_ONLY -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_CONSOLE_OBJS) $(CUDAPP_LIB) # The full test #includes tools/omega.c (with OMEGA_TOOL_NO_MAIN) for the wiring. $(OUT_DIR)/tests-visor/test_visor_console: tools/omega.c diff --git a/mk/visor-machine.mk b/mk/visor-machine.mk index 6299c02b4..30c3d99db 100644 --- a/mk/visor-machine.mk +++ b/mk/visor-machine.mk @@ -1,16 +1,14 @@ # Omega Visor V1 lane 5 (machine + realization lab) test targets. -# The Blackwell realize objects compile and link physics-free (only sha256 + -# omega_core deps). visor_machine.c references omega_blackwell_get_machine_id -# WEAKLY, so build/omega links with or without them; these lane tests link -# them explicitly so the declared Blackwell target shows linked=yes. -VISOR_BW_CORE = omega_vector omega_blackwell_qmd omega_blackwell_encoder omega_blackwell_realize -VISOR_BW_OBJS = $(addprefix $(OUT_DIR)/,$(addsuffix .o,$(filter-out $(VISOR_CORE),$(VISOR_BW_CORE)))) +# The Blackwell realization implementation comes from the canonical archive. +# Its identity is a weak reference in visor_machine.c, so explicitly retain that +# member for these tests, matching their former explicit local-object linkage. +VISOR_BW_LINK = -Wl,--undefined=omega_blackwell_get_machine_id -$(OUT_DIR)/tests-visor/test_visor_machine: tests/visor/test_visor_machine.c $(VISOR_CORE_OBJS) $(VISOR_BW_OBJS) $(VISOR_OBJS) $(LANG_OBJS) | $(OUT_DIR)/tests-visor - $(CC) $(VISOR_CFLAGS) -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_BW_OBJS) $(VISOR_OBJS) $(LANG_OBJS) +$(OUT_DIR)/tests-visor/test_visor_machine: tests/visor/test_visor_machine.c $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(CUDAPP_LIB) | $(OUT_DIR)/tests-visor check-cudapp + $(CC) $(VISOR_CFLAGS) -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(VISOR_BW_LINK) $(CUDAPP_LIB) -$(OUT_DIR)/tests-visor/test_visor_realization: tests/visor/test_visor_realization.c $(VISOR_CORE_OBJS) $(VISOR_BW_OBJS) $(VISOR_OBJS) $(LANG_OBJS) | $(OUT_DIR)/tests-visor - $(CC) $(VISOR_CFLAGS) -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_BW_OBJS) $(VISOR_OBJS) $(LANG_OBJS) +$(OUT_DIR)/tests-visor/test_visor_realization: tests/visor/test_visor_realization.c $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(CUDAPP_LIB) | $(OUT_DIR)/tests-visor check-cudapp + $(CC) $(VISOR_CFLAGS) -Itests/visor -o $@ $< $(VISOR_CORE_OBJS) $(VISOR_OBJS) $(LANG_OBJS) $(VISOR_BW_LINK) $(CUDAPP_LIB) .PHONY: test-visor-machine test-visor-realization test-visor-machine: $(OUT_DIR)/tests-visor/test_visor_machine diff --git a/om/consumer.om b/om/consumer.om new file mode 100644 index 000000000..81aa38aec --- /dev/null +++ b/om/consumer.om @@ -0,0 +1,50 @@ +note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +note Existing one-line CUDApp commit lock followed by observed source revision. +global data uchar 83 +fn main to int +n = ulong 0 +while lt n 83 +r = read 0 data n sub ulong 83 n +if lt r 0 +ret 3 +end +if eq r 0 +break +end +n = add n ulong r +end +if ne n 82 +ret 3 +end +if ne get data 40 10 +ret 3 +end +if ne get data 81 10 +ret 3 +end +nonzero = false +for i ulong 40 +c = get data i +if lt c 48 +ret 3 +end +if gt c 57 +if lt c 97 +ret 3 +end +if gt c 102 +ret 3 +end +end +if ne c 48 +nonzero = true +end +if ne c get data add i 41 +ret 3 +end +end +if not nonzero +ret 3 +end +ret 0 +end diff --git a/om/consumer_receipt.om b/om/consumer_receipt.om new file mode 100644 index 000000000..5b74e905a --- /dev/null +++ b/om/consumer_receipt.om @@ -0,0 +1,121 @@ +om2 +note SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +note Receipt serialization only, never admission or qualification authority. +text JHead "{\"source\":\"git-object\",\"cudapp_pin\":\"" +text JSrc "\",\"source_archive_sha256\":\"" +text JGuard "\",\"guard_sha256\":\"" +text JLib "\",\"library_sha256\":\"" +text JPath "\",\"source_path\":\"" +text JEnd "\"}\n" +text JHex "0123456789abcdef" +fn jr_copy dst edit uchar 16384 pos ulong src view uchar * n ulong to ulong +if gt add pos n len dst +exit 3 +end +for i ulong n +put dst add pos i get src i +end +ret add pos n +end +fn jr_hex b view uchar 8192 start ulong n ulong to void +for i ulong n +c = get b add start i +if not or and ge c 48 le c 57 and ge c 97 le c 102 +exit 3 +end +end +end +fn main to int +b = new uchar 8192 0 +dst = new uchar 16384 0 +used = ulong 0 +while lt used len b bound 8192 +r = read 0 b used sub len b used +if eq r 0 +break +end +if eq r -4 +continue +end +if lt r 0 +ret 3 +end +used = add used ulong r +end +if or lt used 238 ge used len b +ret 3 +end +if or ne get b 40 10 or ne get b 105 10 or ne get b 170 10 ne get b 235 10 +ret 3 +end +if ne get b sub used 1 10 +ret 3 +end +jr_hex b 0 40 +jr_hex b 41 64 +jr_hex b 106 64 +jr_hex b 171 64 +pos = jr_copy dst 0 JHead len JHead +for i ulong 40 +put dst pos get b i +pos = add pos 1 +end +pos = jr_copy dst pos JSrc len JSrc +for i ulong 64 +put dst pos get b add 41 i +pos = add pos 1 +end +pos = jr_copy dst pos JGuard len JGuard +for i ulong 64 +put dst pos get b add 106 i +pos = add pos 1 +end +pos = jr_copy dst pos JLib len JLib +for i ulong 64 +put dst pos get b add 171 i +pos = add pos 1 +end +pos = jr_copy dst pos JPath len JPath +for i ulong sub used 237 +if gt add pos 6 len dst +ret 3 +end +c = get b add 236 i +if eq c 0 +ret 3 +end +if or eq c 34 eq c 92 +put dst pos 92 +pos = add pos 1 +else +if lt c 32 +put dst pos 92 +put dst add pos 1 117 +put dst add pos 2 48 +put dst add pos 3 48 +put dst add pos 4 get JHex shr c 4 +put dst add pos 5 get JHex and c 15 +pos = add pos 6 +continue +end +end +put dst pos c +pos = add pos 1 +end +pos = jr_copy dst pos JEnd len JEnd +sent = ulong 0 +while lt sent pos bound 16384 +r = write 1 dst sent sub pos sent +if eq r -4 +continue +end +if le r 0 +ret 3 +end +sent = add sent ulong r +end +if ne sent pos +ret 3 +end +ret 0 +end diff --git a/om/encoder/bw_enc_sm121.om b/om/encoder/bw_enc_sm121.om deleted file mode 100644 index 4c17bec4a..000000000 --- a/om/encoder/bw_enc_sm121.om +++ /dev/null @@ -1,515 +0,0 @@ -note bw_enc_sm121.om: the sm_121 instruction encoder of CUDApp (aien-dev/CUDApp#79, OM-GPU-RETIRE). -note It turns a solved BlackwellIR program into machine code: four 32-bit words per instruction, -note little-endian, padded with NOPs to a multiple of 8 and at least 32 instructions. -note It replaces encode_single_insn and omega_bw_encode_program of src/omega_blackwell_codegen.c, -note which stays compiled only behind CUDAPP_MIGRATION_PENDING_C_ENCODER as the differential oracle -note (and in the freestanding build, which has no native binding yet). -note -note Input (bw_om_encode in src/omega_blackwell_codegen.c packs it; 8 ulong per instruction, at most 1024 instructions): -note 0 op (the BlackwellIROpcode number) 1 dst_vreg 2 src1_vreg 3 src2_vreg 4 src3_vreg -note 5 ureg (the five vreg fields are C int, passed as 64-bit two's complement: negative = none) -note 6 imm or control shl 32 -note 7 is_uniform or predicate_p0 shl 1 or predicate_not shl 2 or bar_reg shl 8 -note or dst_subreg shl 16 or src1_subreg shl 24 or src2_subreg shl 32 or src3_subreg shl 40 -note phys: vreg_to_phys 0..255 then uvreg_to_phys at 256..287 (C int, two's complement). -note pad 1: omega_bw_encode_program (pad to the multiple of 8, at least 32); pad 0: exactly n instructions. -note Result: the bytes written, or 0 when an instruction is refused (unknown op, an offset outside its -note field, a BSSY delta below 2, a barrier register above 15) or n is above 1024. -note Every constant is the decimal form of the C encoder's hex word (conversions by Wolfram, -note evidence/CUDAPP-OM-ENCODER/wolfram-constants.txt). - -const NEG ulong 9223372036854775808 -const NOPW ulong 31000 -const NOPC ulong 1032192 - -fn put4 w edit ulong 4 a ulong b ulong c ulong d ulong to void -put w 0 a -put w 1 b -put w 2 c -put w 3 d -end - -note the physical register of one operand field: phys + subreg, or dflt when the vreg is negative -fn preg phys view ulong 288 v ulong sb ulong dflt ulong to ulong -if ge v NEG -ret dflt -end -ret add get phys v sb -end - -note 1 when a vreg field is given (not negative), else 0 -fn pres v ulong to ulong -if ge v NEG -ret 0 -end -ret 1 -end - -fn opnds ins view ulong 8192 i ulong phys view ulong 288 o edit ulong 16 to void -b = mul i 8 -f = get ins add b 7 -put o 0 get ins b -put o 1 preg phys get ins add b 1 and shr f 16 255 0 -put o 2 preg phys get ins add b 2 and shr f 24 255 0 -put o 3 preg phys get ins add b 3 and shr f 32 255 0 -put o 4 preg phys get ins add b 4 and shr f 40 255 255 -u = get ins add b 5 -put o 5 0 -if lt u NEG -put o 5 get phys add u 256 -end -put o 14 pres u -x = get ins add b 6 -put o 6 and x 4294967295 -put o 7 shr x 32 -put o 8 and f 1 -put o 9 and shr f 1 1 -put o 10 and shr f 2 1 -put o 11 and shr f 8 255 -put o 12 pres get ins add b 2 -put o 13 pres get ins add b 3 -d = get ins add b 1 -if and eq and f 1 1 lt d NEG -put o 1 get phys add d 256 -end -end - -note the control word: the instruction's own, else the op's default -fn ctl o view ulong 16 dflt ulong to ulong -c = get o 7 -if ne c 0 -ret c -end -ret dflt -end - -note low 8 bits of operand slot k -fn rb o view ulong 16 k ulong to ulong -ret and get o k 255 -end - -note slot k when its vreg (presence slot h) is given, else RZ -fn rz o view ulong 16 k ulong h ulong to ulong -if ne get o h 0 -ret rb o k -end -ret 255 -end - -fn wd o view ulong 16 base ulong to ulong -ret or base shl rb o 1 16 -end - -fn wa o view ulong 16 base ulong to ulong -ret or base shl rb o 2 24 -end - -fn wda o view ulong 16 base ulong to ulong -ret or wd o base shl rb o 2 24 -end - -note the 4-bit guard predicate field: 7 always, 0 @P0, 8 @!P0 -fn pred o view ulong 16 to ulong -if eq get o 9 0 -ret 7 -end -if eq get o 10 0 -ret 0 -end -ret 8 -end - -note a signed 24-bit byte offset (imm read as int32) fits -fn off24 imm ulong to bool -ret or lt imm 8388608 ge imm 4286578688 -end - -note ops 0..14: moves, constants, integer multiply-add, compares and global memory -fn enc_a o view ulong 16 w edit ulong 4 to ulong -op = get o 0 -imm = get o 6 -if eq op 0 -put4 w NOPW 0 0 ctl o NOPC -ret 0 -end -if eq op 1 -put4 w wd o 29186 255 3840 ctl o 1040896 -ret 0 -end -if eq op 2 -put4 w wd o 30722 imm 3840 ctl o 1040896 -ret 0 -end -if eq op 3 -put4 w wd o 31001 0 shl and imm 255 8 ctl o 926208 -ret 0 -end -if eq op 4 -put4 w wd o 4278221698 and shl imm 6 16776960 2048 ctl o 1040896 -ret 0 -end -if eq op 5 -put4 w wd o 4278221698 and shl imm 6 16776960 2560 ctl o 926208 -ret 0 -end -if eq op 6 -put4 w wd o 4278220716 and shl imm 5 16776960 134219776 ctl o 926208 -ret 0 -end -if eq op 7 -put4 w wd o 4278220716 and shl imm 5 16776960 134220288 ctl o 945664 -ret 0 -end -if eq op 8 -if ne get o 13 0 -put4 w wda o 29220 rb o 3 or 126747136 rb o 4 ctl o 2083328 -ret 0 -end -if and ne get o 8 0 ne get o 14 0 -put4 w wda o 31780 rb o 5 or 260964864 rb o 4 ctl o 2083328 -ret 0 -end -put4 w wda o 30756 imm or 126747136 rb o 4 ctl o 2083328 -ret 0 -end -if eq op 9 -put4 w wda o 30757 imm or 126746624 rb o 4 ctl o 2083840 -ret 0 -end -if eq op 10 -if and ne get o 8 0 ne get o 14 0 -put4 w wda o 31756 rb o 5 200302704 ctl o 3136000 -ret 0 -end -put4 w wda o 30732 imm 66085488 ctl o 2087424 -ret 0 -end -if eq op 11 -put4 w wda o 31105 rb o 5 203299072 ctl o 991744 -ret 0 -end -if eq op 12 -if not off24 imm -ret 1 -end -put4 w wa o 31110 or rb o 3 shl and imm 16777215 8 or 202381568 rb o 5 ctl o 1040896 -ret 0 -end -if eq op 13 -put4 w wa o 31110 rb o 3 or 202447104 rb o 5 ctl o 1040896 -ret 0 -end -if eq op 14 -put4 w wda o 29200 rb o 3 134209791 ctl o 17811968 -ret 0 -end -ret 1 -end - -note ops 15..29: tensor core, shifts, wide and strong loads, stores, fences, atomics -fn enc_b o view ulong 16 w edit ulong 4 to ulong -op = get o 0 -imm = get o 6 -if or eq op 15 eq op 16 -p = ulong 0 -if eq op 16 -p = 262144 -end -put4 w wda o 29244 rb o 3 or or rb o 4 6144 p ctl o 1040896 -ret 0 -end -if eq op 17 -put4 w or wd o 30745 4278190080 imm or 71168 rb o 2 ctl o 2083328 -ret 0 -end -if eq op 18 -put4 w wda o 30738 imm 126796031 ctl o 2083328 -ret 0 -end -if eq op 19 -put4 w wda o 31105 rb o 5 203298048 ctl o 991744 -ret 0 -end -if eq op 20 -put4 w wda o 31105 rb o 5 203380992 ctl o 991744 -ret 0 -end -if eq op 21 -put4 w wda o 31105 rb o 5 202250496 ctl o 991744 -ret 0 -end -if eq op 22 -a = wa o 31110 -if ne get o 9 0 -a = or wa o 2438 shl pred o 12 -end -put4 w a rb o 3 or 202463488 rb o 5 ctl o 1040896 -ret 0 -end -if eq op 23 -put4 w 31122 0 45056 ctl o 1043456 -ret 0 -end -if eq op 24 -put4 w 31122 0 12288 ctl o 1043456 -ret 0 -end -if eq op 25 -put4 w 4278221199 0 33554432 ctl o 1042432 -ret 0 -end -if eq op 26 -put4 w wda o 31144 or rb o 3 2147483648 or 136270080 rb o 5 ctl o 3284480 -ret 0 -end -if eq op 27 -put4 w wda o 31144 or rb o 3 2147483648 or 203378944 rb o 5 ctl o 3284480 -ret 0 -end -if eq op 28 -put4 w wa o 29196 rb o 3 66084976 ctl o 2087424 -ret 0 -end -if eq op 29 -put4 w wda o 29202 rb o 3 126762239 ctl o 2083328 -ret 0 -end -ret 1 -end - -note ops 30..45: floating point, special functions, shuffles, shared memory, exit -fn enc_c o view ulong 16 w edit ulong 4 to ulong -op = get o 0 -imm = get o 6 -if eq op 30 -put4 w wda o 29217 rb o 3 0 ctl o 5227520 -ret 0 -end -if eq op 31 -put4 w wda o 29217 or rb o 3 2147483648 0 ctl o 5227520 -ret 0 -end -if eq op 32 -put4 w wda o 29216 rb o 3 4194304 ctl o 5227520 -ret 0 -end -if eq op 33 -put4 w wda o 29219 rb o 3 rb o 4 ctl o 5227520 -ret 0 -end -if eq op 34 -c = ulong 66084864 -if ne imm 0 -c = imm -end -a = or or 29195 shl and get o 1 7 16 shl rb o 2 24 -put4 w a rb o 3 c ctl o 5227520 -ret 0 -end -if eq op 35 -put4 w wda o 29192 rb o 3 and get o 4 7 ctl o 1034752 -ret 0 -end -if eq op 36 -put4 w wda o 29193 rb o 3 58720256 ctl o 5227520 -ret 0 -end -if eq op 37 -put4 w wda o 29193 rb o 3 125829120 ctl o 5227520 -ret 0 -end -if eq op 38 -put4 w wd o 29253 rb o 2 2102272 ctl o 5235200 -ret 0 -end -if eq op 39 -put4 w wd o 29445 rb o 2 2158848 ctl o 5120512 -ret 0 -end -if eq op 40 -put4 w wd o 29448 rb o 2 4096 ctl o 926720 -ret 0 -end -if eq op 41 -put4 w wd o 29448 rb o 2 5120 ctl o 926720 -ret 0 -end -if eq op 42 -put4 w wda o 32649 or 134225664 shl and imm 31 21 917504 ctl o 926720 -ret 0 -end -if eq op 43 -put4 w wda o 31108 0 and imm 65535 ctl o 1040896 -ret 0 -end -if eq op 44 -put4 w wa o 29576 rb o 3 and imm 65535 ctl o 1040896 -ret 0 -end -if eq op 45 -a = ulong 31053 -if ne get o 9 0 -a = 2381 -end -put4 w a 0 58720256 ctl o 1042944 -ret 0 -end -ret 1 -end - -note op 46: BRA. rel = imm - 1 as int32; low 6 bits at w0 18..23, rel arithmetic-shifted by 6 at w1 bit 2 -fn enc_bra o view ulong 16 w edit ulong 4 to ulong -imm = get o 6 -rel = and sub imm 1 4294967295 -s = shr rel 6 -c = ulong 58720256 -if ge rel 2147483648 -s = or s 4227858432 -c = 58982399 -end -d = get o 7 -if eq d 0 -d = 1042944 -if and eq imm 0 eq get o 9 0 -d = NOPC -end -end -a = or or 2375 shl pred o 12 shl and rel 63 18 -put4 w a and shl s 2 4294967295 c d -ret 0 -end - -note ops 46..59: branches, reconvergence, barriers, wide shared loads, three-source integer ops -fn enc_d o view ulong 16 w edit ulong 4 to ulong -op = get o 0 -imm = get o 6 -bar = get o 11 -if eq op 46 -ret enc_bra o w -end -if eq op 47 -put4 w wd o 29448 rb o 2 2048 ctl o 926720 -ret 0 -end -if eq op 48 -put4 w 31517 0 65536 ctl o 1043456 -ret 0 -end -if eq op 49 -put4 w wda o 31108 255 134219776 ctl o 927744 -ret 0 -end -if eq op 50 -put4 w wa o 31112 rb o 3 134220031 ctl o 1040896 -ret 0 -end -if eq op 51 -a = or or 29202 shl rb o 1 16 shl rz o 2 12 24 -put4 w a rz o 3 13 or or 126746624 shl and imm 255 8 rb o 4 ctl o 2083328 -ret 0 -end -if eq op 52 -a = or or 29209 shl rb o 1 16 shl rz o 2 12 24 -put4 w a rz o 3 13 or 1536 rb o 4 ctl o 2083328 -ret 0 -end -if eq op 53 -a = or or 29223 shl rb o 1 16 shl rz o 2 12 24 -put4 w a rz o 3 13 or 126746624 rb o 4 ctl o 2083328 -ret 0 -end -if eq op 54 -if or or lt imm 2 ge imm 2147483648 ge bar 16 -ret 1 -end -a = or or 2373 shl pred o 12 shl bar 16 -put4 w a and mul sub imm 1 16 4294967295 58720768 ctl o 1040896 -ret 0 -end -if eq op 55 -if ge bar 16 -ret 1 -end -a = or or 2369 shl pred o 12 shl bar 16 -put4 w a 0 58720768 ctl o 1042944 -ret 0 -end -if eq op 56 -if not off24 imm -ret 1 -end -put4 w wda o 31105 or rb o 5 shl and imm 16777215 8 203299584 ctl o 991744 -ret 0 -end -if eq op 57 -if not off24 imm -ret 1 -end -put4 w wda o 31105 or rb o 5 shl and imm 16777215 8 203300096 ctl o 991744 -ret 0 -end -if eq op 58 -if ge imm 8388608 -ret 1 -end -put4 w wda o 31108 shl and imm 16777215 8 3072 ctl o 1042432 -ret 0 -end -if eq op 59 -put4 w wd o 29448 rb o 2 3072 ctl o 926720 -ret 0 -end -ret 1 -end - -fn enc1 o view ulong 16 w edit ulong 4 to ulong -op = get o 0 -if lt op 15 -ret enc_a o w -end -if lt op 30 -ret enc_b o w -end -if lt op 46 -ret enc_c o w -end -ret enc_d o w -end - -note the 16 bytes of instruction i, each word little-endian -fn store code edit uchar 16384 i ulong w view ulong 4 to void -for k ulong 4 -x = get w k -q = add mul i 16 mul k 4 -for j ulong 4 -put code add q j uchar and shr x mul j 8 255 -end -end -end - -fn bw_enc_sm121 ins view ulong 8192 phys view ulong 288 n ulong pad ulong code edit uchar 16384 to ulong -o = new ulong 16 0 -w = new ulong 4 0 -if gt n 1024 -ret 0 -end -cnt = n -if ne pad 0 -cnt = mul div add n 7 8 8 -if lt cnt 32 -cnt = 32 -end -end -for i ulong cnt -if lt i n -opnds ins i phys edit o -if ne enc1 view o edit w 0 -ret 0 -end -else -put4 edit w NOPW 0 0 NOPC -end -store code i view w -end -ret mul cnt 16 -end diff --git a/om/units.sh b/om/units.sh index 0129b777e..8aa762ae6 100755 --- a/om/units.sh +++ b/om/units.sh @@ -16,14 +16,13 @@ # unit also embeds its identity (omega2_ident_() in omega_om_units.c). # A unit, compiler or profile that changes without regenerating these files fails --check. # OMEGA_UNITS (the unit list, repo-relative or absolute) and OMEGA_UNITS_DEST (output directory, default src) -# override the defaults; mk/om-encoder.mk uses them to build mutant encoders beside the real binding. +# override the defaults. set -eu OMC_PIN=be8c51301307555254fc59e351d281aae1aa096d91521777e33a41c8b446448a NATIVE_PIN=c77a5922f91d53d4a0bbd4e7b1c4703f7098263abc843be2918db1ece7496782 ROOT=$(cd "$(dirname "$0")/.." && pwd) # One generated library for all units: the bindings share one ABI runtime (ombr_enter). -# om/encoder/bw_enc_sm121.om: the sm_121 instruction encoder, twin of aien-dev/CUDApp's (mk/om-encoder.mk). -UNITS="${OMEGA_UNITS:-om/sha256/sha256-om2.om om/blake3/b3unit.om om/encoder/bw_enc_sm121.om}" +UNITS="${OMEGA_UNITS:-om/sha256/sha256-om2.om om/blake3/b3unit.om}" DEST="${OMEGA_UNITS_DEST:-$ROOT/src}" OUTS="omega_om_units.c omega_native.h omega_api_decl.h omega_om_units.ident" [ -n "${OMEGA_OMC:-}" ] && [ -n "${OMEGA_BRIDGE:-}" ] || { echo "NOT_RUN: set OMEGA_OMC and OMEGA_BRIDGE"; exit 3; } diff --git a/src/.crumb b/src/.crumb index 85650d7f0..b201a270b 100644 --- a/src/.crumb +++ b/src/.crumb @@ -188,14 +188,14 @@ } ], "children_root": "sha256:6ade3e583c9df260fbfc768469dae662b88153725b14f7086431861419cfffe3", - "compiled_at": "2026-10-31T10:16:13Z", + "compiled_at": "2026-10-31T10:53:52Z", "compiler": "crumb-compile/1", - "digest": "sha256:0b45b3b8037fb89222c06563d9cde31caf762b9751994fafa603e1c84d350d91", + "digest": "sha256:0b8df0bac6a60addd4eb8323b0251db5b55b901a9c965d0d12a2e76bfaae661f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "files": 599, - "generated_at_commit": "7715c4e792abc9d99496d4e1ecfe8bccc79a5c17", - "source_tree": "sha256:efcba46d11640ffaa85dc9c407a9dea9d0cbe2b6cc60319505dfd327b4d852d2" + "files": 468, + "generated_at_commit": "8e6277d4e57cf59698be10b268d8a6243526d2ff", + "source_tree": "sha256:f415b6f50e4ab171fa3c1937b6eb64959bc92f8c74f591e9b9038ad324e03370" }, "owner_lane": "", "provenance": { diff --git a/src/omega_blackwell_codegen.c b/src/omega_blackwell_codegen.c deleted file mode 100644 index a0520f4c9..000000000 --- a/src/omega_blackwell_codegen.c +++ /dev/null @@ -1,2737 +0,0 @@ -/* SPDX-License-Identifier: Apache-2.0 - * Copyright 2026 Drake Stapleton (AIEN / aien-dev) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "omega_blackwell_codegen.h" -#include "omega_blackwell_submit.h" -#include "sha256.h" -#include -/* native v1 P07 cut A.2 (aienos#286, docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md): with OMEGA_GPU_NO_POSIX this file - * builds -ffreestanding. Code generation then runs only through the allocation-free entry points - * (omega_blackwell_kernel_encode_into: the caller supplies the code buffer and its capacity); the allocating - * generators, their diagnostics and the printing variation self-test exist only in the hosted build. */ -#ifndef OMEGA_GPU_NO_POSIX -#include -#include -#include -#include -#define BW_DIAG(...) fprintf(stderr, __VA_ARGS__) -#else -#define BW_DIAG(...) ((void)0) -#endif - -void omega_bw_ir_init(BlackwellIRProgram *prog) { - if (!prog) return; - memset(prog, 0, sizeof(*prog)); -} - -int omega_bw_ir_alloc_vreg(BlackwellIRProgram *prog) { - if (!prog || prog->regalloc.num_vregs >= BW_MAX_VREGS) return -1; - int v = prog->regalloc.num_vregs++; - prog->regalloc.intervals[v].vreg = v; - prog->regalloc.intervals[v].first_def = -1; - prog->regalloc.intervals[v].last_use = -1; - prog->regalloc.intervals[v].phys_reg = -1; - prog->regalloc.intervals[v].bundle_size = 1; - prog->regalloc.intervals[v].is_pair = false; - prog->regalloc.intervals[v].is_quad = false; - prog->regalloc.intervals[v].active = false; - prog->regalloc.vreg_to_phys[v] = -1; - return v; -} - -int omega_bw_ir_alloc_vreg64(BlackwellIRProgram *prog) { - if (!prog || prog->regalloc.num_vregs >= BW_MAX_VREGS) return -1; - int v = prog->regalloc.num_vregs++; - prog->regalloc.intervals[v].vreg = v; - prog->regalloc.intervals[v].first_def = -1; - prog->regalloc.intervals[v].last_use = -1; - prog->regalloc.intervals[v].phys_reg = -1; - prog->regalloc.intervals[v].bundle_size = 2; - prog->regalloc.intervals[v].is_pair = true; - prog->regalloc.intervals[v].is_quad = false; - prog->regalloc.intervals[v].active = false; - prog->regalloc.vreg_to_phys[v] = -1; - return v; -} - -int omega_bw_ir_alloc_vreg128(BlackwellIRProgram *prog) { - if (!prog || prog->regalloc.num_vregs >= BW_MAX_VREGS) return -1; - int v = prog->regalloc.num_vregs++; - prog->regalloc.intervals[v].vreg = v; - prog->regalloc.intervals[v].first_def = -1; - prog->regalloc.intervals[v].last_use = -1; - prog->regalloc.intervals[v].phys_reg = -1; - prog->regalloc.intervals[v].bundle_size = 4; - prog->regalloc.intervals[v].is_pair = false; - prog->regalloc.intervals[v].is_quad = true; - prog->regalloc.intervals[v].active = false; - prog->regalloc.vreg_to_phys[v] = -1; - return v; -} - -int omega_bw_ir_alloc_uvreg(BlackwellIRProgram *prog) { - if (!prog || prog->regalloc.num_uvregs >= BW_MAX_UVREGS) return -1; - int uv = prog->regalloc.num_uvregs++; - prog->regalloc.uintervals[uv].vreg = uv; - prog->regalloc.uintervals[uv].first_def = -1; - prog->regalloc.uintervals[uv].last_use = -1; - prog->regalloc.uintervals[uv].phys_reg = -1; - prog->regalloc.uintervals[uv].is_pair = false; - prog->regalloc.uintervals[uv].active = false; - prog->regalloc.uvreg_to_phys[uv] = -1; - return uv; -} - -int omega_bw_ir_alloc_uvreg64(BlackwellIRProgram *prog) { - if (!prog || prog->regalloc.num_uvregs >= BW_MAX_UVREGS) return -1; - int uv = prog->regalloc.num_uvregs++; - prog->regalloc.uintervals[uv].vreg = uv; - prog->regalloc.uintervals[uv].first_def = -1; - prog->regalloc.uintervals[uv].last_use = -1; - prog->regalloc.uintervals[uv].phys_reg = -1; - prog->regalloc.uintervals[uv].is_pair = true; - prog->regalloc.uintervals[uv].active = false; - prog->regalloc.uvreg_to_phys[uv] = -1; - return uv; -} - -int omega_bw_ir_append(BlackwellIRProgram *prog, const BlackwellIRInsn *insn) { - if (!prog || !insn || prog->count >= BW_MAX_IR_INSNS) return -1; - int idx = (int)prog->count++; - prog->insns[idx] = *insn; - - /* Update live-interval def/use tracking */ - if (insn->dst_vreg >= 0 && insn->dst_vreg < prog->regalloc.num_vregs) { - if (!insn->is_uniform) { - OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->dst_vreg]; - if (iv->first_def < 0) iv->first_def = idx; - if (idx > iv->last_use) iv->last_use = idx; - } - } - if (insn->src1_vreg >= 0 && insn->src1_vreg < prog->regalloc.num_vregs) { - OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->src1_vreg]; - if (iv->first_def < 0) iv->first_def = idx; - if (idx > iv->last_use) iv->last_use = idx; - } - if (insn->src2_vreg >= 0 && insn->src2_vreg < prog->regalloc.num_vregs) { - OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->src2_vreg]; - if (iv->first_def < 0) iv->first_def = idx; - if (idx > iv->last_use) iv->last_use = idx; - } - if (insn->src3_vreg >= 0 && insn->src3_vreg < prog->regalloc.num_vregs) { - OmegaLiveInterval *iv = &prog->regalloc.intervals[insn->src3_vreg]; - if (iv->first_def < 0) iv->first_def = idx; - if (idx > iv->last_use) iv->last_use = idx; - } - - /* Uniform register def/use tracking */ - if (insn->is_uniform && insn->dst_vreg >= 0 && insn->dst_vreg < prog->regalloc.num_uvregs) { - OmegaLiveInterval *uiv = &prog->regalloc.uintervals[insn->dst_vreg]; - if (uiv->first_def < 0) uiv->first_def = idx; - if (idx > uiv->last_use) uiv->last_use = idx; - } - if (insn->ureg >= 0 && insn->ureg < prog->regalloc.num_uvregs) { - OmegaLiveInterval *uiv = &prog->regalloc.uintervals[insn->ureg]; - if (uiv->first_def < 0) uiv->first_def = idx; - if (idx > uiv->last_use) uiv->last_use = idx; - } - - return idx; -} - -int omega_bw_regalloc_solve(BlackwellIRProgram *prog) { - if (!prog) return -1; - OmegaRegAlloc *ra = &prog->regalloc; - - /* - * Bounded deterministic linear-scan register allocator. - * Computes genuine live intervals across virtual registers and assigns - * available physical GPRs (R2..R127, or up to the program's opt-in gpr_limit) and UGPRs (UR4..UR31). - * Enforces even-alignment and dual-register reservation for 64-bit pairs. - */ - const int gpr_lim = ra->gpr_limit ? (int)ra->gpr_limit : BW_PHYS_GPR_MAX; - bool gpr_busy[BW_PHYS_GPR_HW_LIMIT]; - memset(gpr_busy, 0, sizeof(gpr_busy)); - - int max_phys_used = BW_PHYS_GPR_START; - - /* Sort virtual register indices chronologically by first_def (Poletto & Sarkar Linear Scan) */ - int order[BW_MAX_VREGS]; - int count = 0; - for (int v = 0; v < ra->num_vregs; v++) { - if (ra->intervals[v].first_def >= 0) { - order[count++] = v; - } else { - ra->intervals[v].phys_reg = BW_PHYS_GPR_START; - ra->vreg_to_phys[v] = ra->intervals[v].phys_reg; - } - } - for (int i = 0; i < count - 1; i++) { - for (int j = i + 1; j < count; j++) { - if (ra->intervals[order[i]].first_def > ra->intervals[order[j]].first_def) { - int tmp = order[i]; - order[i] = order[j]; - order[j] = tmp; - } - } - } - - for (int idx = 0; idx < count; idx++) { - int v = order[idx]; - OmegaLiveInterval *iv = &ra->intervals[v]; - - /* Free physical registers whose virtual live intervals have ended */ - for (int p = 0; p < ra->num_vregs; p++) { - if (ra->intervals[p].active && ra->intervals[p].last_use < iv->first_def) { - int freed = ra->intervals[p].phys_reg; - if (freed >= 0 && freed < gpr_lim) { - uint32_t bsize = ra->intervals[p].bundle_size ? ra->intervals[p].bundle_size : (ra->intervals[p].is_pair ? 2 : (ra->intervals[p].is_quad ? 4 : 1)); - for (uint32_t k = 0; k < bsize && (freed + (int)k) < gpr_lim; k++) { - gpr_busy[freed + k] = false; - } - } - ra->intervals[p].active = false; - } - } - - /* Find lowest available physical register */ - int assigned = -1; - uint32_t bsize = iv->bundle_size ? iv->bundle_size : (iv->is_pair ? 2 : (iv->is_quad ? 4 : 1)); - if (bsize == 4) { - /* 128-bit quad requires 4-alignment and 4 contiguous free registers */ - int start = (BW_PHYS_GPR_START + 3) & ~3; - for (int p = start; p <= gpr_lim - 4; p += 4) { - if (!gpr_busy[p] && !gpr_busy[p + 1] && !gpr_busy[p + 2] && !gpr_busy[p + 3]) { - assigned = p; - for (int k = 0; k < 4; k++) gpr_busy[p + k] = true; - break; - } - } - } else if (bsize == 2) { - /* 64-bit pair requires even alignment and contiguous free registers */ - int start = (BW_PHYS_GPR_START + 1) & ~1; - for (int p = start; p <= gpr_lim - 2; p += 2) { - if (!gpr_busy[p] && !gpr_busy[p + 1]) { - assigned = p; - gpr_busy[p] = true; - gpr_busy[p + 1] = true; - break; - } - } - } else { - for (int p = BW_PHYS_GPR_START; p < gpr_lim; p++) { - if (!gpr_busy[p]) { - assigned = p; - gpr_busy[p] = true; - break; - } - } - } - - if (assigned < 0) { - /* Hardware register capacity exceeded: fail closed loudly */ - return -1; - } - - iv->phys_reg = assigned; - iv->active = true; - ra->vreg_to_phys[v] = assigned; - - int top = assigned + (int)bsize - 1; - if (top > max_phys_used) { - max_phys_used = top; - } - } - ra->peak_gpr_usage = (uint32_t)(max_phys_used + 1); - - /* Allocate uniform registers */ - int cur_u = BW_PHYS_UGPR_START; - for (int uv = 0; uv < ra->num_uvregs; uv++) { - OmegaLiveInterval *uiv = &ra->uintervals[uv]; - if (uiv->is_pair) { - if (cur_u % 2 != 0) cur_u++; - if (cur_u + 1 >= BW_PHYS_UGPR_MAX) return -1; - uiv->phys_reg = cur_u; - ra->uvreg_to_phys[uv] = cur_u; - cur_u += 2; - } else { - if (cur_u >= BW_PHYS_UGPR_MAX) return -1; - uiv->phys_reg = cur_u; - ra->uvreg_to_phys[uv] = cur_u++; - } - } - ra->peak_ugpr_usage = (uint32_t)cur_u; - - return 0; -} - -/* ---- sm_121 instruction encoder (aien-dev/CUDApp#79) --------------------------------------------------- - * The hosted build encodes through om/encoder/bw_enc_sm121.om: seeded Omega, compiled by the pinned omc and - * linked through the omega-bridge native binding src/omega_om_units.c (generated by om/units.sh, never edited - * by hand). The C encoder below is migration-pending: it is compiled only - * - in the freestanding build (OMEGA_GPU_NO_POSIX), because the bridge binding needs pthread and mmap and the - * freestanding binding is still a proposal (successor: the same .om unit behind a caller-stack binding); - * - with CUDAPP_MIGRATION_PENDING_C_ENCODER, the differential oracle build (make CUDAPP_ENCODER=c); - * - with CUDAPP_MIGRATION_PENDING_ENCODER_DIFF, which encodes every instruction and program both ways, aborts on - * any byte difference and logs each agreement to $CUDAPP_ENCODER_DIFF_LOG (make CUDAPP_ENCODER=diff). - * Successor of the C body: bw_enc_sm121.om; it is deleted once the freestanding binding lands. */ -#if defined(OMEGA_GPU_NO_POSIX) || defined(CUDAPP_MIGRATION_PENDING_C_ENCODER) -#define BW_ENC_C_PRIMARY 1 -#endif -#if defined(BW_ENC_C_PRIMARY) && defined(CUDAPP_MIGRATION_PENDING_ENCODER_DIFF) -#error "CUDAPP_MIGRATION_PENDING_ENCODER_DIFF needs the .om encoder: not with OMEGA_GPU_NO_POSIX or the C encoder" -#endif -#if defined(BW_ENC_C_PRIMARY) || defined(CUDAPP_MIGRATION_PENDING_ENCODER_DIFF) -static int bw_c_encode_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc *ra, uint32_t w[4]) { - memset(w, 0, 16); - - int dst = (insn->dst_vreg >= 0) ? (ra->vreg_to_phys[insn->dst_vreg] + insn->dst_subreg) : 0; - int src1 = (insn->src1_vreg >= 0) ? (ra->vreg_to_phys[insn->src1_vreg] + insn->src1_subreg) : 0; - int src2 = (insn->src2_vreg >= 0) ? (ra->vreg_to_phys[insn->src2_vreg] + insn->src2_subreg) : 0; - int src3 = (insn->src3_vreg >= 0) ? (ra->vreg_to_phys[insn->src3_vreg] + insn->src3_subreg) : 0xff; /* Default to RZ (0xff) */ - int ureg = (insn->ureg >= 0) ? ra->uvreg_to_phys[insn->ureg] : 0; - - if (insn->is_uniform && insn->dst_vreg >= 0) { - dst = ra->uvreg_to_phys[insn->dst_vreg]; - } - - switch (insn->op) { - case BW_IR_NOP: - w[0] = 0x00007918; - w[1] = 0x00000000; - w[2] = 0x00000000; - w[3] = insn->control ? insn->control : 0x000fc000; /* control: a timed pause (fragment matmul) */ - break; - - case BW_IR_MOV_RZ: - /* MOV Rd, RZ */ - w[0] = 0x7202 | ((uint32_t)(dst & 0xff) << 16); - w[1] = 0x000000ff; - w[2] = 0x00000f00; - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_MOV_IMM: - /* MOV Rd, imm32 */ - w[0] = 0x7802 | ((uint32_t)(dst & 0xff) << 16); - w[1] = insn->imm; - w[2] = 0x00000f00; - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_S2R: - /* S2R Rd, SR */ - w[0] = 0x7919 | ((uint32_t)(dst & 0xff) << 16); - w[1] = 0x0; - w[2] = (insn->imm & 0xff) << 8; - w[3] = insn->control ? insn->control : 0x000e2200; - break; - - case BW_IR_LDC: - /* LDC Rd, c[0x0][imm] */ - w[0] = 0xff007b82 | ((uint32_t)(dst & 0xff) << 16); - w[1] = (insn->imm << 6) & 0x00ffff00; - w[2] = 0x00000800; - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_LDC64: - /* LDC.64 Rd:Rd+1, c[0x0][imm] */ - w[0] = 0xff007b82 | ((uint32_t)(dst & 0xff) << 16); - w[1] = (insn->imm << 6) & 0x00ffff00; - w[2] = 0x00000a00; - w[3] = insn->control ? insn->control : 0x000e2200; - break; - - case BW_IR_LDCU: - /* LDCU URd, c[0x0][imm] */ - w[0] = 0xff0077ac | ((uint32_t)(dst & 0xff) << 16); - w[1] = (insn->imm << 5) & 0x00ffff00; - w[2] = 0x08000800; - w[3] = insn->control ? insn->control : 0x000e2200; - break; - - case BW_IR_LDCU64: - /* LDCU.64 URd:URd+1, c[0x0][imm] */ - w[0] = 0xff0077ac | ((uint32_t)(dst & 0xff) << 16); - w[1] = (insn->imm << 5) & 0x00ffff00; - w[2] = 0x08000a00; - w[3] = insn->control ? insn->control : 0x000e6e00; - break; - - case BW_IR_IMAD: - if (insn->src2_vreg >= 0) { - /* Register-register: IMAD Rd, Ra, Rb, Rc (0x7224) */ - w[0] = 0x7224 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x078e0200 | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - } else if (insn->is_uniform && insn->ureg >= 0) { - /* Uniform register multiplier: IMAD Rd, Ra, URb, Rc (0x7c24) */ - w[0] = 0x7c24 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff); - w[2] = 0x0f8e0200 | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - } else { - /* Immediate multiplier: IMAD Rd, Ra, imm, Rc (0x7824) */ - w[0] = 0x7824 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = insn->imm; - w[2] = 0x078e0200 | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - } - break; - - case BW_IR_IMAD_WIDE: - /* IMAD.WIDE.U32 Rd:Rd+1, Ra, imm, Rc:Rc+1 */ - w[0] = 0x7825 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = insn->imm; - w[2] = 0x078e0000 | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fcc00; - break; - - case BW_IR_ISETP_GE: - if (insn->is_uniform && insn->ureg >= 0) { - w[0] = 0x7c0c | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff); - w[2] = 0x0bf06070; - w[3] = insn->control ? insn->control : 0x002fda00; - } else { - w[0] = 0x780c | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = insn->imm; - w[2] = 0x03f06270; - w[3] = insn->control ? insn->control : 0x001fda00; - } - break; - - case BW_IR_LDG_E: - /* LDG.E Rd, desc[URd][Ra.64] */ - w[0] = 0x7981 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff); - w[2] = 0x0c1e1900; - w[3] = insn->control ? insn->control : 0x000f2200; - break; - - case BW_IR_STG_E: { - /* STG.E desc[URd][Ra.64+imm], Rb. imm = signed 24-bit byte offset at bits 40..63 (w[1] bits - * 8..31), as for LDG; words from nvcc 13.0.88 -arch=sm_121 (omega_blackwell_verify_codegen_fixtures_fragmm, - * 2026-10-12: STG.E desc[UR4][R4.64+0x4], R9 = 0x0000040904007986 0x000fe8000c101904). */ - int32_t off = (int32_t)insn->imm; - if (off < -(1 << 23) || off >= (1 << 23)) return -1; - w[0] = 0x7986 | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff) | (((uint32_t)off & 0xffffffU) << 8); - w[2] = 0x0c101900 | (uint32_t)(ureg & 0xff); - w[3] = insn->control ? insn->control : 0x000fe200; - break; - } - - case BW_IR_STG_EF: - /* STG.E.MMIO.GPU. Uncached store, meant to be visible without a fence. */ - w[0] = 0x7986 | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x0c111900 | (uint32_t)(ureg & 0xff); - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_IADD3: - /* IADD3 Rd, PT, PT, Ra, Rb, Rc */ - w[0] = 0x7210 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x07ffe0ff; - w[3] = insn->control ? insn->control : 0x010fca00; /* omega-mv#545: the emitter's waits, not a fixed SB4 wait */ - break; - - case BW_IR_HMMA_F16: - case BW_IR_HMMA_BF16: { - /* HMMA.16816.F32[.BF16] Rd, Ra, Rb, Rc */ - w[0] = 0x723c | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - uint32_t prec_bit = (insn->op == BW_IR_HMMA_BF16) ? 0x00040000 : 0x00000000; - w[2] = (uint32_t)(src3 & 0xff) | (0x18 << 8) | prec_bit; - w[3] = insn->control ? insn->control : 0x000fe200; - break; - } - - case BW_IR_SHF_R: - /* SHF.R.U32.HI Rd, RZ, imm, Ra */ - w[0] = 0x7819U | ((uint32_t)(dst & 0xff) << 16) | (0xffU << 24); - w[1] = (uint32_t)insn->imm; - w[2] = 0x00011600 | (uint32_t)(src1 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - break; - - case BW_IR_LOP3_AND: - /* LOP3.LUT Rd, Ra, imm, RZ, 0xc0, !PT */ - w[0] = 0x7812U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)insn->imm; - w[2] = 0x078ec0ff; - w[3] = insn->control ? insn->control : 0x001fca00; - break; - - case BW_IR_LDG_E_64: - case BW_IR_LDG_E_128: { - /* LDG.E.64 / LDG.E.128 Rd, desc[URd][Ra.64+imm]. imm = signed 24-bit byte offset at - * bits 40..63 (w[1] bits 8..31); size field in w[2] bits 9..11 (32 = 4, 64 = 5, 128 = 6). - * Words from nvcc 13.0.88 -arch=sm_121 (omega_blackwell_verify_codegen_fixtures_fragmm). */ - int32_t off = (int32_t)insn->imm; - if (off < -(1 << 23) || off >= (1 << 23)) return -1; - w[0] = 0x7981U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff) | (((uint32_t)off & 0xffffffU) << 8); - w[2] = insn->op == BW_IR_LDG_E_64 ? 0x0c1e1b00U : 0x0c1e1d00U; - w[3] = insn->control ? insn->control : 0x000f2200; - break; - } - - case BW_IR_LDG_E_U16: - /* LDG.E.U16 Rd, desc[URd][Ra.64] */ - w[0] = 0x7981U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff); - w[2] = 0x0c1e1500; - w[3] = insn->control ? insn->control : 0x000f2200; - break; - - case BW_IR_LDG_STRONG_SYS: - /* LDG.E.STRONG.SYS. Same shape as LDG.E; w[2] carries the - * system-scope bits (0x0c1e1900 -> 0x0c1f5900). */ - w[0] = 0x7981 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff); - w[2] = 0x0c1f5900; - w[3] = insn->control ? insn->control : 0x000f2200; - break; - - case BW_IR_LDG_MMIO: - /* LDG.E.EF. Drop the cached line, then load. */ - w[0] = 0x7981 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(ureg & 0xff); - w[2] = 0x0c0e1900; - w[3] = insn->control ? insn->control : 0x000f2200; - break; - - case BW_IR_STG_STRONG_SYS: - w[0] = 0x7986 | ((uint32_t)(src1 & 0xff) << 24); - if (insn->predicate_p0) { - uint32_t pred = insn->predicate_not ? 0x8u : 0x0u; - w[0] = (w[0] & ~0xF000u) | (pred << 12); - } - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x0c115900 | (uint32_t)(ureg & 0xff); - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_MEMBAR_ALL_SYS: - w[0] = 0x00007992; - w[1] = 0x00000000; - w[2] = 0x0000b000; - w[3] = insn->control ? insn->control : 0x000fec00; - break; - - case BW_IR_MEMBAR_SC_SYS: - w[0] = 0x00007992; - w[1] = 0x00000000; - w[2] = 0x00003000; - w[3] = insn->control ? insn->control : 0x000fec00; - break; - - case BW_IR_CCTL_IVALL: - w[0] = 0xff00798f; - w[1] = 0x00000000; - w[2] = 0x02000000; - w[3] = insn->control ? insn->control : 0x000fe800; - break; - - case BW_IR_ATOMG_ADD_STRONG_SYS: - w[0] = 0x79a8 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff) | 0x80000000u; - w[2] = 0x081f5100 | (uint32_t)(ureg & 0xff); - w[3] = insn->control ? insn->control : 0x00321e00; - break; - - case BW_IR_ATOMG_EXCH_STRONG_SYS: - w[0] = 0x79a8 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff) | 0x80000000u; - w[2] = 0x0c1f5100 | (uint32_t)(ureg & 0xff); - w[3] = insn->control ? insn->control : 0x00321e00; - break; - - case BW_IR_ISETP_GE_U32: - /* ISETP.GE.U32.AND P0, PT, Ra, Rb, PT. Checked with nvdisasm -b SM121. */ - w[0] = 0x720c | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x03f06070; - w[3] = insn->control ? insn->control : 0x001fda00; - break; - - case BW_IR_LOP3_XOR: - /* LOP3.LUT Rd, Ra, Rb, RZ, 0x3c, !PT. Checked with nvdisasm -b SM121. */ - w[0] = 0x7212 | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x078e3cff; - w[3] = insn->control ? insn->control : 0x001fca00; - break; - - case BW_IR_FADD: - /* FADD Rd, Ra, Rb */ - w[0] = 0x7221U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x00000000; - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_FSUB: - /* FSUB Rd, Ra, Rb (FADD Rd, Ra, -Rb) */ - w[0] = 0x7221U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff) | 0x80000000U; - w[2] = 0x00000000; - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_FMUL: - /* FMUL Rd, Ra, Rb */ - w[0] = 0x7220U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x00400000; - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_FFMA: - /* FFMA Rd, Ra, Rb, Rc */ - w[0] = 0x7223U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_FSETP: - /* FSETP.cond.AND P0, PT, Ra, Rb, PT */ - w[0] = 0x720bU | ((uint32_t)(dst & 0x7) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = insn->imm ? insn->imm : 0x03f06000; /* Default GE condition */ - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_FSEL: - /* FSEL Rd, Ra, Rb, P0 */ - w[0] = 0x7208U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = (uint32_t)(src3 & 0x7); - w[3] = insn->control ? insn->control : 0x000fca00; - break; - - case BW_IR_FMNMX_MIN: - /* FMNMX Rd, Ra, Rb, PT (minimum) */ - w[0] = 0x7209U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x03800000; - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_FMNMX_MAX: - /* FMNMX Rd, Ra, Rb, !PT (maximum) */ - w[0] = 0x7209U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x07800000; - w[3] = insn->control ? insn->control : 0x004fc400; - break; - - case BW_IR_I2FP: - /* I2FP.F32.S32 Rd, Ra */ - w[0] = 0x7245U | ((uint32_t)(dst & 0xff) << 16); - w[1] = (uint32_t)(src1 & 0xff); - w[2] = 0x00201400; - w[3] = insn->control ? insn->control : 0x004fe200; - break; - - case BW_IR_F2I: - /* F2I.TRUNC.NTZ Rd, Ra */ - w[0] = 0x7305U | ((uint32_t)(dst & 0xff) << 16); - w[1] = (uint32_t)(src1 & 0xff); - w[2] = 0x0020f100; - w[3] = insn->control ? insn->control : 0x004e2200; - break; - - case BW_IR_MUFU_RCP: - /* MUFU.RCP Rd, Ra */ - w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16); - w[1] = (uint32_t)(src1 & 0xff); - w[2] = 0x00001000; - w[3] = insn->control ? insn->control : 0x000e2400; - break; - - case BW_IR_MUFU_LG2: - /* MUFU.LG2 Rd, Ra (nvdisasm 13.0 -b SM121 decodes sub-op 0x0c00 as MUFU.LG2) */ - w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16); - w[1] = (uint32_t)(src1 & 0xff); - w[2] = 0x00000c00; - w[3] = insn->control ? insn->control : 0x000e2400; - break; - - case BW_IR_MUFU_RSQ: - /* MUFU.RSQ Rd, Ra */ - w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16); - w[1] = (uint32_t)(src1 & 0xff); - w[2] = 0x00001400; - w[3] = insn->control ? insn->control : 0x000e2400; - break; - - case BW_IR_SHFL_DOWN: - /* SHFL.DOWN PT, Rd, Ra, offset, 0x1f */ - w[0] = 0x7f89U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = 0x08001f00U | (((uint32_t)insn->imm & 0x1f) << 21); - w[2] = 0x000e0000; - w[3] = insn->control ? insn->control : 0x000e2400; - break; - - case BW_IR_LDS: - /* LDS Rd, [Ra] */ - w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = 0x00000000; - w[2] = (uint32_t)(insn->imm & 0xffff); - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_STS: - /* STS [Ra], Rb */ - w[0] = 0x7388U | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = (uint32_t)(insn->imm & 0xffff); - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - case BW_IR_EXIT: - w[0] = insn->predicate_p0 ? 0x0000094d : 0x0000794d; - w[1] = 0x00000000; - w[2] = 0x03800000; - w[3] = insn->control ? insn->control : 0x000fea00; - break; - - case BW_IR_BRA: { - /* sm_121 BRA. Distance is (target - this) - 1, split across the - * low six bits at instruction bits 18..23 and the rest at bit 34. - * Predicate bits 12..15: 7 = always, 0 = @P0, 8 = @!P0. - * A zero delta with no predicate keeps the self-branch word the - * existing kernels already emit after EXIT. */ - int32_t delta = (int32_t)insn->imm; - int32_t rel = delta - 1; - uint32_t pred_field = 0x7u; - if (insn->predicate_p0) - pred_field = insn->predicate_not ? 0x8u : 0x0u; - w[0] = 0x947u | (pred_field << 12) | (((uint32_t)rel & 0x3fu) << 18); - w[1] = (uint32_t)(rel >> 6) << 2; - w[2] = (rel < 0) ? 0x0383ffffu : 0x03800000u; - if (insn->control) - w[3] = insn->control; - else if (delta == 0 && !insn->predicate_p0) - w[3] = 0x000fc000u; - else - w[3] = 0x000fea00u; - break; - } - - case BW_IR_BSSY: { - /* BSSY.RECONVERGENT Bn, target (omega #308). nvcc 13.0.88 -arch=sm_121: - * [0070] BSSY.RECONVERGENT B0, 0x140 ; 0x000000c000007945 0x000fe20003800200 - * opcode 0x945 (NAK sm70_encode.rs:4165), barrier id at bits 16..19 (set_bar_dst - * 16..20), guard predicate at bits 12..15 like BRA, relative byte offset - * target - (this + 16) at bit 32 (NAK: field 34.. in 4-byte units), the cond - * predicate PT at bits 87..89 (0x0380 << 16 in w[2]) and bit 73 (0x200 in w[2]), - * which the disassembler prints as .RECONVERGENT; nvcc sets it on every BSSY/BSYNC - * for sm_121 and Mesa NAK does not. We follow nvcc. The target is the instruction - * after the matching BSYNC, so the delta is at least 2; smaller is refused. */ - int32_t delta = (int32_t)insn->imm; - if (delta < 2 || insn->bar_reg >= BW_RECONV_MAX_BAR) return -1; - uint32_t pred_field = 0x7u; - if (insn->predicate_p0) - pred_field = insn->predicate_not ? 0x8u : 0x0u; - w[0] = 0x945u | (pred_field << 12) | ((uint32_t)insn->bar_reg << 16); - w[1] = (uint32_t)(delta - 1) * 16u; - w[2] = 0x03800200u; - w[3] = insn->control ? insn->control : 0x000fe200u; - break; - } - - case BW_IR_BSYNC: { - /* BSYNC.RECONVERGENT Bn: [0130] BSYNC.RECONVERGENT B0 ; 0x0000000000007941 0x000fea0003800200 - * opcode 0x941 (NAK sm70_encode.rs:4179), barrier id bits 16..19, cond PT, bit 73. */ - if (insn->bar_reg >= BW_RECONV_MAX_BAR) return -1; - uint32_t pred_field = 0x7u; - if (insn->predicate_p0) - pred_field = insn->predicate_not ? 0x8u : 0x0u; - w[0] = 0x941u | (pred_field << 12) | ((uint32_t)insn->bar_reg << 16); - w[1] = 0; - w[2] = 0x03800200u; - w[3] = insn->control ? insn->control : 0x000fea00u; - break; - } - - case BW_IR_MUFU_EX2: - /* MUFU.EX2 Rd, Ra. nvdisasm 13.0 -b SM121: 0x7308 with sub-op 0x0800 decodes - * "MUFU.EX2 R2, R4" (RCP is 0x1000, RSQ 0x1400 above). */ - w[0] = 0x7308U | ((uint32_t)(dst & 0xff) << 16); - w[1] = (uint32_t)(src1 & 0xff); - w[2] = 0x00000800; - w[3] = insn->control ? insn->control : 0x000e2400; - break; - - case BW_IR_BAR_SYNC: - /* BAR.SYNC.DEFER_BLOCKING 0x0: the exact words src/omega_numeric.c:885 runs on - * the chip (nvdisasm: "BAR.SYNC.DEFER_BLOCKING 0x0"). No registers. */ - w[0] = 0x00007b1dU; - w[1] = 0x00000000; - w[2] = 0x00010000; - w[3] = insn->control ? insn->control : 0x000fec00; - break; - - case BW_IR_LDS128: { - /* LDS.128 Rd..Rd+3, [Ra+imm]. nvcc 13.0.88 -arch=sm_121 words (fixtures below): - * LDS.128 R4, [R20] ; 0x0000000014047984 0x000fe80000000c00 - * LDS.128 R8, [R20+0x40] ; 0x0000400014087984 0x000e280000000c00 - * imm = byte offset at w[1] bits 8..31; size field 6 (128) at w[2] bits 9..11. */ - if (insn->imm >= (1u << 23)) return -1; - w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (insn->imm & 0xffffffU) << 8; - w[2] = 0x00000c00U; - w[3] = insn->control ? insn->control : 0x000fe800; - break; - } - - case BW_IR_LDS32: - /* LDS Rd, [Ra+URZ] (32-bit), the src/omega_numeric.c:886 form. */ - w[0] = 0x7984U | ((uint32_t)(dst & 0xff) << 16) | ((uint32_t)(src1 & 0xff) << 24); - w[1] = 0x000000ff; - w[2] = 0x08000800; - w[3] = insn->control ? insn->control : 0x000e2800; - break; - - case BW_IR_STS32: - /* STS [Ra+URZ], Rb (32-bit), the src/omega_numeric.c:884 form. */ - w[0] = 0x7988U | ((uint32_t)(src1 & 0xff) << 24); - w[1] = (uint32_t)(src2 & 0xff); - w[2] = 0x080008ffU; - w[3] = insn->control ? insn->control : 0x000fe200; - break; - - /* Prime race cut (2026-10-05). An absent operand is RZ for these three ops. */ - case BW_IR_LOP3_LUT: { - /* LOP3.LUT Rd, Ra, Rb, Rc, imm8, !PT. LOP3_XOR above is this form with Rc = RZ, LUT 0x3c. */ - uint32_t a = (insn->src1_vreg >= 0) ? (uint32_t)(src1 & 0xff) : 0xffU; - uint32_t b = (insn->src2_vreg >= 0) ? (uint32_t)(src2 & 0xff) : 0xffU; - w[0] = 0x7212U | ((uint32_t)(dst & 0xff) << 16) | (a << 24); - w[1] = b; - w[2] = 0x078e0000U | ((insn->imm & 0xffU) << 8) | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - break; - } - - case BW_IR_SHF_L_U32: { - /* SHF.L.U32 Rd, Ra, Rb, Rc: register-amount form (0x7219) of SHF_R's 0x7819, with the - * .R (w[2] bit 12) and .HI (bit 16) flags clear. Rc is the funnel high word (RZ). */ - uint32_t a = (insn->src1_vreg >= 0) ? (uint32_t)(src1 & 0xff) : 0xffU; - uint32_t b = (insn->src2_vreg >= 0) ? (uint32_t)(src2 & 0xff) : 0xffU; - w[0] = 0x7219U | ((uint32_t)(dst & 0xff) << 16) | (a << 24); - w[1] = b; - w[2] = 0x00000600U | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - break; - } - - case BW_IR_IMAD_HI_U32: { - /* IMAD.HI.U32 Rd, Ra, Rb, Rc: opcode 0x227 with the IMAD.WIDE.U32 modifier word. */ - uint32_t a = (insn->src1_vreg >= 0) ? (uint32_t)(src1 & 0xff) : 0xffU; - uint32_t b = (insn->src2_vreg >= 0) ? (uint32_t)(src2 & 0xff) : 0xffU; - w[0] = 0x7227U | ((uint32_t)(dst & 0xff) << 16) | (a << 24); - w[1] = b; - w[2] = 0x078e0000U | (uint32_t)(src3 & 0xff); - w[3] = insn->control ? insn->control : 0x001fca00; - break; - } - - default: - return -1; - } - return 0; -} -#endif /* C encoder, migration-pending */ - -#ifdef BW_ENC_C_PRIMARY -static int encode_single_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc *ra, uint32_t w[4]) { - return bw_c_encode_insn(insn, ra, w); -} -#else -#include "omega_native.h" -/* The .om unit reads the IR as 8 ulongs per instruction and the allocation as one 288-entry table; these are the - * layouts its source documents (om/encoder/bw_enc_sm121.om), so the enum values and sizes are pinned here. */ -#define BW_OM_INS_LEN 8192u /* BW_MAX_IR_INSNS * 8 */ -#define BW_OM_PHYS_LEN 288u /* BW_MAX_VREGS + BW_MAX_UVREGS */ -#define BW_OM_CODE_LEN 16384u /* BW_MAX_IR_INSNS * 16 */ -_Static_assert(BW_MAX_IR_INSNS == 1024 && BW_MAX_VREGS == 256 && BW_MAX_UVREGS == 32, "bw_enc_sm121.om array sizes"); -_Static_assert(BW_IR_NOP == 0 && BW_IR_MOV_RZ == 1 && BW_IR_MOV_IMM == 2 && BW_IR_S2R == 3 && BW_IR_LDC == 4 && - BW_IR_LDC64 == 5 && BW_IR_LDCU == 6 && BW_IR_LDCU64 == 7 && BW_IR_IMAD == 8 && BW_IR_IMAD_WIDE == 9 && - BW_IR_ISETP_GE == 10 && BW_IR_LDG_E == 11 && BW_IR_STG_E == 12 && BW_IR_STG_EF == 13 && - BW_IR_IADD3 == 14 && BW_IR_HMMA_F16 == 15 && BW_IR_HMMA_BF16 == 16 && BW_IR_SHF_R == 17 && - BW_IR_LOP3_AND == 18 && BW_IR_LDG_E_U16 == 19 && BW_IR_LDG_STRONG_SYS == 20 && BW_IR_LDG_MMIO == 21 && - BW_IR_STG_STRONG_SYS == 22 && BW_IR_MEMBAR_ALL_SYS == 23 && BW_IR_MEMBAR_SC_SYS == 24 && - BW_IR_CCTL_IVALL == 25 && BW_IR_ATOMG_ADD_STRONG_SYS == 26 && BW_IR_ATOMG_EXCH_STRONG_SYS == 27 && - BW_IR_ISETP_GE_U32 == 28 && BW_IR_LOP3_XOR == 29, "bw_enc_sm121.om opcode numbers 0-29"); -_Static_assert(BW_IR_FADD == 30 && BW_IR_FSUB == 31 && BW_IR_FMUL == 32 && BW_IR_FFMA == 33 && BW_IR_FSETP == 34 && - BW_IR_FSEL == 35 && BW_IR_FMNMX_MIN == 36 && BW_IR_FMNMX_MAX == 37 && BW_IR_I2FP == 38 && - BW_IR_F2I == 39 && BW_IR_MUFU_RCP == 40 && BW_IR_MUFU_RSQ == 41 && BW_IR_SHFL_DOWN == 42 && - BW_IR_LDS == 43 && BW_IR_STS == 44 && BW_IR_EXIT == 45 && BW_IR_BRA == 46 && BW_IR_MUFU_EX2 == 47 && - BW_IR_BAR_SYNC == 48 && BW_IR_LDS32 == 49 && BW_IR_STS32 == 50 && BW_IR_LOP3_LUT == 51 && - BW_IR_SHF_L_U32 == 52 && BW_IR_IMAD_HI_U32 == 53 && BW_IR_BSSY == 54 && BW_IR_BSYNC == 55 && - BW_IR_LDG_E_64 == 56 && BW_IR_LDG_E_128 == 57 && BW_IR_LDS128 == 58 && BW_IR_MUFU_LG2 == 59, - "bw_enc_sm121.om opcode numbers 30-59"); - -/* Encodes n instructions through the .om unit into code (BW_OM_CODE_LEN bytes). pad != 0 is program mode (NOP - * padding to a multiple of 8, at least 32). Returns the bytes written; 0 = refused. */ -static size_t bw_om_encode(const BlackwellIRInsn *insns, size_t n, const OmegaRegAlloc *ra, int pad, uint8_t *code) { - if (n > BW_MAX_IR_INSNS) return 0; - uint64_t ins[BW_OM_INS_LEN], phys[BW_OM_PHYS_LEN]; - for (size_t i = 0; i < n; i++) { - const BlackwellIRInsn *in = &insns[i]; - uint64_t *r = &ins[i * 8]; - r[0] = (uint64_t)(int64_t)(int)in->op; - r[1] = (uint64_t)(int64_t)in->dst_vreg; - r[2] = (uint64_t)(int64_t)in->src1_vreg; - r[3] = (uint64_t)(int64_t)in->src2_vreg; - r[4] = (uint64_t)(int64_t)in->src3_vreg; - r[5] = (uint64_t)(int64_t)in->ureg; - r[6] = (uint64_t)in->imm | (uint64_t)in->control << 32; - r[7] = (uint64_t)in->is_uniform | (uint64_t)in->predicate_p0 << 1 | (uint64_t)in->predicate_not << 2 | - (uint64_t)in->bar_reg << 8 | (uint64_t)in->dst_subreg << 16 | (uint64_t)in->src1_subreg << 24 | - (uint64_t)in->src2_subreg << 32 | (uint64_t)in->src3_subreg << 40; - } - for (size_t i = n * 8; i < BW_OM_INS_LEN; i++) ins[i] = 0; - for (int i = 0; i < BW_MAX_VREGS; i++) phys[i] = (uint64_t)(int64_t)ra->vreg_to_phys[i]; - for (int i = 0; i < BW_MAX_UVREGS; i++) phys[BW_MAX_VREGS + i] = (uint64_t)(int64_t)ra->uvreg_to_phys[i]; - uint64_t bytes = 0; - if (omega_bw_enc_sm121(&bytes, ins, BW_OM_INS_LEN, phys, BW_OM_PHYS_LEN, (uint64_t)n, pad ? 1u : 0u, code, - BW_OM_CODE_LEN) != OMEGA_OK) - return 0; - return (size_t)bytes; -} - -#ifdef CUDAPP_MIGRATION_PENDING_ENCODER_DIFF -/* One line per agreement, appended; any disagreement aborts the process after naming it. */ -static void bw_enc_diff_note(const char *what, size_t insns, const uint8_t *code, size_t len, int agree) { - char hex[17] = "-"; - if (len) { - uint8_t d[SHA256_DIGEST_SIZE]; sha256_hash(code, len, d); - for (int i = 0; i < 8; i++) snprintf(hex + 2 * i, 3, "%02x", (unsigned)d[i]); - } - const char *path = getenv("CUDAPP_ENCODER_DIFF_LOG"); - if (path && path[0]) { - int fd = open(path, O_WRONLY | O_CREAT | O_APPEND | O_CLOEXEC, 0600); - if (fd >= 0) { - char line[160]; - int k = snprintf(line, sizeof line, "%s insns=%zu bytes=%zu sha16=%s %s\n", what, insns, len, hex, - agree ? "SAME" : "DIFFER"); - if (k > 0 && write(fd, line, (size_t)k) != k) BW_DIAG("encoder diff: short log write\n"); - close(fd); - } - } - if (!agree) { - BW_DIAG("ENCODER DIFF: .om and C encoders disagree (%s, %zu insns)\n", what, insns); - abort(); - } -} -#endif - -static int encode_single_insn(const BlackwellIRInsn *insn, const OmegaRegAlloc *ra, uint32_t w[4]) { - uint8_t code[BW_OM_CODE_LEN]; - int rc = bw_om_encode(insn, 1, ra, 0, code) == 16 ? 0 : -1; - memset(w, 0, 16); - if (rc == 0) - for (int k = 0; k < 4; k++) - w[k] = (uint32_t)code[4 * k] | (uint32_t)code[4 * k + 1] << 8 | (uint32_t)code[4 * k + 2] << 16 | - (uint32_t)code[4 * k + 3] << 24; -#ifdef CUDAPP_MIGRATION_PENDING_ENCODER_DIFF - uint32_t c[4]; - int crc = bw_c_encode_insn(insn, ra, c); - bw_enc_diff_note("insn", 1, rc == 0 ? code : NULL, rc == 0 ? 16 : 0, - crc == rc && (rc != 0 || memcmp(c, w, 16) == 0)); -#endif - return rc; -} -#endif - -/* Prime race cut (2026-10-05): golden words for LOP3_LUT, SHF_L_U32 and IMAD_HI_U32. - * Each expected (w0, w1, w2) is the low 96 bits of an instruction nvcc 13.0.88 emitted - * for sm_121 (nvcc -arch=sm_121 -cubin, cuobjdump -sass; source and dump in - * bench/prime_race/tests/encoding_oracle.md). Control words (w3) are scheduler output and - * not compared. nvcc is an offline oracle only; nothing here links CUDA. 0 = all good. */ -int omega_blackwell_verify_codegen_fixtures_intops(void) { - OmegaRegAlloc ra; - memset(&ra, 0, sizeof(ra)); - static const int phys[] = { 0, 2, 6, 7, 9, 11, 13 }; - for (int i = 0; i < (int)(sizeof phys / sizeof phys[0]); i++) ra.vreg_to_phys[i] = phys[i]; - enum { R0 = 0, R2, R6, R7, R9, R11, R13, RZ = -1 }; - static const struct { - BlackwellIROpcode op; int d, a, b, c; uint32_t imm; uint32_t w0, w1, w2; const char *text; - } fx[] = { - { BW_IR_LOP3_LUT, R9, R7, R0, RZ, 0xfc, 0x07097212U, 0x00000000U, 0x078efcffU, "LOP3.LUT R9, R7, R0, RZ, 0xfc, !PT" }, - { BW_IR_LOP3_LUT, R11, R6, R7, R0, 0x78, 0x060b7212U, 0x00000007U, 0x078e7800U, "LOP3.LUT R11, R6, R7, R0, 0x78, !PT" }, - { BW_IR_LOP3_LUT, R13, R6, R7, R0, 0x10, 0x060d7212U, 0x00000007U, 0x078e1000U, "LOP3.LUT R13, R6, R7, R0, 0x10, !PT" }, - { BW_IR_LOP3_LUT, R7, RZ, R9, RZ, 0x33, 0xff077212U, 0x00000009U, 0x078e33ffU, "LOP3.LUT R7, RZ, R9, RZ, 0x33, !PT" }, - { BW_IR_SHF_L_U32, R7, R9, R2, RZ, 0, 0x09077219U, 0x00000002U, 0x000006ffU, "SHF.L.U32 R7, R9, R2, RZ" }, - { BW_IR_SHF_L_U32, R7, R0, R7, RZ, 0, 0x00077219U, 0x00000007U, 0x000006ffU, "SHF.L.U32 R7, R0, R7, RZ" }, - { BW_IR_IMAD_HI_U32, R9, R9, R0, R6, 0, 0x09097227U, 0x00000000U, 0x078e0006U, "IMAD.HI.U32 R9, R9, R0, R6" }, - { BW_IR_IMAD_HI_U32, R7, R0, R7, RZ, 0, 0x00077227U, 0x00000007U, 0x078e00ffU, "IMAD.HI.U32 R7, R0, R7, RZ" }, - }; - for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) { - BlackwellIRInsn in; - memset(&in, 0, sizeof in); - in.op = fx[i].op; in.dst_vreg = fx[i].d; in.src1_vreg = fx[i].a; in.src2_vreg = fx[i].b; - in.src3_vreg = fx[i].c; in.ureg = -1; in.imm = fx[i].imm; - uint32_t w[4]; - if (encode_single_insn(&in, &ra, w) != 0) return -(2 * i + 1); - if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2) return -(2 * i + 2); - } - return 0; -} - -int omega_blackwell_encode_one(const BlackwellIRInsn *insn, uint32_t w[4]) { - if (!insn || !w) return -1; - OmegaRegAlloc ra; - memset(&ra, 0, sizeof ra); - for (int i = 0; i < BW_MAX_VREGS; i++) ra.vreg_to_phys[i] = i; - for (int i = 0; i < BW_MAX_UVREGS; i++) ra.uvreg_to_phys[i] = i; - return encode_single_insn(insn, &ra, w); -} - -/* omega #328: golden words for the fragment-major matmul. Oracle: nvcc 13.0.88 -arch=sm_121 - * -cubin -O3, cuobjdump -sass, on a kernel with uint2 / uint4 loads at immediate offsets and a - * dependent mma.m16n8k16 bf16 chain (source and dump sealed in - * ~/workspace/investigations/2026-10-07-qwen3-decode-matmul/oracle/frag_plain.{cu,sass}): - * LDG.E.64 R2, desc[UR8][R30.64] ; 0x000000081e027981 0x000ea8000c1e1b00 - * LDG.E.64 R28, desc[UR8][R30.64+0x100] ; 0x000100081e1c7981 0x000ee8000c1e1b00 - * LDG.E.128 R8, desc[UR8][R32.64] ; 0x0000000820087981 0x000ea8000c1e1d00 - * LDG.E.128 R20, desc[UR8][R32.64+0x1000] ; 0x0010000820147981 0x000e9e000c1e1d00 - * HMMA.16816.F32.BF16 R8, R12, R6, R8 ; 0x000000060c08723c 0x010fe20000041808 - * NOP ; 0x0000000000007918 0x000fdc0000000000 - * The dependent HMMA chain nvcc emits is HMMA (stall 15) then NOP (stall 14): 29 cycles from - * one HMMA to the next that reads its accumulator. w3 is compared for the NOP only (it is the - * whole point of that instruction). 0 = all good. */ -int omega_blackwell_verify_codegen_fixtures_fragmm(void) { - static const struct { - BlackwellIROpcode op; int d, a, b, c, u; uint32_t imm, control; uint32_t w0, w1, w2, w3; const char *text; - } fx[] = { - { BW_IR_LDG_E_64, 2, 30, -1, -1, 8, 0, 0, 0x1e027981U, 0x00000008U, 0x0c1e1b00U, 0, "LDG.E.64 R2, desc[UR8][R30.64]" }, - { BW_IR_LDG_E_64, 28, 30, -1, -1, 8, 0x100, 0, 0x1e1c7981U, 0x00010008U, 0x0c1e1b00U, 0, "LDG.E.64 R28, desc[UR8][R30.64+0x100]" }, - { BW_IR_LDG_E_128, 8, 32, -1, -1, 8, 0, 0, 0x20087981U, 0x00000008U, 0x0c1e1d00U, 0, "LDG.E.128 R8, desc[UR8][R32.64]" }, - { BW_IR_LDG_E_128, 20, 32, -1, -1, 8, 0x1000, 0, 0x20147981U, 0x00100008U, 0x0c1e1d00U, 0, "LDG.E.128 R20, desc[UR8][R32.64+0x1000]" }, - { BW_IR_HMMA_BF16, 8, 12, 6, 8, -1, 0, 0, 0x0c08723cU, 0x00000006U, 0x00041808U, 0, "HMMA.16816.F32.BF16 R8, R12, R6, R8" }, - { BW_IR_NOP, -1, -1, -1, -1, -1, 0, 0x000fdc00U, 0x00007918U, 0, 0, 0x000fdc00U, "NOP (stall 14)" }, - /* LDS.128 with an immediate offset (attention batched loads, 2026-10-12): nvcc 13.0.88 -arch=sm_121 on - * float4 shared reads at register + constant offsets (fixture source in the omega speed/attention-batched-loads PR) */ - { BW_IR_LDS128, 4, 20, -1, -1, -1, 0, 0, 0x14047984U, 0x00000000U, 0x00000c00U, 0, "LDS.128 R4, [R20]" }, - { BW_IR_LDS128, 8, 20, -1, -1, -1, 0x40, 0, 0x14087984U, 0x00004000U, 0x00000c00U, 0, "LDS.128 R8, [R20+0x40]" }, - { BW_IR_LDS128, 12, 20, -1, -1, -1, 0x100, 0, 0x140c7984U, 0x00010000U, 0x00000c00U, 0, "LDS.128 R12, [R20+0x100]" }, - /* STG.E with an immediate offset (blocked prefill matmul, 2026-10-12): nvcc 13.0.88 -arch=sm_121 on float stores - * at register + constant offsets (~/.claude/jobs/ade3c837/tmp/stg-oracle/stg.cu); the second word is the - * offset-free STG word with UR4 */ - { BW_IR_STG_E, -1, 4, 8, -1, 4, 0, 0, 0x04007986U, 0x00000008U, 0x0c101904U, 0, "STG.E desc[UR4][R4.64], R8" }, - { BW_IR_STG_E, -1, 4, 9, -1, 4, 0x4, 0, 0x04007986U, 0x00000409U, 0x0c101904U, 0, "STG.E desc[UR4][R4.64+0x4], R9" }, - { BW_IR_STG_E, -1, 4, 10, -1, 4, 0x4000, 0, 0x04007986U, 0x0040000aU, 0x0c101904U, 0, "STG.E desc[UR4][R4.64+0x4000], R10" }, - { BW_IR_STG_E, -1, 6, 11, -1, 4, 0xfff00000u, 0, 0x06007986U, 0xf000000bU, 0x0c101904U, 0, "STG.E desc[UR4][R6.64+-0x100000], R11" }, - }; - for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) { - BlackwellIRInsn in; - memset(&in, 0, sizeof in); - in.op = fx[i].op; in.dst_vreg = fx[i].d; in.src1_vreg = fx[i].a; in.src2_vreg = fx[i].b; - in.src3_vreg = fx[i].c; in.ureg = fx[i].u; in.imm = fx[i].imm; in.control = fx[i].control; - uint32_t w[4]; - if (omega_blackwell_encode_one(&in, w) != 0) return -(2 * i + 1); - if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2 || (fx[i].w3 && w[3] != fx[i].w3)) return -(2 * i + 2); - } - /* offsets outside the signed 24-bit field are refused, not wrapped */ - BlackwellIRInsn big; - memset(&big, 0, sizeof big); - big.op = BW_IR_LDG_E_64; big.dst_vreg = 2; big.src1_vreg = 30; big.src2_vreg = -1; big.src3_vreg = -1; big.ureg = 8; - big.imm = 1u << 23; - uint32_t w[4]; - if (omega_blackwell_encode_one(&big, w) == 0) return -100; - big.imm = (uint32_t)-(1 << 23); - if (omega_blackwell_encode_one(&big, w) != 0) return -101; - return 0; -} - -/* omega #308: BSSY / BSYNC golden words. Oracle: nvcc 13.0.88 -arch=sm_121 -cubin -O3 on the - * kernels in docs/gpu-reconvergence-308.md, cuobjdump -sass (low 64-bit word, then high; the - * top 23 bits of the high word are the control word and are not compared here): - * k_loop [0070] BSSY.RECONVERGENT B0, 0x140 ; 0x000000c000007945 0x000fe20003800200 (delta 13) - * k_nested [0070] BSSY.RECONVERGENT B0, 0x300 ; 0x0000028000007945 0x000fe20003800200 (delta 41) - * k_break [0070] BSSY.RECONVERGENT B0, 0x110 ; 0x0000009000007945 0x000fe20003800200 (delta 10) - * k_loop [0130] BSYNC.RECONVERGENT B0 ; 0x0000000000007941 0x000fea0003800200 - * Barrier ids other than B0 and the predicated forms are decoded by tools/reconv_nvdisasm_check.sh - * (nvdisasm -b SM121 text), not by this table. */ -int omega_blackwell_verify_codegen_fixtures_reconv(void) { - static const struct { BlackwellIROpcode op; int delta; int bar; uint32_t w0, w1, w2; } fx[] = { - { BW_IR_BSSY, 13, 0, 0x00007945U, 0x000000c0U, 0x03800200U }, - { BW_IR_BSSY, 41, 0, 0x00007945U, 0x00000280U, 0x03800200U }, - { BW_IR_BSSY, 10, 0, 0x00007945U, 0x00000090U, 0x03800200U }, - { BW_IR_BSYNC, 0, 0, 0x00007941U, 0x00000000U, 0x03800200U }, - }; - for (int i = 0; i < (int)(sizeof fx / sizeof fx[0]); i++) { - BlackwellIRInsn in; - memset(&in, 0, sizeof in); - in.op = fx[i].op; in.dst_vreg = -1; in.src1_vreg = -1; in.src2_vreg = -1; in.src3_vreg = -1; in.ureg = -1; - in.imm = (uint32_t)fx[i].delta; in.bar_reg = (uint8_t)fx[i].bar; - uint32_t w[4]; - if (omega_blackwell_encode_one(&in, w) != 0) return -(2 * i + 1); - if (w[0] != fx[i].w0 || w[1] != fx[i].w1 || w[2] != fx[i].w2) return -(2 * i + 2); - /* control word defaults mirror nvcc's: BSSY 0x000fe200, BSYNC 0x000fea00 */ - if (w[3] != (fx[i].op == BW_IR_BSSY ? 0x000fe200U : 0x000fea00U)) return -(2 * i + 2); - } - /* refusals: a BSSY must name a later instruction (delta >= 2), barrier ids stop at B15 */ - BlackwellIRInsn bad; uint32_t w[4]; - memset(&bad, 0, sizeof bad); bad.op = BW_IR_BSSY; bad.dst_vreg = bad.src1_vreg = bad.src2_vreg = bad.src3_vreg = bad.ureg = -1; - bad.imm = 1; bad.bar_reg = 0; - if (omega_blackwell_encode_one(&bad, w) == 0) return -101; - bad.imm = (uint32_t)-3; - if (omega_blackwell_encode_one(&bad, w) == 0) return -102; - bad.imm = 5; bad.bar_reg = 16; - if (omega_blackwell_encode_one(&bad, w) == 0) return -103; - bad.op = BW_IR_BSYNC; bad.imm = 0; bad.bar_reg = 16; - if (omega_blackwell_encode_one(&bad, w) == 0) return -104; - bad.bar_reg = 15; - if (omega_blackwell_encode_one(&bad, w) != 0 || w[0] != (0x00007941U | (15U << 16))) return -105; - return 0; -} - -/* FB-1 cut 4: word-level fixtures for the four additive ops (checked against the - * nvdisasm decodes recorded in docs/numeric/FB1_CUT4_ELEMENTWISE.md). 0 = all good. */ -int omega_blackwell_verify_codegen_fixtures_fb1cut4(void) { - OmegaRegAlloc ra; - memset(&ra, 0, sizeof(ra)); - ra.vreg_to_phys[0] = 2; /* R2 */ - ra.vreg_to_phys[1] = 4; /* R4 */ - ra.vreg_to_phys[2] = 9; /* R9 */ - ra.vreg_to_phys[3] = 10; /* R10 */ - ra.vreg_to_phys[4] = 8; /* R8 */ - uint32_t w[4]; - - /* MUFU.EX2 R2, R4 */ - BlackwellIRInsn ex2 = { .op = BW_IR_MUFU_EX2, .dst_vreg = 0, .src1_vreg = 1 }; - if (encode_single_insn(&ex2, &ra, w) != 0) return -1; - if (w[0] != 0x00027308U || w[1] != 4 || w[2] != 0x00000800U) return -2; - /* BAR.SYNC.DEFER_BLOCKING 0x0 */ - BlackwellIRInsn bar = { .op = BW_IR_BAR_SYNC }; - if (encode_single_insn(&bar, &ra, w) != 0) return -3; - if (w[0] != 0x00007b1dU || w[1] != 0 || w[2] != 0x00010000U || w[3] != 0x000fec00U) return -4; - /* LDS R9, [R10+URZ] */ - BlackwellIRInsn lds = { .op = BW_IR_LDS32, .dst_vreg = 2, .src1_vreg = 3 }; - if (encode_single_insn(&lds, &ra, w) != 0) return -5; - if (w[0] != 0x0a097984U || w[1] != 0xff || w[2] != 0x08000800U) return -6; - /* STS [R8+URZ], R2 */ - BlackwellIRInsn sts = { .op = BW_IR_STS32, .src1_vreg = 4, .src2_vreg = 0 }; - if (encode_single_insn(&sts, &ra, w) != 0) return -7; - if (w[0] != 0x08007988U || w[1] != 2 || w[2] != 0x080008ffU) return -8; - return 0; -} - -/* Kernel capture (C6 of docs/OMEGA.md, tools/sm121dis): with OMEGA_KERNEL_DUMP_DIR set, every encoded kernel is written - * there as .bin, once per distinct body, so the disassembler can be checked against nvdisasm on - * every kernel the library builds. Unset (the normal case) it does nothing; the freestanding build has no files. */ -void omega_kernel_dump(const uint8_t *code, size_t len) { -#ifndef OMEGA_GPU_NO_POSIX - const char *dir = getenv("OMEGA_KERNEL_DUMP_DIR"); - if (!dir || !dir[0] || !code || !len) return; - uint8_t d[SHA256_DIGEST_SIZE]; sha256_hash(code, len, d); - char path[4096]; - int n = snprintf(path, sizeof path, "%s/%02x%02x%02x%02x%02x%02x%02x%02x.bin", - dir, (unsigned)d[0], (unsigned)d[1], (unsigned)d[2], (unsigned)d[3], - (unsigned)d[4], (unsigned)d[5], (unsigned)d[6], (unsigned)d[7]); - if (n < 0 || (size_t)n >= sizeof path) return; - /* Private, exclusive creation: an existing body or symlink is left alone. */ - int fd = open(path, O_WRONLY | O_CREAT | O_EXCL | O_NOFOLLOW | O_CLOEXEC, 0600); - if (fd < 0) return; - FILE *f = fdopen(fd, "wb"); - if (!f) { close(fd); unlink(path); BW_DIAG("omega_kernel_dump: write failed, removed %s\n", path); return; } - /* A body cut short (a full disk) must not stay under its full-content name: it would be compared as a smaller kernel - * and, created O_EXCL, never rewritten. tools/sm121dis/corpus.sh fails on these diagnostics. */ - int bad = fwrite(code, 1, len, f) != len; - if (fclose(f) != 0) bad = 1; - if (bad) { unlink(path); BW_DIAG("omega_kernel_dump: write failed, removed %s\n", path); } -#else - (void)code; (void)len; -#endif -} - -#ifdef BW_ENC_C_PRIMARY -static int bw_encode_program_bytes(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t req_bytes) { - size_t padded_insns = req_bytes / 16; - uint8_t *p = code_buf; - for (size_t i = 0; i < padded_insns; i++) { - uint32_t w[4]; - if (i < prog->count) { - if (encode_single_insn(&prog->insns[i], &prog->regalloc, w) != 0) { - return -1; - } - } else { - /* Pad with NOP */ - w[0] = 0x00007918; - w[1] = 0x00000000; - w[2] = 0x00000000; - w[3] = 0x000fc000; - } - for (int k = 0; k < 4; k++) { - p[4 * k] = (uint8_t)(w[k] & 0xff); - p[4 * k + 1] = (uint8_t)((w[k] >> 8) & 0xff); - p[4 * k + 2] = (uint8_t)((w[k] >> 16) & 0xff); - p[4 * k + 3] = (uint8_t)((w[k] >> 24) & 0xff); - } - p += 16; - } - return 0; -} -#else -static int bw_encode_program_bytes(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t req_bytes) { - uint8_t code[BW_OM_CODE_LEN]; - size_t got = bw_om_encode(prog->insns, prog->count, &prog->regalloc, 1, code); - int rc = (got == req_bytes && got != 0) ? 0 : -1; -#ifdef CUDAPP_MIGRATION_PENDING_ENCODER_DIFF - /* The C oracle encodes the same program, instruction by instruction, NOP-padded the same way. */ -#ifdef CUDAPP_ENCODER_DIFF_SELFTEST - if (rc == 0) code[0] ^= 1; /* red check of the comparison itself: one flipped bit must abort */ -#endif - uint8_t ref[BW_OM_CODE_LEN]; - int crc = 0; - for (size_t i = 0; i < req_bytes / 16 && crc == 0; i++) { - uint32_t w[4] = { 0x00007918, 0, 0, 0x000fc000 }; - if (i < prog->count) crc = bw_c_encode_insn(&prog->insns[i], &prog->regalloc, w); - for (int k = 0; k < 16; k++) ref[16 * i + (size_t)k] = (uint8_t)(w[k / 4] >> (8 * (k % 4))); - } - bw_enc_diff_note("program", prog->count, rc == 0 ? code : NULL, rc == 0 ? req_bytes : 0, - crc == rc && (rc != 0 || memcmp(code, ref, req_bytes) == 0)); -#endif - if (rc == 0) memcpy(code_buf, code, req_bytes); - return rc; -} -#endif - -int omega_bw_encode_program(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t max_len, size_t *out_len) { - if (!prog || !code_buf || !out_len) return -1; - - size_t padded_insns = (prog->count + 7) & ~7ULL; - if (padded_insns < 32) padded_insns = 32; - - size_t req_bytes = padded_insns * 16; - if (max_len < req_bytes) return -1; - - if (bw_encode_program_bytes(prog, code_buf, req_bytes) != 0) return -1; - - omega_kernel_dump(code_buf, req_bytes); - *out_len = req_bytes; - return 0; -} - -int omega_blackwell_codegen_matmul_i32_prog(const OmegaMatMulSpec *spec, BlackwellIRProgram *prog) { - if (!spec || !prog) return -1; - if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1; - - /* Fail closed loudly if K exceeds bounded unroll limit */ - if (spec->k > 32) { - BW_DIAG("ERROR: MatMul integer codegen exceeds bounded unroll limit (K=%u > 32)\n", spec->k); - return -1; - } - - omega_bw_ir_init(prog); - - /* 1. Allocate virtual registers */ - /* 64-bit base pointers */ - int v_ptr_a = omega_bw_ir_alloc_vreg64(prog); - int v_ptr_b = omega_bw_ir_alloc_vreg64(prog); - int v_ptr_c = omega_bw_ir_alloc_vreg64(prog); - int uv_desc = omega_bw_ir_alloc_uvreg64(prog); - - /* 32-bit CTA / Thread indexing */ - int v_ctaid_x = omega_bw_ir_alloc_vreg(prog); - int v_ctaid_y = omega_bw_ir_alloc_vreg(prog); - int v_tid_x = omega_bw_ir_alloc_vreg(prog); - int v_tid_y = omega_bw_ir_alloc_vreg(prog); - - /* 2D Coordinates & loop invariants */ - int v_col = omega_bw_ir_alloc_vreg(prog); - int v_row = omega_bw_ir_alloc_vreg(prog); - int v_row_k = omega_bw_ir_alloc_vreg(prog); - int v_const_1 = omega_bw_ir_alloc_vreg(prog); - int v_acc = omega_bw_ir_alloc_vreg(prog); - - /* Working registers for memory address and operands */ - int v_idx_a = omega_bw_ir_alloc_vreg(prog); - int v_off_a = omega_bw_ir_alloc_vreg64(prog); - int v_val_a = omega_bw_ir_alloc_vreg(prog); - - int v_idx_b = omega_bw_ir_alloc_vreg(prog); - int v_off_b = omega_bw_ir_alloc_vreg64(prog); - int v_val_b = omega_bw_ir_alloc_vreg(prog); - - int v_idx_c = omega_bw_ir_alloc_vreg(prog); - int v_off_c = omega_bw_ir_alloc_vreg64(prog); - - if (v_off_c < 0) return -1; - - /* 2. Load 64-bit global memory descriptor into uniform register pair */ - /* LDCU.64 uv_desc, c[0x0][0x358] */ - BlackwellIRInsn insn_desc = { .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true }; - omega_bw_ir_append(prog, &insn_desc); - - /* 3. Load 64-bit base pointers from Constant Bank 0 */ - /* LDC.64 v_ptr_a, c[0x0][0x380] */ - BlackwellIRInsn insn_ptra = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380 }; - omega_bw_ir_append(prog, &insn_ptra); - - /* LDC.64 v_ptr_b, c[0x0][0x388] */ - BlackwellIRInsn insn_ptrb = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388 }; - omega_bw_ir_append(prog, &insn_ptrb); - - /* LDC.64 v_ptr_c, c[0x0][0x390] */ - BlackwellIRInsn insn_ptrc = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390 }; - omega_bw_ir_append(prog, &insn_ptrc); - - /* 4. Query 2D CTA and Thread coordinates */ - /* S2R v_ctaid_x, SR_CTAID.X */ - BlackwellIRInsn insn_ctax = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X }; - omega_bw_ir_append(prog, &insn_ctax); - - /* S2R v_ctaid_y, SR_CTAID.Y */ - BlackwellIRInsn insn_ctay = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y }; - omega_bw_ir_append(prog, &insn_ctay); - - /* S2R v_tid_x, SR_TID.X */ - BlackwellIRInsn insn_tidx = { .op = BW_IR_S2R, .dst_vreg = v_tid_x, .imm = BW_SR_TID_X }; - omega_bw_ir_append(prog, &insn_tidx); - - /* S2R v_tid_y, SR_TID.Y */ - BlackwellIRInsn insn_tidy = { .op = BW_IR_S2R, .dst_vreg = v_tid_y, .imm = BW_SR_TID_Y }; - omega_bw_ir_append(prog, &insn_tidy); - - /* 5. Compute 2D (row, col) coordinates */ - /* Standard 16x16 tile threads: col = ctaid_x * 16 + tid_x */ - BlackwellIRInsn insn_col = { .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 16, .src3_vreg = v_tid_x }; - omega_bw_ir_append(prog, &insn_col); - - /* row = ctaid_y * 16 + tid_y */ - BlackwellIRInsn insn_row = { .op = BW_IR_IMAD, .dst_vreg = v_row, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = v_tid_y }; - omega_bw_ir_append(prog, &insn_row); - - /* 6. Precompute row base index: v_row_k = v_row * K + RZ */ - BlackwellIRInsn insn_row_k = { .op = BW_IR_IMAD, .dst_vreg = v_row_k, .src1_vreg = v_row, .src2_vreg = -1, .imm = spec->k, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_row_k); - - /* 7. Initialize v_const_1 = 1 for immediate linear indexing */ - BlackwellIRInsn insn_c1 = { .op = BW_IR_MOV_IMM, .dst_vreg = v_const_1, .imm = 1 }; - omega_bw_ir_append(prog, &insn_c1); - - /* 8. Initialize accumulator to zero: MOV v_acc, RZ */ - BlackwellIRInsn insn_init_acc = { .op = BW_IR_MOV_RZ, .dst_vreg = v_acc }; - omega_bw_ir_append(prog, &insn_init_acc); - - /* 9. Synthesize inner accumulation loop across K iterations */ - for (uint32_t step = 0; step < spec->k; step++) { - /* A[row, step]: idx_a = v_row_k + step = v_const_1 * step + v_row_k */ - BlackwellIRInsn insn_idxa = { .op = BW_IR_IMAD, .dst_vreg = v_idx_a, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = step, .src3_vreg = v_row_k }; - omega_bw_ir_append(prog, &insn_idxa); - - /* off_a = v_ptr_a + idx_a * 4 */ - BlackwellIRInsn insn_offa = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off_a, .src1_vreg = v_idx_a, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_a }; - omega_bw_ir_append(prog, &insn_offa); - - /* Load A[row, step]: LDG.E v_val_a, desc[uv_desc][v_off_a.64] */ - BlackwellIRInsn insn_lda = { .op = BW_IR_LDG_E, .dst_vreg = v_val_a, .src1_vreg = v_off_a, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 }; - omega_bw_ir_append(prog, &insn_lda); - - /* B[step, col]: idx_b = step * N + col = v_const_1 * (step * N) + v_col */ - uint32_t step_n = step * spec->n; - BlackwellIRInsn insn_idxb = { .op = BW_IR_IMAD, .dst_vreg = v_idx_b, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = step_n, .src3_vreg = v_col }; - omega_bw_ir_append(prog, &insn_idxb); - - /* off_b = v_ptr_b + idx_b * 4 */ - BlackwellIRInsn insn_offb = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off_b, .src1_vreg = v_idx_b, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_b }; - omega_bw_ir_append(prog, &insn_offb); - - /* Load B[step, col]: LDG.E v_val_b, desc[uv_desc][v_off_b.64] */ - BlackwellIRInsn insn_ldb = { .op = BW_IR_LDG_E, .dst_vreg = v_val_b, .src1_vreg = v_off_b, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 }; - omega_bw_ir_append(prog, &insn_ldb); - - /* Multiply and accumulate: IMAD v_acc, v_val_a, v_val_b, v_acc */ - BlackwellIRInsn insn_acc = { .op = BW_IR_IMAD, .dst_vreg = v_acc, .src1_vreg = v_val_a, .src2_vreg = v_val_b, .src3_vreg = v_acc, .control = 0x004fca00 }; - omega_bw_ir_append(prog, &insn_acc); - } - - /* 10. Compute output index: idx_c = row * N + col */ - BlackwellIRInsn insn_idxc = { .op = BW_IR_IMAD, .dst_vreg = v_idx_c, .src1_vreg = v_row, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col }; - omega_bw_ir_append(prog, &insn_idxc); - - /* off_c = v_ptr_c + idx_c * 4 */ - BlackwellIRInsn insn_offc = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off_c, .src1_vreg = v_idx_c, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c }; - omega_bw_ir_append(prog, &insn_offc); - - /* Store C[row, col]: STG.E desc[uv_desc][v_off_c.64], v_acc */ - BlackwellIRInsn insn_stc = { .op = BW_IR_STG_E, .src1_vreg = v_off_c, .src2_vreg = v_acc, .src3_vreg = -1, .ureg = uv_desc }; - omega_bw_ir_append(prog, &insn_stc); - - /* 11. Kernel termination */ - BlackwellIRInsn insn_exit = { .op = BW_IR_EXIT, .predicate_p0 = false }; - omega_bw_ir_append(prog, &insn_exit); - - BlackwellIRInsn insn_bra = { .op = BW_IR_BRA }; - omega_bw_ir_append(prog, &insn_bra); - - /* 12. Solve bounded deterministic register allocation */ - if (omega_bw_regalloc_solve(prog) != 0) { - return -1; - } - return 0; -} - -/* ---- native v1 P07 cut A.2: allocation-free kernel encoding --------------------------------- - * The one place a solved IR program becomes a kernel. Hosted and freestanding builds both encode - * through it, so the two produce the same bytes for the same program (make test-codegen-freestanding - * compares them). */ -size_t omega_bw_program_code_bytes(const BlackwellIRProgram *prog) { - if (!prog) return 0; - size_t padded_insns = (prog->count + 7) & ~(size_t)7; - if (padded_insns < 32) padded_insns = 32; - return padded_insns * 16; -} - -int omega_blackwell_kernel_encode_into(const BlackwellIRProgram *prog, uint8_t *code_buf, size_t code_cap, - OmegaBlackwellKernel *kernel) { - if (!kernel) return -1; - memset(kernel, 0, sizeof *kernel); - if (!prog || !code_buf) return -1; - size_t need = omega_bw_program_code_bytes(prog); - if (code_cap < need) return OMEGA_BW_CODE_BUFFER_TOO_SMALL; /* refused before any byte is written */ - size_t emitted_size = 0; - if (omega_bw_encode_program(prog, code_buf, code_cap, &emitted_size) != 0) return -1; - kernel->code = code_buf; - kernel->code_size = emitted_size; - kernel->insn_count = emitted_size / 16; - kernel->gpr_count = prog->regalloc.peak_gpr_usage; - kernel->uniform_gpr_count = prog->regalloc.peak_ugpr_usage; - sha256_hash(kernel->code, kernel->code_size, kernel->code_digest); - return 0; -} - -#ifndef OMEGA_GPU_NO_POSIX -/* Hosted only: the allocating generators keep their names, caps and behavior. Each builds the program, - * mallocs max_bytes (the cap each generator always had) and encodes through omega_blackwell_kernel_encode_into; - * omega_blackwell_kernel_free releases the buffer. */ -static int bw_kernel_alloc_encode(const BlackwellIRProgram *prog, size_t max_bytes, OmegaBlackwellKernel *kernel) { - uint8_t *buf = (uint8_t *)malloc(max_bytes); - if (!buf) { kernel->code = NULL; return -1; } - if (omega_blackwell_kernel_encode_into(prog, buf, max_bytes, kernel) != 0) { - free(buf); - kernel->code = NULL; - return -1; - } - return 0; -} - -int omega_blackwell_codegen_matmul_i32(const OmegaMatMulSpec *spec, OmegaBlackwellKernel *kernel) { - if (!spec || !kernel) return -1; - BlackwellIRProgram prog; - if (omega_blackwell_codegen_matmul_i32_prog(spec, &prog) != 0) return -1; - /* 13. the code buffer is exactly the padded program (the i32 generator never had a fixed cap) */ - return bw_kernel_alloc_encode(&prog, omega_bw_program_code_bytes(&prog), kernel); -} -#endif - -int omega_blackwell_codegen_matmul_tensor_prog(const OmegaMatMulSpec *spec, BlackwellIRProgram *prog) { - if (!spec || !prog) return -1; - if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1; - if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1; - if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k != 16) { - BW_DIAG("ERROR: MatMul tensor codegen requires M multiple of 16, N multiple of 8, K=16 (got %ux%ux%u)\n", - spec->m, spec->k, spec->n); - return -1; - } - - omega_bw_ir_init(prog); - - /* 1. Allocate virtual registers */ - /* 64-bit base pointers */ - int v_ptr_a = omega_bw_ir_alloc_vreg64(prog); - int v_ptr_b = omega_bw_ir_alloc_vreg64(prog); - int v_ptr_c = omega_bw_ir_alloc_vreg64(prog); - int uv_desc = omega_bw_ir_alloc_uvreg64(prog); - - /* 32-bit CTA / Thread indexing */ - int v_tid = omega_bw_ir_alloc_vreg(prog); - int v_ctaid_x = omega_bw_ir_alloc_vreg(prog); - int v_ctaid_y = omega_bw_ir_alloc_vreg(prog); - - /* Tile and thread coordinates */ - int v_group_id = omega_bw_ir_alloc_vreg(prog); - int v_tid_in_grp = omega_bw_ir_alloc_vreg(prog); - int v_row_base = omega_bw_ir_alloc_vreg(prog); - int v_col_base = omega_bw_ir_alloc_vreg(prog); - int v_r0 = omega_bw_ir_alloc_vreg(prog); - int v_r1 = omega_bw_ir_alloc_vreg(prog); - int v_col_b = omega_bw_ir_alloc_vreg(prog); - int v_tid_col2 = omega_bw_ir_alloc_vreg(prog); - int v_const_1 = omega_bw_ir_alloc_vreg(prog); - - /* Bundles for HMMA */ - int v_ra = omega_bw_ir_alloc_vreg128(prog); /* Quad: Ra[0]..Ra[3] */ - int v_rb = omega_bw_ir_alloc_vreg64(prog); /* Pair: Rb[0]..Rb[1] */ - int v_rd = omega_bw_ir_alloc_vreg128(prog); /* Quad: Rd[0]..Rd[3] */ - - /* Scratch registers for indexing and loads */ - int v_idx = omega_bw_ir_alloc_vreg(prog); - int v_off = omega_bw_ir_alloc_vreg64(prog); - int v_b_tmp0 = omega_bw_ir_alloc_vreg(prog); - int v_b_tmp1 = omega_bw_ir_alloc_vreg(prog); - - if (v_b_tmp1 < 0) return -1; - - /* 2. Load 64-bit global memory descriptor into uniform register pair */ - /* LDCU.64 uv_desc, c[0x0][0x358] */ - BlackwellIRInsn insn_desc = { .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true }; - omega_bw_ir_append(prog, &insn_desc); - - /* 3. Load 64-bit base pointers from Constant Bank 0 */ - /* LDC.64 v_ptr_a, c[0x0][0x380] */ - BlackwellIRInsn insn_ptra = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380 }; - omega_bw_ir_append(prog, &insn_ptra); - - /* LDC.64 v_ptr_b, c[0x0][0x388] */ - BlackwellIRInsn insn_ptrb = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388 }; - omega_bw_ir_append(prog, &insn_ptrb); - - /* LDC.64 v_ptr_c, c[0x0][0x390] */ - BlackwellIRInsn insn_ptrc = { .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390 }; - omega_bw_ir_append(prog, &insn_ptrc); - - /* 4. Query Special Registers */ - /* S2R v_tid, SR_TID.X */ - BlackwellIRInsn insn_tidx = { .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X }; - omega_bw_ir_append(prog, &insn_tidx); - - /* S2R v_ctaid_x, SR_CTAID.X */ - BlackwellIRInsn insn_cta_x = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X }; - omega_bw_ir_append(prog, &insn_cta_x); - - /* S2R v_ctaid_y, SR_CTAID.Y */ - BlackwellIRInsn insn_cta_y = { .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y }; - omega_bw_ir_append(prog, &insn_cta_y); - - /* 5. Set up constant 1 */ - BlackwellIRInsn insn_c1 = { .op = BW_IR_MOV_IMM, .dst_vreg = v_const_1, .imm = 1 }; - omega_bw_ir_append(prog, &insn_c1); - - /* 6. Extract warp-level tile and thread coordinates */ - /* group_id = tid >> 2 */ - BlackwellIRInsn insn_grp = { .op = BW_IR_SHF_R, .dst_vreg = v_group_id, .src1_vreg = v_tid, .imm = 2 }; - omega_bw_ir_append(prog, &insn_grp); - - /* tid_in_grp = tid & 3 */ - BlackwellIRInsn insn_tig = { .op = BW_IR_LOP3_AND, .dst_vreg = v_tid_in_grp, .src1_vreg = v_tid, .imm = 3 }; - omega_bw_ir_append(prog, &insn_tig); - - /* row_base = ctaid_y * 16 */ - BlackwellIRInsn insn_rbase = { .op = BW_IR_IMAD, .dst_vreg = v_row_base, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_rbase); - - /* col_base = ctaid_x * 8 */ - BlackwellIRInsn insn_cbase = { .op = BW_IR_IMAD, .dst_vreg = v_col_base, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 8, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_cbase); - - /* r0 = row_base + group_id */ - BlackwellIRInsn insn_r0 = { .op = BW_IR_IADD3, .dst_vreg = v_r0, .src1_vreg = v_row_base, .src2_vreg = v_group_id, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_r0); - - /* r1 = r0 + 8 */ - BlackwellIRInsn insn_r1 = { .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0 }; - omega_bw_ir_append(prog, &insn_r1); - - /* col_b = col_base + group_id */ - BlackwellIRInsn insn_colb = { .op = BW_IR_IADD3, .dst_vreg = v_col_b, .src1_vreg = v_col_base, .src2_vreg = v_group_id, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_colb); - - /* tid_col2 = tid_in_grp * 2 */ - BlackwellIRInsn insn_tcol2 = { .op = BW_IR_IMAD, .dst_vreg = v_tid_col2, .src1_vreg = v_tid_in_grp, .src2_vreg = -1, .imm = 2, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_tcol2); - - /* 7. Load A fragments (16x16 row-major, 2 bytes/element, row stride 32 bytes) */ - /* Pair 0: a0, a1 at r0 * 32 + tid_col2 * 2 */ - BlackwellIRInsn insn_a0_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_a0_idx1); - BlackwellIRInsn insn_a0_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_a0_idx2); - BlackwellIRInsn insn_a0_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a }; - omega_bw_ir_append(prog, &insn_a0_off); - BlackwellIRInsn insn_lda0 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 0, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 }; - omega_bw_ir_append(prog, &insn_lda0); - - /* Pair 1: a2, a3 at r1 * 32 + tid_col2 * 2 */ - BlackwellIRInsn insn_a1_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_a1_idx1); - BlackwellIRInsn insn_a1_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_a1_idx2); - BlackwellIRInsn insn_a1_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a }; - omega_bw_ir_append(prog, &insn_a1_off); - BlackwellIRInsn insn_lda1 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 1, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 }; - omega_bw_ir_append(prog, &insn_lda1); - - /* Pair 2: a4, a5 at r0 * 32 + tid_col2 * 2 + 16 */ - BlackwellIRInsn insn_a2_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_a2_idx1); - BlackwellIRInsn insn_a2_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_a2_idx2); - BlackwellIRInsn insn_a2_idx3 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_a2_idx3); - BlackwellIRInsn insn_a2_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a }; - omega_bw_ir_append(prog, &insn_a2_off); - BlackwellIRInsn insn_lda2 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 2, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 }; - omega_bw_ir_append(prog, &insn_lda2); - - /* Pair 3: a6, a7 at r1 * 32 + tid_col2 * 2 + 16 */ - BlackwellIRInsn insn_a3_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = 32, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_a3_idx1); - BlackwellIRInsn insn_a3_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = 2, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_a3_idx2); - BlackwellIRInsn insn_a3_idx3 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_a3_idx3); - BlackwellIRInsn insn_a3_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 1, .src3_vreg = v_ptr_a }; - omega_bw_ir_append(prog, &insn_a3_off); - BlackwellIRInsn insn_lda3 = { .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 3, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x001ea800 }; - omega_bw_ir_append(prog, &insn_lda3); - - /* 8. Load and pack B fragments (16xN row-major, 2 bytes/element) */ - /* b0 at tid_col2 * N + col_b */ - BlackwellIRInsn insn_b0_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_b }; - omega_bw_ir_append(prog, &insn_b0_idx); - BlackwellIRInsn insn_b0_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b }; - omega_bw_ir_append(prog, &insn_b0_off); - BlackwellIRInsn insn_ldb0 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp0, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 }; - omega_bw_ir_append(prog, &insn_ldb0); - - /* b1 at (tid_col2 + 1) * N + col_b = b0_idx + N */ - BlackwellIRInsn insn_b1_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_b1_idx); - BlackwellIRInsn insn_b1_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b }; - omega_bw_ir_append(prog, &insn_b1_off); - BlackwellIRInsn insn_ldb1 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp1, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 }; - omega_bw_ir_append(prog, &insn_ldb1); - - /* Pack Rb[0] = (b1 << 16) | b0 (wait on barrier 2) */ - BlackwellIRInsn insn_pack_b0 = { .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 0, .src1_vreg = v_b_tmp1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b_tmp0, .control = 0x004fca00 }; - omega_bw_ir_append(prog, &insn_pack_b0); - - /* b2 at (tid_col2 + 8) * N + col_b */ - BlackwellIRInsn insn_b2_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tid_col2, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_b }; - omega_bw_ir_append(prog, &insn_b2_idx1); - BlackwellIRInsn insn_b2_idx2 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 8 * spec->n, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_b2_idx2); - BlackwellIRInsn insn_b2_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b }; - omega_bw_ir_append(prog, &insn_b2_off); - BlackwellIRInsn insn_ldb2 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp0, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 }; - omega_bw_ir_append(prog, &insn_ldb2); - - /* b3 at (tid_col2 + 9) * N + col_b = b2_idx + N */ - BlackwellIRInsn insn_b3_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_b3_idx); - BlackwellIRInsn insn_b3_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b }; - omega_bw_ir_append(prog, &insn_b3_off); - BlackwellIRInsn insn_ldb3 = { .op = BW_IR_LDG_E_U16, .dst_vreg = v_b_tmp1, .src1_vreg = v_off, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = 0x002ea800 }; - omega_bw_ir_append(prog, &insn_ldb3); - - /* Pack Rb[1] = (b3 << 16) | b2 (wait on barrier 2) */ - BlackwellIRInsn insn_pack_b1 = { .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 1, .src1_vreg = v_b_tmp1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b_tmp0, .control = 0x004fca00 }; - omega_bw_ir_append(prog, &insn_pack_b1); - - /* 9. Execute HMMA Tensor Core instruction (wait on barrier 1 for A loads) */ - BlackwellIROpcode mma_op = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16; - BlackwellIRInsn insn_hmma = { - .op = mma_op, - .dst_vreg = v_rd, - .dst_subreg = 0, - .src1_vreg = v_ra, - .src1_subreg = 0, - .src2_vreg = v_rb, - .src2_subreg = 0, - .src3_vreg = -1, /* RZ accumulator input */ - .control = 0x002fca00 /* Wait on barrier 1 */ - }; - omega_bw_ir_append(prog, &insn_hmma); - - /* 10. Store C output fragments (16xN row-major, 4 bytes/float element) */ - /* d0: row r0, col col_base + tid_col2 + 0 */ - BlackwellIRInsn insn_d0_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_base }; - omega_bw_ir_append(prog, &insn_d0_idx1); - BlackwellIRInsn insn_d0_idx2 = { .op = BW_IR_IADD3, .dst_vreg = v_idx, .src1_vreg = v_idx, .src2_vreg = v_tid_col2, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_d0_idx2); - BlackwellIRInsn insn_d0_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c }; - omega_bw_ir_append(prog, &insn_d0_off); - BlackwellIRInsn insn_std0 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 0, .ureg = uv_desc, .control = 0x000fe200 }; - omega_bw_ir_append(prog, &insn_std0); - - /* d1: row r0, col col_base + tid_col2 + 1 */ - BlackwellIRInsn insn_d1_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 1, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_d1_idx); - BlackwellIRInsn insn_d1_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c }; - omega_bw_ir_append(prog, &insn_d1_off); - BlackwellIRInsn insn_std1 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 1, .ureg = uv_desc, .control = 0x000fe200 }; - omega_bw_ir_append(prog, &insn_std1); - - /* d2: row r1, col col_base + tid_col2 + 0 */ - BlackwellIRInsn insn_d2_idx1 = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = spec->n, .src3_vreg = v_col_base }; - omega_bw_ir_append(prog, &insn_d2_idx1); - BlackwellIRInsn insn_d2_idx2 = { .op = BW_IR_IADD3, .dst_vreg = v_idx, .src1_vreg = v_idx, .src2_vreg = v_tid_col2, .src3_vreg = -1 }; - omega_bw_ir_append(prog, &insn_d2_idx2); - BlackwellIRInsn insn_d2_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c }; - omega_bw_ir_append(prog, &insn_d2_off); - BlackwellIRInsn insn_std2 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 2, .ureg = uv_desc, .control = 0x000fe200 }; - omega_bw_ir_append(prog, &insn_std2); - - /* d3: row r1, col col_base + tid_col2 + 1 */ - BlackwellIRInsn insn_d3_idx = { .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_const_1, .src2_vreg = -1, .imm = 1, .src3_vreg = v_idx }; - omega_bw_ir_append(prog, &insn_d3_idx); - BlackwellIRInsn insn_d3_off = { .op = BW_IR_IMAD_WIDE, .dst_vreg = v_off, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c }; - omega_bw_ir_append(prog, &insn_d3_off); - BlackwellIRInsn insn_std3 = { .op = BW_IR_STG_E, .src1_vreg = v_off, .src2_vreg = v_rd, .src2_subreg = 3, .ureg = uv_desc, .control = 0x000fe200 }; - omega_bw_ir_append(prog, &insn_std3); - - /* 11. Program Exit */ - BlackwellIRInsn insn_exit = { .op = BW_IR_EXIT }; - omega_bw_ir_append(prog, &insn_exit); - BlackwellIRInsn insn_bra = { .op = BW_IR_BRA }; - omega_bw_ir_append(prog, &insn_bra); - - /* 12. Run bounded register allocation */ - if (omega_bw_regalloc_solve(prog) != 0) { - return -1; - } - return 0; -} - -#ifndef OMEGA_GPU_NO_POSIX -int omega_blackwell_codegen_matmul_tensor(const OmegaMatMulSpec *spec, OmegaBlackwellKernel *kernel) { - if (!spec || !kernel) return -1; - BlackwellIRProgram prog; - if (omega_blackwell_codegen_matmul_tensor_prog(spec, &prog) != 0) { - return -1; - } - - return bw_kernel_alloc_encode(&prog, OMEGA_BW_CODE_CAP_SMALL, kernel); -} -#endif - -/* ---- FB-1 cut 1b: looped tensor matmul ------------------------------------------ - * - * Control words (bundle bits 105..125, decoded from the chip-proven kernel and from - * the vendor compiler's SASS for an equivalent HMMA loop on this chip, 2026-10-04): - * stall = bits 9..12 of w[3], yield = 13, write barrier = 14..16, read barrier = - * 17..19, wait mask = 20..25. 7 in a barrier field means "none". - * LDG (A) 0x001ea800 stall 4, yield, sets SB2 - * LDG.U16 (B) 0x002ea800 stall 4, yield, sets SB2 - * pack IMAD 0x004fca00 stall 5, waits SB2 (every outstanding load has landed) - * HMMA 0x002fca00 stall 5 (fixed latency: the vendor compiler sets no - * write barrier on HMMA either; consumers wait by stall count) - * STG 0x0007e200 stall 1, yield, read barrier SB3 (the store may read its - * data/address registers late; the next writer waits SB3) - * wait SB3 mask bit 23 (0x00800000) on the first instruction that overwrites a - * register a store reads: the C pointer advance. - * Loop-carried registers are kept live to the end of their loop (keep_alive) because - * the allocator is a straight-line linear scan and knows nothing about back edges. - */ -static void bw_keep_alive(BlackwellIRProgram *prog, int from_idx, int to_idx, int last_idx) { - /* every vreg first defined in [from_idx, to_idx) stays live until last_idx */ - for (int v = 0; v < prog->regalloc.num_vregs; v++) { - OmegaLiveInterval *iv = &prog->regalloc.intervals[v]; - if (iv->first_def >= from_idx && iv->first_def < to_idx && iv->last_use < last_idx) - iv->last_use = last_idx; - } -} - -#define BW_APPEND(prog, ...) do { BlackwellIRInsn _i = { __VA_ARGS__ }; if (omega_bw_ir_append((prog), &_i) < 0) return -1; } while (0) - -int omega_blackwell_codegen_matmul_tensor_loop_prog(const OmegaMatMulSpec *spec, uint32_t grid_x, - int mutant, BlackwellIRProgram *prog) { - if (!spec || !prog) return -1; - if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1; - if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1; - if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k % 16 != 0) { - BW_DIAG("ERROR: looped MatMul tensor codegen requires M%%16, N%%8, K%%16 (got %ux%ux%u)\n", - spec->m, spec->k, spec->n); - return -1; - } - const uint32_t K = spec->k, N = spec->n, NT = N / 8, KSTEPS = K / 16; - if (grid_x == 0 || grid_x > NT) return -1; - /* every immediate below must fit 32 bits: 32 * N (B row-block stride in bytes) is the largest */ - if ((uint64_t)N * 32u > 0xffffffffull || (uint64_t)grid_x * 32u > 0xffffffffull) return -1; - if (mutant && KSTEPS < 2) return -1; - - omega_bw_ir_init(prog); - - int v_ptr_a = omega_bw_ir_alloc_vreg64(prog), v_ptr_b = omega_bw_ir_alloc_vreg64(prog), v_ptr_c = omega_bw_ir_alloc_vreg64(prog); - int uv_desc = omega_bw_ir_alloc_uvreg64(prog); - int v_tid = omega_bw_ir_alloc_vreg(prog), v_ctaid_x = omega_bw_ir_alloc_vreg(prog), v_ctaid_y = omega_bw_ir_alloc_vreg(prog); - int v_group = omega_bw_ir_alloc_vreg(prog), v_tig = omega_bw_ir_alloc_vreg(prog), v_tcol2 = omega_bw_ir_alloc_vreg(prog); - int v_r0 = omega_bw_ir_alloc_vreg(prog), v_r1 = omega_bw_ir_alloc_vreg(prog), v_c1 = omega_bw_ir_alloc_vreg(prog); - int v_idx = omega_bw_ir_alloc_vreg(prog), v_col = omega_bw_ir_alloc_vreg(prog), v_cnt = omega_bw_ir_alloc_vreg(prog); - int v_pa0 = omega_bw_ir_alloc_vreg64(prog), v_pa1 = omega_bw_ir_alloc_vreg64(prog), v_pbcol = omega_bw_ir_alloc_vreg64(prog); - int v_pc0 = omega_bw_ir_alloc_vreg64(prog), v_pc1 = omega_bw_ir_alloc_vreg64(prog); - int v_pa0c = omega_bw_ir_alloc_vreg64(prog), v_pa1c = omega_bw_ir_alloc_vreg64(prog), v_pbc = omega_bw_ir_alloc_vreg64(prog); - int v_ta2 = omega_bw_ir_alloc_vreg64(prog), v_ta3 = omega_bw_ir_alloc_vreg64(prog); - int v_tb1 = omega_bw_ir_alloc_vreg64(prog), v_tb2 = omega_bw_ir_alloc_vreg64(prog), v_tb3 = omega_bw_ir_alloc_vreg64(prog); - int v_tc1 = omega_bw_ir_alloc_vreg64(prog), v_tc3 = omega_bw_ir_alloc_vreg64(prog); - int v_ra = omega_bw_ir_alloc_vreg128(prog), v_rb = omega_bw_ir_alloc_vreg64(prog), v_rd = omega_bw_ir_alloc_vreg128(prog); - int v_b0 = omega_bw_ir_alloc_vreg(prog), v_b1 = omega_bw_ir_alloc_vreg(prog); - if (v_b1 < 0 || uv_desc < 0) return -1; - - const uint32_t CTRL_LDA = 0x001ea800u, CTRL_LDB = 0x002ea800u, CTRL_PACK = 0x004fca00u; - const uint32_t CTRL_HMMA = 0x002fca00u, CTRL_STG_RDBAR3 = 0x0007e200u, CTRL_IMADW_WAIT3 = 0x009fcc00u; - const uint32_t CTRL_MOVRZ_WAIT3 = 0x008fe200u; - - /* prologue: descriptor, pointers, ids */ - BW_APPEND(prog, .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true); - BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380); - BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388); - BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390); - BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X); - BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X); - BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y); - BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_c1, .imm = 1); - BW_APPEND(prog, .op = BW_IR_SHF_R, .dst_vreg = v_group, .src1_vreg = v_tid, .imm = 2); - BW_APPEND(prog, .op = BW_IR_LOP3_AND, .dst_vreg = v_tig, .src1_vreg = v_tid, .imm = 3); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_tcol2, .src1_vreg = v_tig, .src2_vreg = -1, .imm = 2, .src3_vreg = -1); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r0, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = v_group); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0); - /* pa0 = A + (r0*K + tcol2)*2 ; pa1 likewise with r1 (A row-major, K bf16 per row) */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = K, .src3_vreg = v_tcol2); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_a); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = K, .src3_vreg = v_tcol2); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_a); - /* col = ctaid_x (first column tile of this CTA) */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 1, .src3_vreg = -1); - /* pbcol = B + (tcol2*N + col*8 + group)*2 */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_tcol2, .src2_vreg = -1, .imm = N, .src3_vreg = v_group); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 2, .src3_vreg = v_ptr_b); - /* pc0 = C + (r0*N + col*8 + tcol2)*4 ; pc1 with r1 */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c); - - /* ---- column-tile loop ---- */ - const int L_col = (int)prog->count; - /* accumulator = 0 (the first write waits SB3: the previous tile's stores may still read it) */ - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 0, .control = CTRL_MOVRZ_WAIT3); - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 1); - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 2); - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 3); - /* K cursors start at the row/column bases (IMAD.WIDE with imm 0 is a 64-bit copy) */ - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa0c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa0); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa1c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa1); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pbcol); - BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_cnt, .imm = mutant ? KSTEPS - 1 : KSTEPS); - - /* ---- K loop: one 16x16 A fragment and one 16x8 B fragment per step ---- */ - const int L_k = (int)prog->count; - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_ta2, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_pa0c); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_ta3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 16, .src3_vreg = v_pa1c); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tb1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 2u * N, .src3_vreg = v_pbc); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tb2, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 16u * N, .src3_vreg = v_pbc); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tb3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 18u * N, .src3_vreg = v_pbc); - /* A: a0,a1 at (r0, kk+tcol2) ; a2,a3 at (r1, ...) ; a4,a5 at (r0, +8) ; a6,a7 at (r1, +8) */ - BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 0, .src1_vreg = v_pa0c, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA); - BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 1, .src1_vreg = v_pa1c, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA); - BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 2, .src1_vreg = v_ta2, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA); - BW_APPEND(prog, .op = BW_IR_LDG_E, .dst_vreg = v_ra, .dst_subreg = 3, .src1_vreg = v_ta3, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDA); - /* B: rows kk+tcol2, +1, +8, +9 at column col*8+group */ - BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b0, .src1_vreg = v_pbc, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB); - BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b1, .src1_vreg = v_tb1, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 0, .src1_vreg = v_b1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b0, .control = CTRL_PACK); - BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b0, .src1_vreg = v_tb2, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB); - BW_APPEND(prog, .op = BW_IR_LDG_E_U16, .dst_vreg = v_b1, .src1_vreg = v_tb3, .src2_vreg = -1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_LDB); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_rb, .dst_subreg = 1, .src1_vreg = v_b1, .src2_vreg = -1, .imm = 0x10000, .src3_vreg = v_b0, .control = CTRL_PACK); - /* rd += ra * rb (accumulate in place) */ - BW_APPEND(prog, .op = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16, - .dst_vreg = v_rd, .dst_subreg = 0, .src1_vreg = v_ra, .src1_subreg = 0, .src2_vreg = v_rb, .src2_subreg = 0, - .src3_vreg = v_rd, .src3_subreg = 0, .control = CTRL_HMMA); - /* advance K: A by 16 bf16 (32 bytes), B by 16 rows (32 N bytes); every load above has landed (packs waited SB2) */ - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa0c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 32, .src3_vreg = v_pa0c); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa1c, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 32, .src3_vreg = v_pa1c); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 32u * N, .src3_vreg = v_pbc); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_cnt, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0xffffffffu, .src3_vreg = v_cnt); - BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_cnt, .src2_vreg = -1, .imm = 1, .src3_vreg = -1); - { - int here = (int)prog->count; - BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_k - here), .predicate_p0 = true); - } - const int L_k_end = (int)prog->count - 1; - - /* ---- store the 16x8 tile: d0 (r0, c), d1 (r0, c+1), d2 (r1, c), d3 (r1, c+1) ---- */ - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc0); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc1); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc0, .src2_vreg = v_rd, .src2_subreg = 0, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc1, .src2_vreg = v_rd, .src2_subreg = 1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc1, .src2_vreg = v_rd, .src2_subreg = 2, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc3, .src2_vreg = v_rd, .src2_subreg = 3, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); - /* next column tile of this CTA: col += grid_x ; B by grid_x*8 bf16 ; C by grid_x*8 f32 (waits SB3 first) */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x, .src3_vreg = v_col); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 32u, .src3_vreg = v_pc0, .control = CTRL_IMADW_WAIT3); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 32u, .src3_vreg = v_pc1); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_c1, .src2_vreg = -1, .imm = grid_x * 16u, .src3_vreg = v_pbcol); - BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_col, .src2_vreg = -1, .imm = NT, .src3_vreg = -1); - { - int here = (int)prog->count; - BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_col - here), .predicate_p0 = true, .predicate_not = true); - } - const int L_col_end = (int)prog->count - 1; - BW_APPEND(prog, .op = BW_IR_EXIT); - BW_APPEND(prog, .op = BW_IR_BRA); - - /* loop-carried values live to the end of their loop */ - bw_keep_alive(prog, 0, L_col, L_col_end); - bw_keep_alive(prog, L_col, L_k, L_k_end); - /* K-loop temporaries too: a load's address pair must never be recycled by a - * later instruction of the same iteration (the load may read it late). */ - bw_keep_alive(prog, L_k, L_k_end, L_k_end); - /* the accumulator is read by the stores after the K loop */ - if (prog->regalloc.intervals[v_rd].last_use < L_col_end) prog->regalloc.intervals[v_rd].last_use = L_col_end; - - return omega_bw_regalloc_solve(prog); -} - -#ifndef OMEGA_GPU_NO_POSIX -int omega_blackwell_codegen_matmul_tensor_loop(const OmegaMatMulSpec *spec, uint32_t grid_x, - int mutant, OmegaBlackwellKernel *kernel) { - if (!spec || !kernel) return -1; - BlackwellIRProgram prog; - if (omega_blackwell_codegen_matmul_tensor_loop_prog(spec, grid_x, mutant, &prog) != 0) return -1; - return bw_kernel_alloc_encode(&prog, OMEGA_BW_CODE_CAP_SMALL, kernel); -} -#endif - -/* ---- omega #328: fragment-major tensor matmul ---------------------------------------- - * - * The looped kernel above reads B as four scattered 2-byte loads per K step and waits for - * them before the next step (pack waits SB2), so each warp has one 256-byte step in flight; - * at m = 1 on GB10 that streams the weights at about 28 GB/s (omega #328 measurement). - * Here A and B arrive in the order HMMA.16816 consumes them (omega_matmul_frag_pack_a / _b): - * A block (mt, ks): 512 bytes, lane L at L*16: a0..a7, one LDG.E.128 per step; - * B block (nt, ks): 256 bytes, lane L at L*8: b0..b3, one LDG.E.64 per step; - * consecutive K steps of one tile are adjacent, so a warp streams its column tile. Each loop - * pass issues `unroll` steps of loads at immediate offsets (A on SB2, B on SB4), then runs the HMMA - * chain: every HMMA waits SB2 and SB4 (stall 15) and a NOP (stall 14) follows it, the 29 cycles nvcc - * puts between dependent HMMA.16816 (omega_blackwell_verify_codegen_fixtures_fragmm). - * The cursors advance only after the chain, when every load has landed (the HMMAs waited - * SB2 and SB4), as in the looped kernel. Stores, the column-tile loop and the C layout (row-major - * f32) are the looped kernel's. */ -/* A loads set SB2 and B loads SB4 (nvcc spreads loads over several scoreboards too); at the - * product unroll of 4 that is 4 loads per scoreboard per pass. The scoreboard depth is not - * documented to us; splitting did not make unroll 8 complete (omega_matmul_frag_unroll). */ -#define BW_FRAG_CTRL_LDG_A 0x000ea800u /* stall 4, yield, sets SB2 (nvcc word) */ -#define BW_FRAG_CTRL_LDG_B 0x000f2800u /* stall 4, yield, sets SB4 (nvcc word) */ -#define BW_FRAG_CTRL_HMMA 0x014fde00u /* stall 15, waits SB2 and SB4 (nvcc: dependent HMMA chain) */ -#define BW_FRAG_CTRL_NOP 0x000fdc00u /* stall 14 (nvcc, between dependent HMMAs) */ - -static void bw_live_until(BlackwellIRProgram *prog, int vreg, int last_idx) { - if (prog->regalloc.intervals[vreg].last_use < last_idx) prog->regalloc.intervals[vreg].last_use = last_idx; -} - -int omega_blackwell_codegen_matmul_frag_prog(const OmegaMatMulSpec *spec, uint32_t grid_x, uint32_t unroll, - int mutant, BlackwellIRProgram *prog) { - if (!spec || !prog) return -1; - if (spec->m == 0 || spec->k == 0 || spec->n == 0) return -1; - if (spec->precision != OMEGA_MATMUL_PRECISION_FP16 && spec->precision != OMEGA_MATMUL_PRECISION_BF16) return -1; - if (spec->m % 16 != 0 || spec->n % 8 != 0 || spec->k % 16 != 0) return -1; - if (unroll != 1 && unroll != 2 && unroll != 4 && unroll != 8) return -1; - const uint32_t K = spec->k, N = spec->n, NT = N / 8, KS = K / 16; - if (KS % unroll != 0) return -1; - const uint32_t ITERS = KS / unroll; - if (grid_x == 0 || grid_x > NT) return -1; - if (mutant && ITERS < 2) return -1; - /* every index and immediate below must fit 32 bits (rows up to OMEGA_BW_MATMUL_MAX_M) */ - if ((uint64_t)NT * KS * 32u > 0xffffffffull || (uint64_t)(OMEGA_BW_MATMUL_MAX_M / 16u) * KS * 32u > 0xffffffffull || - (uint64_t)grid_x * KS * 256u > 0xffffffffull || (uint64_t)N * 32u > 0xffffffffull || - (uint64_t)OMEGA_BW_MATMUL_MAX_M * N > 0xffffffffull) - return -1; - - omega_bw_ir_init(prog); - int v_ptr_a = omega_bw_ir_alloc_vreg64(prog), v_ptr_b = omega_bw_ir_alloc_vreg64(prog), v_ptr_c = omega_bw_ir_alloc_vreg64(prog); - int uv_desc = omega_bw_ir_alloc_uvreg64(prog); - int v_tid = omega_bw_ir_alloc_vreg(prog), v_ctaid_x = omega_bw_ir_alloc_vreg(prog), v_ctaid_y = omega_bw_ir_alloc_vreg(prog); - int v_group = omega_bw_ir_alloc_vreg(prog), v_tig = omega_bw_ir_alloc_vreg(prog), v_tcol2 = omega_bw_ir_alloc_vreg(prog); - int v_r0 = omega_bw_ir_alloc_vreg(prog), v_r1 = omega_bw_ir_alloc_vreg(prog), v_c1 = omega_bw_ir_alloc_vreg(prog); - int v_idx = omega_bw_ir_alloc_vreg(prog), v_col = omega_bw_ir_alloc_vreg(prog), v_cnt = omega_bw_ir_alloc_vreg(prog); - int v_pa = omega_bw_ir_alloc_vreg64(prog), v_pbcol = omega_bw_ir_alloc_vreg64(prog); - int v_pc0 = omega_bw_ir_alloc_vreg64(prog), v_pc1 = omega_bw_ir_alloc_vreg64(prog); - int v_pac = omega_bw_ir_alloc_vreg64(prog), v_pbc = omega_bw_ir_alloc_vreg64(prog); - int v_tc1 = omega_bw_ir_alloc_vreg64(prog), v_tc3 = omega_bw_ir_alloc_vreg64(prog); - int v_rd = omega_bw_ir_alloc_vreg128(prog); - int v_ra[8], v_rb[8]; - for (uint32_t u = 0; u < unroll; u++) { v_ra[u] = omega_bw_ir_alloc_vreg128(prog); v_rb[u] = omega_bw_ir_alloc_vreg64(prog); } - if (v_rb[unroll - 1] < 0 || v_ra[unroll - 1] < 0 || uv_desc < 0) return -1; - - const uint32_t CTRL_STG_RDBAR3 = 0x0007e200u, CTRL_IMADW_WAIT3 = 0x009fcc00u, CTRL_MOVRZ_WAIT3 = 0x008fe200u; - - /* prologue: descriptor, pointers, ids (as the looped kernel) */ - BW_APPEND(prog, .op = BW_IR_LDCU64, .dst_vreg = uv_desc, .imm = 0x358, .is_uniform = true); - BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_a, .imm = 0x380); - BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_b, .imm = 0x388); - BW_APPEND(prog, .op = BW_IR_LDC64, .dst_vreg = v_ptr_c, .imm = 0x390); - BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_tid, .imm = BW_SR_TID_X); - BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_x, .imm = BW_SR_CTAID_X); - BW_APPEND(prog, .op = BW_IR_S2R, .dst_vreg = v_ctaid_y, .imm = BW_SR_CTAID_Y); - BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_c1, .imm = 1); - BW_APPEND(prog, .op = BW_IR_SHF_R, .dst_vreg = v_group, .src1_vreg = v_tid, .imm = 2); - BW_APPEND(prog, .op = BW_IR_LOP3_AND, .dst_vreg = v_tig, .src1_vreg = v_tid, .imm = 3); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_tcol2, .src1_vreg = v_tig, .src2_vreg = -1, .imm = 2, .src3_vreg = -1); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r0, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = 16, .src3_vreg = v_group); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_r1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 8, .src3_vreg = v_r0); - /* pa = A + (ctaid_y * KS * 32 + tid) * 16: this CTA's row tile, this lane's 16 bytes of step 0 */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_ctaid_y, .src2_vreg = -1, .imm = KS * 32u, .src3_vreg = v_tid); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pa, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 16, .src3_vreg = v_ptr_a); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_col, .src1_vreg = v_ctaid_x, .src2_vreg = -1, .imm = 1, .src3_vreg = -1); - /* pbcol = B + (col * KS * 32 + tid) * 8: column tile col, this lane's 8 bytes of step 0 */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = KS * 32u, .src3_vreg = v_tid); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbcol, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 8, .src3_vreg = v_ptr_b); - /* pc0 = C + (r0*N + col*8 + tcol2)*4 ; pc1 with r1 */ - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r0, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc0, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_r1, .src2_vreg = -1, .imm = N, .src3_vreg = v_tcol2); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_idx, .src1_vreg = v_col, .src2_vreg = -1, .imm = 8, .src3_vreg = v_idx); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pc1, .src1_vreg = v_idx, .src2_vreg = -1, .imm = 4, .src3_vreg = v_ptr_c); - - /* ---- column-tile loop ---- */ - const int L_col = (int)prog->count; - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 0, .control = CTRL_MOVRZ_WAIT3); - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 1); - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 2); - BW_APPEND(prog, .op = BW_IR_MOV_RZ, .dst_vreg = v_rd, .dst_subreg = 3); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pac, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pa); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0, .src3_vreg = v_pbcol); - BW_APPEND(prog, .op = BW_IR_MOV_IMM, .dst_vreg = v_cnt, .imm = mutant ? ITERS - 1 : ITERS); - - /* ---- K loop: `unroll` steps of loads, then the HMMA chain ---- */ - const int L_k = (int)prog->count; - for (uint32_t u = 0; u < unroll; u++) { - BW_APPEND(prog, .op = BW_IR_LDG_E_128, .dst_vreg = v_ra[u], .src1_vreg = v_pac, .src2_vreg = -1, .src3_vreg = -1, - .ureg = uv_desc, .imm = u * 512u, .control = BW_FRAG_CTRL_LDG_A); - BW_APPEND(prog, .op = BW_IR_LDG_E_64, .dst_vreg = v_rb[u], .src1_vreg = v_pbc, .src2_vreg = -1, .src3_vreg = -1, - .ureg = uv_desc, .imm = u * 256u, .control = BW_FRAG_CTRL_LDG_B); - } - const BlackwellIROpcode hmma = (spec->precision == OMEGA_MATMUL_PRECISION_BF16) ? BW_IR_HMMA_BF16 : BW_IR_HMMA_F16; - for (uint32_t u = 0; u < unroll; u++) { - BW_APPEND(prog, .op = hmma, .dst_vreg = v_rd, .src1_vreg = v_ra[u], .src2_vreg = v_rb[u], .src3_vreg = v_rd, - .control = BW_FRAG_CTRL_HMMA); - BW_APPEND(prog, .op = BW_IR_NOP, .dst_vreg = -1, .src1_vreg = -1, .src2_vreg = -1, .src3_vreg = -1, .ureg = -1, - .control = BW_FRAG_CTRL_NOP); - } - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pac, .src1_vreg = v_c1, .src2_vreg = -1, .imm = unroll * 512u, .src3_vreg = v_pac); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_pbc, .src1_vreg = v_c1, .src2_vreg = -1, .imm = unroll * 256u, .src3_vreg = v_pbc); - BW_APPEND(prog, .op = BW_IR_IMAD, .dst_vreg = v_cnt, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 0xffffffffu, .src3_vreg = v_cnt); - BW_APPEND(prog, .op = BW_IR_ISETP_GE, .dst_vreg = -1, .src1_vreg = v_cnt, .src2_vreg = -1, .imm = 1, .src3_vreg = -1); - { - int here = (int)prog->count; - BW_APPEND(prog, .op = BW_IR_BRA, .imm = (uint32_t)(int32_t)(L_k - here), .predicate_p0 = true); - } - const int L_k_end = (int)prog->count - 1; - - /* ---- store the 16x8 tile (as the looped kernel) ---- */ - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc1, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc0); - BW_APPEND(prog, .op = BW_IR_IMAD_WIDE, .dst_vreg = v_tc3, .src1_vreg = v_c1, .src2_vreg = -1, .imm = 4, .src3_vreg = v_pc1); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc0, .src2_vreg = v_rd, .src2_subreg = 0, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_tc1, .src2_vreg = v_rd, .src2_subreg = 1, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); - BW_APPEND(prog, .op = BW_IR_STG_E, .src1_vreg = v_pc1, .src2_vreg = v_rd, .src2_subreg = 2, .src3_vreg = -1, .ureg = uv_desc, .control = CTRL_STG_RDBAR3); ``` The diff is longer than this page shows; the raw diff has all of it.