Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/CUDApp/tree/main/om/moe # CUDApp CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `CUDApp / om / moe` `4c7c43d` MoE: accept Qwen3.8-Flash-Next shapes (ragged-K FP8 GEMV, wide plan/group/window/admission units) Drake Stapleton committed 2026-11-18 ``` .. .crumb 759 README.md 12836 closure_alloc.om 260 closure_bind.om 293 closure_blob.om 287 closure_code.om 240 closure_dir.om 256 closure_launch.om 317 closure_pack.om 261 closure_series.om 293 moe_admit.om 1691 moe_admit_wide.om 1862 moe_group.om 2156 moe_group_wide.om 2517 moe_ids32.om 427 moe_ids32_wide.om 525 moe_maps32.om 674 moe_maps32_wide.om 745 moe_plan.om 3512 moe_plan_wide.om 3744 moe_segs32.om 1529 moe_segs32_wide.om 1629 moe_windows.om 1742 moe_windows_wide.om 1968 q36-prefill-integration.patch 7059 ``` README.md # Stable indexed MoE plans Issue #159, separate from fusion #18. This lane reuses the existing q36 batch GROUP and indexed GEMM path; batch grouping was already GPU-resident. It does not claim another kernel gain for #137. New planning, validation, wire conversion and admission logic is seeded Omega; C in tests is an independent incumbent oracle/native ABI caller. ## Native plan contract `moe_plan` is pure. Six disjoint ABI1 arrays: cfg ulong[8], ids ulong[1024], work ulong[10368], segments ulong[1028], maps ulong[2320], meta ulong[8]. The production bridge accepts ulong/uchar, not uint arrays. These logical ulong words are deliberately NOT the GPU representation. Explicit Omega serializers below produce existing u32 maps and Seg32 bytes, without a new format or host algorithm. Cfg: version1, tokens0..128, route slots0..8, routed expert count1..256, shared id exactly expert count, work capacity in records, segment capacity in records, map capacity per map including eight padding entries. Maximum backing capacities:1152,257,1160. Input IDs are token-major original slots, either below routed expert count or UINT32_MAX (absent). Every other ID refuses, never `id & 255` as in historical pf_group. All bounds and IDs are validated before any output write. Each work record has nine fields: expert id, source activation row, token id, original route slot, token-local weight slot, containing segment offset, containing segment count, original dense contribution destination, original contribution order. Stable order is expert then token then original slot. Shared expert is explicit, one contribution per token, with slot/weight/order equal to routed slot count. Shared is the final segment, never merged into routed expert255. Segments contain expert, global work offset, count, shared flag. They have no addresses and must not be cast to Seg32. Gate/up uses X/Y maps; down uses Y/Y. X starts at0; Y starts at1160. Eight zero entries follow active rows of each map. Other unused outputs remain unchanged. Meta: work count, segment count, routed count, shared count, version1, three zero reserved words. Return0 success;1 invalid cfg;2 invalid ID;3 capacity. Refusals preserve all outputs. Zero tokens and shared-only work are supported. No-pick plans retain holes and original route slots. They are NOT directly admissible to unchanged dense q36 combine: a consumer must clear omitted destinations or combine only present contributions in original order. The resident candidate admits only the incumbent complete router outputs, not this general sparse extension. `moe_ids32` decodes active existing little-endian router u32 picks into logical ABI words, without masking. `moe_maps32` validates every active value then writes existing little-endian u32 map bytes, including padding, preserving unused output bytes. `moe_segs32` validates ranges and live aligned directory entries then writes exact existing32-byte Seg32 records: weight VA, scale VA, row0 u32, count u32, reserved zero u64. Its directory is the incumbent257 pairs(weight,scale), shared index256; call once for gate/up and once for down. Quantization descriptors remain the canonical QuantSchema contract, not another MoE serializer. ## Resident scheduling candidate `moe_group` emits exactly64 bytes / OMEGA_DEC_GR_WORDS16 for existing K_GROUP groups9. Request16 words: ids VA, GU table VA, down table VA, GU segment VA, down segment VA, X map VA, Y map VA, router stride, window tokens, segment capacity, per-map capacity, directory slots9, session generation, current generation, admitted flag, shared id256. All seven addresses are nonzero/eight-byte aligned; stride is u32/16-byte aligned and covers a nine-entry table row. Checked address extents cannot wrap. Every written range is disjoint from all readers and other writers; read-only router fields may share their strided allocation. Return1 shape,2 capacity/stride extent,3 alignment/address,4 generation/admission,5 alias/extent overflow; output unchanged on refusal. Matching generation0 is valid, as in the canonical Cache/Selector. This low-level helper does not authenticate qualification or device residency. Trusted graph state checks allocation bounds and same-expert directory coherence under its existing session lock. GROUP writes trailing descriptors through R-1 even when only one expert occurs: segment capacity must cover R, not distinct experts. GROUP's current one-CTA row bound is128; there is no inter-CTA spinning or new executor. `moe_windows` covers the entire existing prefill token range0..128 with stable token windows satisfying `window_tokens*9 <= 128`. Input8: version1,total tokens,H2048,EI512,contributions9,router stride,window-record capacity<=128,flush_each(only0). Output backing ulong[1024], eight fields/window: token0,tokens,rows,XP byte offset,GU byte offset,ACT byte offset,DN byte offset,router byte offset. Meta4: windows,total tokens,total rows,version1. It validates capacities before publication. Thus large prefill does not require an unqualified multi-CTA GROUP. Each window records existing GROUP -> permutation -> indexed GU(X/Y) -> SwiGLU -> permutation -> indexed down(Y/Y), with addresses shifted to its original contribution slots. Existing command-list barriers complete down before the next window overwrites shared maps/descriptors. Original ordered combine runs after all windows. There is no host picks readback/sync between router and experts. No cross-window reassociation occurs. `moe_admit` consumes exact canonical PipelineSelect q64/a1024 and KernelCache pool528; it calls the actual `pl_pin`, requires staged/indexed family3 and releases its recorded pin on wrong-family refusal. It does not define identity, quantization or qualification schemas. Owner must first validate immutable canonical realization via `pl_realcheck`; graph registration is private/trusted and remains fail-closed without qualification authority. Existing session lock spans admission/recording. Existing cache acquire, observed-completion retire and recorded-list unpin are authoritative. Failure without proven completion must not fabricate a retire. `q36-prefill-integration.patch` supplies the shared-file owner with router output projection, R+padding map allocation and actual window/combine record adapters calling its `native_record_gemm`. It does not activate a public production path. Shared build/bridge outputs, graph-owned trusted resolver and final consumer wiring belong to the integration owner. Unmodified incumbent API and receipts remain retained until reviewed cutover. The patch's GPU behavior is NOT_RUN, not covered by host native-plan evidence. ## Source and evidence Source baseline CUDApp `b759afc3f5e46f152ffb06b39882ffa28cacaf96`: q36 K_GROUP batch path; pf_group; pf_record_experts; Seg32/indexed GEMM contracts. Compiler SHA256 `2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f`; native bridge source `c77a5922f91d53d4a0bbd4e7b1c4703f7098263abc843be2918db1ece7496782`. Actual Omega MCP assistance used lookup(array), compile, explain_error(error12), run. Pinned compiler register exhaustion was fixed by splitting helpers, not changing the pin. `tests/moe/run.sh` requires OMEGA_OMC, OMEGA_BRIDGE and canonical QUANT_ROOT/CACHE_ROOT/COMPOSE_ROOT/PIPELINE_ROOT checkouts. It generates only temporary bindings; calls native compiled Omega through the actual bridge ABI; links and calls unchanged incumbent pf_group with a verification-only tensor-directory oracle; independently checks GROUP rank/segment format. Cases include duplicate/all-same/all-distinct/uneven/ragged/no-pick/shared-only/invalid/alias/capacity; order/missing-shared/map/segment mutants; exact u32/Seg32 serializers and rejection canaries; all supported total-token window sizes. A separate compiled Omega caller composes actual canonical selector/cache functions and exercises prepared residency, recorded pin, simulated submit acquire, retire/unpin, missing/stale/wrong-family refusal. Those are metadata lifecycle operations, NOT an actual device submission. Host fixtures passed; no GPU instruction was executed and synthetic policy records confer no authority. Finite map arithmetic was independently checked via mounted Wolfram tools, relayed by Main. WolframLanguageEvaluator: `With[{routed=Flatten[Table[9 t+s,{t,0,127},{s,0,7}]],shared=Table[9 t+8,{t,0,127}]},{Length[routed],Length[Union[routed]],Length[Union[routed]]==Length[routed],Intersection[shared,routed]}]` -> `{1024,1024,True,{}}`. This establishes finite routed destination uniqueness and shared/routed disjointness only, not kernel execution or capacity safety. Generic Reduce queries emitted warnings and are not used as proofs. Saved model config only: `$HOME/models/qwen3.6-35b-a3b-fp8-95a723d0/config.json` matches SHA256 `570ef7ea45a7e1d3de2b1d3c70c4ac3562d0e768acdc195778cb4f4d95025845`, also recorded in the cached #604 receipt `baseline-20261025T021219Z/cached/provenance.txt`. It declares Qwen3_5MoeForConditionalGeneration, hidden2048,layers40,experts256,picks8,MoE intermediate512,shared intermediate512. No live model endpoint was queried. Current runtime identity verification is PENDING. ## Remaining full acceptance IMPLEMENTED / HOST_EXERCISED is not QUALIFIED, MERGED or DEPLOYED. No GPU/model launch, server/driver/firmware change, deployment or merge occurred. Remaining acceptance is unchanged: reviewed graph consumer integration and trusted-record authority; independent repaired-encoder/machine-code verification; reserved chip numerical and refusal controls; B=1 decode, supported request batching and prefill; paired whole-model quality and latency against cached-scratch incumbent. #18 fusion is separate and #137's previous kernel gain is not counted again. ADR 0042 is Accepted (aien-architecture-mv main, 2026-10-30). Host fixtures do not satisfy physical or whole-model gates. ## Wide units (Qwen3.8-Flash-Next) The legacy units above stay byte-identical for their callers: the bridge checks fixed view sizes, so a larger shape gets parallel `_wide` units with the same algorithms, larger views and shape values read from the input where the legacy code had a literal. Target shape from `$HOME/models/qwen3.8-flash-next-fp8-7fb48d70/config.json` `text_config`: hidden 2560, 512 routed experts, 10 routed picks plus the shared expert (11 contributions per token), MoE and shared intermediate 640. The wide units also accept the Qwen3.6-35B profile, and `tests/moe/run_wide.sh` checks that they give the legacy units' answers there. - `moe_plan_wide`: cfg `version 2,tokens<=128,slots<=10,experts<=512,shared_id==experts,work_cap<=1408,segment_cap<=513,map_cap<=1416`. Views: ids `ulong[1280]`, work `ulong[12672]` (1408 records of 9 fields), segments `ulong[2052]` (513 of 4), maps `ulong[2832]` with X at 0 and Y at 1416, meta `ulong[8]` with `meta[4]=2`. - `moe_ids32_wide`: router u32 picks `uchar[5120]` to ids `ulong[1280]`. - `moe_maps32_wide`: maps to u32 bytes `uchar[11328]`, X at byte 0, Y at byte 1416*4. - `moe_segs32_wide`: Seg32 records `uchar[16416]` from a directory of 513 (weight,scale) pairs `ulong[1026]`; the shared expert's index is the plan's `shared_id`. - `moe_group_wide`: the 16-word GROUP request; contributions per token come from `directory_slots`. Admitted profiles: `(directory_slots 9, shared_id 256)` and `(11, 512)`; every other pair returns 1 with the output unchanged. - `moe_windows_wide`: profiles `(H,EI,contributions)` `(2048,512,9)` and `(2560,640,11)`; window size is 128/contributions tokens (14 or 11). - `moe_admission_wide` (`moe_group_wide` + `moe_admit_wide`): the `moe_admit` contract with the wide GROUP check, refusal `80+GROUP code`. Tests: `make test-moe-wide` (carried host row; `tests/moe/run_wide.sh`, which prints `MOE-WIDE HOST PASS` and `MOE-WIDE-ADMIT HOST PASS`) and `make test-moe-wide-mutants` (`tests/moe/wide_mutants.py`, one-line source mutants of every wide unit and the verifier, each killed by a named assertion). Without `OMEGA_OMC` and `OMEGA_BRIDGE`, `run_wide.sh` prints NOT_RUN and exits 3. Every refusal case in `tests/moe/caller_wide.c` has a passing twin from the same run. Scope: host descriptors and plans only. The device GROUP kernel (`OMEGA_DEC_GROUP`, `om/codegen/cg_dec.om`) takes 1..16 slots per head and sorts u32 expert ids, so it serves 11 slots and 512 experts without a change: `tests/codegen_dec_group_sim_test.c` (`make test-codegen-dec-group-sim`) runs it at 9 and 11 slots on the host warp simulator against a host reference. The FP8 GEMV for the Flash-Next expert matrices (k = 640 down_proj) is the ragged-K kernel (`omega_blackwell_codegen_fp8_gemv_ragged_prog`). Chip status: NOT_RUN. Receipts: `evidence/FLASH-NEXT-MOE-SHAPES-20261118/wide-units/` (wide units), `evidence/FLASH-NEXT-MOE-SHAPES-20261118/` (the rest).