interplane.Get Omega
Read in your language

aien-sovereign-core-mv

AienOS host runtime: inference scheduling, paged KV state, the aien CLI and Spark verification tooling. Its inference engine is in alpha testing (DGX Spark GB10); Omega is the implementation destination.

Brought by drakestapleton

branch main Branches Tags History

aien-sovereign-core-mv / crates / aien-kv-cache / OWNERSHIP.md

174 lines · 30570 bytes Raw Blame History Source

KV memory ownership and concurrency: the contract as the code has it

This page maps who owns every KV buffer and staging region, how they change state, who may write when, what makes a write visible to the GPU, and what bounds, cancellation, reuse and restart recovery actually exist. It is a map of current code and receipts, not a design. The design authority for persistent KV is ADR 0003; this page links into it instead of repeating it. Tracker: aien-spark/aien-architecture#233 (P1 memory contracts lane). Owning issues: sc#485 (KV offload concurrency), sc#494 (Wayfinder: persistent KV on the Spark), aienos#367 (native persistent KV), aienos#327 (native GB10 model).

Why it lives here: aien-kv-cache owns the pool and the block tables every other layer writes through, and the issue asks for documentation next to the source rather than another top-level document. docs/persistent-kv/ covers persistence only; this page also covers the in-memory pool and GPU visibility.

How to read the claims

1. Platforms are separate claims

