Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
About Files History Releases Proposed changes Issues For developers
Expert Ribbon P1: fixed GPU slots that experts are paged into from the SSD
closed 4cce1a874d7a3869 #561 · opened 2026-10-18 17:27 UTC · closed 2026-10-29 19:02 UTC
Imported from GitHub aien-dev/omega-mv#561, by drakestapleton
Base f4a9849fb127f8d2d664dfc56890752ad180c507 · Head 98d138fff1b83cca1f9bc6d58ee2cfba05d91d80
drakestapleton wrote on 2026-10-18 17:27 UTC
Refs aienix#4, omega#533.
What
Fixed-size GPU expert slots for the OWN-30B MoE so only part of the experts stay in GPU memory and the rest are paged in from the NVMe on demand (+997 lines, 19 files, all new code plus Makefile/README lines).
Evidence (worker report, 2026-10-18)
flock /tmp/aien-gb10.lock tools/run_gpu_fp8_slots_chip.sh <evid> ~/workspace/physics-own30b-k: host checks 24/24, 3 chip runs PASS (32/32 each), negative control CAUGHT.
End to end through sovereign-core (sc ribbon/p1-store): output identical to the all-in-memory reference on 2 prompts at 1/8 of experts resident and on 4 prompts at 1/2 resident. Warm decode 7.07 words/s (calc:59123200 ).
Not tested / limits
Batched prompt path and decode graph refuse a paged load; prompts run one token at a time in paged mode.
Router directory entries are filled with a fixed placeholder in paged mode (router insists on non-zero entries it never reads); the GPU-side slot table is part 3.
SSD-to-GPU overlap (sc#631) not started.
Merge order
Draft until the Qwen3.8 stack (#547..#559) lands: both add Makefile and README lines, so this branch needs one mechanical rebase after it. A twin branch ribbon/slots-on-4799f9eb (1549caae ) carries the same slot code on the omega commit sovereign-core pins; it is a pin target, not for merge.
🤖 Generated with Claude Code
drakestapleton wrote on 2026-10-29 19:02 UTC
Closing in org cleanup (Drake, 2026-10-29): abandoned: no activity in 11 days with merge conflicts and failing CI checks. Reopen if still needed.
Apply it
git checkout -b patch-4cce1a874d7a3869 f4a9849fb127f8d2d664dfc56890752ad180c507
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/4cce1a874d7a3869 .patch | git am
Raw patch (mbox) · 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
561
98d138fff1b83cca1f9bc6d58ee2cfba05d91d80
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":561,"url":"https://github.com/aien-dev/omega-mv/pull/561","export_sha256":"7319147b350ad908bf0b731068ec3be7b8dee848041dc862f71455e8e4680140 ","imported_utc":"2026-11-18T16:35:55Z"}
Changes
diff --git a/Makefile b/Makefile
index 3551fea3f ..874d87b0d 100644
--- a/Makefile
+++ b/Makefile
@@ -30,6 +30,8 @@ SRCS += src/omega_gpu_moe_api.c
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
# OWN-30B (2026-10-13): libm-free host math (omega_gpu_hostmath.h) so libomega_gpu.a links without -lm
@@ -2604,3 +2606,13 @@ $(GPU_LAUNCH_COST_TEST): tests/gpu_launch_cost_test.c src/omega_gpu_fp8_api.h sr
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
+
+# Expert Ribbon P1 (aienix#4 / omega#533, 2026-10-18): versioned replaceable FP8 expert slots (omega_gpu_fp8_slots.h).
+# test-gpu-fp8-slots is host-only (slot state machine, threaded race, mutant); the chip gate is
+# 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
+test-gpu-fp8-slots: $(GPU_FP8_SLOTS_TEST)
+ ./$(GPU_FP8_SLOTS_TEST) --host-only
diff --git a/README.md b/README.md
index 87f91fbf1 ..cf4d01603 100644
--- a/README.md
+++ b/README.md
@@ -15,6 +15,7 @@ Research-grade and pre-alpha. Plainly:
- **Omega Systems Core compiler:** OSC-0 is frozen as a design. OSC-1 and OSC-2 are implemented with host receipts and are NOT QUALIFIED. OSC-3 is in progress ([OSC-3-DESIGN](docs/osc/OSC-3-DESIGN.md)). It is not self-hosting and there is no general Omega compiler yet; the old Milestone 6 "self-host" result was a fixed-output self-copy check, not compilation ([note](docs/osc/OSC-1-SELF-HOST-STATEMENT.md)).
- **Reaction runtime:** the R1 to R16 qualification ladder passed on builds that predate the composition modules (omega#126), a historical result. Requalification at `3108fc2 ` recorded R15 FAIL (14 of 16 gates: G1, G15) and R16 FAIL (`evidence/REQUAL-3108fc2 /`); the R16 receipt `22d7a79a ` at `850fc54 ` is invalid as a current claim because its script was later found defective; none of R1 to R16 is requalified on the current candidate, and the ladder rerun is in progress. The R16 loop-site inventory was reconciled on the candidate tree (502 sites, 0 unclassified, 0 stale, PR #279); that is the inventory gate only, not R16. The current living build is IMPLEMENTED / NOT QUALIFIED until re-qualified. Composition, Capability Graph, Skill Router, J-Space and Cortex run on the host; the Fabric interface is a host-only loopback with no network; none of this is on silicon as a qualified system.
- **Numerics (E1):** closed 2026-10-02 on the GB10 chip campaign (Gate 5 26/26 with 47 parity lines, reductions SUM/MAX/MIN/MEAN, nine transcendental ops over all 2^32 inputs each, 148 load/store kernels), consolidated receipt `evidence/E1-CLOSURE/e7851c69d34ac777a9436af16d0bdd5d69264c8528c62d562b600f5d89153061 .json`; exclusions (natural-base EXP/LOG have no GB10 kernel) are listed in [E1_GAP_TABLE](docs/numeric/E1_GAP_TABLE.md).
+- **Expert slots (Expert Ribbon, omega#533):** `src/omega_gpu_fp8_slots.h` keeps a fixed pool of FP8 expert slots that can be refilled while a model runs. A slot is hidden while it is rewritten, gets a new version only after the copy is complete, and cannot be rewritten while any launch or recorded command list still reads it. Shown on the GB10 (`tools/run_gpu_fp8_slots_chip.sh`, receipts in `evidence/RIBBON-SLOTS-*`): a slot gives bit-identical results to the same expert held resident, and the negative control (pins ignored) is caught. The SSD side and the model wiring live in aien-sovereign-core.
- **Hardware:** results on the DGX Spark GB10 are tied to the exact commit in each receipt. Host and emulator passes are never reported as hardware qualification.
The live status is owned by [aien-architecture](https://github.com/aien-spark/aien-architecture): [CURRENT_EXECUTION_PLAN.md](https://github.com/aien-spark/aien-architecture/blob/main/CURRENT_EXECUTION_PLAN.md) and [doctrine/ROADMAP.md](https://github.com/aien-spark/aien-architecture/blob/main/doctrine/ROADMAP.md). This file does not restate numbers that drift. Historical milestone receipts (for example Milestone 4, `OMEGA_SEMANTICS`, 12 of 12 gates) stay in `evidence/` unchanged as history.
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/SHA256SUMS b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/SHA256SUMS
new file mode 100644
index 000000000 ..11d1911e1
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/SHA256SUMS
@@ -0,0 +1,8 @@
+00a8e06bde00952188aa2397c1410ee9436a6c47d17ceed674205abdd5d4e047 device.txt
+e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 build.log
+a279ca79c644c80f7a5b96064ae8467c0a10f381e5e7eefb3ec420b1ea473512 summary.txt
+5b5d7f7bbb8fb424e458ed20b2c82c77d3717783b965a4e1569ef7ef9eba41c8 host.log
+6ff1d93f7ae1523c94ce9b915e90d1483b62dda4d0cbc01874e09410689b93f6 chip-r1.log
+5ed0ea4eb4747d888c88200d4b84c62137ffe576c34fdbce5778f7e59e7cea12 chip-r2.log
+89cc8b1203d4cf0a0b68f6db637febb5e1b864d8f307d0c6575de783d7cf9c4e chip-r3.log
+ae3afea7c3304c5d378330b0c34b803705f409b7d3ce97768c6ebae037478453 control-mutant.log
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/build.log b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/build.log
new file mode 100644
index 000000000 ..e69de29bb
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r1.log b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r1.log
new file mode 100644
index 000000000 ..39c6197d5
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r1.log
@@ -0,0 +1,38 @@
+== shape n=1536 k=2048, 12 resident experts, pool of 5 slots, 64 churn rounds
+ok pool driver bytes 15732736 for 15732480 payload bytes (page rounding only)
+ok parity: 130 launches, pool y bit-identical to the resident tensor after every reload
+ok pin slot 0
+ok load into a pinned slot refused BUSY
+ok evict of a pinned slot refused BUSY
+ok entry of an unpinned slot refused
+ok reload slot 0 -> newer version
+ok launch with the replaced version refused STALE (nothing launched)
+ok NaN weight refused
+ok refused load leaves the slot EMPTY; its old version cannot be pinned
+ok references: experts 2 and 3 give different y
+ok load into the slot a recorded list reads: refused BUSY
+ok the list read the pinned expert 2 bit-exactly (submit ok=1)
+stats slots=5 device_bytes=15732480 loads=71 load_failures=1 busy=3 stale=2 pins=328 pinned_now=0 pinned_high=5 bytes_loaded=223401216 load_ns=75008057 load_GBps=2.978
+ok no pin leaked (pinned_now 0, high-water 5 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 10 -> 12)
+== shape n=2048 k=768, 12 resident experts, pool of 5 slots, 64 churn rounds
+ok pool driver bytes 7868416 for 7866240 payload bytes (page rounding only)
+ok parity: 130 launches, pool y bit-identical to the resident tensor after every reload
+ok pin slot 0
+ok load into a pinned slot refused BUSY
+ok evict of a pinned slot refused BUSY
+ok entry of an unpinned slot refused
+ok reload slot 0 -> newer version
+ok launch with the replaced version refused STALE (nothing launched)
+ok NaN weight refused
+ok refused load leaves the slot EMPTY; its old version cannot be pinned
+ok references: experts 2 and 3 give different y
+ok load into the slot a recorded list reads: refused BUSY
+ok the list read the pinned expert 2 bit-exactly (submit ok=1)
+stats slots=5 device_bytes=7866240 loads=71 load_failures=1 busy=3 stale=2 pins=328 pinned_now=0 pinned_high=5 bytes_loaded=111700608 load_ns=36773901 load_GBps=3.037
+ok no pin leaked (pinned_now 0, high-water 5 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 24 -> 26)
+GPU_FP8_SLOTS: PASS (32 checks, 0 failed)
+# exit 0
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r2.log b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r2.log
new file mode 100644
index 000000000 ..70972639b
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r2.log
@@ -0,0 +1,38 @@
+== shape n=1536 k=2048, 12 resident experts, pool of 5 slots, 64 churn rounds
+ok pool driver bytes 15732736 for 15732480 payload bytes (page rounding only)
+ok parity: 130 launches, pool y bit-identical to the resident tensor after every reload
+ok pin slot 0
+ok load into a pinned slot refused BUSY
+ok evict of a pinned slot refused BUSY
+ok entry of an unpinned slot refused
+ok reload slot 0 -> newer version
+ok launch with the replaced version refused STALE (nothing launched)
+ok NaN weight refused
+ok refused load leaves the slot EMPTY; its old version cannot be pinned
+ok references: experts 2 and 3 give different y
+ok load into the slot a recorded list reads: refused BUSY
+ok the list read the pinned expert 2 bit-exactly (submit ok=1)
+stats slots=5 device_bytes=15732480 loads=71 load_failures=1 busy=3 stale=2 pins=328 pinned_now=0 pinned_high=5 bytes_loaded=223401216 load_ns=74660335 load_GBps=2.992
+ok no pin leaked (pinned_now 0, high-water 5 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 10 -> 12)
+== shape n=2048 k=768, 12 resident experts, pool of 5 slots, 64 churn rounds
+ok pool driver bytes 7868416 for 7866240 payload bytes (page rounding only)
+ok parity: 130 launches, pool y bit-identical to the resident tensor after every reload
+ok pin slot 0
+ok load into a pinned slot refused BUSY
+ok evict of a pinned slot refused BUSY
+ok entry of an unpinned slot refused
+ok reload slot 0 -> newer version
+ok launch with the replaced version refused STALE (nothing launched)
+ok NaN weight refused
+ok refused load leaves the slot EMPTY; its old version cannot be pinned
+ok references: experts 2 and 3 give different y
+ok load into the slot a recorded list reads: refused BUSY
+ok the list read the pinned expert 2 bit-exactly (submit ok=1)
+stats slots=5 device_bytes=7866240 loads=71 load_failures=1 busy=3 stale=2 pins=328 pinned_now=0 pinned_high=5 bytes_loaded=111700608 load_ns=36664375 load_GBps=3.047
+ok no pin leaked (pinned_now 0, high-water 5 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 24 -> 26)
+GPU_FP8_SLOTS: PASS (32 checks, 0 failed)
+# exit 0
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r3.log b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r3.log
new file mode 100644
index 000000000 ..fd17b51da
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/chip-r3.log
@@ -0,0 +1,38 @@
+== shape n=1536 k=2048, 12 resident experts, pool of 5 slots, 64 churn rounds
+ok pool driver bytes 15732736 for 15732480 payload bytes (page rounding only)
+ok parity: 130 launches, pool y bit-identical to the resident tensor after every reload
+ok pin slot 0
+ok load into a pinned slot refused BUSY
+ok evict of a pinned slot refused BUSY
+ok entry of an unpinned slot refused
+ok reload slot 0 -> newer version
+ok launch with the replaced version refused STALE (nothing launched)
+ok NaN weight refused
+ok refused load leaves the slot EMPTY; its old version cannot be pinned
+ok references: experts 2 and 3 give different y
+ok load into the slot a recorded list reads: refused BUSY
+ok the list read the pinned expert 2 bit-exactly (submit ok=1)
+stats slots=5 device_bytes=15732480 loads=71 load_failures=1 busy=3 stale=2 pins=328 pinned_now=0 pinned_high=5 bytes_loaded=223401216 load_ns=75230871 load_GBps=2.970
+ok no pin leaked (pinned_now 0, high-water 5 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 10 -> 12)
+== shape n=2048 k=768, 12 resident experts, pool of 5 slots, 64 churn rounds
+ok pool driver bytes 7868416 for 7866240 payload bytes (page rounding only)
+ok parity: 130 launches, pool y bit-identical to the resident tensor after every reload
+ok pin slot 0
+ok load into a pinned slot refused BUSY
+ok evict of a pinned slot refused BUSY
+ok entry of an unpinned slot refused
+ok reload slot 0 -> newer version
+ok launch with the replaced version refused STALE (nothing launched)
+ok NaN weight refused
+ok refused load leaves the slot EMPTY; its old version cannot be pinned
+ok references: experts 2 and 3 give different y
+ok load into the slot a recorded list reads: refused BUSY
+ok the list read the pinned expert 2 bit-exactly (submit ok=1)
+stats slots=5 device_bytes=7866240 loads=71 load_failures=1 busy=3 stale=2 pins=328 pinned_now=0 pinned_high=5 bytes_loaded=111700608 load_ns=36729599 load_GBps=3.041
+ok no pin leaked (pinned_now 0, high-water 5 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 24 -> 26)
+GPU_FP8_SLOTS: PASS (32 checks, 0 failed)
+# exit 0
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/control-mutant.log b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/control-mutant.log
new file mode 100644
index 000000000 ..d78147dbc
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/control-mutant.log
@@ -0,0 +1,11 @@
+== shape n=1536 k=2048, 12 resident experts, pool of 5 slots, 64 churn rounds (MUTANT)
+ok pool driver bytes 15732736 for 15732480 payload bytes (page rounding only)
+ok references: experts 0 and 1 give different y
+info mutant: load into the pinned slot returned OK
+FAIL NEGATIVE CONTROL: list output equals pinned expert 0 (expected to FAIL under the mutant; read B=1)
+stats slots=5 device_bytes=15732480 loads=6 load_failures=0 busy=0 stale=0 pins=2 pinned_now=0 pinned_high=1 bytes_loaded=18878976 load_ns=6618002 load_GBps=2.853
+ok no pin leaked (pinned_now 0, high-water 1 <= 5)
+ok pool freed
+ok pool returned its 2 driver buffers (frees 9 -> 11)
+GPU_FP8_SLOTS_NEGATIVE_CONTROL: CAUGHT (1 of 6 checks failed)
+# exit 1
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/device.txt b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/device.txt
new file mode 100644
index 000000000 ..64c430064
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/device.txt
@@ -0,0 +1,5 @@
+start 2026-10-18T16:44:24Z omega=a8ae3a1f50d1d9115a24454b8a09b0cccf9620af branch=ribbon/slots dirty=1 physics=/home/drakestapleton/workspace/physics-own30b-k physics_commit=6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf physics_lock=6d7cf0d4d8eb2cda7b512100ff6058e25dbb3ddf
+Linux spark-b87b 7.0.0-1019-nvidia #19~24.04.2-Ubuntu SMP PREEMPT_DYNAMIC Sun Sep 6 18:35:11 UTC 2 aarch64 aarch64 aarch64 GNU/Linux
+NVIDIA GB10, 580.173.02
+ total used free shared buff/cache available
+Mem: 121 12 108 0 5 109
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/host.log b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/host.log
new file mode 100644
index 000000000 ..bb0a7363f
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/host.log
@@ -0,0 +1,27 @@
+ok init 4 slots
+ok pin of a never-loaded slot is STALE
+ok begin load slot 0
+ok double load refused BUSY
+ok a LOADING slot cannot be pinned (not visible before publish)
+ok publish -> version 1
+ok finish without begin refused
+ok pin v1
+ok reload while pinned refused BUSY
+ok evict while pinned refused BUSY
+ok unpin with a wrong version refused
+ok unpin v1
+ok unpin without a pin refused
+ok reload -> newer version
+ok stale handle (old version) refused after reload
+ok same key reloaded gets a fresh version (no ABA): v1=1 v3=3
+ok failed load publishes nothing
+ok failed load leaves the slot EMPTY
+ok evicted slot cannot be pinned
+ok out-of-range slot refused
+ok 1000 evict/reinsert cycles: versions strictly increase
+ok idle when nothing is pinned or loading
+ok race: 32085 reloads, 167915 busy refusals, 235768 reader pins, rewrites seen under a pin = 0
+info negative control (mutant ignores pins): 200000 reloads, 202018 reader pins, rewrites seen under a pin = 372037 (CAUGHT)
+ok mutant: readers observe rewrites under a pin (the race check has teeth)
+GPU_FP8_SLOTS: PASS (24 checks, 0 failed)
+# exit 0
diff --git a/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/summary.txt b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/summary.txt
new file mode 100644
index 000000000 ..c0e7b370b
--- /dev/null
+++ b/evidence/RIBBON-SLOTS-a8ae3a1f -20261018T1644Z/summary.txt
@@ -0,0 +1,5 @@
+host GPU_FP8_SLOTS: PASS (24 checks, 0 failed) exit=0
+chip r1 GPU_FP8_SLOTS: PASS (32 checks, 0 failed) exit=0
+chip r2 GPU_FP8_SLOTS: PASS (32 checks, 0 failed) exit=0
+chip r3 GPU_FP8_SLOTS: PASS (32 checks, 0 failed) exit=0
+control GPU_FP8_SLOTS_NEGATIVE_CONTROL: CAUGHT (1 of 6 checks failed) exit=1
diff --git a/src/omega_fp8_slot_table.c b/src/omega_fp8_slot_table.c
new file mode 100644
index 000000000 ..ca4acd47b
--- /dev/null
+++ b/src/omega_fp8_slot_table.c
@@ -0,0 +1,117 @@
+/* omega_fp8_slot_table.c: host-only slot state machine (see the header). */
+#include "omega_fp8_slot_table.h"
+#include <stdlib.h>
+#include <string.h>
+
+int omega_fp8_slot_table_init(OmegaFp8SlotTable *t, uint32_t slots) {
+ if (!t || slots == 0) return OMEGA_FP8_SLOT_BAD_ARGS;
+ memset(t, 0, sizeof *t);
+ t->rec = calloc(slots, sizeof *t->rec);
+ if (!t->rec) return OMEGA_FP8_SLOT_BAD_ARGS;
+ if (pthread_mutex_init(&t->mu, NULL) != 0) { free(t->rec); t->rec = NULL; return OMEGA_FP8_SLOT_BAD_ARGS; }
+ t->slots = slots;
+ t->next_version = 1;
+ return OMEGA_FP8_SLOT_OK;
+}
+
+void omega_fp8_slot_table_fini(OmegaFp8SlotTable *t) {
+ if (!t || !t->rec) return;
+ pthread_mutex_destroy(&t->mu);
+ free(t->rec);
+ t->rec = NULL;
+ t->slots = 0;
+}
+
+#define LOCKED(t, body) do { pthread_mutex_lock(&(t)->mu); body; pthread_mutex_unlock(&(t)->mu); } while (0)
+
+int omega_fp8_slot_begin_load(OmegaFp8SlotTable *t, uint32_t slot) {
+ if (!t || !t->rec || slot >= t->slots) return OMEGA_FP8_SLOT_BAD_ARGS;
+ int rc = OMEGA_FP8_SLOT_OK;
+ LOCKED(t, {
+ OmegaFp8SlotRec *r = &t->rec[slot];
+ if (r->state == OMEGA_FP8_SLOT_LOADING || (r->pins && !t->mutant)) { rc = OMEGA_FP8_SLOT_BUSY; t->stats.busy_refusals++; }
+ else r->state = OMEGA_FP8_SLOT_LOADING; /* hides the old version: pin(old) is STALE from here */
+ });
+ return rc;
+}
+
+int omega_fp8_slot_finish_load(OmegaFp8SlotTable *t, uint32_t slot, uint64_t key, int ok, uint64_t *version) {
+ if (version) *version = 0;
+ if (!t || !t->rec || slot >= t->slots) return OMEGA_FP8_SLOT_BAD_ARGS;
+ int rc = OMEGA_FP8_SLOT_OK;
+ LOCKED(t, {
+ OmegaFp8SlotRec *r = &t->rec[slot];
+ if (r->state != OMEGA_FP8_SLOT_LOADING) rc = OMEGA_FP8_SLOT_BAD_ARGS;
+ else if (ok) {
+ r->state = OMEGA_FP8_SLOT_READY; r->key = key; r->version = t->next_version++;
+ if (version) *version = r->version;
+ t->stats.loads++;
+ } else { r->state = OMEGA_FP8_SLOT_EMPTY; r->key = 0; t->stats.load_failures++; }
+ });
+ return rc;
+}
+
+int omega_fp8_slot_pin(OmegaFp8SlotTable *t, uint32_t slot, uint64_t version) {
+ if (!t || !t->rec || slot >= t->slots) return OMEGA_FP8_SLOT_BAD_ARGS;
+ int rc = OMEGA_FP8_SLOT_OK;
+ LOCKED(t, {
+ OmegaFp8SlotRec *r = &t->rec[slot];
+ if (r->state != OMEGA_FP8_SLOT_READY || r->version != version || version == 0) { rc = OMEGA_FP8_SLOT_STALE; t->stats.stale_refusals++; }
+ else {
+ r->pins++; t->stats.pins++; t->stats.pinned_now++;
+ if (t->stats.pinned_now > t->stats.pinned_high) t->stats.pinned_high = t->stats.pinned_now;
+ }
+ });
+ return rc;
+}
+
+int omega_fp8_slot_unpin(OmegaFp8SlotTable *t, uint32_t slot, uint64_t version) {
+ if (!t || !t->rec || slot >= t->slots) return OMEGA_FP8_SLOT_BAD_ARGS;
+ int rc = OMEGA_FP8_SLOT_OK;
+ LOCKED(t, {
+ OmegaFp8SlotRec *r = &t->rec[slot];
+ /* Under the mutant a pinned slot may have been reloaded: the pin is still dropped (version not checked). */
+ if (r->pins == 0 || (!t->mutant && r->version != version)) rc = OMEGA_FP8_SLOT_BAD_ARGS;
+ else { r->pins--; t->stats.pinned_now--; }
+ });
+ return rc;
+}
+
+int omega_fp8_slot_evict(OmegaFp8SlotTable *t, uint32_t slot) {
+ if (!t || !t->rec || slot >= t->slots) return OMEGA_FP8_SLOT_BAD_ARGS;
+ int rc = OMEGA_FP8_SLOT_OK;
+ LOCKED(t, {
+ OmegaFp8SlotRec *r = &t->rec[slot];
+ if (r->pins || r->state == OMEGA_FP8_SLOT_LOADING) { rc = OMEGA_FP8_SLOT_BUSY; t->stats.busy_refusals++; }
+ else { if (r->state == OMEGA_FP8_SLOT_READY) t->stats.evictions++; r->state = OMEGA_FP8_SLOT_EMPTY; r->key = 0; }
+ });
+ return rc;
+}
+
+int omega_fp8_slot_query(OmegaFp8SlotTable *t, uint32_t slot, OmegaFp8SlotRec *out) {
+ if (!t || !t->rec || slot >= t->slots || !out) return OMEGA_FP8_SLOT_BAD_ARGS;
+ LOCKED(t, { *out = t->rec[slot]; });
+ return OMEGA_FP8_SLOT_OK;
+}
+
+int omega_fp8_slot_table_idle(OmegaFp8SlotTable *t) {
+ if (!t || !t->rec) return 1;
+ int idle = 1;
+ LOCKED(t, {
+ for (uint32_t i = 0; i < t->slots; i++)
+ if (t->rec[i].pins || t->rec[i].state == OMEGA_FP8_SLOT_LOADING) { idle = 0; break; }
+ });
+ return idle;
+}
+
+void omega_fp8_slot_table_stats(OmegaFp8SlotTable *t, OmegaFp8SlotStats *out) {
+ if (!out) return;
+ memset(out, 0, sizeof *out);
+ if (!t || !t->rec) return;
+ LOCKED(t, { *out = t->stats; });
+}
+
+void omega_fp8_slot_table_set_mutant(OmegaFp8SlotTable *t, int mutant) {
+ if (!t || !t->rec) return;
+ LOCKED(t, { t->mutant = mutant; });
+}
diff --git a/src/omega_fp8_slot_table.h b/src/omega_fp8_slot_table.h
new file mode 100644
index 000000000 ..66dca74ce
--- /dev/null
+++ b/src/omega_fp8_slot_table.h
@@ -0,0 +1,77 @@
+#ifndef OMEGA_FP8_SLOT_TABLE_H
+#define OMEGA_FP8_SLOT_TABLE_H
+/*
+ * omega_fp8_slot_table: the host-only state machine behind omega_gpu_fp8_slots (Expert Ribbon, omega#533).
+ * No device code: every rule about who may read or rewrite a slot lives here so it can be tested without a chip.
+ *
+ * One record per slot: state, pins, key (caller's expert identity), version.
+ * EMPTY --begin_load--> LOADING --finish_load(ok)--> READY (version = next ring-wide version, never reused)
+ * LOADING --finish_load(fail)-> EMPTY (nothing published)
+ * READY --begin_load (0 pins)--> LOADING (the old version dies at that moment: pin(old) is STALE from then on)
+ * READY --evict (0 pins)--> EMPTY
+ * pin(slot, version) succeeds only on READY with exactly that version; begin_load and evict refuse (BUSY) while
+ * pins > 0. A pin is held for as long as any launch or recorded command list may read the slot; the caller drops it
+ * after the launch's completion marker (synchronous APIs: when the call returns; command lists: after submit).
+ * Versions are a single ring-wide counter starting at 1, so a (slot, version) pair names exactly one load (no ABA).
+ * Thread-safe (one mutex per table).
+ */
+#include <pthread.h>
+#include <stdint.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+enum {
+ OMEGA_FP8_SLOT_OK = 0,
+ OMEGA_FP8_SLOT_BAD_ARGS = -1, /* slot out of range, unpin without a pin, NULL */
+ OMEGA_FP8_SLOT_BUSY = -6, /* pinned or already loading: nothing changed */
+ OMEGA_FP8_SLOT_STALE = -7 /* the slot is not READY at that version (evicted, reloaded or never loaded) */
+};
+
+typedef enum { OMEGA_FP8_SLOT_EMPTY = 0, OMEGA_FP8_SLOT_LOADING = 1, OMEGA_FP8_SLOT_READY = 2 } OmegaFp8SlotState;
+
+typedef struct {
+ uint32_t state; /* OmegaFp8SlotState */
+ uint32_t pins;
+ uint64_t key; /* caller's identity of the loaded expert (meaningful in READY) */
+ uint64_t version; /* version of the READY contents; 0 = never published */
+} OmegaFp8SlotRec;
+
+typedef struct {
+ uint64_t loads; /* finish_load(ok) */
+ uint64_t load_failures; /* finish_load(fail) */
+ uint64_t busy_refusals; /* begin_load / evict refused because pinned or loading */
+ uint64_t stale_refusals; /* pin refused */
+ uint64_t evictions;
+ uint64_t pins; /* successful pins */
+ uint32_t pinned_now; /* sum of pins over slots */
+ uint32_t pinned_high; /* high-water of pinned_now */
+} OmegaFp8SlotStats;
+
+typedef struct {
+ pthread_mutex_t mu;
+ uint32_t slots;
+ OmegaFp8SlotRec *rec;
+ uint64_t next_version;
+ int mutant; /* TEST ONLY: 1 = begin_load ignores pins (the negative control must catch a rewritten in-use slot) */
+ OmegaFp8SlotStats stats;
+} OmegaFp8SlotTable;
+
+int omega_fp8_slot_table_init(OmegaFp8SlotTable *t, uint32_t slots);
+void omega_fp8_slot_table_fini(OmegaFp8SlotTable *t);
+int omega_fp8_slot_begin_load(OmegaFp8SlotTable *t, uint32_t slot);
+/* ok != 0 publishes (READY, *version = new version); ok == 0 leaves the slot EMPTY. Must follow begin_load. */
+int omega_fp8_slot_finish_load(OmegaFp8SlotTable *t, uint32_t slot, uint64_t key, int ok, uint64_t *version);
+int omega_fp8_slot_pin(OmegaFp8SlotTable *t, uint32_t slot, uint64_t version);
+int omega_fp8_slot_unpin(OmegaFp8SlotTable *t, uint32_t slot, uint64_t version);
+int omega_fp8_slot_evict(OmegaFp8SlotTable *t, uint32_t slot);
+int omega_fp8_slot_query(OmegaFp8SlotTable *t, uint32_t slot, OmegaFp8SlotRec *out);
+/* 1 when no slot is pinned or loading (safe to free the memory behind the table). */
+int omega_fp8_slot_table_idle(OmegaFp8SlotTable *t);
+void omega_fp8_slot_table_stats(OmegaFp8SlotTable *t, OmegaFp8SlotStats *out);
+void omega_fp8_slot_table_set_mutant(OmegaFp8SlotTable *t, int mutant);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/omega_gpu_fp8_api.c b/src/omega_gpu_fp8_api.c
index 199dab47a ..0af0a44b0 100644
--- a/src/omega_gpu_fp8_api.c
+++ b/src/omega_gpu_fp8_api.c
@@ -10,6 +10,7 @@
#include "omega_gpu_session.h"
#include "omega_gpu_fmt.h"
#include "omega_gpu_cmdlist.h"
+#include "omega_gpu_fp8_internal.h"
#include <stdlib.h>
#include <string.h>
@@ -414,3 +415,36 @@ int omega_gpu_fp8_gemv_grouped_record(OmegaGpuCmdList *cl, const OmegaGpuFp8Tens
/* ---- weight cache policy (OWN-30B L2 kernel-time cut) ---- */
void omega_gpu_fp8_set_weight_cache(int on) { omega_gpu_session_lock(); g.weights_cached = on ? 1 : 0; g.weights_cached_set = 1; omega_gpu_session_unlock(); }
int omega_gpu_fp8_weight_cache(void) { return g.weights_cached; }
+
+/* ---- slot pool support (omega_gpu_fp8_internal.h, Expert Ribbon omega#533) ---- */
+int omega_gpu_fp8_tensor_alloc_uncached(uint32_t experts, uint32_t n, uint32_t k, OmegaGpuFp8Tensor **out) {
+ if (out) *out = NULL;
+ if (!out || experts == 0 || n == 0 || k == 0 || n % OMEGA_FP8_BLOCK || k % OMEGA_FP8_BLOCK) return OMEGA_GPU_FP8_BAD_ARGS;
+ if (k > OMEGA_FP8_MAX_K) return OMEGA_GPU_FP8_TOO_LARGE;
+ const size_t wbytes = (size_t)experts * n * k, scount = (size_t)experts * (n / OMEGA_FP8_BLOCK) * (k / OMEGA_FP8_BLOCK);
+ OmegaGpuFp8Tensor *t = omega_gpu_host_calloc(1, sizeof *t);
+ if (!t) return OMEGA_GPU_FP8_BAD_ARGS;
+ t->experts = experts; t->n = n; t->k = k;
+ int rc = OMEGA_GPU_FP8_OK;
+ omega_gpu_session_lock();
+ if (!dev_open_locked() || omega_gpu_session_alloc(wbytes, &t->w) != 0 || omega_gpu_session_alloc(scount * 4u, &t->s) != 0) rc = OMEGA_GPU_FP8_CHIP_FAIL;
+ omega_gpu_session_unlock();
+ if (rc == OMEGA_GPU_FP8_OK) {
+ memset(t->w.cpu, 0, wbytes);
+ memset(t->s.cpu, 0, scount * 4u);
+ if (omega_gpu_session_sync_to_gpu(&t->w) != 0 || omega_gpu_session_sync_to_gpu(&t->s) != 0) rc = OMEGA_GPU_FP8_CHIP_FAIL;
+ }
+ if (rc != OMEGA_GPU_FP8_OK) { omega_gpu_fp8_tensor_free(t); return rc; }
+ *out = t;
+ return OMEGA_GPU_FP8_OK;
+}
+int omega_gpu_fp8_tensor_cpu_view(const OmegaGpuFp8Tensor *t, uint32_t expert, uint8_t **w, float **s) {
+ if (!t || !t->w.cpu || !t->s.cpu || expert >= t->experts || !w || !s) return OMEGA_GPU_FP8_BAD_ARGS;
+ *w = (uint8_t *)t->w.cpu + (size_t)expert * t->n * t->k;
+ *s = (float *)t->s.cpu + (size_t)expert * (t->n / OMEGA_FP8_BLOCK) * (t->k / OMEGA_FP8_BLOCK);
+ return OMEGA_GPU_FP8_OK;
+}
+int omega_gpu_fp8_tensor_sync_to_gpu(const OmegaGpuFp8Tensor *t) {
+ if (!t) return -1;
+ return (omega_gpu_session_sync_to_gpu(&t->w) != 0 || omega_gpu_session_sync_to_gpu(&t->s) != 0) ? -1 : 0;
+}
diff --git a/src/omega_gpu_fp8_internal.h b/src/omega_gpu_fp8_internal.h
new file mode 100644
index 000000000 ..4ceca4bcf
--- /dev/null
+++ b/src/omega_gpu_fp8_internal.h
@@ -0,0 +1,16 @@
+#ifndef OMEGA_GPU_FP8_INTERNAL_H
+#define OMEGA_GPU_FP8_INTERNAL_H
+/* Library-internal helpers of omega_gpu_fp8_api.c for omega_gpu_fp8_slots.c (Expert Ribbon, omega#533). Not part of the
+ * public ABI: the slot pool owns its tensor and is the only caller. */
+#include "omega_gpu_fp8_api.h"
+#include <stddef.h>
+#include <stdint.h>
+/* A zero-filled FP8 tensor of `experts` x [n][k] in GPU-UNCACHED memory, whatever omega_gpu_fp8_set_weight_cache says:
+ * slots are rewritten by the CPU while the process runs, and nvos.h:1117-1118 says GPU-cached system memory "will not be
+ * coherent with direct CPU mappings" (omega #457 measured 4096/4096 stale lines on a cached rewrite; uncached FRESH). */
+int omega_gpu_fp8_tensor_alloc_uncached(uint32_t experts, uint32_t n, uint32_t k, OmegaGpuFp8Tensor **out);
+/* CPU views of one expert: n*k weight bytes and (n/128)*(k/128) packed f32 scales. */
+int omega_gpu_fp8_tensor_cpu_view(const OmegaGpuFp8Tensor *t, uint32_t expert, uint8_t **w, float **s);
+/* CPU writes before the device reads them (platform SYNC on both buffers; Linux reference: dsb sy). 0 ok, -1. */
+int omega_gpu_fp8_tensor_sync_to_gpu(const OmegaGpuFp8Tensor *t);
+#endif
diff --git a/src/omega_gpu_fp8_slots.c b/src/omega_gpu_fp8_slots.c
new file mode 100644
index 000000000 ..839f466a0
--- /dev/null
+++ b/src/omega_gpu_fp8_slots.c
@@ -0,0 +1,155 @@
+/* omega_gpu_fp8_slots.c: versioned replaceable FP8 expert slots (see the header). */
+#include "omega_gpu_fp8_slots.h"
+#include "omega_gpu_fp8_internal.h"
+#include "omega_fp8_slot_table.h"
+#include "omega_gpu_session.h"
+#include "omega_gpu_fmt.h"
+#include <stdlib.h>
+#include <string.h>
+
+struct OmegaGpuFp8Slots {
+ uint32_t slots, n, k;
+ OmegaGpuFp8Tensor *t;
+ OmegaFp8SlotTable tab;
+ pthread_mutex_t mu; /* bytes_loaded / load_ns */
+ uint64_t bytes_loaded, load_ns;
+};
+
+const char *omega_gpu_fp8_slots_rc_name(int rc) {
+ switch (rc) {
+ case OMEGA_GPU_FP8_SLOTS_BUSY: return "BUSY";
+ case OMEGA_GPU_FP8_SLOTS_STALE: return "STALE";
+ default: return omega_gpu_fp8_rc_name(rc);
+ }
+}
+
+/* The table's codes are the pool's codes (OK 0, BAD_ARGS -1, BUSY -6, STALE -7). */
+_Static_assert(OMEGA_FP8_SLOT_BUSY == OMEGA_GPU_FP8_SLOTS_BUSY && OMEGA_FP8_SLOT_STALE == OMEGA_GPU_FP8_SLOTS_STALE &&
+ (int)OMEGA_FP8_SLOT_BAD_ARGS == (int)OMEGA_GPU_FP8_BAD_ARGS, "slot table codes");
+
+int omega_gpu_fp8_slots_alloc(uint32_t slots, uint32_t n, uint32_t k, OmegaGpuFp8Slots **out) {
+ if (out) *out = NULL;
+ if (!out || slots == 0) return OMEGA_GPU_FP8_BAD_ARGS;
+ OmegaGpuFp8Slots *p = calloc(1, sizeof *p);
+ if (!p) return OMEGA_GPU_FP8_BAD_ARGS;
+ p->slots = slots; p->n = n; p->k = k;
+ int rc = omega_gpu_fp8_tensor_alloc_uncached(slots, n, k, &p->t);
+ if (rc != OMEGA_GPU_FP8_OK) { free(p); return rc; }
+ if (omega_fp8_slot_table_init(&p->tab, slots) != 0 || pthread_mutex_init(&p->mu, NULL) != 0) {
+ omega_gpu_fp8_tensor_free(p->t); omega_fp8_slot_table_fini(&p->tab); free(p); return OMEGA_GPU_FP8_BAD_ARGS;
+ }
+ *out = p;
+ return OMEGA_GPU_FP8_OK;
+}
+
+int omega_gpu_fp8_slots_free(OmegaGpuFp8Slots *p) {
+ if (!p) return OMEGA_GPU_FP8_OK;
+ if (!omega_fp8_slot_table_idle(&p->tab)) return OMEGA_GPU_FP8_SLOTS_BUSY;
+ omega_gpu_fp8_tensor_free(p->t);
+ omega_fp8_slot_table_fini(&p->tab);
+ pthread_mutex_destroy(&p->mu);
+ free(p);
+ return OMEGA_GPU_FP8_OK;
+}
+
+const OmegaGpuFp8Tensor *omega_gpu_fp8_slots_tensor(const OmegaGpuFp8Slots *p) { return p ? p->t : NULL; }
+
+int omega_gpu_fp8_slots_load(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t key, const uint8_t *w, const uint16_t *scale,
+ uint64_t *version) {
+ if (version) *version = 0;
+ if (!p || !w || !scale || !version) return OMEGA_GPU_FP8_BAD_ARGS;
+ if (omega_gpu_session_is_blocked()) return OMEGA_GPU_FP8_CHIP_FAIL;
+ const uint64_t t0 = omega_gpu_session_now_ns();
+ int rc = omega_fp8_slot_begin_load(&p->tab, slot);
+ if (rc != OMEGA_FP8_SLOT_OK) return rc;
+ /* From here the slot is LOADING: invisible to pin, so the bytes below are never read half-written. */
+ const size_t wbytes = (size_t)p->n * p->k, scount = (size_t)(p->n / OMEGA_FP8_BLOCK) * (p->k / OMEGA_FP8_BLOCK);
+ uint8_t *wd = NULL; float *sd = NULL;
+ size_t first = 0;
+ if (omega_gpu_fp8_tensor_cpu_view(p->t, slot, &wd, &sd) != 0) rc = OMEGA_GPU_FP8_BAD_ARGS;
+ else if (omega_fp8_pack_scan_nan(w, wbytes, &first)) {
+ char e[120]; omega_gpu_fmt(e, sizeof e, "fp8 slot load: e4m3 NaN code at byte %zu", first);
+ omega_gpu_session_set_error(e);
+ rc = OMEGA_GPU_FP8_NAN_WEIGHT;
+ } else if (omega_fp8_pack_scales(scale, scount, sd, 0) != 0) {
+ omega_gpu_session_set_error("fp8 slot load: NaN, inf or overflowing scale");
+ rc = OMEGA_GPU_FP8_BAD_ARGS;
+ } else {
+ memcpy(wd, w, wbytes);
+ if (omega_gpu_fp8_tensor_sync_to_gpu(p->t) != 0) rc = OMEGA_GPU_FP8_CHIP_FAIL;
+ }
+ int frc = omega_fp8_slot_finish_load(&p->tab, slot, key, rc == OMEGA_GPU_FP8_OK, version);
+ if (rc == OMEGA_GPU_FP8_OK && frc != OMEGA_FP8_SLOT_OK) rc = frc;
+ if (rc == OMEGA_GPU_FP8_OK) {
+ pthread_mutex_lock(&p->mu);
+ p->bytes_loaded += wbytes + scount * 4u;
+ p->load_ns += omega_gpu_session_now_ns() - t0;
+ pthread_mutex_unlock(&p->mu);
+ }
+ return rc;
+}
+
+int omega_gpu_fp8_slots_pin(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t version) {
+ return p ? omega_fp8_slot_pin(&p->tab, slot, version) : OMEGA_GPU_FP8_BAD_ARGS;
+}
+int omega_gpu_fp8_slots_unpin(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t version) {
+ return p ? omega_fp8_slot_unpin(&p->tab, slot, version) : OMEGA_GPU_FP8_BAD_ARGS;
+}
+int omega_gpu_fp8_slots_evict(OmegaGpuFp8Slots *p, uint32_t slot) {
+ return p ? omega_fp8_slot_evict(&p->tab, slot) : OMEGA_GPU_FP8_BAD_ARGS;
+}
+
+int omega_gpu_fp8_slots_entry(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t version, uint64_t *w_va, uint64_t *s_va) {
+ if (!p || !w_va || !s_va) return OMEGA_GPU_FP8_BAD_ARGS;
+ OmegaFp8SlotRec r;
+ int rc = omega_fp8_slot_query(&p->tab, slot, &r);
+ if (rc != OMEGA_FP8_SLOT_OK) return rc;
+ if (r.state != OMEGA_FP8_SLOT_READY || r.version != version || version == 0) return OMEGA_GPU_FP8_SLOTS_STALE;
+ if (r.pins == 0) { omega_gpu_session_set_error("fp8 slot entry: slot not pinned (pin before taking its address)"); return OMEGA_GPU_FP8_BAD_ARGS; }
+ return omega_gpu_fp8_tensor_entry(p->t, slot, w_va, s_va);
+}
+
+int omega_gpu_fp8_slots_query(OmegaGpuFp8Slots *p, uint32_t slot, OmegaGpuFp8SlotInfo *out) {
+ if (!p || !out) return OMEGA_GPU_FP8_BAD_ARGS;
+ OmegaFp8SlotRec r;
+ int rc = omega_fp8_slot_query(&p->tab, slot, &r);
+ if (rc != OMEGA_FP8_SLOT_OK) return rc;
+ out->state = r.state; out->pins = r.pins; out->key = r.key; out->version = r.version;
+ return OMEGA_GPU_FP8_OK;
+}
+
+void omega_gpu_fp8_slots_stats(OmegaGpuFp8Slots *p, OmegaGpuFp8SlotsStats *out) {
+ if (!out) return;
+ memset(out, 0, sizeof *out);
+ if (!p) return;
+ OmegaFp8SlotStats s;
+ omega_fp8_slot_table_stats(&p->tab, &s);
+ out->slots = p->slots; out->n = p->n; out->k = p->k;
+ out->device_bytes = (uint64_t)p->slots * ((uint64_t)p->n * p->k + (uint64_t)(p->n / OMEGA_FP8_BLOCK) * (p->k / OMEGA_FP8_BLOCK) * 4u);
+ out->loads = s.loads; out->load_failures = s.load_failures; out->busy_refusals = s.busy_refusals;
+ out->stale_refusals = s.stale_refusals; out->evictions = s.evictions; out->pins = s.pins;
+ out->pinned_now = s.pinned_now; out->pinned_high = s.pinned_high;
+ pthread_mutex_lock(&p->mu);
+ out->bytes_loaded = p->bytes_loaded; out->load_ns = p->load_ns;
+ pthread_mutex_unlock(&p->mu);
+}
+
+int omega_gpu_fp8_slots_gemv_grouped_f32(OmegaGpuFp8Slots *p, uint32_t groups, const uint32_t *slots, const uint64_t *versions,
+ const float *x, uint32_t x_rows, float *y, OmegaGpuFp8Info *info) {
+ if (!p || !slots || !versions || groups == 0) return OMEGA_GPU_FP8_BAD_ARGS;
+ if (groups > OMEGA_GPU_FP8_MAX_GROUPS) return OMEGA_GPU_FP8_TOO_LARGE;
+ uint32_t pinned = 0;
+ int rc = OMEGA_GPU_FP8_OK;
+ for (; pinned < groups; pinned++) {
+ rc = omega_fp8_slot_pin(&p->tab, slots[pinned], versions[pinned]);
+ if (rc != OMEGA_FP8_SLOT_OK) break;
+ }
+ if (rc == OMEGA_GPU_FP8_OK) rc = omega_gpu_fp8_gemv_grouped_f32(p->t, groups, slots, x, x_rows, y, info);
+ /* The call returned after the launch's completion marker (or failed): no reader of these slots remains. */
+ for (uint32_t i = 0; i < pinned; i++) (void)omega_fp8_slot_unpin(&p->tab, slots[i], versions[i]);
+ return rc;
+}
+
+void omega_gpu_fp8_slots_test_set_mutant(OmegaGpuFp8Slots *p, int mutant) {
+ if (p) omega_fp8_slot_table_set_mutant(&p->tab, mutant);
+}
diff --git a/src/omega_gpu_fp8_slots.h b/src/omega_gpu_fp8_slots.h
new file mode 100644
index 000000000 ..1ad8f6475
--- /dev/null
+++ b/src/omega_gpu_fp8_slots.h
@@ -0,0 +1,84 @@
+#ifndef OMEGA_GPU_FP8_SLOTS_H
+#define OMEGA_GPU_FP8_SLOTS_H
+/*
+ * omega_gpu_fp8_slots: versioned, replaceable FP8 expert slots (Expert Ribbon, aienix#4 / omega#533).
+ *
+ * A pool is S fixed slots of one FP8 projection shape [n][k] (weights + block-128 scales), backed by ONE
+ * OmegaGpuFp8Tensor with experts = S, so every existing FP8 launch (grouped GEMV by slot index, the record path through
+ * a group table of omega_gpu_fp8_slots_entry addresses) reads a slot exactly as it reads a resident expert. Same kernel,
+ * same arithmetic: a slot holding expert E gives bit-identical y to a resident tensor holding E.
+ *
+ * Memory: GPU-UNCACHED always (nvos.h:1117-1118: GPU-cached system memory "will not be coherent with direct CPU
+ * mappings"; omega #457 gpu_l2_stale_test: a CPU rewrite of a cached weight buffer read stale lines, uncached FRESH).
+ * The AIEN_OMEGA_FP8_WEIGHT_CACHE / omega_gpu_fp8_set_weight_cache setting does not apply to pools.
+ *
+ * Protocol (state machine in omega_fp8_slot_table.h, host-tested):
+ * load(slot, key, w, scales) -> version
+ * refused BUSY while the slot is pinned or loading; the slot is hidden (LOADING) before the first byte is written,
+ * so no reader can pin the old or the half-written contents. NaN e4m3 codes refuse (NAN_WEIGHT), NaN/inf scales
+ * refuse (BAD_ARGS); a refused load leaves the slot EMPTY. Weights are copied byte for byte, scales packed as by
+ * omega_gpu_fp8_tensor_upload (f32 * 2^56); then the platform SYNC (CPU writes before device reads); only then is a
+ * new ring-wide version published. Versions never repeat, so (slot, version) names one load (no ABA).
+ * Does NOT take the session lock: a load may run while launches on other slots are in flight.
+ * pin(slot, version) / unpin(slot, version)
+ * a pin is the reader fence: hold it from before the launch is built until its completion marker is seen
+ * (synchronous APIs: until the call returns; a command list: until omega_gpu_cmdlist_submit returns).
+ * pin is refused STALE when the slot was reloaded, evicted or never loaded.
+ * entry(slot, version) -> {w_va, s_va}: only while pinned at that version (for a group table / router directory).
+ * evict(slot): BUSY while pinned.
+ * gemv_grouped_f32(slots, versions, ...): pins every slot, one grouped launch, unpins after the completion marker.
+ *
+ * Return codes: OMEGA_GPU_FP8_* (omega_gpu_fp8_api.h) plus BUSY / STALE below.
+ */
+#include "omega_gpu_fp8_api.h"
+#include <stdint.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define OMEGA_GPU_FP8_SLOTS_BUSY (-6)
+#define OMEGA_GPU_FP8_SLOTS_STALE (-7)
+
+typedef struct OmegaGpuFp8Slots OmegaGpuFp8Slots;
+
+typedef struct {
+ uint32_t state; /* 0 EMPTY, 1 LOADING, 2 READY */
+ uint32_t pins;
+ uint64_t key; /* caller's expert identity of the READY contents */
+ uint64_t version; /* 0 = never published */
+} OmegaGpuFp8SlotInfo;
+
+typedef struct {
+ uint32_t slots, n, k;
+ uint64_t device_bytes; /* weights + packed scales of the whole pool */
+ uint64_t loads, load_failures, busy_refusals, stale_refusals, evictions, pins;
+ uint32_t pinned_now, pinned_high;
+ uint64_t bytes_loaded; /* weight + scale bytes copied by successful loads */
+ uint64_t load_ns; /* summed wall time of successful loads (scan + copy + pack + sync) */
+} OmegaGpuFp8SlotsStats;
+
+int omega_gpu_fp8_slots_alloc(uint32_t slots, uint32_t n, uint32_t k, OmegaGpuFp8Slots **out);
+/* BUSY (nothing freed) while any slot is pinned or loading. */
+int omega_gpu_fp8_slots_free(OmegaGpuFp8Slots *p);
+/* The backing tensor (experts = slots): pass slot indices as expert ids to the FP8 launches. */
+const OmegaGpuFp8Tensor *omega_gpu_fp8_slots_tensor(const OmegaGpuFp8Slots *p);
+int omega_gpu_fp8_slots_load(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t key, const uint8_t *w, const uint16_t *scale_inv_bf16,
+ uint64_t *version);
+int omega_gpu_fp8_slots_pin(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t version);
+int omega_gpu_fp8_slots_unpin(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t version);
+int omega_gpu_fp8_slots_evict(OmegaGpuFp8Slots *p, uint32_t slot);
+int omega_gpu_fp8_slots_entry(OmegaGpuFp8Slots *p, uint32_t slot, uint64_t version, uint64_t *w_va, uint64_t *s_va);
+int omega_gpu_fp8_slots_query(OmegaGpuFp8Slots *p, uint32_t slot, OmegaGpuFp8SlotInfo *out);
+void omega_gpu_fp8_slots_stats(OmegaGpuFp8Slots *p, OmegaGpuFp8SlotsStats *out);
+/* Pins every (slot, version) (STALE: nothing launched, nothing left pinned), one grouped launch on the pool tensor
+ * (omega_gpu_fp8_gemv_grouped_f32 semantics: x_rows 1 or groups), unpins after it returned. */
+int omega_gpu_fp8_slots_gemv_grouped_f32(OmegaGpuFp8Slots *p, uint32_t groups, const uint32_t *slots, const uint64_t *versions,
+ const float *x, uint32_t x_rows, float *y, OmegaGpuFp8Info *info);
+const char *omega_gpu_fp8_slots_rc_name(int rc);
+/* TEST ONLY: 1 = load ignores pins (negative control: a reader must then see replaced weights). */
+void omega_gpu_fp8_slots_test_set_mutant(OmegaGpuFp8Slots *p, int mutant);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/tests/gpu_fp8_slots_test.c b/tests/gpu_fp8_slots_test.c
new file mode 100644
index 000000000 ..1ef57aa4f
--- /dev/null
+++ b/tests/gpu_fp8_slots_test.c
@@ -0,0 +1,289 @@
+/* gpu_fp8_slots_test: Expert Ribbon P1 (aienix#4 / omega#533), versioned replaceable FP8 expert slots.
+ *
+ * --host-only the slot state machine (omega_fp8_slot_table.c) without a device: publish only after a finished load,
+ * stale handles, double load, load/evict while pinned, ABA across reuse, failed loads, a threaded race
+ * (readers pin/unpin while a writer reloads; a reader must never observe its slot rewritten), mutant.
+ * --chip the pool on the GB10 (caller holds the GB10 lock):
+ * 1. parity: E random experts resident (one tensor) vs the same experts loaded into a smaller pool,
+ * grouped launch, y bit-identical, gate|up (1536x2048) and down (2048x768) shapes;
+ * 2. churn: --rounds reloads cycling every slot through every expert, parity after each reload;
+ * 3. refusals on the chip pool: load while pinned BUSY, pin of a replaced version STALE, entry unpinned;
+ * 4. reader fence through a recorded command list: the list's group table points at a pinned slot; a
+ * load into that slot before submit must be refused and the list must read the pinned expert;
+ * NEGATIVE CONTROL (--mutant): the pool ignores pins, the load goes through and the list reads the
+ * replaced weights, which the parity check must catch (exit 1 = caught);
+ * 5. memory: pool device bytes vs the session's driver allocation counter, pinned high-water.
+ * Exit 0 PASS, 1 FAIL (or, with --mutant, CAUGHT), 2 usage. Verdict line last. */
+#include "omega_fp8_slot_table.h"
+#include "omega_gpu_fp8_slots.h"
+#include "omega_gpu_fp8_api.h"
+#include "omega_gpu_session.h"
+#include "omega_gpu_cmdlist.h"
+#include <inttypes.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int g_failed, g_checks;
+#define CHECK(c, ...) do { g_checks++; if (c) { printf("ok "); } else { printf("FAIL "); g_failed++; } printf(__VA_ARGS__); printf("\n"); } while (0)
+
+static uint32_t lcg(uint32_t *s) { *s = *s * 1664525u + 1013904223u; return *s; }
+
+/* ---------------- host-only: the state machine ---------------- */
+
+typedef struct { OmegaFp8SlotTable *t; uint64_t *shadow_version; volatile int stop; uint64_t observed_rewrites, pins_ok; } Race;
+
+static void *reader(void *arg) {
+ Race *r = arg;
+ while (!r->stop) {
+ OmegaFp8SlotRec rec;
+ if (omega_fp8_slot_query(r->t, 0, &rec) != 0) continue;
+ if (rec.state != OMEGA_FP8_SLOT_READY) continue;
+ if (omega_fp8_slot_pin(r->t, 0, rec.version) != 0) continue;
+ r->pins_ok++;
+ /* while pinned, the shadow (the slot bytes) must keep holding the content of the pinned key */
+ for (int i = 0; i < 64; i++) if (__atomic_load_n(r->shadow_version, __ATOMIC_ACQUIRE) != rec.key) r->observed_rewrites++;
+ (void)omega_fp8_slot_unpin(r->t, 0, rec.version);
+ }
+ return NULL;
+}
+
+static int host_tests(void) {
+ OmegaFp8SlotTable t;
+ CHECK(omega_fp8_slot_table_init(&t, 4) == 0, "init 4 slots");
+ uint64_t v1 = 0, v2 = 0, v3 = 0;
+ CHECK(omega_fp8_slot_pin(&t, 0, 1) == OMEGA_FP8_SLOT_STALE, "pin of a never-loaded slot is STALE");
+ CHECK(omega_fp8_slot_begin_load(&t, 0) == 0, "begin load slot 0");
+ CHECK(omega_fp8_slot_begin_load(&t, 0) == OMEGA_FP8_SLOT_BUSY, "double load refused BUSY");
+ CHECK(omega_fp8_slot_pin(&t, 0, 1) == OMEGA_FP8_SLOT_STALE, "a LOADING slot cannot be pinned (not visible before publish)");
+ CHECK(omega_fp8_slot_finish_load(&t, 0, 100, 1, &v1) == 0 && v1 == 1, "publish -> version 1");
+ CHECK(omega_fp8_slot_finish_load(&t, 0, 100, 1, &v2) == OMEGA_FP8_SLOT_BAD_ARGS && v2 == 0, "finish without begin refused");
+ CHECK(omega_fp8_slot_pin(&t, 0, v1) == 0, "pin v1");
+ CHECK(omega_fp8_slot_begin_load(&t, 0) == OMEGA_FP8_SLOT_BUSY, "reload while pinned refused BUSY");
+ CHECK(omega_fp8_slot_evict(&t, 0) == OMEGA_FP8_SLOT_BUSY, "evict while pinned refused BUSY");
+ CHECK(omega_fp8_slot_unpin(&t, 0, v1 + 7) == OMEGA_FP8_SLOT_BAD_ARGS, "unpin with a wrong version refused");
+ CHECK(omega_fp8_slot_unpin(&t, 0, v1) == 0, "unpin v1");
+ CHECK(omega_fp8_slot_unpin(&t, 0, v1) == OMEGA_FP8_SLOT_BAD_ARGS, "unpin without a pin refused");
+ CHECK(omega_fp8_slot_begin_load(&t, 0) == 0 && omega_fp8_slot_finish_load(&t, 0, 200, 1, &v2) == 0 && v2 > v1, "reload -> newer version");
+ CHECK(omega_fp8_slot_pin(&t, 0, v1) == OMEGA_FP8_SLOT_STALE, "stale handle (old version) refused after reload");
+ /* ABA: slot 0 holds key 200; load key 100 again: the version must differ from v1 */
+ CHECK(omega_fp8_slot_begin_load(&t, 0) == 0 && omega_fp8_slot_finish_load(&t, 0, 100, 1, &v3) == 0 && v3 != v1 && v3 > v2,
+ "same key reloaded gets a fresh version (no ABA): v1=%" PRIu64 " v3=%" PRIu64, v1, v3);
+ CHECK(omega_fp8_slot_begin_load(&t, 1) == 0 && omega_fp8_slot_finish_load(&t, 1, 5, 0, &v2) == 0 && v2 == 0, "failed load publishes nothing");
+ OmegaFp8SlotRec rec;
+ CHECK(omega_fp8_slot_query(&t, 1, &rec) == 0 && rec.state == OMEGA_FP8_SLOT_EMPTY, "failed load leaves the slot EMPTY");
+ CHECK(omega_fp8_slot_evict(&t, 0) == 0 && omega_fp8_slot_pin(&t, 0, v3) == OMEGA_FP8_SLOT_STALE, "evicted slot cannot be pinned");
+ CHECK(omega_fp8_slot_begin_load(&t, 9) == OMEGA_FP8_SLOT_BAD_ARGS, "out-of-range slot refused");
+ /* repeated evict/reinsert: versions strictly increase */
+ uint64_t last = v3; int mono = 1;
+ for (int i = 0; i < 1000; i++) {
+ uint64_t v = 0;
+ if (omega_fp8_slot_begin_load(&t, (uint32_t)(i % 4)) != 0 || omega_fp8_slot_finish_load(&t, (uint32_t)(i % 4), (uint64_t)i, 1, &v) != 0 || v <= last) mono = 0;
+ last = v;
+ if (i % 3 == 0 && omega_fp8_slot_evict(&t, (uint32_t)(i % 4)) != 0) mono = 0;
+ }
+ CHECK(mono, "1000 evict/reinsert cycles: versions strictly increase");
+ CHECK(omega_fp8_slot_table_idle(&t), "idle when nothing is pinned or loading");
+ omega_fp8_slot_table_fini(&t);
+
+ /* threaded race: 4 readers pin slot 0 at its current version; one writer reloads it as fast as it can. The shadow
+ * stands for the slot's bytes: the writer bumps it between begin_load and finish_load (while the slot is hidden). */
+ for (int mutant = 0; mutant <= 1; mutant++) {
+ OmegaFp8SlotTable rt; omega_fp8_slot_table_init(&rt, 1);
+ omega_fp8_slot_table_set_mutant(&rt, mutant);
+ uint64_t shadow = 0, v = 0;
+ omega_fp8_slot_begin_load(&rt, 0); omega_fp8_slot_finish_load(&rt, 0, 0, 1, &v);
+ __atomic_store_n(&shadow, 0, __ATOMIC_RELEASE);
+ Race r = { .t = &rt, .shadow_version = &shadow };
+ pthread_t th[4];
+ for (int i = 0; i < 4; i++) pthread_create(&th[i], NULL, reader, &r);
+ uint64_t reloads = 0, busy = 0;
+ for (int i = 0; i < 200000; i++) {
+ if (omega_fp8_slot_begin_load(&rt, 0) != 0) { busy++; continue; }
+ __atomic_store_n(&shadow, 0xDEADull << 32, __ATOMIC_RELEASE); /* "bytes" half-written */
+ __atomic_store_n(&shadow, (uint64_t)i + 1, __ATOMIC_RELEASE); /* "bytes" complete: the content of key i + 1 */
+ uint64_t nv = 0; omega_fp8_slot_finish_load(&rt, 0, (uint64_t)i + 1, 1, &nv);
+ reloads++;
+ }
+ r.stop = 1;
+ for (int i = 0; i < 4; i++) pthread_join(th[i], NULL);
+ if (!mutant)
+ CHECK(r.observed_rewrites == 0 && reloads > 0 && r.pins_ok > 0,
+ "race: %" PRIu64 " reloads, %" PRIu64 " busy refusals, %" PRIu64 " reader pins, rewrites seen under a pin = %" PRIu64,
+ reloads, busy, r.pins_ok, r.observed_rewrites);
+ else
+ printf("info negative control (mutant ignores pins): %" PRIu64 " reloads, %" PRIu64 " reader pins, rewrites seen under a pin = %" PRIu64 " (%s)\n",
+ reloads, r.pins_ok, r.observed_rewrites, r.observed_rewrites ? "CAUGHT" : "not observed this run");
+ if (mutant) CHECK(r.observed_rewrites > 0, "mutant: readers observe rewrites under a pin (the race check has teeth)");
+ omega_fp8_slot_table_fini(&rt);
+ }
+ return 0;
+}
+
+/* ---------------- chip ---------------- */
+
+static void fill_expert(uint32_t seed, uint32_t n, uint32_t k, uint8_t *w, uint16_t *s) {
+ uint32_t st = seed * 2654435761u + 7u;
+ for (size_t i = 0; i < (size_t)n * k; i++) { uint8_t b = (uint8_t)(lcg(&st) >> 24); w[i] = (b & 0x7F) == 0x7F ? 0x3C : b; }
+ for (size_t i = 0; i < (size_t)(n / 128) * (k / 128); i++) s[i] = (uint16_t)(0x3B00u + (lcg(&st) >> 24) % 0x200u); /* bf16 ~2^-9..2^-7 */
+}
+
+static int chip_shape(uint32_t n, uint32_t k, uint32_t E, uint32_t S, uint32_t rounds, int mutant) {
+ printf("== shape n=%u k=%u, %u resident experts, pool of %u slots, %u churn rounds%s\n", n, k, E, S, rounds, mutant ? " (MUTANT)" : "");
+ const size_t wb = (size_t)n * k, sc = (size_t)(n / 128) * (k / 128);
+ uint8_t *w = malloc(wb * E); uint16_t *s = malloc(sc * 2 * E);
+ float *x = malloc((size_t)k * 4 * 8), *yr = malloc((size_t)n * 4 * 8), *yp = malloc((size_t)n * 4 * 8);
+ if (!w || !s || !x || !yr || !yp) return 1;
+ for (uint32_t e = 0; e < E; e++) fill_expert(e + n, n, k, w + wb * e, s + sc * e);
+ uint32_t st = 99;
+ for (uint32_t i = 0; i < k * 8; i++) x[i] = (float)(lcg(&st) >> 8) / 16777216 .0f * 2.0f - 1.0f;
+ OmegaGpuFp8Tensor *res = NULL;
+ int rc = omega_gpu_fp8_tensor_upload(E, n, k, w, s, &res);
+ if (rc != 0) { printf("FAIL resident upload: %s (%s)\n", omega_gpu_fp8_rc_name(rc), omega_gpu_fp8_last_error()); return 1; }
+ OmegaGpuAllocStats a0; omega_gpu_session_alloc_stats(&a0);
+ OmegaGpuFp8Slots *p = NULL;
+ rc = omega_gpu_fp8_slots_alloc(S, n, k, &p);
+ OmegaGpuAllocStats a1; omega_gpu_session_alloc_stats(&a1);
+ if (rc != 0) { printf("FAIL pool alloc: %s (%s)\n", omega_gpu_fp8_rc_name(rc), omega_gpu_fp8_last_error()); return 1; }
+ OmegaGpuFp8SlotsStats ps; omega_gpu_fp8_slots_stats(p, &ps);
+ CHECK(a1.alloc_bytes - a0.alloc_bytes >= ps.device_bytes && a1.alloc_bytes - a0.alloc_bytes <= ps.device_bytes + 2u * 65536u,
+ "pool driver bytes %" PRIu64 " for %" PRIu64 " payload bytes (page rounding only)", a1.alloc_bytes - a0.alloc_bytes, ps.device_bytes);
+ uint64_t *ver = calloc(S, 8); uint32_t *held = calloc(S, 4);
+ for (uint32_t sl = 0; sl < S; sl++) {
+ held[sl] = sl % E;
+ rc = omega_gpu_fp8_slots_load(p, sl, held[sl], w + wb * held[sl], s + sc * held[sl], &ver[sl]);
+ if (rc != 0) { printf("FAIL load slot %u: %s\n", sl, omega_gpu_fp8_slots_rc_name(rc)); return 1; }
+ }
+ /* 1 + 2: parity after every reload; groups = min(S, 8) slots per launch, shared x row (gate|up) or a row per group (down) */
+ const uint32_t G = S < 8 ? S : 8;
+ uint32_t mism = 0, launches = 0;
+ for (uint32_t r = 0; r <= rounds && !mutant; r++) {
+ if (r > 0) { /* reload one slot with the next expert in the cycle */
+ uint32_t sl = (r - 1) % S; held[sl] = (held[sl] + 1 + (r % 3)) % E;
+ rc = omega_gpu_fp8_slots_load(p, sl, held[sl], w + wb * held[sl], s + sc * held[sl], &ver[sl]);
+ if (rc != 0) { printf("FAIL reload r%u: %s\n", r, omega_gpu_fp8_slots_rc_name(rc)); mism++; break; }
+ }
+ uint32_t sls[8], ids[8]; uint64_t vs[8];
+ for (uint32_t g = 0; g < G; g++) { sls[g] = (r + g) % S; vs[g] = ver[sls[g]]; ids[g] = held[sls[g]]; }
+ const uint32_t xr = (r & 1) ? G : 1;
+ int a = omega_gpu_fp8_gemv_grouped_f32(res, G, ids, x, xr, yr, NULL);
+ int b = omega_gpu_fp8_slots_gemv_grouped_f32(p, G, sls, vs, x, xr, yp, NULL);
+ launches += 2;
+ if (a != 0 || b != 0) { printf("FAIL launch r%u: resident %s pool %s (%s)\n", r, omega_gpu_fp8_rc_name(a), omega_gpu_fp8_slots_rc_name(b), omega_gpu_fp8_last_error()); mism++; break; }
+ if (memcmp(yr, yp, (size_t)G * n * 4) != 0) mism++;
+ }
+ if (!mutant) CHECK(mism == 0, "parity: %u launches, pool y bit-identical to the resident tensor after every reload", launches);
+
+ /* 3: refusals on the chip pool */
+ if (!mutant) {
+ CHECK(omega_gpu_fp8_slots_pin(p, 0, ver[0]) == 0, "pin slot 0");
+ uint64_t vx = 0;
+ CHECK(omega_gpu_fp8_slots_load(p, 0, 7, w, s, &vx) == OMEGA_GPU_FP8_SLOTS_BUSY && vx == 0, "load into a pinned slot refused BUSY");
+ CHECK(omega_gpu_fp8_slots_evict(p, 0) == OMEGA_GPU_FP8_SLOTS_BUSY, "evict of a pinned slot refused BUSY");
+ omega_gpu_fp8_slots_unpin(p, 0, ver[0]);
+ uint64_t wva, sva;
+ CHECK(omega_gpu_fp8_slots_entry(p, 0, ver[0], &wva, &sva) == OMEGA_GPU_FP8_BAD_ARGS, "entry of an unpinned slot refused");
+ uint64_t old = ver[0];
+ CHECK(omega_gpu_fp8_slots_load(p, 0, held[0], w + wb * held[0], s + sc * held[0], &ver[0]) == 0 && ver[0] > old, "reload slot 0 -> newer version");
+ uint32_t sl0 = 0;
+ CHECK(omega_gpu_fp8_slots_gemv_grouped_f32(p, 1, &sl0, &old, x, 1, yp, NULL) == OMEGA_GPU_FP8_SLOTS_STALE, "launch with the replaced version refused STALE (nothing launched)");
+ uint8_t *bad = malloc(wb); memcpy(bad, w, wb); bad[wb / 2] = 0x7F;
+ uint64_t vb = 1;
+ CHECK(omega_gpu_fp8_slots_load(p, 1, 9, bad, s, &vb) == OMEGA_GPU_FP8_NAN_WEIGHT && vb == 0, "NaN weight refused");
+ OmegaGpuFp8SlotInfo inf; omega_gpu_fp8_slots_query(p, 1, &inf);
+ CHECK(inf.state == 0 && omega_gpu_fp8_slots_pin(p, 1, ver[1]) == OMEGA_GPU_FP8_SLOTS_STALE, "refused load leaves the slot EMPTY; its old version cannot be pinned");
+ free(bad);
+ rc = omega_gpu_fp8_slots_load(p, 1, held[1], w + wb * held[1], s + sc * held[1], &ver[1]);
+ if (rc != 0) g_failed++;
+ }
+
+ /* 4: reader fence through a recorded command list */
+ {
+ if (mutant) omega_gpu_fp8_slots_test_set_mutant(p, 1);
+ const uint32_t A = held[0], B = (held[0] + 1) % E;
+ OmegaGpuCmdList *cl = NULL; OmegaGpuMem tab, xd, yd;
+ if (omega_gpu_cmdlist_create(4, &cl) != 0) { printf("FAIL cmdlist create: %s\n", omega_gpu_session_last_error()); return 1; }
+ omega_gpu_session_lock();
+ int arc = omega_gpu_session_alloc(16u, &tab) | omega_gpu_session_alloc((size_t)k * 4u, &xd) | omega_gpu_session_alloc((size_t)n * 4u, &yd);
+ omega_gpu_session_unlock();
+ if (arc) { printf("FAIL alloc: %s\n", omega_gpu_session_last_error()); return 1; }
+ omega_fp8_pack_x_f32(x, k, xd.cpu);
+ float *y = yd.cpu; for (uint32_t i = 0; i < n; i++) y[i] = -999.0f;
+ /* reference for A and B on the resident tensor */
+ float *ya = malloc((size_t)n * 4), *yb = malloc((size_t)n * 4);
+ int r1 = omega_gpu_fp8_gemv_grouped_f32(res, 1, &A, x, 1, ya, NULL), r2 = omega_gpu_fp8_gemv_grouped_f32(res, 1, &B, x, 1, yb, NULL);
+ CHECK(r1 == 0 && r2 == 0 && memcmp(ya, yb, (size_t)n * 4) != 0, "references: experts %u and %u give different y", A, B);
+ /* warm the kernel (grouped 1, x_rows 1) through the pool before recording */
+ uint32_t sl0 = 0; float *yw = malloc((size_t)n * 4);
+ (void)omega_gpu_fp8_slots_gemv_grouped_f32(p, 1, &sl0, &ver[0], x, 1, yw, NULL);
+ int ok = omega_gpu_fp8_slots_pin(p, 0, ver[0]) == 0;
+ uint64_t *tw = tab.cpu;
+ ok = ok && omega_gpu_fp8_slots_entry(p, 0, ver[0], &tw[0], &tw[1]) == 0;
+ ok = ok && omega_gpu_session_sync_to_gpu(&tab) == 0 && omega_gpu_session_sync_to_gpu(&xd) == 0 && omega_gpu_session_sync_to_gpu(&yd) == 0;
+ omega_gpu_session_lock();
+ omega_gpu_cmdlist_reset(cl);
+ ok = ok && omega_gpu_fp8_gemv_grouped_record(cl, omega_gpu_fp8_slots_tensor(p), 1, tab.va, xd.va, 1, yd.va) == 0;
+ omega_gpu_session_unlock();
+ /* the replacement attempt: between record and submit (the list may read the slot from here until submit returns) */
+ uint64_t vnew = 0;
+ int lrc = omega_gpu_fp8_slots_load(p, 0, B, w + wb * B, s + sc * B, &vnew);
+ if (!mutant) CHECK(lrc == OMEGA_GPU_FP8_SLOTS_BUSY, "load into the slot a recorded list reads: refused BUSY");
+ else printf("info mutant: load into the pinned slot returned %s\n", omega_gpu_fp8_slots_rc_name(lrc));
+ OmegaGpuCmdListOpts o; memset(&o, 0, sizeof o); o.mode = OMEGA_GPU_CMDLIST_PCAS;
+ OmegaGpuCmdListStats cs; memset(&cs, 0, sizeof cs);
+ omega_gpu_session_lock();
+ ok = ok && omega_gpu_cmdlist_submit(cl, &o, &cs) == 0;
+ omega_gpu_session_unlock();
+ ok = ok && omega_gpu_session_sync_to_cpu(&yd) == 0;
+ (void)omega_gpu_fp8_slots_unpin(p, 0, ver[0]);
+ const int same_a = ok && memcmp(y, ya, (size_t)n * 4) == 0, same_b = ok && memcmp(y, yb, (size_t)n * 4) == 0;
+ if (!mutant) CHECK(ok && same_a, "the list read the pinned expert %u bit-exactly (submit ok=%d)", A, ok);
+ else {
+ CHECK(ok && same_a, "NEGATIVE CONTROL: list output equals pinned expert %u (expected to FAIL under the mutant; read B=%d)", A, same_b);
+ }
+ free(ya); free(yb); free(yw);
+ omega_gpu_session_lock(); omega_gpu_session_free(&tab); omega_gpu_session_free(&xd); omega_gpu_session_free(&yd); omega_gpu_session_unlock();
+ omega_gpu_cmdlist_free(cl);
+ if (mutant) omega_gpu_fp8_slots_test_set_mutant(p, 0);
+ }
+
+ omega_gpu_fp8_slots_stats(p, &ps);
+ printf("stats slots=%u device_bytes=%" PRIu64 " loads=%" PRIu64 " load_failures=%" PRIu64 " busy=%" PRIu64 " stale=%" PRIu64
+ " pins=%" PRIu64 " pinned_now=%u pinned_high=%u bytes_loaded=%" PRIu64 " load_ns=%" PRIu64 " load_GBps=%.3f\n",
+ ps.slots, ps.device_bytes, ps.loads, ps.load_failures, ps.busy_refusals, ps.stale_refusals, ps.pins, ps.pinned_now,
+ ps.pinned_high, ps.bytes_loaded, ps.load_ns, ps.load_ns ? (double)ps.bytes_loaded / (double)ps.load_ns : 0.0);
+ CHECK(ps.pinned_now == 0 && ps.pinned_high <= G, "no pin leaked (pinned_now 0, high-water %u <= %u)", ps.pinned_high, G);
+ OmegaGpuAllocStats a2; omega_gpu_session_alloc_stats(&a2);
+ CHECK(omega_gpu_fp8_slots_free(p) == 0, "pool freed");
+ OmegaGpuAllocStats a3; omega_gpu_session_alloc_stats(&a3);
+ CHECK(a3.frees >= a2.frees + 2, "pool returned its 2 driver buffers (frees %" PRIu64 " -> %" PRIu64 ")", a2.frees, a3.frees);
+ omega_gpu_fp8_tensor_free(res);
+ free(w); free(s); free(x); free(yr); free(yp); free(ver); free(held);
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ int host = 0, chip = 0, mutant = 0; uint32_t rounds = 64;
+ for (int i = 1; i < argc; i++) {
+ if (!strcmp(argv[i], "--host-only")) host = 1;
+ else if (!strcmp(argv[i], "--chip")) chip = 1;
+ else if (!strcmp(argv[i], "--mutant")) mutant = 1;
+ else if (!strcmp(argv[i], "--rounds") && i + 1 < argc) rounds = (uint32_t)atoi(argv[++i]);
+ else { printf("usage: %s --host-only | --chip [--rounds R] [--mutant]\n", argv[0]); return 2; }
+ }
+ if (!host && !chip) { printf("usage: %s --host-only | --chip [--rounds R] [--mutant]\n", argv[0]); return 2; }
+ if (host) host_tests();
+ if (chip) {
+ (void)omega_gpu_session_set_spin_us(2000);
+ chip_shape(1536, 2048, 12, 5, rounds, mutant); /* gate|up */
+ if (!mutant) chip_shape(2048, 768, 12, 5, rounds, 0); /* down */
+ if (omega_gpu_session_is_blocked()) { printf("FAIL session latched\n"); g_failed++; }
+ }
+ if (mutant) {
+ printf("GPU_FP8_SLOTS_NEGATIVE_CONTROL: %s (%d of %d checks failed)\n", g_failed ? "CAUGHT" : "NOT CAUGHT", g_failed, g_checks);
+ return g_failed ? 1 : 0;
+ }
+ printf("GPU_FP8_SLOTS: %s (%d checks, %d failed)\n", g_failed ? "FAIL" : "PASS", g_checks, g_failed);
+ return g_failed ? 1 : 0;
+}
diff --git a/tools/run_gpu_fp8_slots_chip.sh b/tools/run_gpu_fp8_slots_chip.sh
new file mode 100755
index 000000000 ..412875073
--- /dev/null
+++ b/tools/run_gpu_fp8_slots_chip.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+# run_gpu_fp8_slots_chip.sh EVIDENCE_DIR [PHYSICS_DIR]
+# Expert Ribbon P1 chip gate (aienix#4 / omega#533): versioned replaceable FP8 expert slots on the GB10.
+# host tests/gpu_fp8_slots_test.c --host-only (state machine, threaded race, mutant)
+# chip r1-3 --chip: parity vs a resident tensor after every reload (gate|up 1536x2048 and down 2048x768), refusals,
+# reader fence through a recorded command list, memory accounting. Must PASS (exit 0) 3/3.
+# control --chip --mutant: the pool ignores pins; the recorded list must read replaced weights and the parity
+# check must catch it (exit 1, "CAUGHT"). A control that is NOT caught fails the gate.
+# Caller holds the GB10 lock: flock /tmp/aien-gb10.lock tools/run_gpu_fp8_slots_chip.sh EVID
+# Verdict line last: "GPU_FP8_SLOTS_CHIP: PASS|FAIL".
+set -u
+EVID="${1:?evidence dir}"; PHYS="${2:-$HOME/workspace/physics-own30b-k}"
+HERE="$(cd "$(dirname "$0")/.." && pwd)"
+mkdir -p "$EVID"
+cd "$HERE" || exit 2
+{
+ echo "start $(date -u +%FT%TZ) omega=$(git rev-parse HEAD) branch=$(git rev-parse --abbrev-ref HEAD) dirty=$(git status --porcelain | wc -l) physics=$PHYS physics_commit=$(git -C "$PHYS" rev-parse HEAD) physics_lock=$(head -1 physics.lock)"
+ uname -a; nvidia-smi --query-gpu=name,driver_version --format=csv,noheader 2>/dev/null; free -g | head -2
+} > "$EVID/device.txt"
+make PHYSICS_DIR="$PHYS" -j10 build/gpu_fp8_slots_test > "$EVID/build.log" 2>&1 || { echo "GPU_FP8_SLOTS_CHIP: FAIL build"; exit 1; }
+# A stale nvrm.o compiled from another physics checkout survives a PHYSICS_DIR change (make sees it up to
+# date) and changes the allocator under the test: refuse the run unless nvrm.o came from $PHYS.
+NVRM_D=$(find build -name nvrm.d | head -1)
+if [ -z "$NVRM_D" ] || ! grep -q "$(cd "$PHYS" && pwd)/nvrm/nvrm.c" "$NVRM_D"; then
+ echo "GPU_FP8_SLOTS_CHIP: FAIL build (nvrm.o not built from $PHYS; rm -rf build and rerun)"; exit 1
+fi
+T=./build/gpu_fp8_slots_test
+fail=0
+$T --host-only > "$EVID/host.log" 2>&1; e=$?; echo "# exit $e" >> "$EVID/host.log"; [ "$e" = 0 ] || fail=1
+echo "host $(tail -2 "$EVID/host.log" | head -1) exit=$e" | tee "$EVID/summary.txt"
+for r in 1 2 3; do
+ f="$EVID/chip-r$r.log"
+ $T --chip --rounds 64 > "$f" 2>&1; e=$?; echo "# exit $e" >> "$f"
+ [ "$e" = 0 ] || fail=1
+ echo "chip r$r $(grep -h '^GPU_FP8_SLOTS' "$f" | tail -1) exit=$e" | tee -a "$EVID/summary.txt"
+done
+f="$EVID/control-mutant.log"
+$T --chip --mutant > "$f" 2>&1; e=$?; echo "# exit $e" >> "$f"
+grep -q 'NEGATIVE_CONTROL: CAUGHT' "$f" && [ "$e" = 1 ] || fail=1
+echo "control $(grep -h 'NEGATIVE_CONTROL' "$f" | tail -1) exit=$e" | tee -a "$EVID/summary.txt"
+( cd "$EVID" && sha256sum device.txt build.log summary.txt host.log chip-r*.log control-mutant.log > SHA256SUMS )
+if [ $fail = 0 ]; then echo "GPU_FP8_SLOTS_CHIP: PASS"; else echo "GPU_FP8_SLOTS_CHIP: FAIL"; exit 1; fi