Files
leleka/gpu/kar

KAR CUDA smoke target

vendor/libkar.h and vendor/libkar.cu are copied unchanged from local koference commit 806d2398ae1daaceb2917242911e5680cbfb3608, paths r08/code/libkar.h and r08/code/libkar.cu. Their SHA-256 values are 1d725069fd2c275423f5db70fb4190e7d51760e0c48a2a5ebe8c91993936ca92 and 331babd2a2f260abb7de602d414edd97399542ec1bccb23ffcdfad69dc0ade28 respectively. Keep these bytes and upstream provenance traceable when making local changes.

On Linux with CUDA 13 and a supported NVIDIA GPU, create a model-free fixture and compare its CPU and GPU decode checksums:

strata-next model smoke-fixture --output /tmp/strata-smoke.kar
cmake -S gpu/kar -B artifacts/kar-gpu-build -G Ninja -DCMAKE_CUDA_ARCHITECTURES=120
cmake --build artifacts/kar-gpu-build --target strata-kar-gpu-smoke
artifacts/kar-gpu-build/strata-kar-gpu-smoke /tmp/strata-smoke.kar smoke.expert 2 30
strata-next model checksum-kar-preview /tmp/strata-smoke.kar smoke.expert 2
artifacts/kar-gpu-build/strata-kar-gpu-smoke /tmp/strata-smoke.kar smoke.expert 2 30 --row 0
strata-next model checksum-kar-row /tmp/strata-smoke.kar smoke.expert 2 --row 0

An optional fifth argument is an overlay archive. The smoke target opens both archives with payload CRC verification, checks their virtual-F32 source identity and every replacement's name, shape, source dtype, source digest, and source offset, then reserves and decodes the requested tensor from the overlay when it is present there. It prints source=base or source=overlay. For a real overlay, first run strata-next model resolve-kar-overlay --base BASE.kar --overlay OVERLAY.kar: that Rust verifier additionally checks complete archive SHA-256 values and provenance. Keep both files unchanged between resolution and this smoke run. The smoke target alone does not authenticate the archive files against provenance and is not a serving loader.

The smoke program validates the KAR container and payload CRCs, reserves a chosen tensor's compressed level prefix in VRAM, decodes it on a CUDA stream, and reports a warm kernel median over the requested iterations. Compare output_fnv1a64 with the native CPU command above using the selected archive, tensor, and level. This is a kernel smoke measurement, not an end-to-end inference comparison or a model quality result. It does not yet link the decoder into Strata's serving path. Use the original model digest, archive digest, driver/CUDA versions, GPU, tensor, cache state, and iteration count when recording results.

Before any CUDA allocation, the smoke program checks the selected prefix, F32 output, and optional row ID against currently free VRAM. It leaves at least 512 MiB or one sixteenth of total VRAM free, whichever is larger, and refuses the run if that reserve would be crossed. This admission check protects shared GPU experiments; another process can still allocate memory afterward, so CUDA allocation errors remain possible. It is not an inference scheduler.

--row ROW_ID selects the CUDA row-gather decoder for one row of a compressed record. The row ID is local to the selected KAR part, so --row 0 on a split PLE part addresses that part's first row. This mode stages the same complete compressed level prefix with kar_reserve, then allocates and writes only one F32 row. It reports mode=row and the one-row output checksum. Compare a real-model result with model checksum-kar-row on the selected archive and part name; that CPU command verifies the complete archive before bounded range decoding. The one-row synthetic fixture above has the same checksum as its full-tensor decode. Row mode does not reduce the initial PCIe transfer of that part and does not make the full model fit in VRAM.

The smoke program caps the decoded F32 output at 100 million elements. A large PLE part can therefore be used with --row if its selected compressed prefix fits the available VRAM; its complete tensor need not fit the full-output cap.

For a private real-model overlay, scripts/check-kar-cuda-records.py accepts a JSON list of {name, elements} records (or a report with a records array), an archive, the Rust CLI, and the CUDA smoke binary. It checks byte-level CPU/CUDA output parity for each record, using the full tensor up to one million values and row 0 above that limit. It writes the complete result outside Git with mode 0600. Its event timings cover warm CUDA decoding only; it does not time PCIe transfer or multiply, and parity with the CPU KAR decoder is separate from quality against GGUF or end-to-end inference.

Selective row transfer prototype

strata-kar-sparse-row-smoke tests a different staging geometry. The upstream kar_decode_rows computes only requested rows but kar_reserve first transfers the record's complete level prefix. The prototype verifies the KAR archive, gathers only the selected rows' codebook, group scales, and bit-plane words from the mapped file into a compact host packet, transfers that packet once, and decodes the rows on CUDA. It does not modify the pinned libkar source. Its output is compared with model checksum-kar-row for each selected row.

cmake --build artifacts/kar-gpu-build --target strata-kar-sparse-row-smoke
artifacts/kar-gpu-build/strata-kar-sparse-row-smoke OVERLAY.kar blk.0.ffn_gate_inp.weight 3 30 0 1

The smoke reports packet bytes, the full-record prefix bytes, warm H2D event time, warm CUDA decode event time, and per-row byte checksums. Packet construction, archive verification, page faults, output transfer, matrix multiplication, and runtime scheduling are not included in those event times. Random rows may trigger storage reads and CPU work, so fewer PCIe bytes do not by themselves establish lower request latency. A production path needs a bounded packet cache, coalescing across requests, provenance binding, backpressure, and integration with the PLE consumer before it can be evaluated as inference.