Qwen batch-one linear ABI v1
The compiler combines seeded Omega sources into a static AArch64 ELF. At runtime the process emits two SM121 instruction streams into its own GPU mapping and submits QMDs through the raw NVIDIA driver. The build reads immutable blobs from the owner store. The context, vector and launch source comes from the CUDApp units carried in aien-train. The instruction, packet and wait helpers come from its gk and gr units. Exact revisions are in build.sh. Python, NumPy and nvdisasm are external test tools.
Integrating the library
Run OUT=/absolute/build/path sh build.sh. Use the emitted library.om once in the primary compilation unit, keeping a single leading om2 and appending the primary entry point. A build already using these same GPU globals must share the definitions. This version owns a private context and its launch slots. All calls and descriptor writes must be serialized by the caller.
- Call
lqopen -> boolonce inside the owned GPU window. It opens the private channel, allocates launch storage, uploads both kernels and constructs the E4M3FN lookup. After a partially failed open, calllqcloseto release owned resources. An already-open unrelated context causes refusal. - Allocate data using
nvalloc byte_count true -> longin this context. A positive result is a managed mapping handle. Upload weights, optional scales and input usingmapwrite. Keep weights and scales resident across calls. Reserve writable output space. - Populate the four global descriptors below, including exact logical lengths, then call
lqrun fmt m k sr sc -> boolwith five uints. A successful call has retired on the GPU and flushed output for host readback. Consume Y as the next device input or read it through the mapping. - The caller owns data slices. Reuse or drop individual allocations with
nvdropafter completion.lqclose -> boolcalls the context teardown, which also releases outstanding allocations, including the launch storage. Closing invalidates every descriptor. On a failed launch treat output as invalid, inspectnvstage,nverr,nvfault, and close the context before reopening if faulted. A false close requires inspection and cleanup retry.
| Descriptor index | Contents | Exact logical length in bytes |
|---|---|---|
| 0 | W, contiguous row-major [M,K] | BF16 2×M×K or FP8 M×K |
| 1 | S, contiguous row-major BF16 inverse scales | 2×sr×sc for FP8, zero for BF16 |
| 2 | X, contiguous f32[K] | 4×K |
| 3 | Y, contiguous f32[M] | 4×M |
For each index set lqmap[i] (long handle), lqoff[i] (ulong byte offset), and lqlen[i] (ulong byte count). BF16 uses fmt=0, sr=sc=0 and may leave S unmapped. E4M3FN uses fmt=1, sr=ceil(M/128), sc=ceil(K/128). All byte offsets must meet natural alignment. Offsets are relative to the managed allocation. Each expert or shared projection gets its own matrix origin and scale origin. A submatrix beginning partway through a scale tile requires repacking or the original tile origin. The loader is responsible for checking dtype, tensor identity, and the logical extent of its shard slice. Map bounds alone cannot detect a wrong tensor of identical shape.
The kernel multiplies the decoded FP8 weight by S[row/128,col/128] in f32. Each lane accumulates a stride-32 column sequence using f32 FFMA. Five butterfly additions reduce each warp, and lane zero writes its row. Any positive M through the grid limit is accepted, including a partial scale row. K must be a positive multiple of 32. Partial final scale columns work. Other K values, inconsistent scale dimensions, mismatched lengths, output overlap, unregistered handles, reserved launch buffers, and out-of-range or misaligned slices are refused. The row byte stride must fit uint. The native allocation limits still apply. The same descriptor ABI applies to the vocabulary projection, router, shared and numbered experts.
Standalone reference and controls
linear r reads nine little-endian u64 values from stdin (fmt, M, K, sr, sc, W bytes, S bytes, X bytes, Y bytes), followed by W, S and X, then EOF. It emits little-endian f32 output using a scalar host reference with f64 accumulation. linear g uses the same wire format and executes on the GPU. The caller must hold its FIFO grant. linear s accepts only the header and checks geometry. Modes b and f dump the two Omega-emitted instruction streams, and t dumps the decode table. Standalone exits are 0 success, 2 bad packet, 3 setup/allocation, 4 launch, 5 I/O and 6 cleanup.
Run OUT=/absolute/build/path sh check.sh for the host tests. The frozen input vector is generated exactly from the column index in verify.py. The independent oracle decodes weights with the E4M3FN exponent formula and sums products in NumPy float64. The instruction simulator executes the nvdisasm listing over distinct virtual allocations, with per-lane registers, memory access checks, branches, shuffles and predicated stores. This checks arithmetic and address formation. Raw packet, output and executable hashes are in HOST-RECEIPT.txt.
To run the remaining hardware comparison within this lane's or the primary's explicitly claimed FIFO grant, pass that grant's returned identifier to spark-window run python3 verify.py /absolute/build/path/linear --gpu "$owned_window_id" from this directory. The test checks the live grant again before each GPU process. Retain its output, exit status, executable digest and FIFO receipt. The standalone test opens a fresh context per case. Integrated callers amortize setup across projections.
Measurement status
The original host simulation used a worker sandbox. That sandbox has no NVIDIA device nodes and its real FIFO queue directory is read-only. Host checks exercise kernel emission, actual instruction semantics under simulation, QMD construction and refusal paths. The simulator does not model scoreboards, driver behavior, cache ordering or chip timing. GPU numerical agreement, repeated resident launches, setup cost, synchronous launch overhead, bandwidth and throughput remain unmeasured. The whole-model graph and release belong to the primary.
On November 18 the Spark ran both real first-layer projections against a double-precision oracle. Across 10,240 dense output rows and 8,192 routed-model rows, maximum absolute error was 2.79e-7 and 1.57e-7 respectively. Both whole-model reference generations matched the 24 expected IDs. Spark measurements and source