PlatformKV code that runs thereStrongest evidence
Linux-hosted Spark, CPU reference backendAienKvManager + UnifiedKvTensorPool on a host-mapped LinuxUnifiedBuffer; persistent KV through aien-kv-store[H] the tests named below
Linux-hosted Spark, GB10 through the NVIDIA Linux driver (OmegaGb10Backend, 8B daemon path)same manager, pool memory from omega's resident allocation[C] docs/inference/evidence/cta1024-20261012T0315Z/ (section 4)
Linux-hosted Spark, OWN-30B door (aien-serve-http)the engine's own single-sequence KV (OmegaPagedKv, OmegaFusedKv), not AienKvManager block tables; park/restore through kv_persist.rs[H] host engine tests; chip check crates/aien-serve-http/tests/kv_persist_chip.rs is #[ignore], NOT_RUN (sc#507)
Native Aienux, Pi 5 CPUaienos-infer DecodeState: one dense f32 cache, no paging, no sharing, no persistence[N] aienos docs/native/PI5-6-INFER-RUNS.md (8 tokens equal llama.cpp, "KV capacity 64 in this probe")
Native Aienux, GB10 GPUnone: no native GPU platform implementation existsNOT_RUN (aienos#327; omega docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md section 2 rows NOT_RUN)
Emulator / QEMU onlynative persistent-KV slab is PLANNED in QEMU (ADR 0003 section 11, cuts N2/N3/N5); no code existsNOT_RUN (aienos#367)

A hosted chip result never stands in for native GB10, and a Pi 5 result never stands in for the Spark.

2. Owners

BufferOwner and lifetimeEvidence
Block allocator, block metadata, block tables, prefix cacheAienKvManager (SC/crates/aien-kv-cache/src/lib.rs#L830), shared as SharedKvManager = Arc<RwLock<AienKvManager<B>>> (#L1890). One manager for spine and backend: "creates ONE manager with a physical tensor pool ... and hands the same Arc to the spine ... and to the backend" (shared_kv.rs#L5-L10)[S]
Pool bytesUnifiedKvTensorPool owns its buffer B (lib.rs#L399-L403); freed when the pool drops[S]
Pool backing, case A: host-mappedLinuxUnifiedBuffer::allocate(..., ResidencyPolicy::FaultIn) (lib.rs#L643-L664); HeapUnifiedBuffer off Linux and in tests (#L347-L397)[S]
Pool backing, case B: omega resident poolomega allocates, the pool borrows: external_default_buffer "release runs exactly once, when the buffer is dropped" (lib.rs#L322-L344); requested by OmegaGb10Backend::alloc_kv_pool (omega_backend.rs#L1125-L1150) and by the 30B OmegaPagedKv::new (qwen3_moe_omega.rs#L2968). "One per process" (aien-omega-gpu/src/lib.rs#L1170-L1175); a second request is refused "attention pool: already allocated" (OM/src/omega_gpu_attention_api.c#L775) and the caller falls back to case A[S]
Dense per-sequence copyNativeTransformerBackend.sequences: HashMap<u64, SequenceState> (transformer_backend.rs#L163). With a pool attached it is scratch: "Drop the dense copy only when the physical pool holds the K/V" (#L1694-L1698)[S]
Chip staging (q, table, out, staged pool)omega statics g_q, g_pool, g_tab, g_out "staging, grown to the high-water mark, reused per call" (OM/src/omega_gpu_attention_api.c#L744), all session allocations GPU-uncached (OM/src/omega_gpu_session.c#L228)[S]
30B engine KVOmegaPagedKv (one sequence, blocks in order, resident pool when granted, qwen3_moe_omega.rs#L2943-L2950); OmegaFusedKv wraps aien_omega_dattn::DecodeAttnCache, "GPU-resident KV, one sequence", the chip does "the bf16 K/V append" (qwen3_moe_omega_dattn.rs#L1-L18)[S]
Storage references (park and restore)a holder is a real block table under a reserved id, HOLDER_SLOT << 32 \| job (lib.rs#L11-L29); the storage worker never holds a raw block id (ADR 0003 section 5.2)[S], [H] holder_ownership_tests.rs::holder_id_never_collides_with_arena_ids
Worker in-flight buffersthe worker keeps every source and destination until that job's terminal completion (ADR 0003 section 7.5 (a))[H] worker_tests.rs::worker_shutdown_keeps_buffers_until_each_job_terminal
Persisted objectshost store files under AIEN_KV_STORE_DIR (aien-kv-store/src/host_fs.rs); opt-in, off when unset (shared_kv.rs#L590-L604)[S], [H] kv_restart_test.rs::persistence_off_when_store_dir_unset_changes_nothing
Native Pi KVDecodeState.k/.v, "[layer][pos][kv_dim]", allocated once for capacity (aienos crates/aienos-infer/src/decode.rs L21, L56-L62 at aienos b7ebf7c)[S], [N] runs above
Native NVMe bounce bufferthe driver's own: "Every request goes through the bounce buffer ... One command is outstanding at a time" (aienos native/disk/disk_nvme.h L17-L19)[S]; no KV code uses it yet

3. State transitions

Block (KvBlock { ref_count, num_tokens, is_shared }, lib.rs#L675-L681):

free --allocate_block (ref 1, zeroed)--> private --fork_sequence / fork_range / assemble_table (ref +1, is_shared)--> shared
shared --append on a partial shared tail: copy-on-write into a new private block, old ref -1--> (old stays shared or private)
any --free_sequence / truncate_sequence: ref -1; at ref 0 back on the free list--> free

Block table readiness (PrefillState, lib.rs#L683-L700): Allocated -> PrefillPending -> PrefillReady -> SharedFrozen; complete_prefill is "the ONLY setter of PrefillReady" (#L1155-L1176), called by the scheduler after the forward returned Ok (aien-scheduler/src/lib.rs#L1257). [S], [H] lib.rs tests test_prefill_gate_*.

Sequence residency (persistent KV, kv_residency.rs#L26-L39, design in ADR 0003 section 5.1):

Resident --finish: fork_range one holder per chunk (S1), sequence freed--> (parked = objects in the store; no runtime state)
submit: chain hit --S2--> Restoring --every job Completed + S3--> Prefilling --suffix prefilled--> Resident
Restoring --any job fails or is cancelled--> Draining --every sibling terminal--> Failed --plain prefill--> Resident

"Parked is a property of the store (objects exist), not of the runtime" (ADR 0003 section 5.1). [S]. Host tests: kv_park_restore_test.rs::finished_turn_publishes_full_chunks_and_partial_tail, awaiting_restore_is_not_admitted_until_all_chunks_completed, restore_txn_adopts_assembled_table_only_after_all_jobs_terminal, multi_chunk_restore_failure_does_not_free_destination_in_use. [H]

30B door (separate path, no residency map): park exports after a generation under the GPU lock, restore imports all or nothing; restore_kv "On any error the engine is reset (empty history)" (qwen3_moe_omega.rs#L3959-L3964; kv_persist.rs#L11-L22). [S], [H] host engine tests (sc#514); chip NOT_RUN.

Native Pi: no states beyond pos; reset "Forget the sequence (buffers are kept)" sets pos = 0 (aienos decode.rs L93-L96). [S]

4. Who may write when

5. GPU and DMA visibility

Hosted GB10, resident pool (case B):

  1. Memory: every omega session allocation is .gpu_cache = OMEGA_GPU_CACHE_GPU_UNCACHED (OM/src/omega_gpu_session.c#L228); the binding states "one GPU-uncached, host-visible allocation ... whose chip address equals its host address" (aien-omega-gpu/src/lib.rs#L1170-L1175). [S]
  2. Host write: plain CPU stores into the pool under the KV write guard (section 4). [S]
  3. Publish to the chip: each attention launch calls omega_gpu_session_sync_to_gpu on the resident pool (OM/src/omega_gpu_attention_api.c#L911-L914); the Linux platform's sync is a full barrier, "uncached system memory: a full barrier is the whole sync" (dsb sy on AArch64, OM/src/omega_gpu_platform_linux.c#L239-L258). A GPU-cached buffer would instead queue an L2 invalidate on the next submit (same lines, omega#457). [S]
  4. Completion: the CPU polls an uncached marker written after L2_FLUSH_DIRTY (OM/src/omega_gpu_session.c#L501-L511); the rule "anything the CPU polls for a device write is HOST_POLLED and must be GPU_UNCACHED" is enforced by the platform check (omega docs/numeric/OMEGA_GPU_NATIVE_BOUNDARY.md section 2). [S]
  5. Synchronous: chip_attention holds the backend's single chip mutex across the call ("One lock serializes every chip call", omega_backend.rs#L81-L83, #L543-L570), so no host write to the pool races a running launch from this backend [S for the lock, I for the conclusion].
  6. Receipt: [C] docs/inference/evidence/cta1024-20261012T0315Z/FINDINGS.md "Decode attention reads a resident KV pool" and smoke-ctx-resident.json: kv_resident_calls_total=12312, fallback 0, output ids equal to the staged run. Built at omega 809c0aa6, not the current pin 4799f9e; it shows correct replies, not the barrier in isolation.

Other paths:

6. Bounded queueing and backpressure

BoundWhereEvidence
Storage intake per class: 48 restore ops, 64 park ops, 256 MiB in flight, 16 waiters per job, 1024 waiters total, dispatch depth 4WorkerConfig::default (aien-kv-store/src/worker.rs#L58-L71); refusal is PlatformError::QueueFull (#L417, credit_check #L500)[S], [H] worker_tests.rs::worker_bounds_ops_and_bytes_in_flight, coalesced_waiters_are_bounded
Dispatch fairness 3 restores : 1 parkworker.rs#L712-L726[S]; the 10 000-op saturation test is PLANNED in ADR 0003 section 7.2, UNVERIFIED that it exists
Refused park = "not parked this turn"ADR 0003 section 7.1[H] kv_concurrency_test.rs::queue_full_and_disk_full_under_load_never_lose_resident_progress
Restore refused below the scheduler watermarkS2, kv_residency.rs#L14-L16[H] kv_park_restore_test.rs::restore_refused_below_watermark_falls_back
KV admission: blocks needed (incremental_blocks_needed) plus watermark (default 4 blocks); preempt below watermark; max_batch_size 64 per stepaien-scheduler/src/lib.rs#L44-L55, #L718-L752, #L953-L968[S], [H] incremental_blocks_tests.rs::prediction_matches_real_appends_across_shapes, kv_concurrency_test.rs::memory_pressure_restore_and_admission_make_progress_without_deadlock
Pool exhaustion is a loud error, checked before mutationtransformer_backend.rs#L1156-L1158[S], [H] kv_lifecycle_qualification.rs::exhaustion_refuses_without_changing_state
Scheduler waiting queueVecDeque with no length limit (aien-scheduler/src/lib.rs#L114); the arena "capacity" is only the initial size: allocate_slot pushes a new slot when none is free (sequence.rs#L418-L444)[S]: no bound observed; whether the socket/HTTP intake bounds requests is UNVERIFIED
Native NVMeone outstanding command; ADR plans a step-budgeted kv_slab_pump (ADR 0003 section 9 item 3)[S] driver; pump NOT_RUN, no code

Overlap. [H] kv_concurrency_test.rs::resident_sequence_emits_tokens_before_unrelated_restore_completes shows a resident sequence emitting tokens while a slow fake restore is pending, on the CPU reference backend. That is progress ordering, not measured I/O-compute overlap. Chip and native overlap: NOT_RUN (sc#508, aienos#367 "prove overlap or explicitly report the limitation"; ADR 0003 section 9 item 8 reports it as a limitation).

7. Cancellation

8. Reuse

9. Restart recovery

10. Open items this page does not close