From 665ae37b73d5eb387d86add48e3dcb0cc7ebae39 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 22:21:33 -0500 Subject: [PATCH 1/4] omega: CUDA++ sources move in, and the motor gets its home Eight Omega pieces move from the omega compiler branch into this repo: doorbell token and ring, GSP sequencer, NVRM submit, VA allocator, open plan, kernel policy, userspace submit, and the motor launch scheme copied from the FP8 path (omega_gpu_session_launch). The gate is tests/omega/run.sh, which runs the omega compiler harness against this repo's omega/slices. motor/README.md makes this repo the home for motor work going forward. Gate: slice-run 92/92 at commit time, RC=0. --- motor/README.md | 21 +++++ omega/slices/doorbell.osc | 57 +++++++++++++ omega/slices/kmod.osc | 84 +++++++++++++++++++ omega/slices/launch.osc | 86 +++++++++++++++++++ omega/slices/mesa.osc | 66 +++++++++++++++ omega/slices/nvrm.osc | 141 +++++++++++++++++++++++++++++++ omega/slices/open_plan.osc | 60 ++++++++++++++ omega/slices/sequencer.osc | 123 +++++++++++++++++++++++++++ omega/slices/va.osc | 166 +++++++++++++++++++++++++++++++++++++ tests/omega/run.sh | 14 ++++ 10 files changed, 818 insertions(+) create mode 100644 motor/README.md create mode 100644 omega/slices/doorbell.osc create mode 100644 omega/slices/kmod.osc create mode 100644 omega/slices/launch.osc create mode 100644 omega/slices/mesa.osc create mode 100644 omega/slices/nvrm.osc create mode 100644 omega/slices/open_plan.osc create mode 100644 omega/slices/sequencer.osc create mode 100644 omega/slices/va.osc create mode 100755 tests/omega/run.sh diff --git a/motor/README.md b/motor/README.md new file mode 100644 index 00000000..6460ef52 --- /dev/null +++ b/motor/README.md @@ -0,0 +1,21 @@ +# motor + +The motor is CUDA++ serving: the live 35B on port 18091, the stroke, chunked +prefill, and the FP8 grouped GEMM. This directory is its home in CUDA++. + +What is here now: + +- `../omega/slices/launch.osc` is the motor's submit scheme in Omega, copied + from `omega_gpu_session_launch`: the method header `bw_mthd`, the 18 + compute-class setup words, the shader-cache invalidate, the constant-bank + bind, and the QMD launch method 0x0318 with its two address words. + +What is still in `~/workspace/omega-motor` on this box (C, to port): + +- `src/omega_gpu_session.c`: session open, alloc, launch, retire. +- `src/omega_blackwell_submit.c`: pushbuffer build and submit. +- `src/omega_gpu_fp8gemm_api.c`: the FP8 GEMM the prefill runs. + +New motor work lands here, in Omega, with a run line per behaviour. The gate +is `tests/omega/run.sh` at the repo root. Nothing here restarts the live +server or touches the GPU outside a scheduled window. diff --git a/omega/slices/doorbell.osc b/omega/slices/doorbell.osc new file mode 100644 index 00000000..d1dc14f0 --- /dev/null +++ b/omega/slices/doorbell.osc @@ -0,0 +1,57 @@ +// slice-entry: doorbell_token doorbell_off doorbell_bar doorbell_ring +// Our doorbell. No video path. Channel id in bits 11:0, runlist id in bits 22:16. +// A value that does not fit refuses. The store is one write of that token at byte +// offset 144, cell 18 of the usermode page. BAR0 offset of the same word is 196752. +// Expected values from Wolfram: (3,42)->196650, (127,4095)->8327167, (64,0)->4194304. +// slice-run: doorbell_token bytes: 0 1 -> 1 +// slice-run: doorbell_token bytes: 1 0 -> 65536 +// slice-run: doorbell_token bytes: 3 42 -> 196650 +// slice-run: doorbell_token bytes: 0 4095 -> 4095 +// slice-run: doorbell_token bytes: 127 4095 -> 8327167 +// slice-run: doorbell_token bytes: 64 0 -> 4194304 +// slice-run: doorbell_token bytes: 0 4096 -> 18446744073709551615 +// slice-run: doorbell_token bytes: 128 0 -> 18446744073709551615 +// slice-run: doorbell_off bytes: -> 144 +// slice-run: doorbell_bar bytes: -> 196752 + + +// slice-run: doorbell_ring cells:32 3 42 -> 0 cells=0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,196650,0,0,0,0,0,0,0,0,0,0,0,0,0 +// slice-run: doorbell_ring cells:8 0 1 -> 18446744073709551615 +// slice-run: doorbell_ring cells:32 128 0 -> 18446744073709551615 +fn doorbell_token(b: bytes, runlist: u64, channel: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if channel > 4095 { + return 18446744073709551615; + } + if runlist > 127 { + return 18446744073709551615; + } + return channel | (runlist << 16); +} + +fn doorbell_off(b: bytes) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + return 144; +} + +fn doorbell_bar(b: bytes) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + return 196752; +} + +fn doorbell_ring(page: cells, runlist: u64, channel: u64) -> u64 { + if page.len < 19 { + return 18446744073709551615; + } + if channel > 4095 || runlist > 127 { + return 18446744073709551615; + } + page[18] = channel | (runlist << 16); + return 0; +} diff --git a/omega/slices/kmod.osc b/omega/slices/kmod.osc new file mode 100644 index 00000000..0f9659ce --- /dev/null +++ b/omega/slices/kmod.osc @@ -0,0 +1,84 @@ +// slice-entry: kmod_bind kmod_rd kmod_wr kmod_fw kmod_ring +// Our GPU kernel module, in Omega. This is the policy aien-gpu enforces. +// It is not nvidia.ko and it is not loaded here. One chip: vendor 4318 +// (0x10de), device 11794 (0x2e12). Bind refuses if the NVIDIA module is +// loaded or allow_bind is off. A register write is permitted only for the +// six start-up offsets. A read is permitted only for the identity registers +// and the start-up registers. Firmware length must be 75012080. The SEC2 +// doorbell may be written once per load. +// slice-run: kmod_bind bytes: 4318 11794 0 1 -> 0 +// slice-run: kmod_bind bytes: 4318 11794 1 1 -> 18446744073709551615 +// slice-run: kmod_bind bytes: 4318 11794 0 0 -> 18446744073709551615 +// slice-run: kmod_bind bytes: 4318 0 0 1 -> 18446744073709551615 +// slice-run: kmod_wr bytes: 1117184 -> 0 +// slice-run: kmod_wr bytes: 8653824 -> 0 +// slice-run: kmod_wr bytes: 64 -> 18446744073709551615 +// slice-run: kmod_rd bytes: 0 -> 0 +// slice-run: kmod_rd bytes: 2560 -> 0 +// slice-run: kmod_rd bytes: 64 -> 18446744073709551615 +// slice-run: kmod_fw bytes: 75012080 -> 0 +// slice-run: kmod_fw bytes: 1 -> 18446744073709551615 +// slice-run: kmod_ring bytes: 0 -> 0 +// slice-run: kmod_ring bytes: 1 -> 18446744073709551615 + +fn kmod_bind(b: bytes, vendor: u64, device: u64, nvidia_up: u64, allow: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if vendor != 4318 || device != 11794 { + return 18446744073709551615; + } + if nvidia_up != 0 || allow != 1 { + return 18446744073709551615; + } + return 0; +} + +fn kmod_rd(b: bytes, off: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if off == 0 || off == 2560 { + return 0; + } + if off == 8650816 || off == 8650820 || off == 8653504 || off == 8653824 || off == 8653828 { + return 0; + } + if off == 1114176 || off == 1114180 || off == 1114240 || off == 1114356 || off == 1117184 || off == 1119112 { + return 0; + } + return 18446744073709551615; +} + +fn kmod_wr(b: bytes, off: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if off == 8653504 || off == 8653508 || off == 8653824 || off == 8653828 { + return 0; + } + if off == 1114240 || off == 1117184 { + return 0; + } + return 18446744073709551615; +} + +fn kmod_fw(b: bytes, size: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if size != 75012080 { + return 18446744073709551615; + } + return 0; +} + +fn kmod_ring(b: bytes, already: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if already != 0 { + return 18446744073709551615; + } + return 0; +} diff --git a/omega/slices/launch.osc b/omega/slices/launch.osc new file mode 100644 index 00000000..7749d0bc --- /dev/null +++ b/omega/slices/launch.osc @@ -0,0 +1,86 @@ +// slice-entry: mthd_hdr qmd_mthd qmd_addr_hi qmd_addr_lo setup_words +// The FP8 path's submit scheme, copied into Omega. This is the proven way a +// kernel gets onto the chip (omega_gpu_session_launch). A pushbuffer word is +// one method header: opcode 2 in bits 31:28, count in 28:16, subchannel in +// 15:13, method in 12:0 as mthd>>2. A method must be 4-aligned and at most +// 0x7ffc, count at most 0x1fff, subchannel at most 7. The kernel launch is +// method 0x0318 on subchannel 1 with dependence 2. Its address is two words: +// bit 30 and address bits 48:40 in the first, address bits 39:8 in the second. +// The compute-class setup is the FP8 path's 18 words, byte for byte. +// Expected values from Wolfram. +// slice-run: mthd_hdr bytes: 1 540 1 -> 536944775 +// slice-run: mthd_hdr bytes: 1 392 2 -> 537010274 +// slice-run: mthd_hdr bytes: 1 384 2 -> 537010272 +// slice-run: mthd_hdr bytes: 1 432 1 -> 536944748 +// slice-run: mthd_hdr bytes: 0 92 5 -> 537198615 +// slice-run: mthd_hdr bytes: 0 40 4 -> 537133066 +// slice-run: mthd_hdr bytes: 1 542 1 -> 18446744073709551615 +// slice-run: mthd_hdr bytes: 8 392 2 -> 18446744073709551615 +// slice-run: qmd_mthd bytes: -> 543301830 +// slice-run: qmd_addr_hi bytes: 21474836480 -> 1073741824 +// slice-run: qmd_addr_lo bytes: 21474836480 -> 83886080 +// slice-run: qmd_addr_lo bytes: 4886718345 -> 19088743 +// slice-run: setup_words cells:18 -> 0 cells=536944737,52928,536944786,1,536944808,15,536946013,3,536946014,536870912,536946015,1048575,536946007,3,536946008,570425344,536946009,0 +// slice-run: setup_words cells:4 -> 18446744073709551615 + +fn mthd_hdr(b: bytes, subc: u64, mthd: u64, count: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if subc > 7 || count > 8191 { + return 18446744073709551615; + } + if mthd & 3 != 0 || mthd > 32764 { + return 18446744073709551615; + } + return 536870912 | (count << 16) | (subc << 13) | (mthd >> 2); +} + +fn qmd_mthd(b: bytes) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + return 543301830; +} + +fn qmd_addr_hi(b: bytes, va: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if va >= 562949953421312 { + return 18446744073709551615; + } + return 1073741824 | ((va >> 40) & 511); +} + +fn qmd_addr_lo(b: bytes, va: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + return va >> 8; +} + +fn setup_words(out: cells) -> u64 { + if out.len < 18 { + return 18446744073709551615; + } + out[0] = 536944737; + out[1] = 52928; + out[2] = 536944786; + out[3] = 1; + out[4] = 536944808; + out[5] = 15; + out[6] = 536946013; + out[7] = 3; + out[8] = 536946014; + out[9] = 536870912; + out[10] = 536946015; + out[11] = 1048575; + out[12] = 536946007; + out[13] = 3; + out[14] = 536946008; + out[15] = 570425344; + out[16] = 536946009; + out[17] = 0; + return 0; +} diff --git a/omega/slices/mesa.osc b/omega/slices/mesa.osc new file mode 100644 index 00000000..d7a465e8 --- /dev/null +++ b/omega/slices/mesa.osc @@ -0,0 +1,66 @@ +// slice-entry: mesa_ctx mesa_entry mesa_token +// Our userspace GPU driver, in Omega. This is the job Mesa does for a +// compute submit, and none of Mesa is linked. A context is accepted only +// when the device exposes Blackwell compute (52928), Blackwell GPFIFO +// (51567) and Hopper usermode (50785). A submit is one GP entry, LEVEL_MAIN +// clear, plus the doorbell token. A value that does not fit refuses. +// Expected GP entry and token from the same Wolfram values as the NVRM slice. +// slice-run: mesa_ctx cells:4=3,52928,51567,50785 -> 7 +// slice-run: mesa_ctx cells:4=2,52928,51567,0 -> 18446744073709551615 +// slice-run: mesa_entry bytes: 4096 4 -> 17592186048512 +// slice-run: mesa_entry bytes: 4097 4 -> 18446744073709551615 +// slice-run: mesa_entry bytes: 0 0 -> 18446744073709551615 +// slice-run: mesa_token bytes: 3 42 -> 196650 +// slice-run: mesa_token bytes: 128 0 -> 18446744073709551615 + +fn mesa_ctx(cls: cells) -> u64 { + if cls.len < 1 { + return 18446744073709551615; + } + let n: u64 = cls[0]; + if n > cls.len - 1 { + return 18446744073709551615; + } + let mut found: u64 = 0; + let mut i: u64 = 0; + while i < n bound 512 { + let id: u64 = cls[1 + i]; + if id == 52928 { + found = found | 1; + } + if id == 51567 { + found = found | 2; + } + if id == 50785 { + found = found | 4; + } + i = i + 1; + } + if found != 7 { + return 18446744073709551615; + } + return found; +} + +fn mesa_entry(b: bytes, va: u64, nwords: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if va & 3 != 0 || va >= 1099511627776 { + return 18446744073709551615; + } + if nwords == 0 || nwords > 2097151 { + return 18446744073709551615; + } + return va | (nwords << 42); +} + +fn mesa_token(b: bytes, runlist: u64, channel: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if channel > 4095 || runlist > 127 { + return 18446744073709551615; + } + return channel | (runlist << 16); +} diff --git a/omega/slices/nvrm.osc b/omega/slices/nvrm.osc new file mode 100644 index 00000000..a1a323eb --- /dev/null +++ b/omega/slices/nvrm.osc @@ -0,0 +1,141 @@ +// slice-entry: gp_entry gpput_off span_ok enqueue retire channel_plan +// CUDA++ NVRM client, in Omega. This is the submit half of nvrm.c: the GP entry, +// the ring, the retire rule, and the channel plan. The C client asked the driver +// for the work-submit token (command 0xc36f0108). This plan computes it. Channel +// in bits 11:0, runlist in bits 22:16, the GB100 form. Slot 15 of the plan is 0, +// meaning that command is not issued. +// GP entry from clc96f.h: GET is the low 40 bits of a dword-aligned VA, LEVEL_MAIN +// is 0 (bit 41 clear), LENGTH is nwords in bits 62:42, SYNC_PROCEED is 0 (bit 63 +// clear). The C client sets bit 41, which the header defines as LEVEL_SUBROUTINE. +// This function does not. Expected values from Wolfram. +// slice-run: gp_entry bytes: 4096 4 -> 17592186048512 +// slice-run: gp_entry bytes: 305419896 1 -> 4398351931000 +// slice-run: gp_entry bytes: 1095216660496 8 -> 36279588749328 +// slice-run: gp_entry bytes: 4097 4 -> 18446744073709551615 +// slice-run: gp_entry bytes: 1099511627776 4 -> 18446744073709551615 +// slice-run: gp_entry bytes: 0 0 -> 18446744073709551615 +// slice-run: gp_entry bytes: 0 2097152 -> 18446744073709551615 +// slice-run: gp_entry bytes: 0 2097151 -> 9223367638808264704 +// slice-run: gpput_off bytes: 1024 -> 8332 +// slice-run: gpput_off bytes: 1 -> 18446744073709551615 +// slice-run: span_ok bytes:00000000000000000000000000000000 0 4 -> 0 +// slice-run: span_ok bytes:00000000000000000000000000000000 4 4 -> 18446744073709551615 +// slice-run: span_ok bytes:00000000000000000000000000000000 1 1 -> 18446744073709551615 +// slice-run: enqueue cells:4=0,0,0,0 4096 4 cells:8=0,0,4,0,0,0,0,0 -> 1 cells=17592186048512,0,0,0 +// slice-run: enqueue cells:4=0,0,0,0 4096 4 cells:8=3,0,4,0,0,0,0,0 -> 18446744073709551615 +// slice-run: retire cells:4=5,0,0,0 3 -> 3 cells=5,3,0,0 +// slice-run: retire cells:4=5,0,0,0 9 -> 0 cells=5,0,0,0 +// slice-run: channel_plan cells:16 3 42 -> 196650 cells=41068,1,36967,1,65536,1048576,1024,8192,51567,52928,196650,67108864,144,50785,140,0 +// slice-run: channel_plan cells:16 128 0 -> 18446744073709551615 + +fn gp_entry(b: bytes, va: u64, nwords: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if va & 3 != 0 { + return 18446744073709551615; + } + if va >= 1099511627776 { + return 18446744073709551615; + } + if nwords == 0 || nwords > 2097151 { + return 18446744073709551615; + } + return va | (nwords << 42); +} + +fn gpput_off(b: bytes, entries: u64) -> u64 { + if b.len > 0 { + return 18446744073709551615; + } + if entries < 2 || entries > 65536 { + return 18446744073709551615; + } + return entries * 8 + 140; +} + +fn span_ok(b: bytes, off: u64, nwords: u64) -> u64 { + if off & 3 != 0 { + return 18446744073709551615; + } + if nwords == 0 || nwords > 2097151 { + return 18446744073709551615; + } + if nwords > 4611686018427387903 { + return 18446744073709551615; + } + let nbytes: u64 = nwords * 4; + if off > 18446744073709551615 - nbytes { + return 18446744073709551615; + } + if off + nbytes > b.len { + return 18446744073709551615; + } + return 0; +} + +fn enqueue(ring: cells, va: u64, nwords: u64, st: cells) -> u64 { + if st.len < 4 || ring.len < 2 { + return 18446744073709551615; + } + let put: u64 = st[0]; + let retired: u64 = st[1]; + let entries: u64 = st[2]; + if entries != ring.len || entries < 2 { + return 18446744073709551615; + } + if put < retired { + return 18446744073709551615; + } + if put - retired >= entries - 1 { + return 18446744073709551615; + } + if va & 3 != 0 || va >= 1099511627776 || nwords == 0 || nwords > 2097151 { + return 18446744073709551615; + } + let idx: u64 = put % entries; + ring[idx] = va | (nwords << 42); + st[0] = put + 1; + st[3] = (put + 1) % entries; + return put + 1; +} + +fn retire(st: cells, upto: u64) -> u64 { + if st.len < 2 { + return 18446744073709551615; + } + let put: u64 = st[0]; + let retired: u64 = st[1]; + if upto >= retired && upto <= put { + st[1] = upto; + return upto; + } + return retired; +} + +fn channel_plan(st: cells, runlist: u64, channel: u64) -> u64 { + if st.len < 16 { + return 18446744073709551615; + } + if channel > 4095 || runlist > 127 { + return 18446744073709551615; + } + let token: u64 = channel | (runlist << 16); + st[0] = 41068; + st[1] = 1; + st[2] = 36967; + st[3] = 1; + st[4] = 65536; + st[5] = 1048576; + st[6] = 1024; + st[7] = 8192; + st[8] = 51567; + st[9] = 52928; + st[10] = token; + st[11] = 67108864; + st[12] = 144; + st[13] = 50785; + st[14] = 140; + st[15] = 0; + return token; +} diff --git a/omega/slices/open_plan.osc b/omega/slices/open_plan.osc new file mode 100644 index 00000000..09ebc9ed --- /dev/null +++ b/omega/slices/open_plan.osc @@ -0,0 +1,60 @@ +// slice-entry: open_plan class_pick +// CUDA++ NVRM open sequence, in Omega. These are the classes and sizes nvrm_open +// asks the driver for, in that order. The calls themselves are still the C file: +// the compiler refuses the syscall word. Slot values are the header constants, +// not guesses. class_pick is the loop that accepts a device only when it exposes +// Blackwell compute (0xCEC0), Blackwell GPFIFO (0xC96F) and Hopper usermode (0xC661). +// slice-run: open_plan cells:16 -> 0 cells=3472883713,65,128,0,8320,112,562949953421311,52928,51567,50785,65536,144,37105,4096,562949869535232,72 +// slice-run: class_pick cells:4=3,52928,51567,50785 -> 7 +// slice-run: class_pick cells:4=2,52928,51567,0 -> 3 +// slice-run: class_pick cells:4=0,0,0,0 -> 0 +// slice-run: class_pick cells:4=5,0,0,0 -> 18446744073709551615 + +fn open_plan(st: cells) -> u64 { + if st.len < 16 { + return 18446744073709551615; + } + st[0] = 3472883713; + st[1] = 65; + st[2] = 128; + st[3] = 0; + st[4] = 8320; + st[5] = 112; + st[6] = 562949953421311; + st[7] = 52928; + st[8] = 51567; + st[9] = 50785; + st[10] = 65536; + st[11] = 144; + st[12] = 37105; + st[13] = 4096; + st[14] = 562949869535232; + st[15] = 72; + return 0; +} + +fn class_pick(cls: cells) -> u64 { + if cls.len < 1 { + return 18446744073709551615; + } + let n: u64 = cls[0]; + if n > cls.len - 1 { + return 18446744073709551615; + } + let mut found: u64 = 0; + let mut i: u64 = 0; + while i < n bound 512 { + let id: u64 = cls[1 + i]; + if id == 52928 { + found = found | 1; + } + if id == 51567 { + found = found | 2; + } + if id == 50785 { + found = found | 4; + } + i = i + 1; + } + return found; +} diff --git a/omega/slices/sequencer.osc b/omega/slices/sequencer.osc new file mode 100644 index 00000000..4a7df878 --- /dev/null +++ b/omega/slices/sequencer.osc @@ -0,0 +1,123 @@ +// slice-entry: seq_run seq_store +// CUDA++ sequencer, in Omega. The chip sends this program back during boot and NVIDIA's +// driver used to run it (kgspExecuteSequencerBuffer). Opcodes and sizes are the ones in +// rmgspseq.h from the 580.173.02 open driver: +// 0 write (addr, val), 1 modify (addr, mask, val), 2 poll (addr, mask, val, timeout, error), +// 3 delay (us), 4 store (addr, index), 5..8 core ops. +// Core ops refuse: they restart the chip, and this function has no core to restart. +// mem[0..7] is the register file. mem[8..15] is the save area. An address or a save +// index of 8 or more refuses. end is cmdIndex and must be strictly inside the buffer. +// slice-run: seq_run bytes:0000000001000000bc0a000000000000 3 cells:16 -> 0 cells=0,2748,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +// slice-run: seq_run bytes:01000000020000000f0000000500000000000000 4 cells:16=0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0 -> 0 cells=0,0,245,0,0,0,0,0,0,0,0,0,0,0,0,0 +// slice-run: seq_run bytes:0200000003000000ff000000070000000a0000000100000000000000 6 cells:16=0,0,0,7,0,0,0,0,0,0,0,0,0,0,0,0 -> 0 +// slice-run: seq_run bytes:020000000300000001000000010000000a0000002a00000000000000 6 cells:16 -> 18446744073709551615 +// slice-run: seq_run bytes:030000001900000000000000 2 cells:16 -> 0 +// slice-run: seq_store bytes:04000000040000000000000000000000 3 cells:16=0,0,0,0,17,0,0,0,0,0,0,0,0,0,0,0 -> 17 +// slice-run: seq_run bytes:04000000040000000800000000000000 3 cells:16=0,0,0,0,17,0,0,0,0,0,0,0,0,0,0,0 -> 18446744073709551615 +// slice-run: seq_run bytes:0800000000000000 1 cells:16 -> 18446744073709551615 +// slice-run: seq_run bytes:6300000000000000 1 cells:16 -> 18446744073709551615 +// slice-run: seq_run bytes:000000000100000000000000 2 cells:16 -> 18446744073709551615 +// slice-run: seq_run bytes:0000000001000000bc0a000000000000 4 cells:16 -> 18446744073709551615 +// slice-run: seq_run bytes: 0 cells:16 -> 18446744073709551615 + +fn word_at(b: bytes, i: u64) -> u64 { + let o: u64 = i * 4; + return b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24); +} + +fn payload_n(op: u64) -> u64 { + if op == 0 { + return 2; + } + if op == 1 { + return 3; + } + if op == 2 { + return 5; + } + if op == 3 { + return 1; + } + if op == 4 { + return 2; + } + if op == 5 || op == 6 || op == 7 || op == 8 { + return 0; + } + return 18446744073709551615; +} + +fn seq_run(buf: bytes, end: u64, mem: cells) -> u64 { + if mem.len < 16 { + return 18446744073709551615; + } + if buf.len < 4 { + return 18446744073709551615; + } + if buf.len % 4 != 0 { + return 18446744073709551615; + } + let nwords: u64 = buf.len / 4; + if end >= nwords { + return 18446744073709551615; + } + let mut i: u64 = 0; + while i < end bound 256 { + let op: u64 = word_at(buf, i); + i = i + 1; + let n: u64 = payload_n(op); + if n == 18446744073709551615 { + return 18446744073709551615; + } + if i + n > end { + return 18446744073709551615; + } + if op >= 5 { + return 18446744073709551615; + } + if op == 0 { + let addr: u64 = word_at(buf, i); + if addr >= 8 { + return 18446744073709551615; + } + mem[addr] = word_at(buf, i + 1); + } + if op == 1 { + let addr: u64 = word_at(buf, i); + if addr >= 8 { + return 18446744073709551615; + } + let mask: u64 = word_at(buf, i + 1); + let val: u64 = word_at(buf, i + 2); + mem[addr] = (mem[addr] & (~mask)) | val; + } + if op == 2 { + let addr: u64 = word_at(buf, i); + if addr >= 8 { + return 18446744073709551615; + } + let mask: u64 = word_at(buf, i + 1); + let val: u64 = word_at(buf, i + 2); + if (mem[addr] & mask) != val { + return 18446744073709551615; + } + } + if op == 4 { + let addr: u64 = word_at(buf, i); + let index: u64 = word_at(buf, i + 1); + if addr >= 8 || index >= 8 { + return 18446744073709551615; + } + mem[8 + index] = mem[addr]; + } + i = i + n; + } + return 0; +} + +fn seq_store(buf: bytes, end: u64, mem: cells) -> u64 { + if seq_run(buf, end, mem) != 0 { + return 18446744073709551615; + } + return mem[8]; +} diff --git a/omega/slices/va.osc b/omega/slices/va.osc new file mode 100644 index 00000000..2bb7577c --- /dev/null +++ b/omega/slices/va.osc @@ -0,0 +1,166 @@ +// slice-entry: va_take va_release +// CUDA++ NVRM virtual-address allocator, in Omega. Same rules as nvrm.c va_take +// and va_release: first-fit on a free list sorted by address, then a bump. +// mem[0] is the bump. mem[1] is the free-list count. Entries start at mem[2], +// address then size. A failure is all-ones, not zero, so address 0 can be real. +// Alignment must be a power of two. An overlapping release refuses and leaves +// the list alone. Coalesce only when the ranges touch. +// slice-run: va_take cells:8=4096,0,0,0,0,0,0,0 4096 4096 -> 4096 cells=8192,0,0,0,0,0,0,0 +// slice-run: va_take cells:8=4352,0,0,0,0,0,0,0 4096 4096 -> 8192 cells=12288,0,0,0,0,0,0,0 +// slice-run: va_take cells:8=65536,1,20480,4096,0,0,0,0 4096 4096 -> 20480 cells=65536,0,0,0,0,0,0,0 +// slice-run: va_take cells:8=0,0,0,0,0,0,0,0 0 4096 -> 18446744073709551615 +// slice-run: va_take cells:8=0,0,0,0,0,0,0,0 4096 3 -> 18446744073709551615 +// slice-run: va_release cells:8=65536,1,4096,4096,0,0,0,0 8192 4096 -> 0 cells=65536,1,4096,8192,0,0,0,0 +// slice-run: va_release cells:8=65536,1,12288,4096,0,0,0,0 8192 4096 -> 0 cells=65536,1,8192,8192,0,0,0,0 +// slice-run: va_release cells:8=65536,1,4096,8192,0,0,0,0 8192 4096 -> 18446744073709551615 cells=65536,1,4096,8192,0,0,0,0 + +fn pow2(n: u64) -> u64 { + if n == 0 { + return 0; + } + if n & (n - 1) != 0 { + return 0; + } + return 1; +} + +fn va_take(mem: cells, size: u64, align: u64) -> u64 { + if mem.len < 4 || size == 0 || pow2(align) == 0 { + return 18446744073709551615; + } + let room: u64 = (mem.len - 2) / 2; + let mut count: u64 = mem[1]; + if count > room { + return 18446744073709551615; + } + let mut i: u64 = 0; + while i < count bound 4096 { + let base: u64 = mem[2 + 2 * i]; + let sz: u64 = mem[3 + 2 * i]; + if align - 1 > 18446744073709551615 - base { + return 18446744073709551615; + } + if sz > 18446744073709551615 - base { + return 18446744073709551615; + } + let rounded: u64 = base + align - 1; + let aligned: u64 = rounded & (~(align - 1)); + let pad: u64 = aligned - base; + if pad <= sz && size <= sz - pad { + let used_end: u64 = aligned + size; + let range_end: u64 = base + sz; + if pad == 0 && used_end == range_end { + let mut j: u64 = i; + while j + 1 < count bound 4096 { + mem[2 + 2 * j] = mem[2 + 2 * (j + 1)]; + mem[3 + 2 * j] = mem[3 + 2 * (j + 1)]; + j = j + 1; + } + mem[2 + 2 * (count - 1)] = 0; + mem[3 + 2 * (count - 1)] = 0; + mem[1] = count - 1; + } + if pad == 0 && used_end < range_end { + mem[2 + 2 * i] = used_end; + mem[3 + 2 * i] = range_end - used_end; + } + if pad > 0 && used_end < range_end && count >= room { + } else { + if pad > 0 { + mem[3 + 2 * i] = pad; + if used_end < range_end { + let mut j: u64 = count; + while j > i + 1 bound 4096 { + mem[2 + 2 * j] = mem[2 + 2 * (j - 1)]; + mem[3 + 2 * j] = mem[3 + 2 * (j - 1)]; + j = j - 1; + } + mem[2 + 2 * (i + 1)] = used_end; + mem[3 + 2 * (i + 1)] = range_end - used_end; + mem[1] = count + 1; + } + } + return aligned; + } + } + i = i + 1; + } + let next: u64 = mem[0]; + if align - 1 > 18446744073709551615 - next { + return 18446744073709551615; + } + let rounded: u64 = next + align - 1; + let va: u64 = rounded & (~(align - 1)); + if size > 18446744073709551615 - va { + return 18446744073709551615; + } + mem[0] = va + size; + return va; +} + +fn va_release(mem: cells, va: u64, size: u64) -> u64 { + if mem.len < 4 || size == 0 { + return 18446744073709551615; + } + if size > 18446744073709551615 - va { + return 18446744073709551615; + } + let end: u64 = va + size; + let room: u64 = (mem.len - 2) / 2; + let count: u64 = mem[1]; + if count > room { + return 18446744073709551615; + } + let mut pos: u64 = 0; + while pos < count && mem[2 + 2 * pos] < va bound 4096 { + pos = pos + 1; + } + if pos > 0 { + let prev: u64 = mem[2 + 2 * (pos - 1)]; + let psz: u64 = mem[3 + 2 * (pos - 1)]; + if psz > 18446744073709551615 - prev || prev + psz > va { + return 18446744073709551615; + } + } + if pos < count && end > mem[2 + 2 * pos] { + return 18446744073709551615; + } + if count >= room { + return 18446744073709551615; + } + let mut i: u64 = count; + while i > pos bound 4096 { + mem[2 + 2 * i] = mem[2 + 2 * (i - 1)]; + mem[3 + 2 * i] = mem[3 + 2 * (i - 1)]; + i = i - 1; + } + mem[2 + 2 * pos] = va; + mem[3 + 2 * pos] = size; + let mut n: u64 = count + 1; + if pos + 1 < n && mem[2 + 2 * pos] + mem[3 + 2 * pos] == mem[2 + 2 * (pos + 1)] { + mem[3 + 2 * pos] = mem[3 + 2 * pos] + mem[3 + 2 * (pos + 1)]; + let mut j: u64 = pos + 1; + while j + 1 < n bound 4096 { + mem[2 + 2 * j] = mem[2 + 2 * (j + 1)]; + mem[3 + 2 * j] = mem[3 + 2 * (j + 1)]; + j = j + 1; + } + mem[2 + 2 * (n - 1)] = 0; + mem[3 + 2 * (n - 1)] = 0; + n = n - 1; + } + if pos > 0 && mem[2 + 2 * (pos - 1)] + mem[3 + 2 * (pos - 1)] == mem[2 + 2 * pos] { + mem[3 + 2 * (pos - 1)] = mem[3 + 2 * (pos - 1)] + mem[3 + 2 * pos]; + let mut j: u64 = pos; + while j + 1 < n bound 4096 { + mem[2 + 2 * j] = mem[2 + 2 * (j + 1)]; + mem[3 + 2 * j] = mem[3 + 2 * (j + 1)]; + j = j + 1; + } + mem[2 + 2 * (n - 1)] = 0; + mem[3 + 2 * (n - 1)] = 0; + n = n - 1; + } + mem[1] = n; + return 0; +} diff --git a/tests/omega/run.sh b/tests/omega/run.sh new file mode 100755 index 00000000..712a4c3a --- /dev/null +++ b/tests/omega/run.sh @@ -0,0 +1,14 @@ +#!/bin/sh +# Run the omega compiler harness against this repo's omega/slices. +# Usage: tests/omega/run.sh [FUZZ] (default 120) +set -eu +W=$HOME/workspace/omega-osc-cubin # the compiler harness build +R=$(cd "$(dirname "$0")/../.." && pwd) # this repo checkout +FUZZ=${1:-120} +T=$(mktemp -d) +mkdir -p "$T/slices" +ln -s "$W/tests/compiler/progs" "$T/progs" +ln -s "$W/tests/compiler/neg" "$T/neg" +cp "$R"/omega/slices/*.osc "$T/slices/" +cd "$W" +exec ./build/compiler/test_osc_compiler "$FUZZ" "$T" From c008e1ea3309cf08067d91602ae6a05f24d47546 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 22:30:18 -0500 Subject: [PATCH 2/4] omega: review fixes: 32-bit qmd address low word, gate hygiene qmd_addr_lo now refuses any address 2^49 or larger, the same rule qmd_addr_hi already used, and masks the word to 32 bits, matching the C launch emitter. Two new run lines pin it: 2^40+256 folds to 1, and the first out-of-range address refuses. tests/omega/run.sh lists the eight slices by name so a missing file fails loudly, and removes its temp directory on exit. Review: every pinned value re-derived independently, 92/92 run lines. --- omega/slices/launch.osc | 7 ++++++- tests/omega/run.sh | 11 +++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/omega/slices/launch.osc b/omega/slices/launch.osc index 7749d0bc..dd63aa96 100644 --- a/omega/slices/launch.osc +++ b/omega/slices/launch.osc @@ -20,6 +20,8 @@ // slice-run: qmd_addr_hi bytes: 21474836480 -> 1073741824 // slice-run: qmd_addr_lo bytes: 21474836480 -> 83886080 // slice-run: qmd_addr_lo bytes: 4886718345 -> 19088743 +// slice-run: qmd_addr_lo bytes: 1099511628032 -> 1 +// slice-run: qmd_addr_lo bytes: 562949953421312 -> 18446744073709551615 // slice-run: setup_words cells:18 -> 0 cells=536944737,52928,536944786,1,536944808,15,536946013,3,536946014,536870912,536946015,1048575,536946007,3,536946008,570425344,536946009,0 // slice-run: setup_words cells:4 -> 18446744073709551615 @@ -57,7 +59,10 @@ fn qmd_addr_lo(b: bytes, va: u64) -> u64 { if b.len > 0 { return 18446744073709551615; } - return va >> 8; + if va >= 562949953421312 { + return 18446744073709551615; + } + return (va >> 8) & 4294967295; } fn setup_words(out: cells) -> u64 { diff --git a/tests/omega/run.sh b/tests/omega/run.sh index 712a4c3a..5208bffd 100755 --- a/tests/omega/run.sh +++ b/tests/omega/run.sh @@ -5,10 +5,17 @@ set -eu W=$HOME/workspace/omega-osc-cubin # the compiler harness build R=$(cd "$(dirname "$0")/../.." && pwd) # this repo checkout FUZZ=${1:-120} +# Every slice must be present by name: a deleted file is a loud failure here, +# not a silently smaller keyed count in the harness summary. +SLICES="doorbell.osc sequencer.osc nvrm.osc va.osc open_plan.osc kmod.osc mesa.osc launch.osc" +for f in $SLICES; do + [ -f "$R/omega/slices/$f" ] || { echo "missing slice: omega/slices/$f" >&2; exit 1; } +done T=$(mktemp -d) +trap 'rm -rf "$T"' EXIT mkdir -p "$T/slices" ln -s "$W/tests/compiler/progs" "$T/progs" ln -s "$W/tests/compiler/neg" "$T/neg" -cp "$R"/omega/slices/*.osc "$T/slices/" +for f in $SLICES; do cp "$R/omega/slices/$f" "$T/slices/"; done cd "$W" -exec ./build/compiler/test_osc_compiler "$FUZZ" "$T" +./build/compiler/test_osc_compiler "$FUZZ" "$T" From 4dd83150e90bdfd66ec5dffdecbe54baf08568d9 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 23:09:07 -0500 Subject: [PATCH 3/4] docs: tool inventory - same names, Omega underneath --- docs/TOOL_INVENTORY.md | 120 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 docs/TOOL_INVENTORY.md diff --git a/docs/TOOL_INVENTORY.md b/docs/TOOL_INVENTORY.md new file mode 100644 index 00000000..1c174f34 --- /dev/null +++ b/docs/TOOL_INVENTORY.md @@ -0,0 +1,120 @@ +# Tool inventory: everything becomes Omega, nothing gets renamed + +The key point: developers who are using these tools today keep using the same +names, the same paths, the same flags and the same output. A tool is replaced +when the Omega build sits at the same path and behaves the same. Nobody has to +learn anything. What changes under the hood is that the logic is written in our +language, compiled from the seed, and fast. + +Rule per tool: the Omega source lives in this repo under `tools//`, the +gate is `tests/omega/run.sh`, and the shipped binary installs over +`~/.local/bin/`. A replacement that changes an output format or a flag is +a bug, not a rewrite. + +## What is on the box today + +`~/.local/bin` holds 163 entries: about 120 real tools and launchers (the rest +are `.bak-*` copies). By interpreter: 37 `/bin/sh`, 19 `/bin/bash`, 38 +`/usr/bin/env` (python or node), 47 compiled binaries or data. Three shell +libraries behind them (`~/.local/lib/aien-local-ci/`, `~/.local/lib/aien-watch/`, +`~/.local/lib/gh-guard/`). About 25 cron jobs and roughly 20 active user +services call into these. + +## Tier 1 - pure logic, replace now (OSC, already possible) + +| Tool | Lines | Language | Does | +|---|---|---|---| +| `ledger` | 54 | python | TSV ledger: add/note/done/list/stale | +| `spark-window` | 378 | sh | chip window allocator and lock ledger | +| `quiet-build` | 58 | sh | quiet-lock build runner | +| `quiet-measure` | 44 | sh | chip-lock measurement runner | +| `lock-long-holds` | 76 | sh | lock janitor | +| `q36-extra` | 68 | bash | extra model load gate | +| `org-check` | 60 | sh | repo dashboard checks | +| `org-mirror` | 19 | sh | org mirror | +| `ghmerge` | 18 | bash | merge queue helper | +| `watch-merge` | 16 | bash | merge watcher | +| `rebase-crumb` | 34 | bash | crumb on rebase | +| `spark-sensors` | 15 | sh | repo dashboard sensor | +| `spark-receipt` | 102 | sh | receipt builder | +| `spark-calibrate` | 97 | sh | calibration receipt | +| `spark-baseline` | 149 | sh | baseline receipt | +| `spark-build-once` | 121 | sh | keyed build cache | +| `after-window-18191` | 14 | bash | window follow-up | +| `sweep-build-scratch` | 14 | python | build scratch sweeper | +| `wip-snapshot` | 29 | python | WIP snapshots | +| `vault-add-secret` | 9 | bash | vault add | +| `wall-power-log.sh` | 7 | sh | power log | +| `claude-chat-status` | 13 | python | chat status line | +| `qwen-logs` / `qwen-restart` / `qwen-stop` / `qwen-runtime` / `qwen-gate` | 49 | python | model server control | + +Tier-1 cores are parse-and-decide: TSV and lock files, budget arithmetic, +allowlists. Their Omega ports are the pattern already proven by `nvrm.osc` and +`kmod.osc`: the decision logic in `.osc` with a run line per rule, a thin +same-name launcher in front. + +## Tier 2 - file and process inspection, replace now (syscall landed) + +`osc/syscall@01f933a8` unblocked these: open, read, write, close, +clock_gettime, getpid are real words. + +| Tool | Lines | Language | Does | +|---|---|---|---| +| `chip-watchdog` | 30 | bash | stops hung lock holders (reads /proc, nvidia-smi) | +| `agent-revive` | 21 | bash | dead agent reaper | +| `coordinator-tick` | 11 | bash | restart-request reader | +| `aien-local-ci` | 54 | bash | PR judge entry (`lib/pipeline.sh`, `cron-tick.sh` behind it) | +| `aien-watch` | 124 | python | watch daemon pass (`lib/aien-watch.sh`) | +| `now-publish` | 70 | python | aienos.com /now/ publisher | +| `spark-cleanup` | 366 | python | worktree/target cleaner | +| `investigate.sh` | 49 | sh | incident probe | +| `hw-grep` / `hw-page` / `docs-read` / `env` | 44 | sh | small readers | +| `claude-chat-feed` / `claude-inbox-hook` | 34 | python | chat archival | +| `renda` | 34 | python | PR desk entry | +| `renda-local` | 278 | python | local-model PR desk | +| `forgejo-backup` | 212 | sh | forge backup | +| `agent-mail` | 19 | python | mail entry | +| `cortex-tool` | 135 | python | cortex client | +| `crumb` / `crumb-doctor` | 300 | python | crumb notes | +| `gh` | 314 | python | guarded gh wrapper (the guard logic ports; the gh binary stays) | + +## Tier 3 - needs fork/exec/argv (next compiler rungs) + +These launch other programs, so they wait on `execve` with argv arrays and +`wait4`. Named now so the rung is planned, not discovered later: +`renda-harness` (577 lines, drives review lanes), `renda-loop`, +`spark-connector-supervise`, `qwen-code`, `spark-window`'s launch path, +`aien-watch-hook`, `approve-cleared`, `ask-muse`, `rad-push`. + +## Tier 4 - compiled services (stay until the runtime grows) + +Rust/Go binaries running as services: `cortex-rs`, `cortex-encoder-rs`, +`spark-cockpit-rs`, `aien` (53k lines), `aien-mail`, `conduit`, `rad`, +`radicle-node`, `git-remote-rad`, `forgejo-runner`, `mobhub`, `tectonic`, +`ripwire`, `scrub`, `openclaw`, `agy`, `grok`, `spark-*` compiled daemons +(dream, harness, supervisor, debugger, distill, discord-hub, muse-bridge, +mail, inquisitor, connector, rsi, crumbs), `muse`, `agent`, `agent-archive`. +Their service contracts stay identical; each becomes a porting lane with the +same name when the runtime can host it. + +## Keep as-is (not our logic) + +Third-party binaries and their thin launchers where the wrapper adds no +decision: `claude`, `codex`, `code`, `gh`'s underlying binary, `pnpm`/`pnpx`, +`python3.11`, `hermes*`, `bw` (Bitwarden CLI), `greptile-mcp`, `qwen-code`'s +npm entry. Wrappers whose guard logic is ours (the `gh` guard, the `claude` +guard) get their guard ported to Omega at Tier 2 while the wrapped binary +stays. + +## Order + +1. Tier 1 in this repo, `tools//`, same-name drop-ins: `ledger` first + (smallest, most used), then `quiet-build`, `quiet-measure`, `spark-window` + (the big one at 378 lines), then the rest of the table. +2. Tier 2 as syscall use matures, one tool per branch, each keeping its name. +3. Tier 3 opens when `execve` + `wait4` land; `renda-harness` is the first + target and the biggest win. +4. Tier 4 lanes open per service; the Rust ones stay until then. + +Every replacement keeps the old tool archived at `.pre-omega-` +and a receipt: same inputs, same output, byte for byte, before the swap. From 01fb7249cf359e433e4a034a5b2a98b83cb8a9a6 Mon Sep 17 00:00:00 2001 From: Drake Stapleton Date: Wed, 21 Oct 2026 23:11:13 -0500 Subject: [PATCH 4/4] docs: name the gate - wrapped binaries are lanes too, gated on an Omega TLS stack --- docs/TOOL_INVENTORY.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/TOOL_INVENTORY.md b/docs/TOOL_INVENTORY.md index 1c174f34..b1414b4a 100644 --- a/docs/TOOL_INVENTORY.md +++ b/docs/TOOL_INVENTORY.md @@ -97,6 +97,17 @@ mail, inquisitor, connector, rsi, crumbs), `muse`, `agent`, `agent-archive`. Their service contracts stay identical; each becomes a porting lane with the same name when the runtime can host it. +The wrapped third-party binaries are not exceptions either: they are Tier 4 +lanes, and the gate is named. For gh (about 100k lines of Go), claude and bw: +the JSON parsing and the API client surface are pure logic and can be written +in Omega now; sockets are syscalls and are reachable now; the one physical +gate is a TLS stack written in Omega, which is its own project and a +security-sensitive one, because a wrong TLS is a hole, not a slowdown. +Everything we own both ends of (the motor on 127.0.0.1:18091, the ledger, the +desk handoffs, local CI) needs no TLS, so Omega HTTP over loopback comes +first. Until a lane completes, the wrapper keeps its guard logic in Omega +(Tier 2) and the wrapped binary stays: same name, same behavior. + ## Keep as-is (not our logic) Third-party binaries and their thin launchers where the wrapper adds no