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/CUDApp/patches/0d18758bf12c274f # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers ## Mirror omega `b5ab3fe` GPU drift and record the rest merged `0d18758bf12c274f` #203 · opened 2026-10-30 22:00 UTC · closed 2026-10-31 02:41 UTC · merged 2026-10-31 02:41 UTC Imported from GitHub aien-dev/CUDApp#203, by drakestapleton Base `802b6c74f77c83b815367be09a4e707c48ed358a` · Head `d2c83a197118d9abc328dee9a64243d9014c15b8` Merged on GitHub as `769997d5697561a646bc4d74224c11f706d779d6`; reachable from main `21d8de285f713adf09e0d6ba6db2b37139d0674e` (observed 2026-11-18T16:38:23Z) drakestapleton wrote on 2026-10-30 22:00 UTC ## Evidence on head `d2c83a197118d9abc328dee9a64243d9014c15b8` - `tools/extract/drift.sh --self-test 4376c2112d7469b6908c6403720c9001de4622b5`, rerun on this head (aarch64 host): - `control 1: red as required (Makefile)` - `control 2: red as required (src/omega_gpu_attention_api.c edited in a scratch Omega commit)` - `DRIFT-GATE: PASS (783 GPU paths, omega 4376c2112d74, none moved away from CUDA++ since the baseline)` - `SELF-TEST: PASS (both controls red, real check green)` - `make test-gpu-decode-graph test-gpu-prefill-host check-own30b-decode-profile test-gpu-fp8-slots test-gpu-fp8gemm` passed at `02538d3` (host and simulator only). `d2c83a1` adds one baseline row and crumbs, no code. - `crumb verify .`: `OK: 33 crumbs current` on this head. - GB10 hardware tests. NOT RUN. No GPU window; `/dev/nvidia*` was not opened. ## What this PR does now Main already holds the earlier omega `b5ab3fe` sync (#207). This branch merged main, took main's side for every file of the earlier `b5ab3fe` commits, and now carries only the sync to omega-mv `4376c2112d7469b6908c6403720c9001de4622b5` (train r3 omega-mv#979, omega#456). Before this branch the drift gate failed on main with 4 of 782 GPU paths changed in omega `4376c2112d74` and not in CUDA++: `Makefile`, `src/omega_gpu_decode_graph.c`, `src/omega_gpu_fp8_api.c`, `tests/gpu_fp8gemm_test.c`. Carried from omega#456: - the decode graph per-token timeline never writes past `stamp[]`; new host test `tests/test_omega_gpu_decode_graph_timeline.c` (fake platform, no device) and `test-gpu-decode-graph-timeline` with 2 mutants, run by `test-gpu-decode-graph`; - fp8 tensor upload fills and syncs under the session lock, and `omega_gpu_fp8_test_set_no_fold` writes under the lock; - `gpu_fp8gemm_test` `emu_row` uses a static buffer bounded by k; - `test-gpu-prefill-host` (8 prefill tests, host model and simulator) and `check-own30b-decode-profile` with `tools/own30b_decode_profile.c`. CUDA++ code that was ahead stays: the fp8 upload owner generation and the `test_out_open` 0600 receipt in `gpu_fp8gemm_test`. `tools/extract/drift-baseline.tsv` records the `4376c21` blobs and names those paths. Not carried: the `require_physics_pin.sh` line in omega's chip runners (no such runners here). Drift row: `d2c83a1` adds omega's blob for `tests/test_omega_gpu_decode_graph_timeline.c` to the baseline, so the new mirrored test is tracked by the gate. Crumbs: `crumb compile .` with crumb tool `d0f0b95` also rewrote `om/moe/.crumb` and `tools/extract/.crumb`, which were STALE on main; only generated fields changed. ## Removed from the earlier head `063a0c2` - A stricter dagsim mutant check (the assertion name had to appear on a `FAIL` line). That is a CUDApp gate change without a Drake decision, so it is not in this PR. - The `omega_runtime_api.internal` abort_token row: main declares that function in the manifest as EXPERIMENTAL. ## Known limitations NOT_RUN on GB10: decode graph timeline and fp8 upload locking on the chip; all claims above are host and simulator only. Grokbot drakestapleton reviewed (COMMENTED) on 2026-10-30 22:03 UTC Review at `b3f3d5ea140ec2fc501c9d2ce8b77851545c8bdb` (the head is unchanged; not a draft; base main `b5746b94`). Classification: needs-changes. The PR is small and correct where it mirrors. One recorded divergence hides a real gap and should be mirrored now (tests/gpu_decode_attn_test.c, see below). Three CI jobs were also still running. ### CI at this head (I didn't rely on the VM numbers) - drift (`124335613116`): success. The log says `DRIFT-GATE: PASS (772 GPU paths, omega b5ab3fe94304, none moved away from CUDA++ since the baseline)` and `SELF-TEST: PASS (both controls red, real check green)`. CI's own omega clone resolved to `b5ab3fe94304`. - Passing: runtime-api, library, audit-scanner, sim, build (`124335614026`), build (`124335612635`), om-units, sbom, hello-sim, fresh-checkout, figures, Analyze (actions), Analyze (python). - Neutral: CodeQL. - Still running: host-tests (`124335614249`), x86-host-tests (`124335613853`), Analyze (c-cpp) (`124335609474`). Until host-tests finishes, the author's `HOST TESTS PASS (58 targets)` is a VM receipt only. - Fake-green: none found. No workflow file and no tools/extract/drift.sh change. The self-test still requires both controls red. All 375 data rows in drift-baseline.tsv carry omega's blob at `b5ab3fe` exactly (0 mismatches), so a recorded path goes red again as soon as omega changes it. Nothing is permanently allowlisted. ### Exact mirrors: 18/18 byte-identical I compared git blob SHAs with omega-mv `b5ab3fe943048ac896b368a687a38fdc1dea4077`. All 18 listed paths match, and so do the 7 companions: mk/omega-mufu-ftz.mk, tests/test_omega_gpu_decode_graph_abort.c and the 5 tests/dagsim/fixtures/*.oev. src/omega_cubin.c (frozen, ADR 0044) is untouched, and no backend// path is touched. ### Recorded divergences: 31 of the 49, plus 2 extras The count adds up: 18 mirrored + 31 recorded = 49. The two extras (tests/dagsim/mutant_lifetime.sh, tests/dagsim/mutant_predict.sh) are recorded at drift-baseline.tsv:345 and :347. Each recorded path has a `# Divergence:` reason on the line above its row, and CUDApp's blob does differ from omega's for every one. My verdicts, by drift-baseline.tsv row: Justified: CUDA++ build, docs, ABI or licence - :7 Makefile - :9 docs/runtime/API.md, :11 PORTABILITY.md, :13 omega_runtime_api.manifest, :15 portability_table.tsv (0.6.0 vs omega 0.1) - :158 mk/om-encoder.mk, :161 mk/omega-gpu-engine.mk, :164 mk/runtime-r1.mk, :166 mk/runtime-r3.mk (SPDX only) - :316 src/omega_runtime_api.h (0.6.0) - :406 tests/test_omega_codegen_freestanding.c (licence header only) Justified: not imported (persistent device omega #575 / hazard checker / FP8 slot pool), with ADR 0043 Decision 0 relevance - Persistent device: :210 src/omega_blackwell_engine.c, :212 src/omega_blackwell_engine.h, :404 tests/test_omega_blackwell_engine.c, :351 tests/fake_m16_native.c, :353 tests/fake_m16_native.h. Not importing persistence is consistent with the Decision 0 gate. Making it permanent needs an Architecture ruling. - Hazard checker: :226 src/omega_bw_hazard.c, :228 src/omega_bw_hazard.h, :327 tests/bw_hazard_test.c. Its fixtures quote an nvcc listing, which is a provenance concern. - FP8 slot pool: :254 src/omega_gpu_fp8_api.c, :257 src/omega_gpu_fp8_internal.h, :260 src/omega_gpu_fp8_slots.c, :262 src/omega_gpu_fp8_slots.h, :367 tests/gpu_fp8_slots_test.c. It depends on src/omega_fp8_slot_table.c, which is outside the GPU map. Justified but needs an Architecture ruling - :169 src/omega_blackwell_codegen.c. Besides the header and `cudapp_native.h` differences, I confirmed a real encoding fork: CUDApp emits `LDG.E.MMIO.GPU` with w[2]=0x0c1f1900, and omega now emits `LDG.E.EF` with 0x0c0e1900. Keeping CUDApp's word is right without chip evidence, because both are NOT_RUN on GB10. It is an instruction-encoding decision, though, and should go to Architecture. It isn't omega_cubin.c and isn't under backend//. Acceptable deferral (comment-only, or a test-reference style difference) - :303 src/omega_gpu_session.h (omega's change is comments only) - :355 tests/gpu_attention_test.c, :384 tests/gpu_pfgemm_test.c, :388 tests/gpu_prefill_attn_test.c, :391 tests/gpu_qgemm_test.c (MUFU helper routing). These are reasonable to defer now that tests/bw_mufu_ftz.h is mirrored, but they should be follow-ups. Deferred mirror: should be mirrored now - :361 tests/gpu_decode_attn_test.c. This PR mirrors src/omega_gpu_decode_attn_api.h, which raises MAX_POS to 131072, but keeps the test sampling `% 65536u`. The host has no coverage for the doubled cap. Omega's host-only extension costs nothing, so please mirror it (or add equivalent host checks up to 131072). Chip points above 65536 stay NOT_RUN. Extras (justified): :345 and :347. They link src/sha256.c because this tree has no omega_om_units.c. ### Makefile (hand-edited) - The dagsim unit link adds `-Wl,--wrap=rx_cm_predict`, matching omega. - test-dagsim runs both mutant scripts. - `test-mufu-ftz` is on HOST_TESTS. - test-gpu-decode-graph now depends on the abort test plus 5 sed mutants. Each mutant fails if its pattern isn't found, if it survives, or if it runs with zero FAIL lines. `grep -c … || true` only feeds that count, so it isn't fake-green. ### Companion scripts mutant_lifetime.sh and mutant_predict.sh both use `set -eu` and check that the mutation applied. They require a nonzero exit plus the named assertion in the output. Nit: they only `grep -q` the assertion name, so a crash that happened to print that name in a PASS line would count as a kill. Matching a FAIL-prefixed line would be stricter. ### API surface omega_gpu_decode_graph_abort_token is added to docs/runtime/omega_runtime_api.internal:130 as INTERNAL. src/omega_runtime_api.h is not changed by this PR, so it has no version bump and the public surface stays 0.6.0. The runtime-api job passed. ### Chip claims I found no GB10 or hardware claim without evidence. The PR body marks IMAD.HI even-Rc pairs, MUFU flush, decode-graph abort, contexts above 65536, and the doctor result as NOT_RUN or host-only. The Makefile comment at the #492 note says `chip probe NOT_RUN`. — Grokbot github-advanced-security[bot] reviewed (COMMENTED) on 2026-10-30 22:13 UTC github-advanced-security[bot] commented on `tests/gpu_decode_attn_test.c` line 337 on 2026-10-30 22:13 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 `tests/gpu_decode_attn_test.c` line 435 on 2026-10-30 22:13 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 drakestapleton reviewed (COMMENTED) on 2026-10-30 22:21 UTC Re-review at `063a0c2d9df8956650ea95395433406afc905022`. The head matches what was requested and the PR isn't a draft. Compared with my previous review head `b3f3d5ea`, this push is one commit touching 4 files. Classification: ready-to-merge on content, once host-tests goes green. host-tests (`124339970655`) was still running at 5:20 PM CT. Separately, the failing CodeQL check is the 2 expected alerts in the mirrored test (below), which still need to be dismissed. The must-fix from my last review is resolved. ### 1. tests/gpu_decode_attn_test.c - Now a byte copy of omega. Its blob is `ff35e2a039efa661a056ab6a289e47a9b43cc73b`, the same blob the baseline recorded for omega-mv `b5ab3fe`. - Recorded row removed. The `# Divergence` comment and the row (formerly drift-baseline.tsv:360-361) are both gone. - The 131072 cap is now covered on the host: - fixed positions now include 65536, 99999 and 131071; - the random samples are taken `% OMEGA_GPU_DATTN_MAX_POS`; - a new check refuses `OMEGA_GPU_DATTN_MAX_POS + 256` before any device work. - Chip points 65536, 100000 and 131072 were added to the default chip mode. These are NOT_RUN: no receipt is claimed. ### 2. LDG word divergence in src/omega_blackwell_codegen.c (drift-baseline.tsv:168) The comment now records the encoder word as a CUDApp edit: CUDApp replaced omega's 0x0c0e1900 with LDG.E.MMIO.GPU 0x0c1f1900 in `3c163287d27b6e5a5f5b90c15b61ac83d8f26e2d`, after the shared import. - `3c163287` checked: it exists in this repo and edits this file: "Honor the LDG MMIO GPU IR contract…", 2026-10-28, 1:04 PM CT. - No NAK citation. - No GB10 claim. The comment says neither word has a NAK citation or a GB10 test, so neither wins under ADR 0043 provenance. That's correct, and it keeps the question open for an Architecture ruling. - The file and its baseline blob are unchanged. No frozen-stack path (omega_cubin.c, backend//) is touched. ### 3. Mutant scripts - tests/dagsim/mutant_lifetime.sh:33 now matches `^ FAIL .*inverted_lifetime_masks_overflow`. - tests/dagsim/mutant_predict.sh:35 and :40 match `^ FAIL .*predict_unsupported_despite_known` and `^ FAIL .*predict_refused_despite_known`. - The regex fits the real output. dagsim_unit.c's CHECK writes `" FAIL %s:%d "` and then the message, on one line to stderr. The messages start with those assertion names (dagsim_unit.c:458, 465, 575), and the scripts capture `2>&1`. - No fake-green. The scripts still need a nonzero exit, still use `set -eu`, and still check that the mutation applied. A PASS or summary line can no longer count as a kill. ### 4. What changed since `b3f3d5ea` (nothing else is new) - tests/gpu_decode_attn_test.c (+27/−14): the full omega mirror described above. - tools/extract/drift-baseline.tsv (+1/−3): the reworded LDG comment, and the removed decode-attention divergence. - tests/dagsim/mutant_lifetime.sh (+1/−1) and tests/dagsim/mutant_predict.sh (+2/−2): the FAIL-line anchors. There are no Makefile, workflow, drift.sh, src/ or API changes. CodeQL (`124340161204`): failure, 2 new high-severity alerts. These are the expected pair in the mirrored test, where `fopen` creates a file with default 0666 permissions: - line 337, `fopen(out_path, "w")` in chip_run, visible in the diff; - line 435. They come with the byte mirror and are being dismissed as "used in tests", so I'm not counting them as must-fix. The check reports exactly 2 annotations and no others. ### 5. Drift baseline 19 mirrored + 30 recorded = 49, and the 2 mutant-script rows are still recorded separately. drift (`124339970752`) passed at 5:11 PM CT. ### 6. Checks at this head (CT) - Running: host-tests `124339970655` (started 5:11 PM). - Failure: CodeQL `124340161204`, the 2 alerts above. - Passing: x86-host-tests `124339970723` (finished 5:16 PM), drift `124339970752`, build `124339971023`, build `124339970583`, runtime-api `124339970895`, library `124339970449`, sim `124339970386`, om-units `124339970927`, sbom `124339970943`, hello-sim `124339971047`, fresh-checkout `124339970759`, figures `124339971011`, audit-scanner `124339970836`, Analyze (c-cpp) `124339959499`, Analyze (python) `124339959400`, Analyze (actions) `124339959221`. — Grokbot ### Fetch it A git bundle of the pull request's head, 24828 bytes. ``` curl -fsSL https://interplane.io/drakestapleton/CUDApp/patches/0d18758bf12c274f.bundle -o 0d18758bf12c274f.bundle git fetch 0d18758bf12c274f.bundle refs/pull/203/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/CUDApp 203 d2c83a197118d9abc328dee9a64243d9014c15b8 ``` ``` {"kind":"github-import","owner":"aien-dev","repo":"CUDApp","number":203,"url":"https://github.com/aien-dev/CUDApp/pull/203","export_sha256":"0aafd51b77ff5776d6baaf9b88b48c8b36a6e27c8d829ae8ded561b71712b17a","imported_utc":"2026-11-18T16:38:23Z"} ``` ### Changes ``` diff --git a/Makefile b/Makefile index 2f119ff0..330501ff 100644 --- a/Makefile +++ b/Makefile @@ -382,6 +382,32 @@ test-gemm-selectors: $(GPU_PFGEMM_TEST) $(GPU_QGEMM_TEST) $(GPU_FP8GEMM_TEST) 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 +# 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 +test-gpu-prefill-host: $(GPU_TC_PROBE_TEST) $(GPU_TCGEMM_TEST) $(GPU_PATTN_TEST) $(GPU_PF_MEM_TEST) $(GPU_PFGEMM_TEST) \ + $(GPU_QMMA_PROBE_TEST) $(GPU_QGEMM_TEST) $(GPU_PFHOST_TEST) + ./$(GPU_TC_PROBE_TEST) --host-only + ./$(GPU_QMMA_PROBE_TEST) --host-only + ./$(GPU_PF_MEM_TEST) --host-only + ./$(GPU_TCGEMM_TEST) --host-only + ./$(GPU_TCGEMM_TEST) --sim + ./$(GPU_PATTN_TEST) --host-only + ./$(GPU_PATTN_TEST) --sim + ./$(GPU_PFGEMM_TEST) --host-only + ./$(GPU_PFGEMM_TEST) --sim + ./$(GPU_QGEMM_TEST) --host-only + ./$(GPU_QGEMM_TEST) --sim + ./$(GPU_PFHOST_TEST) --host-only + ./$(GPU_PFHOST_TEST) --sim + @echo "test-gpu-prefill-host: PASS (8 prefill tests, host model + warp simulator, no device)" +# 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 + @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)" # OWN-30B W-L2 (2026-10-13): command list (many launches, one submission) + decode glue kernels. test-gpu-cmdlist is # host-only + warp simulator; the chip gate is tools/run_gpu_cmdlist_chip.sh under the GB10 lock. .PHONY: test-gpu-cmdlist @@ -399,7 +425,7 @@ 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 -test-gpu-decode-graph: $(GPU_DECODE_GRAPH_TEST) $(GPU_DGRAPH_ABORT_TEST) test-gpu-decode-graph-abort-mutants +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) @@ -430,6 +456,32 @@ test-gpu-decode-graph-abort-mutants: $(OUT_DIR)/libomega_gpu.a dmut abort-submits 's|^int omega_gpu_decode_graph_abort_token(OmegaGpuDecodeGraph \*g) {$$|&\n if (g \&\& g->in_token) return omega_gpu_decode_graph_end_token(g, NULL, NULL);|'; \ echo "test-gpu-decode-graph-abort-mutants: $$killed of 5 mutants killed" +# omega #456: the per-token timeline (set_stamps) never writes past stamp[]: 4096 stamped launches fill it, the 4097th +# (flush_each, one submission per launch) fails the token and leaves no timeline. Fake platform that completes every +# submission; no device. Each mutant breaks one rule in a copy of omega_gpu_decode_graph.c linked ahead of the library; +# the overflow case must FAIL on it. +.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 +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; \ + 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; \ + echo "mutant $$name killed"; }; \ + tmut room-off-by-one 's|(uint32_t)(cnt - from) > room) {|(uint32_t)(cnt - from) > room + 1u) {|'; \ + 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). 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 diff --git a/om/moe/.crumb b/om/moe/.crumb index 3794ff0d..f3815351 100644 --- a/om/moe/.crumb +++ b/om/moe/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-28T17:07:44Z", + "compiled_at": "2026-10-31T02:10:04Z", "compiler": "crumb-compile/1", - "digest": "sha256:ffd66b6634b55e7e3d9780a321ad4c9bc4383b9c681f5a718479826cc0c71329", + "digest": "sha256:860df8a631262e15e20d1cb08f33090a8038ea5071a027ae157f53a93bb9f69f", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 17, - "generated_at_commit": "313fae26af8d0b9a26897a584efc3bfde358f7e6", - "source_tree": "sha256:0ec79f49af490b0b4d08109ab154971b22ee272e26c36543bf7fb296ad9db97b" + "generated_at_commit": "802b6c74f77c83b815367be09a4e707c48ed358a", + "source_tree": "sha256:a74e2ad255115f50654a809d5dc063d2fe61d39eb0f26e944b3ba0365e037814" } }, "name": "moe", diff --git a/src/omega_gpu_decode_graph.c b/src/omega_gpu_decode_graph.c index 9c126171..dba9984f 100644 --- a/src/omega_gpu_decode_graph.c +++ b/src/omega_gpu_decode_graph.c @@ -227,7 +227,16 @@ static int submit_now(OmegaGpuDecodeGraph *g) { uint64_t tmp[OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 1]; int cnt = omega_gpu_cmdlist_stamps(g->cl, tmp, OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 1); if (cnt < 0) rc = -1; - else { const int from = g->n_stamp == 0 ? 0 : 1; for (int i = from; i < cnt; i++) g->stamp[g->n_stamp++] = tmp[i]; } + else { + const int from = g->n_stamp == 0 ? 0 : 1; + const uint32_t room = (uint32_t)(sizeof g->stamp / sizeof g->stamp[0]) - g->n_stamp; + if (cnt > from && (uint32_t)(cnt - from) > room) { /* more launches this token than the timeline holds */ + omega_gpu_session_set_error("decode graph: timeline full (more launches per token than OMEGA_GPU_CMDLIST_MAX_LAUNCHES)"); + rc = -1; + } else { + for (int i = from; i < cnt; i++) g->stamp[g->n_stamp++] = tmp[i]; + } + } } g->tagged_in_list = 0; omega_gpu_cmdlist_reset(g->cl); @@ -417,7 +426,7 @@ void omega_gpu_decode_graph_set_stamps(OmegaGpuDecodeGraph *g, int on) { if (g & int omega_gpu_decode_graph_stamps(const OmegaGpuDecodeGraph *g, uint64_t *stamps, uint8_t *kinds, uint32_t cap) { if (!g || g->in_token || !stamps || !kinds) return OMEGA_GPU_DGRAPH_BAD_ARGS; - if (!g->stamps || g->n_stamp != g->n_kind + 1u) { omega_gpu_session_set_error("decode graph: no timeline for the last token (stamps off or it failed)"); return OMEGA_GPU_DGRAPH_BAD_ARGS; } + if (!g->stamps || g->failed || g->n_stamp != g->n_kind + 1u) { omega_gpu_session_set_error("decode graph: no timeline for the last token (stamps off or it failed)"); return OMEGA_GPU_DGRAPH_BAD_ARGS; } if (cap < g->n_stamp) { omega_gpu_session_set_error("decode graph: timeline buffers too small"); return OMEGA_GPU_DGRAPH_BAD_ARGS; } memcpy(stamps, g->stamp, (size_t)g->n_stamp * sizeof stamps[0]); memcpy(kinds, g->kind, (size_t)g->n_kind); diff --git a/src/omega_gpu_fp8_api.c b/src/omega_gpu_fp8_api.c index f5e46d04..5e502950 100644 --- a/src/omega_gpu_fp8_api.c +++ b/src/omega_gpu_fp8_api.c @@ -110,7 +110,7 @@ void omega_gpu_fp8_set_depth(int set, uint32_t depth) { omega_gpu_session_lock() void omega_gpu_fp8_set_gpr_pad(uint32_t pad) { omega_gpu_session_lock(); g.gpr_pad = pad; omega_gpu_session_unlock(); } void omega_gpu_fp8_set_cta_budget(uint32_t ctas) { omega_gpu_session_lock(); g.cta_budget_set = ctas != 0; g.cta_budget = ctas ? ctas : OMEGA_GPU_FP8_MAX_CTAS; cache_clear_locked(); omega_gpu_session_unlock(); } void omega_gpu_fp8_test_set_mutant(int m) { omega_gpu_session_lock(); g.mutant = m; cache_clear_locked(); omega_gpu_session_unlock(); } -void omega_gpu_fp8_test_set_no_fold(int on) { g.no_fold = on ? 1 : 0; } +void omega_gpu_fp8_test_set_no_fold(int on) { omega_gpu_session_lock(); g.no_fold = on ? 1 : 0; omega_gpu_session_unlock(); } void omega_gpu_fp8_seal(int on) { omega_gpu_session_lock(); g.sealed = on ? 1 : 0; omega_gpu_session_unlock(); } /* ---- GEMV variant (W-L2c): 1 = omega_blackwell_codegen_moe.c (default), 2 = omega_blackwell_codegen_moe2.c (row-pipelined) ---- */ @@ -456,6 +456,9 @@ int omega_gpu_fp8_tensor_upload(uint32_t experts, uint32_t n, uint32_t k, const t->owner_generation = next_owner; t->allocation_epoch = omega_gpu_session_epoch(); } + /* Fill and sync under the lock (omega#456): t is not shared yet, but its CPU views belong to the open device, and a + * device close on another thread between unlock and memcpy would unmap them; sync_to_gpu also reads the open state. + * g.no_fold is read under the lock, as its setter now writes it. The cost is holding the lock for one weight copy. */ if (rc == OMEGA_GPU_FP8_OK) { memcpy(t->w.cpu, w, wbytes); if (omega_fp8_pack_scales(scale, scount, t->s.cpu, g.no_fold) != 0) { omega_gpu_session_set_error("fp8 upload: NaN, inf or overflowing scale"); rc = OMEGA_GPU_FP8_BAD_ARGS; } diff --git a/tests/gpu_fp8gemm_test.c b/tests/gpu_fp8gemm_test.c index cf603a5d..988d8a24 100644 --- a/tests/gpu_fp8gemm_test.c +++ b/tests/gpu_fp8gemm_test.c @@ -49,7 +49,10 @@ static void weights_free(Weights *W) { free(W->w); free(W->s); } * bytes (word, byte), acc = fma(dot, S', acc), then the SHFL.DOWN tree 16..1. w: the row's k bytes, s: its k/128 scale words * (bf16 bits of one 128-row block), x: natural-order activation row. */ static float emu_row(const uint8_t *w, const uint16_t *s, const float *x, uint32_t k, uint32_t lb) { - float xp[16384]; omega_fp8_pack_x_f32(x, k, xp); + /* static, not 64 KB of stack (omega#456); this test runs one thread. k is bounded by OMEGA_FP8_MAX_K (16384). */ + static float xp[16384]; + if (k > sizeof xp / sizeof xp[0]) { fprintf(stderr, "emu_row: k=%u exceeds %zu\n", k, sizeof xp / sizeof xp[0]); exit(2); } + omega_fp8_pack_x_f32(x, k, xp); float a[32]; const uint32_t steps = k / (32u * lb); for (unsigned lane = 0; lane < 32; lane++) { float acc = 0.0f; diff --git a/tests/test_omega_gpu_decode_graph_timeline.c b/tests/test_omega_gpu_decode_graph_timeline.c new file mode 100644 index 00000000..610976c9 --- /dev/null +++ b/tests/test_omega_gpu_decode_graph_timeline.c @@ -0,0 +1,303 @@ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* test_omega_gpu_decode_graph_timeline: the decode graph's per-token timeline never writes past stamp[] (omega #456). + * Host program on a FAKE OmegaGpuPlatform that completes every submission (markers, launch semaphores, stamp reports); + * links libomega_gpu.a with the fake installed first; opens no device, touches no GPU. + * + * The timeline holds OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 1 stamps. Batched, a token's list never holds more launches than + * that. With flush_each (one submission per launch) the list is emptied after every launch, so nothing in the command + * list bounds the number of launches a token records: before #456 the 4097th stamped launch wrote stamp[4097], past the + * end of the graph. Contract under test: 4096 launches fill the timeline exactly (stamps() returns 4096); one more fails + * the token (CHIP_FAIL, timeline refused, lock released) and the next token runs normally. + * + * Each case runs in its own child process. + */ +#include "omega_gpu_decode_graph.h" +#include "omega_gpu_session.h" +#include "omega_gpu_platform.h" +#include "omega_gpu_cmdlist.h" +#include "omega_blackwell_submit.h" + +#include +#include +#include +#include +#include + +static int case_ok; +#define EXPECT(c) do { if (!(c)) { case_ok = 0; printf(" expect failed at line %d: %s\n", __LINE__, #c); } } while (0) + +/* ---- the fake platform: every submitted word stream "runs" ---- */ +#define NB OMEGA_GPU_HANDLE_SLOTS +#define VA_BASE 0x100000000ull +#define VA_STRIDE 0x1000000ull +static struct { + OmegaGpuHandleTable t; + void *mem[NB]; + OmegaGpuBufferDesc desc[NB]; + OmegaGpuDeviceHandle dev; + OmegaGpuQueueHandle q; + OmegaGpuBufferHandle ring; + uint64_t ns; + unsigned locks_held, double_locks, bad_unlocks, submits; + uint64_t dev_token_va; /* nonzero: the device wrote dev_token there (seen at the gpu->cpu sync) */ + uint32_t dev_token; +} fk; + +static uint64_t f_now_ns(void *c) { (void)c; fk.ns += 1000u; return fk.ns; } +static uint64_t f_now_ms(void *c) { return f_now_ns(c) / 1000000u; } +static int f_wait(void *c, uint64_t ms) { (void)c; fk.ns += ms * 1000000u; return 0; } +static int f_lock(void *c, uint32_t id) { + (void)c; + if (id != OMEGA_GPU_SESSION_LOCK_ID) return OMEGA_GPU_PLAT_REFUSED_ARGS; + if (fk.locks_held) { fk.double_locks++; return OMEGA_GPU_PLAT_REFUSED_BUSY; } /* a real lock would block forever */ + fk.locks_held = 1; + return 0; +} +static int f_unlock(void *c, uint32_t id) { + (void)c; + if (id != OMEGA_GPU_SESSION_LOCK_ID || !fk.locks_held) { fk.bad_unlocks++; return OMEGA_GPU_PLAT_REFUSED_ARGS; } + fk.locks_held = 0; + return 0; +} +static const char *f_diag(void *c) { (void)c; return ""; } +static int f_dev_open(void *c, uint32_t ord, OmegaGpuDeviceHandle *out) { + (void)c; + if (ord != 0 || fk.dev.generation) return OMEGA_GPU_PLAT_REFUSED_LIMIT; + int rc = omega_gpu_handles_open(&fk.t, OMEGA_GPU_HANDLE_DEVICE, 0, 1, 0, &out->index, &out->generation); + if (rc == 0) fk.dev = *out; + return rc; +} +static int f_dev_close(void *c, OmegaGpuDeviceHandle d) { + (void)c; + int rc = omega_gpu_handles_check(&fk.t, d.index, d.generation, OMEGA_GPU_HANDLE_DEVICE); + if (rc) return rc; + (void)omega_gpu_handles_close(&fk.t, d.index, d.generation, OMEGA_GPU_HANDLE_DEVICE); + memset(&fk.dev, 0, sizeof fk.dev); + return 0; +} +static OmegaGpuPlatformCaps g_caps = { + .abi_major = OMEGA_GPU_PLATFORM_ABI_MAJOR, .abi_minor = OMEGA_GPU_PLATFORM_ABI_MINOR, + .services = OMEGA_GPU_SVC_REQUIRED_SESSION, .max_devices = 1, .max_buffers = 1000, .max_queues = 1, .max_inflight = 1, + .max_buffer_bytes = 1ull << 30, .max_total_bytes = 1ull << 32, +}; +static int f_alloc(void *c, OmegaGpuDeviceHandle d, const OmegaGpuBufferDesc *desc, OmegaGpuBufferHandle *o, + OmegaCpuView *cpu, OmegaGpuVa *g, OmegaGpuBusAddr *b) { + (void)c; + int rc = omega_gpu_handles_check(&fk.t, d.index, d.generation, OMEGA_GPU_HANDLE_DEVICE); + if (!rc) rc = omega_gpu_platform_check_buffer(desc, &g_caps); + if (!rc) rc = omega_gpu_handles_open(&fk.t, desc->kind, desc->bytes, 1000, 1ull << 32, &o->index, &o->generation); + if (rc) return rc; + void *m = calloc(1, desc->bytes); + if (!m) { (void)omega_gpu_handles_close(&fk.t, o->index, o->generation, desc->kind); return OMEGA_GPU_PLAT_REFUSED_LIMIT; } + fk.mem[o->index] = m; fk.desc[o->index] = *desc; + cpu->ptr = m; cpu->len = desc->bytes; g->va = VA_BASE + (uint64_t)o->index * VA_STRIDE; b->iova = 0; + return 0; +} +static int f_free(void *c, OmegaGpuBufferHandle h) { + (void)c; + if (h.index >= NB) return OMEGA_GPU_PLAT_REFUSED_BAD_HANDLE; + int rc = omega_gpu_handles_close(&fk.t, h.index, h.generation, fk.t.kind[h.index]); + if (rc) return rc; + free(fk.mem[h.index]); fk.mem[h.index] = NULL; + return 0; +} +static int buf_live(OmegaGpuBufferHandle h) { return h.index < NB && fk.t.live[h.index] && fk.t.generation[h.index] == h.generation; } +static void *va_to_cpu(uint64_t va) { + for (uint32_t i = 0; i < NB; i++) { + if (!fk.mem[i] || !fk.t.live[i]) continue; + const uint64_t base = VA_BASE + (uint64_t)i * VA_STRIDE; + if (va >= base && va < base + fk.desc[i].bytes) return (uint8_t *)fk.mem[i] + (va - base); + } + return NULL; +} +static int sync_check(OmegaGpuBufferHandle h, uint64_t off, uint64_t len) { + if (!buf_live(h)) return OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE; + if (len == 0 || off > fk.desc[h.index].bytes || len > fk.desc[h.index].bytes - off) return OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH; + return 0; +} +static int f_c2g(void *c, OmegaGpuBufferHandle h, uint64_t off, uint64_t len) { (void)c; return sync_check(h, off, len); } +/* gpu->cpu: a command list's launch semaphores (16-byte slots, every one still INIT) read DONE: the launches ran. + * Only a range whose every 16-byte slot holds INIT is taken for a semaphore array. */ +static int f_g2c(void *c, OmegaGpuBufferHandle h, uint64_t off, uint64_t len) { + (void)c; + int rc = sync_check(h, off, len); + if (rc) return rc; + if (len % 16u == 0) { + uint32_t *w = (uint32_t *)((uint8_t *)fk.mem[h.index] + off); + uint64_t i = 0, n = len / 16u; + while (i < n && w[4 * i] == OMEGA_BW_SEMAPHORE_INTERMEDIATE_INIT) i++; + if (i == n) for (i = 0; i < n; i++) w[4 * i] = OMEGA_BW_SEMAPHORE_INTERMEDIATE_DONE; + } + if (fk.dev_token_va) { uint32_t *t = va_to_cpu(fk.dev_token_va); if (t) t[0] = fk.dev_token; } + return 0; +} +static int f_poll(void *c, OmegaGpuBufferHandle h, uint64_t off, uint32_t want, uint64_t ms, uint32_t *seen) { + (void)c; + if (!buf_live(h)) return OMEGA_GPU_PLAT_REFUSED_STALE_HANDLE; + if (!(fk.desc[h.index].rights & OMEGA_GPU_RIGHT_HOST_POLLED)) return OMEGA_GPU_PLAT_REFUSED_BAD_RIGHTS; + const volatile uint32_t *w = (const volatile uint32_t *)((uint8_t *)fk.mem[h.index] + off); + *seen = *w; + if ((int32_t)(*w - want) >= 0) return 0; + fk.ns += ms * 1000000u; + return OMEGA_GPU_POLL_TIMED_OUT; +} +static int f_qopen(void *c, OmegaGpuDeviceHandle d, OmegaGpuBufferHandle ring, OmegaGpuQueueHandle *o) { + (void)c; + int rc = omega_gpu_handles_check(&fk.t, d.index, d.generation, OMEGA_GPU_HANDLE_DEVICE); + if (!rc && (!buf_live(ring) || fk.t.kind[ring.index] != OMEGA_GPU_HANDLE_BUF_QUEUE)) rc = OMEGA_GPU_PLAT_REFUSED_BAD_KIND; + if (!rc) rc = omega_gpu_handles_open(&fk.t, OMEGA_GPU_HANDLE_QUEUE, 0, 1, 0, &o->index, &o->generation); + if (!rc) { fk.q = *o; fk.ring = ring; } + return rc; +} +static int f_qclose(void *c, OmegaGpuQueueHandle q) { + (void)c; + int rc = omega_gpu_handles_close(&fk.t, q.index, q.generation, OMEGA_GPU_HANDLE_QUEUE); + if (!rc) memset(&fk.q, 0, sizeof fk.q); + return rc; +} +static uint32_t mthd(uint32_t subc, uint32_t m, uint32_t count) { return (2u << 28) | (count << 16) | (subc << 13) | (m >> 2); } +/* The fake device runs the stream: semaphore releases (0x005c: the completion markers) write their payload, compute + * report semaphores (0x0158, four-word: the stamps) write {payload, timestamp}. */ +static int f_submit(void *c, OmegaGpuQueueHandle q, const uint32_t *w, uint32_t n) { + (void)c; + int rc = omega_gpu_handles_check(&fk.t, q.index, q.generation, OMEGA_GPU_HANDLE_QUEUE); + if (rc) return rc; + if ((uint64_t)n * 4u > fk.desc[fk.ring.index].bytes) return OMEGA_GPU_PLAT_REFUSED_BAD_LENGTH; + fk.submits++; + for (uint32_t i = 0; i + 5 < n; i++) { + if (w[i] == mthd(0, 0x005c, 5)) { + uint32_t *m = va_to_cpu((uint64_t)w[i + 1] | ((uint64_t)w[i + 2] << 32)); + if (m) *m = w[i + 3]; + i += 5; + } else if (w[i] == mthd(1, 0x0158, 5)) { + uint64_t *s = va_to_cpu((uint64_t)w[i + 3] | ((uint64_t)w[i + 4] << 32)); + if (s) { s[0] = (uint64_t)w[i + 1] | ((uint64_t)w[i + 2] << 32); s[1] = (fk.ns += 1000u); } + i += 5; + } + } + return 0; +} +static int f_retire(void *c, OmegaGpuQueueHandle q) { (void)c; (void)q; return 0; } +static void *f_halloc(void *c, size_t b) { (void)c; return malloc(b); } +static void f_hfree(void *c, void *p) { (void)c; free(p); } + +static OmegaGpuPlatform g_plat = { + .ctx = &fk, .time_now_ms = f_now_ms, .wait_ms = f_wait, .lock = f_lock, .unlock = f_unlock, + .dma_alloc = f_alloc, .dma_free = f_free, .sync_cpu_to_gpu = f_c2g, .sync_gpu_to_cpu = f_g2c, .poll_word = f_poll, + .device_open = f_dev_open, .device_close = f_dev_close, .diag_text = f_diag, + .queue_open = f_qopen, .queue_close = f_qclose, .queue_submit = f_submit, .queue_retire = f_retire, + .time_now_ns = f_now_ns, .host_alloc = f_halloc, .host_free = f_hfree, +}; + +/* ---- a one-layer graph on the fake ---- */ +#define LAYERS 1u +#define VOCAB 256u +#define MAX_POS 256u +typedef struct { + OmegaGpuDecodeAttnCache *attn; + OmegaGpuRouter *router; + OmegaGpuBf16Tensor *lm; + OmegaGpuDecodeGraph *g; +} World; + +static int world_build(World *w) { + memset(w, 0, sizeof *w); + static uint16_t lm_w[VOCAB * OMEGA_GPU_DGRAPH_HIDDEN]; /* zeros: finite bf16 */ + if (omega_gpu_decode_attn_cache_alloc(LAYERS, MAX_POS, 1e6, &w->attn) != 0) return -1; + if (omega_gpu_router_alloc(LAYERS, &w->router) != 0) return -1; + if (omega_gpu_bf16_tensor_upload(VOCAB, OMEGA_GPU_DGRAPH_HIDDEN, lm_w, &w->lm) != 0) return -1; + OmegaGpuDecodeGraphConfig cfg; memset(&cfg, 0, sizeof cfg); + cfg.layers = LAYERS; cfg.vocab = VOCAB; cfg.eps = 1e-6f; cfg.norm_topk = 1; + cfg.router = w->router; cfg.attn = w->attn; cfg.lm_head = w->lm; + if (omega_gpu_decode_graph_create(&cfg, &w->g) != OMEGA_GPU_DGRAPH_OK) return -1; + omega_gpu_decode_graph_set_stamps(w->g, 1); + omega_gpu_decode_graph_set_flush_each(w->g, 1); /* one submission per launch: the list never bounds the token */ + return 0; +} + +static float g_x[OMEGA_GPU_DGRAPH_HIDDEN]; +#define EXPECT_LOCK_FREE() do { EXPECT(fk.locks_held == 0); EXPECT(fk.double_locks == 0); EXPECT(fk.bad_unlocks == 0); } while (0) + +static int install(void) { + memset(&fk, 0, sizeof fk); omega_gpu_handles_init(&fk.t); + for (unsigned i = 0; i < OMEGA_GPU_DGRAPH_HIDDEN; i++) g_x[i] = (float)(i % 7) - 3.0f; + return omega_gpu_session_set_platform(&g_plat, &g_caps); +} + +/* One token of `launches` SWIGLU glue launches (each submitted on its own); returns end_token's code, fills *refused + * with the first record that did not return OK (launches when every record did). */ +static int token_of(World *w, uint32_t launches, uint32_t want, uint32_t *refused, uint32_t *tok) { + OmegaGpuDecodeGraphVas v; omega_gpu_decode_graph_vas(w->g, &v); + fk.dev_token_va = v.token; fk.dev_token = want; + *refused = launches; + if (omega_gpu_decode_graph_begin_token(w->g, g_x) != OMEGA_GPU_DGRAPH_OK) return -1000; + for (uint32_t i = 0; i < launches; i++) + if (omega_gpu_decode_graph_record_swiglu(w->g, v.gu, v.act, 1.0f) != OMEGA_GPU_DGRAPH_OK && *refused == launches) *refused = i; + const int rc = omega_gpu_decode_graph_end_token(w->g, tok, NULL); + fk.dev_token_va = 0; + return rc; +} + +static uint64_t g_st[OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 2]; +static uint8_t g_kd[OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 2]; + +/* MAX_LAUNCHES stamped launches: the timeline is exactly full and reads back whole. */ +static void c_full(void) { + World w; + if (install() != OMEGA_GPU_PLAT_OK) { EXPECT(!"fake platform installs"); return; } /* never fall back to the real driver */ + if (world_build(&w) != 0) { EXPECT(!"world builds on the fake"); return; } + uint32_t refused = 0, tok = 0; + EXPECT(token_of(&w, OMEGA_GPU_CMDLIST_MAX_LAUNCHES, 7, &refused, &tok) == OMEGA_GPU_DGRAPH_OK); + EXPECT(refused == OMEGA_GPU_CMDLIST_MAX_LAUNCHES && tok == 7); + EXPECT(fk.submits == OMEGA_GPU_CMDLIST_MAX_LAUNCHES); + EXPECT_LOCK_FREE(); + EXPECT(omega_gpu_decode_graph_stamps(w.g, g_st, g_kd, OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 2) == (int)OMEGA_GPU_CMDLIST_MAX_LAUNCHES); + for (uint32_t i = 0; i < OMEGA_GPU_CMDLIST_MAX_LAUNCHES; i++) if (!(g_st[i + 1] > g_st[i])) { EXPECT(!"stamps increase"); break; } +} + +/* One launch more than the timeline holds: that record fails the token, nothing is written past stamp[], the lock is + * released at end_token, no timeline is offered, and the next (small) token runs and reads back normally. */ +static void c_overflow(void) { + World w; + if (install() != OMEGA_GPU_PLAT_OK) { EXPECT(!"fake platform installs"); return; } + if (world_build(&w) != 0) { EXPECT(!"world builds on the fake"); return; } + uint32_t refused = 0, tok = 0xdeadu; + EXPECT(token_of(&w, OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 1u, 7, &refused, &tok) == OMEGA_GPU_DGRAPH_CHIP_FAIL); + EXPECT(refused == OMEGA_GPU_CMDLIST_MAX_LAUNCHES); /* the 4097th launch, the first that has no stamp slot */ + EXPECT(tok == 0xdeadu); + EXPECT(strstr(omega_gpu_session_last_error(), "timeline full") != NULL); + EXPECT_LOCK_FREE(); + EXPECT(omega_gpu_decode_graph_stamps(w.g, g_st, g_kd, OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 2) == OMEGA_GPU_DGRAPH_BAD_ARGS); + EXPECT(token_of(&w, 3, 9, &refused, &tok) == OMEGA_GPU_DGRAPH_OK); + EXPECT(refused == 3 && tok == 9); + EXPECT_LOCK_FREE(); + EXPECT(omega_gpu_decode_graph_stamps(w.g, g_st, g_kd, OMEGA_GPU_CMDLIST_MAX_LAUNCHES + 2) == 3); +} + +static const struct { const char *name; void (*fn)(void); } CASES[] = { + { "timeline exactly full: 4096 stamped launches read back", c_full }, + { "one launch past the timeline: token fails, no write past stamp[]", c_overflow }, +}; + +int main(int argc, char **argv) { + const unsigned n = sizeof CASES / sizeof CASES[0]; + if (argc == 2) { /* one case in this process (debugging): its index */ + const unsigned i = (unsigned)atoi(argv[1]); + if (i >= n) return 2; + case_ok = 1; CASES[i].fn(); + printf("%s %s\n", case_ok ? "ok " : "FAIL", CASES[i].name); + return case_ok ? 0 : 1; + } + unsigned failed = 0; + for (unsigned i = 0; i < n; i++) { + fflush(stdout); + pid_t pid = fork(); + if (pid == 0) { case_ok = 1; CASES[i].fn(); fflush(stdout); _exit(case_ok ? 0 : 1); } + int status = 0; + int ok = pid > 0 && waitpid(pid, &status, 0) == pid && WIFEXITED(status) && WEXITSTATUS(status) == 0; + printf("%s %s\n", ok ? "ok " : "FAIL", CASES[i].name); + if (!ok) failed++; + } + printf("test_omega_gpu_decode_graph_timeline: %u of %u cases passed: %s\n", n - failed, n, failed ? "FAIL" : "PASS"); + return failed ? 1 : 0; +} diff --git a/tools/extract/.crumb b/tools/extract/.crumb index 4024be03..c2e3f388 100644 --- a/tools/extract/.crumb +++ b/tools/extract/.crumb @@ -3,14 +3,14 @@ "generated": { "children": [], "children_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", - "compiled_at": "2026-10-29T02:13:05Z", + "compiled_at": "2026-10-31T02:18:53Z", "compiler": "crumb-compile/1", - "digest": "sha256:d0c7122592333dfe6ea9a77efb7fa1722f69525ce0b4c1ef1fb774dd9c4da4dc", + "digest": "sha256:a35550169b7ad8d28e821d6e5354a9a3ced03dcf9556dbf5c96dd08310c4944a", "evidence_files": 0, "evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855", "files": 30, - "generated_at_commit": "c67fc2772186b35b562d5067449fb3dc8997bc57", - "source_tree": "sha256:6e807561b32f039d7bc048885a7f8ce3a9e96f42945f35deee971c1eb2407d24" + "generated_at_commit": "02538d3bd12a14fce0c5875ac491203919e505ef", + "source_tree": "sha256:396ddda55052497750b75bebda7820fb6f86c309fb153a738b2744c65b74a94b" } }, "name": "extract", diff --git a/tools/extract/drift-baseline.tsv b/tools/extract/drift-baseline.tsv index d3a7f0d7..fa503c5b 100644 --- a/tools/extract/drift-baseline.tsv +++ b/tools/extract/drift-baseline.tsv @@ -6,7 +6,10 @@ # src/omega_blackwell_codegen.c (cudapp_om_units.c / cudapp_native.h names only); mk/runtime-r1.mk, mk/runtime-r3.mk, docs/runtime/API.md, omega_runtime_api.manifest, src/omega_runtime_api.h (CUDA++ runtime API 0.6.0 supersedes the omega #955 backport); # docs/runtime/PORTABILITY.md, portability_table.tsv (#954 rows and reclassifications carried; CUDA++ rows and its sha256 build differ); tests/dagsim/mutant_{lifetime,predict}.sh (link src/sha256.c); # the merged src/ and tests/ files keep the CUDA++ licence header and CUDA++-ahead code with the omega change applied. -Makefile 5527cafecd0cee9f87a7907b9065b8a8479ba057 +# Blobs omega changed through 4376c2112d7469b6908c6403720c9001de4622b5 (train r3 #979, omega#456 OWN-30B follow-ups) are that commit's (CUDApp sync/drift-omega-4376c21). +# Still differ at 4376c21 on purpose: Makefile (CUDA++ build); src/omega_gpu_fp8_api.c (CUDA++ owner-generation upload kept, omega#456 lock-held fill already there); +# tests/gpu_fp8gemm_test.c (CUDA++ test_out_open 0600 receipt kept over omega's 0644 open); licence headers. +Makefile b6ceafb7625f3a974efce405e2bd79393045f8f8 evidence/C3-GEMM/01-host-only.log c581c5126718bc24ef10ed1b1637528018a260e5 evidence/C3-GEMM/02-sim.log fd97da9f29871abfc16fb2ed938c38a4d3c2314f evidence/C3-GEMM/README.md 0e730a9bf2072f34d59d9cdc1961f4112a7ff90e @@ -222,7 +225,7 @@ src/omega_gpu_decode_attn256_api.c 77fc4ba1fd9df0939a57df3aa669e18fd9be2785 src/omega_gpu_decode_attn256_api.h d0212c2cbac34dcd69b8e50b298a94c715039a7f src/omega_gpu_decode_attn_api.c ac6542487249e5571684e00dc115d4e00c1462a1 src/omega_gpu_decode_attn_api.h c3e88b2eb4b94a9abaad04770cad4a93ff8cca1e -src/omega_gpu_decode_graph.c 43717c2a400b1517a0db3d21c90b2700bc873b1c +src/omega_gpu_decode_graph.c 211a08ec35f70025287683d8c565b77c791e6114 src/omega_gpu_decode_graph.h bb8a78b320d677cce2905b1f75868993caf022da src/omega_gpu_elementwise_api.c 7871035b91175ed90cb2c384c9c757236a41ff5a src/omega_gpu_elementwise_api.h 243b1ed9ca99c563fa2ad5c7fe95be01d63f1f58 @@ -230,7 +233,7 @@ src/omega_gpu_engine.c 9965ca19a345fa8fc441102146bf99d0706dc045 src/omega_gpu_engine.h 3733d534aaab756e0bfaff361021fe695d248f20 src/omega_gpu_fmt.c 270f3fe3e6d9715650867cbb04afdde88c63adec src/omega_gpu_fmt.h 8a308f4b22f43c340c03ffe7acff43319c58fed2 -src/omega_gpu_fp8_api.c c1dcc83246942c6e5f2f986d6c4d5f14a58557ac +src/omega_gpu_fp8_api.c b9b9b52960daa4bb95d25900353774ec5b9d19a9 src/omega_gpu_fp8_api.h 9c7caf2d269947e80554d029a1ed01a6c04f279b src/omega_gpu_fp8_pack.c 77bd62063fb3b6641221466e813760282cb3b81c src/omega_gpu_fp8gemm_api.c 5605a6ea823d9b41db741f249523cf38e75818ff @@ -321,7 +324,7 @@ tests/gpu_decode_graph_test.c 8af07f1e423f3db54438749eb4a76a1c9f09443c tests/gpu_elementwise_test.c 7a270eb5f45e96aa89d2e6fed6963b2ee044d05b tests/gpu_exact_head_test.c 5258f3d84f5bc44eca597666f146bb2cc54bcdf0 tests/gpu_fp8_api_test.c 8fcf839dce9575af4b0abde499eb809e64ad36f7 -tests/gpu_fp8gemm_test.c 1a9669f47793fe77f75da31aff8321834a439199 +tests/gpu_fp8gemm_test.c d44d35a68da5358868820aed5f5ab423d513d112 tests/gpu_gdn_multi_test.c 108578a8fc7dbb8b95db323e5ea1752da767601b tests/gpu_gdn_test.c 655875a653860259e3d93f80fb54bded048b26af tests/gpu_gemm_test.c b60f70964f40113d59931993e1c9eaa046008cfa @@ -386,3 +389,4 @@ mk/runtime-r3.mk 9c541fbb2574df1e91d291dd7b365cfce9fd471b src/omega_runtime_api.h 89e2acbee00c0fee71c0fa78913726ccc8e2f708 tests/dagsim/mutant_lifetime.sh b3641225446bc7750b9f49d2e62050a7fadf316a tests/dagsim/mutant_predict.sh 89df5266df444b0a91d4d4c6f120d69ad52c61ef +tests/test_omega_gpu_decode_graph_timeline.c 619eac986fb47f17e76d8e5c9bad137237146d6d diff --git a/tools/own30b_decode_profile.c b/tools/own30b_decode_profile.c new file mode 100644 index 00000000..1ec75d6c --- /dev/null +++ b/tools/own30b_decode_profile.c @@ -0,0 +1,133 @@ +/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */ +/* Link-only recorder for OWN-30B decode. No production launcher changes. + * Link with -Wl,--wrap=omega_gpu_session_launch and this object. + * Measures HOST times: elapsed_ns is submit-to-second-marker, NOT GPU cycles. + * Only complete sequences of 48 x (qkv, attention, o, router, gu, down) + head + * following a head are retained. Prefill, controls and partial steps are rejected. + * No allocation or I/O in the measured path. Dump raw integer totals at exit. + */ +#include "omega_gpu_session.h" +#include "omega_blackwell_codegen_moe.h" +#include "omega_blackwell_codegen_attn.h" +#include "omega_blackwell_codegen_router.h" +#include "omega_blackwell_codegen_bf16.h" +#include +#include +#include + +enum { QKV, ATTN, O, ROUTER, GU, DOWN, HEAD, OTHER, STAGES = OTHER }; +static const char *names[STAGES] = { "qkv", "attention", "o", "router", "gate_up", "down", "lm_head" }; +typedef struct { uint64_t calls, bytes, session_ns, submit_wait_ns, gap_before_ns; } Row; +typedef struct { Row stage[STAGES]; uint64_t end_ns, start_ns; uint32_t pos; } Token; +static Token pending, tokens[4096]; +static size_t used, dropped; +static int armed, invalid; +static uint64_t last_end; + +static int classify(const OmegaGpuLaunch *l, uint64_t *bytes) { + *bytes = 0; + if (!l || !l->args) return OTHER; + if (l->n_args == OMEGA_FP8_ARGS_WORDS) { + uint32_t n = l->args[8] / 4u, g = l->grid_y, k; + int s; + if (g == 1 && n == 5120) { s = QKV; k = 2048; } + else if (g == 1 && n == 2048) { s = O; k = 4096; } + else if (g == 8 && n == 1536) { s = GU; k = 2048; } + else if (g == 8 && n == 2048) { s = DOWN; k = 768; } + else return OTHER; + *bytes = (uint64_t)g * n * k; + return s; + } + if (l->n_args == OMEGA_DATTN_ARGS_WORDS && l->num_elements == 4096) { + *bytes = 2ull * 4 * ((uint64_t)l->args[18] + 1) * 256; + return ATTN; + } + if (l->n_args == OMEGA_ROUTER_ARGS_WORDS && l->num_elements == 2048) { + *bytes = 128ull * 2048 * 2; + return ROUTER; + } + if (l->n_args == OMEGA_BF16_ARGS_WORDS && l->num_elements == 151936) { + *bytes = 151936ull * 2048 * 2; + return HEAD; + } + return OTHER; +} + +static void record(int s, uint64_t bytes, uint64_t begin, uint64_t end, uint64_t elapsed, int rc) { + if (armed) { + int expected = pending.pos < 288 ? (int)(pending.pos % 6) : HEAD; + if (rc || s != expected || pending.pos > 288) invalid = 1; + if (!invalid) { + Row *r = &pending.stage[s]; + r->calls++; + r->bytes += bytes; + r->session_ns += end - begin; + r->submit_wait_ns += elapsed; + r->gap_before_ns += begin - last_end; + pending.pos++; + } + } + if (s == HEAD) { + if (armed && !invalid && pending.pos == 289) { + pending.end_ns = end; + if (used < sizeof tokens / sizeof tokens[0]) tokens[used++] = pending; + else dropped++; + } + memset(&pending, 0, sizeof pending); + pending.start_ns = end; + armed = !rc; + invalid = 0; + } + last_end = end; +} + +#ifndef OWN30B_PROFILE_TEST +int __real_omega_gpu_session_launch(const OmegaGpuLaunch *, uint64_t *, uint32_t *); +int __wrap_omega_gpu_session_launch(const OmegaGpuLaunch *l, uint64_t *elapsed, uint32_t *marker) { + uint64_t bytes, local_elapsed = 0; + int s = classify(l, &bytes); + uint64_t begin = omega_gpu_session_now_ns(); + int rc = __real_omega_gpu_session_launch(l, &local_elapsed, marker); + uint64_t end = omega_gpu_session_now_ns(); + if (elapsed) *elapsed = local_elapsed; + record(s, bytes, begin, end, local_elapsed, rc); + return rc; +} + +__attribute__((destructor)) static void dump(void) { + fprintf(stderr, "DECODE_PROFILE semantics=host_session_and_submit_wait weight_bytes_exclude_scales pure_gpu_time=UNKNOWN tokens=%zu dropped=%zu\n", used, dropped); + for (size_t t = 0; t < used; ++t) { + fprintf(stderr, "DECODE_TOKEN token=%zu wall_ns=%" PRIu64 " launches=%u\n", t, tokens[t].end_ns - tokens[t].start_ns, tokens[t].pos); + for (int s = 0; s < STAGES; ++s) { + Row *r = &tokens[t].stage[s]; + fprintf(stderr, "DECODE_STAGE token=%zu stage=%s calls=%" PRIu64 " bytes=%" PRIu64 " session_ns=%" PRIu64 " submit_wait_ns=%" PRIu64 " gap_before_ns=%" PRIu64 "\n", + t, names[s], r->calls, r->bytes, r->session_ns, r->submit_wait_ns, r->gap_before_ns); + } + } +} +#else +#include +int main(void) { + uint32_t args[32] = {0}; + OmegaGpuLaunch l = { .args = args, .n_args = OMEGA_FP8_ARGS_WORDS, .grid_y = 8 }; + uint64_t bytes; + args[8] = 2048 * 4; + assert(classify(&l, &bytes) == DOWN && bytes == 8ull * 2048 * 768); + l.grid_y = 7; + assert(classify(&l, &bytes) == OTHER); + record(HEAD, 0, 0, 1, 1, 0); + for (unsigned i = 0; i < 289; i++) record(i < 288 ? i % 6 : HEAD, 10, 2 + i * 3, 4 + i * 3, 1, 0); + assert(used == 1 && tokens[0].pos == 289); + uint64_t sum = 0; + for (int s = 0; s < STAGES; s++) sum += tokens[0].stage[s].session_ns + tokens[0].stage[s].gap_before_ns; + assert(sum == tokens[0].end_ns - tokens[0].start_ns); + /* Swapped/missing/failed stages must never become a decode timing. */ + record(O, 0, 1000, 1001, 1, 0); + record(HEAD, 0, 1002, 1003, 1, 0); + assert(used == 1); + record(QKV, 0, 1004, 1005, 1, -1); + record(HEAD, 0, 1006, 1007, 1, 0); + assert(used == 1); + printf("PROFILE_HOST_PASS sequence, accounting, malformed shape, missing stage, failed launch; %s\n", names[HEAD]); +} +#endif ```