Skip to content

spark-runtime: shift Ling shard mmaps off ARM64 contpte boundaries - #445

Open
data-angel wants to merge 1 commit into
Atlas-Inf:mainfrom
Enntity:ling/fix-fp8-contpte-439
Open

data-angel wants to merge 1 commit into
Atlas-Inf:mainfrom
Enntity:ling/fix-fp8-contpte-439

Conversation

@data-angel

Copy link
Copy Markdown
Contributor

Summary

On Linux aarch64 (CONFIG_ARM64_CONTPTE=y) with NVIDIA GB10 hardware ATS, 64 KiB-aligned file-backed mmaps allow contpte_set_ptes / __contpte_try_fold to fold 16 contiguous 4 KiB PTEs of a large file folio into a 64 KiB PTE_CONT mapping. When multiple GPU warps concurrently fault subpages 1..15 of an unmapped 64 KiB folio over ATS, faulting 32-byte GPU cache sectors silently read subpage 0 ((addr & ~0xffff) | (addr & 0xfff)), returning valid FP8 weight bytes from 4-60 KiB earlier in the shard. Subsequent reads see settled PTEs and return the true bytes.

This change shifts LingPagingReader's MAP_PRIVATE shard base by one base page off a 2 MiB boundary (va_base % 2 MiB == page_size) on linux/aarch64 by reserving a PROT_NONE VA span, overlaying MAP_PRIVATE | MAP_FIXED, and unmapping the unused prefix and suffix. Buddy-allocated large folios (order >= 4) have aligned PFNs, so (va >> PAGE_SHIFT) % CONT_PTES != pfn % CONT_PTES holds permanently across kswapd reclaim and re-faults across 4 KiB (64 KiB PTE_CONT), 16 KiB (2 MiB), and 64 KiB (2 MiB) kernels as well as 2 MiB PMDs. Tensor alignment (4 KiB, hence 4/16/128-byte), RAM footprint, CUDA graph capture, and zero-copy ATS reads are unchanged.

Moves ling_paging unit tests to crates/spark-runtime/src/weights/ling_paging_tests.rs so both files stay under the 500-LoC cap (415 and 175 lines).

Closes #439

Evidence

Tested on GB10 (ennspark03, Linux 7.0.0-1019-nvidia aarch64, CONFIG_ARM64_4K_PAGES=y, CONFIG_ARM64_CONTPTE=y, NVIDIA Open Kernel Module 580.178.04, uvm_ats_mode=1, uvm_disable_hmm=Y):

  • Standalone shard probe (no Atlas code): Mapping the 13 inclusionAI/Ling-3.2-air shards MAP_PRIVATE and unmapping PTEs via madvise(MADV_DONTNEED) with 54+ GiB free RAM (pgsteal_file=0) reproduced the mismatch 4 times across shards 2, 7, and 9. Every corrupted byte matched (foff & ~0xffff) | (foff & 0xfff), while a second GPU read (g2) and CPU mmap matched pread byte for byte.
  • Interleaved A/B on identical physical folios: Mapping the same 256 MiB pattern file twice in one process, once 64 KiB-aligned (va % 65536 == 0) and once shifted by +4096 (va % 65536 == 4096), alternating every iteration:
    • MAP_PRIVATE (5,000 iters): 29 / 5,000 corrupt (19,863 words) aligned vs 0 / 5,000 shifted
    • MAP_SHARED (5,000 iters): 16 / 5,000 corrupt (7,418 words) aligned vs 0 / 5,000 shifted
    • Combined: 45 / 10,000 vs 0 / 10,000 (p < 3e-14). MADV_NOHUGEPAGE still failed (2 / 5,000 MAP_SHARED, 6 / 5,000 MAP_PRIVATE) because it only controls PMD THP, not ARM64 contpte.
  • End-to-end inclusionAI/Ling-3.2-air FP8 strict on GB10: Measured on 4f763f9 with the +4096 VA shift (128 KiB base alignment, va % 65536 == 4096, verified live in /proc/1/maps on all 12 deferred shards; ATLAS_KV_MAX_BLOCKS=32769, CUDA graph decode on):
    • Two fresh server boots with cold shard page cache (POSIX_FADV_DONTNEED) before boot A on the 8-prompt greedy_eq suite (C1, temperature=0, cached: [0..0]): 8/8 identical across reasoning, content, finish_reason, and completion_tokens (7x length/320, 1x stop/246; hashes cfa0d2, a842a5, b019ed, c07367, b7fa1a, 0b1fa5, e806b0, 96d91a). Cold prompt 0 wall time 193.2 s vs 191.4 s unpatched, decode 3.1-10.6 tok/s.
    • Same-process double-launch check (LING439_REPEAT=1 on ling_fp8_gate_up_shared): 0 mismatches across 1,760 token/layer launches.
  • This PR (38485bfb9, based on main e5530ce4d) widens the guard alignment from 32 * page_size (128 KiB) to 2 MiB so va_base % 65536 == 4096 holds identically on 4 KiB kernels and also covers 16 KiB / 64 KiB CONT_PTES and 2 MiB PMDs. The PR tip passed Rust 1.93.1 Linux aarch64 fmt, clippy --workspace --tests, ling_paging unit tests (7/7), and cargo doc; the 2-boot GPU serve run above was recorded on 4f763f9 with the 128 KiB shift before widening the alignment to 2 MiB.

