Files
leleka/gpu/kar

KAR CUDA smoke target

The optional strata_next_kar_ple_probe target belongs to the imported Strata engine build when STRATA_NEXT_EXPERIMENTAL_KAR_PLE=ON. It exercises the separate CPU PLE quality arm on real KAR rows. A successful checksum does not imply the sparse CUDA packet path is wired into serving.

For a same-process CPU gather comparison on the target model, run strata_next_kar_ple_probe --compare-random BASE.kar 2 PLE.gguf 4096 42 5 200000000. The final number bounds the sampled global row IDs; use the row count of the selected KAR part when matching a sparse CUDA packet run. The probe alternates native and KAR gathers after one warmup of each and reports the median over the requested repeats. The first native gather may incur storage page faults, while KAR opening already scanned the archive; compare the warm medians and report first-run times separately.

For a model-free reader check, run strata-next model ple-smoke-fixture --output /tmp/ple-smoke.kar, then strata_next_kar_ple_probe /tmp/ple-smoke.kar 2 --expected-rows 4 0 1 2 3. The four checksums must match those printed by the Rust fixture command. Remove the temporary archive afterward.

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
artifacts/kar-gpu-build/strata-kar-sparse-row-smoke BASE.kar 'per_layer_token_embd.weight#strata-part-001-of-002' 2 1000 --range 0 4096
artifacts/kar-gpu-build/strata-kar-sparse-row-smoke BASE.kar 'per_layer_token_embd.weight#strata-part-001-of-002' 2 1000 --random 4096 42

The smoke reports packet bytes, the full-record prefix bytes, warm H2D event time, warm CUDA decode event time, and per-row byte checksums. It reports archive verification and one packet build separately as host wall time; those are not included in the GPU event times. Page faults, output transfer, matrix multiplication, and runtime scheduling need separate accounting. 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.

The --range START COUNT form generates consecutive local row IDs, up to 200,000 rows and the same 100-million-value output cap. --random COUNT SEED generates deterministic pseudorandom local IDs within the selected tensor record. Both omit individual row checksums for more than 128 rows but still report the whole output checksum. The contiguous selection is useful for GPU transfer scaling; random selection probes host packet assembly with scattered rows. Neither selection is a representative storage page-fault benchmark because archive payload verification reads the complete file first and can warm the page cache. The smoke times both first packet assembly and a median of five repeated assemblies on the same rows. It also times an upload of the same number of F32 rows from pinned host memory into the output buffer. That upload is the GPU stage of Strata's current PLE prefill path. The comparison excludes its CPU row decoding; compare it with the separate CPU gather probe. Compare the measured stages at the same row count rather than inferring latency from byte counts alone.