Test plan

  • cargo fmt --all -- --check
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo clippy --locked --workspace --tests (Rust 1.93.1, Linux aarch64)
  • ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo test --locked -p spark-runtime --lib -- ling_paging (7/7 passed on Linux aarch64, including live shifts_mapping_base_off_arm64_contpte_boundary and cross-platform contpte_shifted_span_fits_inside_guard_for_all_page_alignments)
  • RUSTDOCFLAGS="-D warnings" ATLAS_SKIP_BUILD=1 CUDARC_CUDA_VERSION=13000 cargo doc --locked -p spark-runtime --no-deps
  • python3 scripts/check_spdx.py, python3 scripts/check_kernel_shadows.py, typos, and 500-LoC cap (ling_paging.rs: 415 lines, ling_paging_tests.rs: 175 lines)
  • End-to-end GB10 verification on inclusionAI/Ling-3.2-air FP8 strict (8/8 identical across 2 fresh boots + 0/1,760 repeat mismatches on 4f763f9 + +4096 shift)

Notes for reviewers

  • LingPagingReader is the only file-backed mmap passed to GPU ATS in the workspace (ling_moe_fast.rs, ling_moe_load.rs, ling_sante.rs); spark-storage mmaps are RDMA/NIC-only.
  • No new ATLAS_* environment variables or CLI flags are added.

Authorship

AI-authored: Antigravity (Gemini), directed and reviewed by a human; no hand-written code.

CLA

On Linux aarch64 with CONFIG_ARM64_CONTPTE=y and GB10 hardware ATS, a
64 KiB-aligned file-backed mmap lets contpte_set_ptes / __contpte_try_fold
fold 16 contiguous 4 KiB PTEs of a large file folio into a 64 KiB PTE_CONT
entry. When multiple GPU warps concurrently fault subpages 1..15 of an
unmapped large folio over ATS, faulting 32-byte cache sectors silently read
subpage 0 of that 64 KiB folio ((addr & ~0xffff) | (addr & 0xfff)), causing
run-to-run greedy divergence on FP8 strict Ling-3.2-air (Atlas-Inf#439).

On linux/aarch64, map Ling shards by reserving a private PROT_NONE span,
mapping the file MAP_PRIVATE | MAP_FIXED at a 2 MiB-aligned address plus one
base page, and unmapping the unused guard edges. Shifting va_base by one
base page breaks (va >> PAGE_SHIFT) % CONT_PTES == pfn % CONT_PTES for
buddy-allocated large folios across 4K/16K/64K kernels (and 2 MiB PMDs)
permanently across kswapd reclaim and re-faults, while preserving 4 KiB
tensor alignment and zero-copy ATS reads.

Move ling_paging unit tests to ling_paging_tests.rs to stay under the
500-LoC file cap and add coverage for the guard/shift placement math and
live aarch64 base-address offset.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ling-3.2-air FP8 strict: greedy decode not reproducible run to run (NVFP4A16 is)

1 participant