Skip to content

CUDA (GB10): Nemotron KV caches in the display carveout, opt-in - #487

Merged
ashhart merged 7 commits into
ashhart:mainfrom
urtho:drm-carveout-v2
Oct 10, 2026
Merged

ashhart merged 7 commits into
ashhart:mainfrom
urtho:drm-carveout-v2

Conversation

@urtho

@urtho urtho commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Base branch: main. CONTRIBUTING names main as the Zig engine's main line, #452 names no other release branch,
and main, zig-flashnext and zig-preview are all 041d14a, so the diff is the same against any of them.
Retarget to zig-flashnext if you'd rather take Zig work there.

What this changes

On GB10, tensorfold run --carveout, or TF_CUDA_CARVEOUT=1 for tensorfold run and tensorfold-native,
maps the ~1.75 GiB of memory the display controller reserves (a DRM dumb buffer, registered with CUDA) and
puts Nemotron's KV cache planes there. That frees the same amount of ordinary memory. It is off by default, and
the output tokens don't change. Host setup (kernel mode setting, no display, card access, a check) is in
docs/recipes/cuda.md. Closes #452.

Receipt

  • Environment, with the TensorFold commit, MLX or PyTorch version, machine and GPU, checkpoint and revision:
    • Branch drm-carveout-v2: 6 commits on 041d14a (the sixth is documentation only) (TensorFold 1.0.1). The base build is 041d14a itself.
    • Zig 0.17.0. Builds ran in nvcr.io/nvidia/pytorch:26.07-py3 (PyTorch 2.13.0a0+9186a08b2c.nv26.07, nvcc
      13.3.73, -Dsm=121, -Doptimize=safe as box/build.sh builds). Driver 595.91.07, CUDA 13.3 (13030).
    • One DGX Spark: NVIDIA GB10, sm_121, 48 SMs, 128 GB class (124,546 MiB total), Ubuntu 24.04 aarch64,
      nvidia_drm modeset=1 fbdev=0 (DGX OS sets modeset=1), every connector disconnected,
      multi-user.target.
    • Checkpoint TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit, revision d9d758fb.
    • GPU runs used a container started with --gpus all --device /dev/dri/card0. The host user can't open the
      card node.
    • Kernel set:
      • Captured per zig/tests/cuda/nemotron/box/README.md: cap1 at the defaults, then cap2 with
        --context 262144 --repeats 1 --max-tokens 32.
      • Packed with aot_pack.py into cap1 (32 kernels) and both (36 kernels, adding the NCH 513 attention
        pair).
      • main no longer carries the Python engine the capture runs. The oracle was src/tensorfold from
        4af9503, the last main tree that had it (parent of 394d566). Its Nemotron draft vocabulary is
        byte-identical to zig/src/families/nemotron/draft_ids.txt here.
      • The capture tooling came from this branch. The box scripts' preflight refuses while any container runs,
        and two resident monitoring containers (no GPU use) were running. So the scripts' docker steps were run by
        hand with the same arguments.
      • box/build.sh printed SASS-EQUAL for every kernel of the 7 fatbin pairs (SASS-LAYOUT on experts'
        plan_kernel). It still exits 1, because it calls zig/tests/cuda/copies.py, which main removed.
  • Exactness, from tools/bench_concurrent.py --alone --serial or token_sha against "draft": false:
    • Served: the base, this branch off and this branch on (TF_CUDA_CARVEOUT=1), 3 interleaved sessions each.

      • Command: bench_concurrent.py URL nemotron --tokens 256 --reps 1 --temperatures 0 --levels 1,4 --alone --serial.
      • Every cell in every session: alone equal 3/3 at 1 stream and 12/12 at 4 streams, serial equal 3/3, no
        failures.
      • The server's per-request sha= was the same in all 9 sessions for every request: code 6c283e8c11ae
        (81 replies), chat f19104bea28f (81 replies), and each cold prompt's two tokens.
    • CLI, the repository gate (zig/tests/cuda/nemotron/gate.py, the capture's four prompts, 256 tokens, greedy,
      against the Python engine's serial tokens):

      Mode Carveout Result ms/token story / code / facts / long
      serial (--no-drafts) off PASS 4 of 4 8.729 / 8.732 / 8.782 / 8.840
      serial (--no-drafts) on PASS 4 of 4 8.782 / 8.766 / 8.822 / 8.835
      drafted off PASS 4 of 4 7.189 / 4.885 / 6.562 / 6.987
      drafted on PASS 4 of 4 7.168 / 4.814 / 6.597 / 6.951

      Shas (first 12 hex) in all four runs: story 26c86e423075, code b61f085a2d9b, facts ecc75781fbe3,
      long eb17a9a9c8d4.

    • CLI decode below: all 18 runs carry token_sha256 b61f085a2d9be1bcaf62298ebfb2ae7634532b68c5cba4d1c6c20b93d6c361f2.
      The 18 memory runs (64 tokens) carry one sha, 9e9b73b1aa77....

  • Decode speed before and after, from tools/bench_openai.py:
    • Served: bench_openai.py URL nemotron --tokens 256 --reps 1 --temperatures 0, --context 65600 --prompt-cache-gib 0. Sessions interleaved base, off, on, three times. Decode tok/s:

      Prompt base 041d14a branch, carveout off branch, carveout on
      fibonacci-raw (completion) 209.0, 209.0, 207.1 (median 209.0) 207.9, 208.5, 208.7 (208.5) 209.3, 209.6, 209.8 (209.6)
      gpu-chat-no-think 153.8, 152.8, 152.6 (152.8) 154.0, 154.5, 154.8 (154.5) 154.3, 157.7, 155.7 (155.7)
    • The same sessions, from bench_concurrent.py. Aggregate tok/s, one value per session:

      Cell base off on
      code, 1 stream 209.0, 209.1, 207.4 207.7, 209.3, 208.8 208.7, 209.8, 210.2
      chat, 1 stream 153.3, 153.2, 153.1 154.1, 155.3, 154.8 154.1, 157.7, 155.5
      code, 4 streams 453.6, 451.9, 326.5 341.0, 457.8, 356.8 341.3, 340.8, 300.1
      chat, 4 streams 362.1, 291.9, 363.5 292.7, 327.5, 292.3 361.7, 288.8, 292.0

      The 4-stream aggregate is bimodal in all three builds (about 290-360 vs 360-460 tok/s), the base included.
      Three sessions can't separate a carveout effect from that. With the carveout on, the lane streams' KV
      (387 MiB each at this window) sits in the carveout while it has room.

    • CLI: tensorfold run MODEL --tokens CODE_IDS --max-tokens 256 --kernels cap1 [--no-drafts] [--carveout],
      the 41-token code prompt, default context. Three reps, interleaved base, off, on within each rep.
      ms/token:

      Mode base 041d14a off on
      drafted 4.877, 4.827, 4.877 (median 4.877, 205.0 tok/s) 4.857, 4.851, 4.897 (4.857, 205.9) 4.843, 4.878, 4.881 (4.878, 205.0)
      --no-drafts 8.917, 8.888, 8.918 (8.917, 112.1) 8.883, 8.897, 8.880 (8.883, 112.6) 8.884, 8.863, 8.877 (8.877, 112.6)

      carved_bytes is 103,809,024 with --carveout: the own sequence's K and V planes, 99 MiB.

  • Prompt speed before and after, from tools/prefill_cold.py:
    • tools/prefill_cold.py is not in main; it is on python-0.6. It builds chat prompts with the Python
      package's tokenizer and template, so its prompts land near each length, not on it.

    • Instead, a standard-library client sent exact token-id arrays through /v1/completions to the same native
      servers, max_tokens 2, temperature 0, streamed. The client (coldw.py, warmed; cold.py without the warm-up request) and arrays.json follow in a comment.

    • The arrays hold exactly 2,048, 8,192, 32,768 and 65,536 ids: Request cold-N.\n plus this repository's
      zig/src/**/*.zig at 041d14a, sorted by path, tokenized by the server's /tokenize, then cut to N.
      sha256 of each id list:

      • 2,048: 9931dbaa...2eda16
      • 8,192: 57f98569...772027
      • 32,768: 9b44904c...6273cb
      • 65,536: c8b428d6...f2bd62
    • Every request reported prompt_tokens = N and cached_tokens 0. A fresh session ran each round, with
      --prompt-cache-gib 0, so each prompt started on fresh KV.

    • An unmeasured 1,024-id request opens each session, as prefill_cold.py does. Without it, the first
      measured request carried a warm-up cost: 2,048 ids took 0.2741 s on the base vs 0.2774 and 0.2782 s on the
      branch. That run's 8k to 64k timings match the table below.

    • TTFT in seconds over three interleaved sessions, median, then prompt tok/s:

      Prompt ids base 041d14a off on
      2,048 0.2620, 0.2644, 0.2652: 0.2644 (7,746) 0.2645, 0.2665, 0.2635: 0.2645 (7,743) 0.2649, 0.2650, 0.2722: 0.2650 (7,728)
      8,192 1.0808, 1.0981, 1.1012: 1.0981 (7,460) 1.0878, 1.0992, 1.1018: 1.0992 (7,453) 1.0970, 1.1016, 1.0994: 1.0994 (7,451)
      32,768 4.9666, 5.0357, 5.0459: 5.0357 (6,507) 4.9982, 5.0393, 5.0475: 5.0393 (6,502) 5.0361, 5.0484, 5.0492: 5.0484 (6,491)
      65,536 11.7137, 11.8751, 11.8843: 11.8751 (5,519) 11.8207, 11.8791, 11.8712: 11.8712 (5,521) 11.8709, 11.8905, 11.8857: 11.8857 (5,514)
    • No mlx_lm or vLLM comparison was run. This change moves buffers and leaves the prompt arithmetic alone.

    • Memory receipt, served at --context 65600 (8 streams admitted in every build). The lowest MemAvailable,
      sampled every 0.2 s over each session (median of 3), and the engine's own device byte counter
      (tensorfold:device_memory_bytes once loaded, then device_memory_peak_bytes at the end):

      Build Lowest MemAvailable Device bytes loaded / peak VmHWM
      base 041d14a 99,016 MiB 18,880 / 20,427 MiB 787-788 MB
      off 99,032 MiB 18,880 / 20,427 MiB 787-788 MB
      on 100,443 MiB (+1,411) 18,493 / 19,008 MiB 787-788 MB

      With the carveout on, the startup line reads model 18.06 GiB instead of 18.44 GiB: the own sequence's
      387 MiB of KV is carved. The carved spans are borrowed, so the device counter leaves them out.

    • Memory receipt, CLI (--no-drafts, 64 tokens, kernel set both). The lowest MemAvailable, median of 3, and
      the peak process RSS:

      --context base off on KV carved
      16,880 101,938 MiB 101,904 MiB 102,192 MiB (+288) 99 MiB
      262,640 100,507 MiB 100,663 MiB 101,886 MiB (+1,223) 1,539 MiB
      • Peak RSS was 368 MiB in every run: on GB10, CUDA allocations don't show in RSS.
      • cuMemGetInfo free is printed only with --carveout (the cache room line). It read 101,322-101,836
        MiB at 16,880 and 101,031-101,308 MiB at 262,640, with 1,693 and 253 MiB left in the carveout.
      • On GB10 that figure moves by up to ±1.8 GiB between identical processes, so it can't resolve the
        difference. MemAvailable and the engine's counter can.
  • Tests run, with pass, fail and skip counts:
    • zig build test:
      • x86_64 workstation: 17/17 steps, 84/84 passed. The base passes 76/76; the 8 new tests are 7 in
        carveout.zig plus one in memory.zig.
      • GB10 box (aarch64): 84/84 passed.
      • Both runs used a tmpfs --cache-dir. With the cache on ext4, direct_io's "direct reads return the same
        bytes as buffered reads" fails on the base and on the branch alike (83/84 here, 75/76 base). That test
        opens the test binary itself with O_DIRECT, so it is inherited and depends on the filesystem.
    • zig build test-golden: not applicable on Linux; the step exists only in the macOS (Metal) build graph.
    • python3 tools/zig/lean_check.py: 513 problems on the base (764 files) and 513 on the branch (766 files),
      so zero added.
      • All findings are inherited: 386 comments past 120 columns, 89 multi-line comments, 29 docstrings past 120
        columns, 4 multi-line docstrings, 4 files over 600 lines and 1 block comment.
      • Three of them are in files this branch touches, on lines it doesn't touch: cuda_engine.zig:266, :329
        and tests/cuda/main.zig:1.
    • zig fmt --check: the branch's hunks are clean. Two touched files also fail on the base, in lines this
      branch doesn't touch (cuda_state.zig's size table and scratchPtrs, tests/cuda/main.zig's info
      print). They were left alone.
    • carveout.zig and memory.zig compile for aarch64-macos, x86_64-linux and aarch64-linux
      (zig test -fno-emit-bin), including a forced analysis of Carveout.open for macOS.
    • Device, tf-cuda-test: info, smoke 5 PASS (and the expected refusals), graph 3 PASS, sample PASS.
      carveout passed in three runs:
      • registered DEVICEMAP|IOMEMORY; MemAvailable moved 10-31 MiB;
      • copies into and out of the carveout 57-60 GB/s, against 121-123 GB/s device to device;
      • axpy reading x from the carveout 232-235 GB/s, against 249-250 GB/s from device memory.
    • Skip and refusal paths:
      • tf-cuda-test carveout 1792 /dev/dri/card9: SKIP, rc 0.
      • The host user without access to the card node: SKIP, rc 0.
      • TF_DRM_CARD=/dev/dri/card7 with tensorfold run --carveout or TF_CUDA_CARVEOUT=1 tensorfold-native serve: display carveout of 1792 MiB from /dev/dri/card7: CardUnavailable (needs nvidia_drm modeset=1, the card's device node and no display in use). The server then refuses the load, rc 1.
  • Not run, and why:
    • Metal M1 to M5: not run, because I have no Mac. The change is CUDA-only. zig build test on a Mac
      also builds the CUDA host tests, so carveout.zig gets analyzed there: compile-only status above, not
      executed on macOS.
    • Discrete GPUs (RTX PRO 6000 and others): not applicable. A discrete card has no display carveout in system
      memory. The device test skips on a GPU that is not integrated, and the option is off unless asked for.
    • Two ranks: not run (one Spark used).
    • The resumed-prompt contract: not exercised. Nemotron CUDA has no prompt reuse at this base. Nemotron CUDA prompt reuse #467 adds it,
      through Buffers.snapshot and restore, which this branch changes to walk the seven planes.
    • The memory-bound context limit: not searched. 262,640 is where the captured attention kernels stop
      (NCH 513), in both modes.
    • The 4-stream throughput difference: not resolved, see the decode section.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.
    Drafted equals serial and concurrent equals solo in every session, carveout off and on. The resumed prompt
    was not tested: Nemotron CUDA has no prompt reuse at this base.
  • No precision traded for speed. If the bits change, the description says which sums change and why. No
    kernel or sum changes; only where the KV planes live.
  • Prompt processing is no slower than the last release. The off build is level with 041d14a. On, 2k to 64k
    is within 0.0-0.3% of the base medians, inside the run-to-run ranges.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not.
  • New tests fail before the change, pass after it, and skip cleanly without their dependency. The new tests
    cover new code: DRM ioctl numbers and struct layouts, span placement, opt-in parsing, borrowed-span frees and
    the device round trips. They have no "before" to fail on. The device test skips cleanly (shown above).
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

Notes for review

  • Commits:
    1. CUDA runtime: GB10's display memory as device memory. zig/src/cuda/carveout.zig (new, 232 lines):

      • the DRM ioctls from drm_mode.h, mmap, then cuMemHostRegister (DEVICEMAP, then
        DEVICEMAP|IOMEMORY) and cuMemHostGetDevicePointer;
      • a first-fit span list that hands out zeroed, 256-byte-aligned spans as borrowed DeviceBuffers.

      abi.zig adds cuMemHostRegister_v2 and cuMemHostUnregister with the flags. In memory.zig, free
      leaves a borrowed span alone and keeps it out of the new device byte counters.

    2. tf-cuda-test carveout: round trips and a copy and kernel-read bandwidth probe. It skips without the
      card.

    3. Nemotron CUDA: KV caches in the display carveout behind --carveout.

      • Each sequence's K and V planes go there while it holds both. Mamba and conv state, window io and
        scratch stay in device memory.
      • Snapshot, restore, reset and the segments' state digest walk the seven planes.
    4. The device test skips on a discrete GPU; the recipe wording changes.

    5. The native server's opt-in, TF_CUDA_CARVEOUT=1. The family owns the carveout and closes it after
      the engine.

    6. Recipe: preparing a DGX Spark for the carveout. Kernel mode setting, no display or desktop session,
      access to the card node (the video group or a container device), and tf-cuda-test carveout as the check.

      Stream admission still counts each stream's full bytes, so admission stays conservative. Should the
      carved room feed admission? That is open for you to decide.

  • Rebase onto 041d14a:
    • memory.zig gained the device byte counters upstream. A borrowed span now skips both cuMemFree and the
      counter.
    • Seq.init now takes the owning stream as well as the carveout. Seq.bytes, which admission uses, stays
      the full size.
    • seq_fields follows upstream (rule).
  • Overlap with Nemotron CUDA prompt reuse #467 (Nemotron CUDA prompt reuse, open, base zig-flashnext):
    • Both touch zig/src/families/nemotron/cuda_native.zig, around Owned and open, and
      cuda_engine.zig, in different functions. This branch doesn't touch zig/src/native/cuda.zig.
    • Nemotron CUDA prompt reuse #467's cuda_reuse.zig calls e.b.stateBytes(), e.b.snapshot() and e.b.restore(). This branch keeps
      their signatures. A snapshot is now packed plane by plane, because the KV pair may live in the carveout.
    • Whichever lands second needs a small textual merge in cuda_native.zig.
  • Credit:
    • The idea of keeping caches in GB10's display-reserved memory comes from coolbho3k's
      DeepSeek-v4.1-Flash-2x-DGX-Spark, which
      is AGPL-3.0. None of that code is used. This implementation is written from the Linux DRM UAPI
      (drm_mode.h) and NVIDIA's CUDA driver API documentation.
    • The measured reference is our independent Python implementation (urtho/TensorFold, dsv41-cuda).

urtho added 6 commits October 7, 2026 17:58
On a DGX Spark the display controller reserves about 1.75 GiB of system
memory that MemAvailable never counts. A DRM dumb buffer on the card is
backed by it. carveout.zig creates one (DRM_IOCTL_MODE_CREATE_DUMB, a
4096-wide 32-bpp buffer), maps it (MAP_DUMB, mmap) and registers it with
cuMemHostRegister: DEVICEMAP first, then DEVICEMAP | IOMEMORY, which is
what GB10's driver takes. A Carveout value owns the fd, the dumb handle,
the mapping and the registration, and releases them in reverse order.

Spans come from a first-fit list (a bump allocator until something is
given back). They are 256-byte aligned and zeroed, and each is returned
as a DeviceBuffer marked borrowed, so free leaves the memory and the
process's device byte counts alone, and give() hands it back.

The structs and ioctl numbers follow drm_mode.h, and the unit tests check
them, the span placement, exhaustion and the opt-in parsing on any host.
Nothing runs unless a caller opens a carveout.
…memory

`tf-cuda-test carveout [MiB] [card]` opens the carveout, writes a 1 MiB
pattern from the host and reads it back through a device copy, fills a
span with tf_probe_fill and reads the floats through the mapping, then
times copies into and out of it and an axpy whose input lives there. It
prints SKIP and passes when the card cannot be opened.

GB10, 1792 MiB, four runs: registered DEVICEMAP|IOMEMORY, MemAvailable
moved 0-32 MiB; copies 57-60 GB/s into and 56-60 out of the carveout
against 118-121 device to device; axpy reading its input from the
carveout 220-234 GB/s against 247-250 from device memory.
With `tensorfold run --carveout` (or TF_CUDA_CARVEOUT=1; size
TF_CUDA_CARVEOUT_MIB, default 1792; card TF_DRM_CARD) each sequence's K
and V planes go into the display carveout while it holds both: the
engine's own sequence first, then the lane sequences newSeq makes. The
Mamba state, conv state, window io and scratch stay in device memory.
The recurrent state is read and written whole every round, so it is
left out on purpose. A sequence gives its planes back when it is freed.
Placement only: no kernel or sum changes, so the output does not change.

The seven cache and state planes are no longer one device range.
Snapshot and restore copy them plane by plane into a packed buffer,
reset fills each plane, and the segments' state digest hashes the planes
(it skips the alignment gaps the old range covered). The CLI prints the
room: the device's free memory plus what is left in the carveout.

Off by default. It needs nvidia_drm modeset=1, the card's device node and
no display in use. Without the card, the CLI names the step that failed
and stops.

The idea of keeping caches in GB10's display memory comes from coolbho3k's
DeepSeek-v4.1-Flash-2x-DGX-Spark. This is an independent implementation
from the DRM UAPI and the CUDA driver API.
… measured

The device test now skips before touching the card when the GPU is not
integrated, so a desktop card is never asked for a 1.75 GiB dumb buffer.
The recipe gives copies at about half speed and kernel reads at about 90%,
and says the output should not change rather than that it was checked.
tensorfold-native now serves Nemotron on CUDA, so the family opens the
display carveout when TF_CUDA_CARVEOUT=1 is set (TF_CUDA_CARVEOUT_MIB and
TF_DRM_CARD as for `tensorfold run`) and hands it to the engine: the own
sequence's and each admitted stream's KV planes go there while it holds
both. The family owns it and closes it after the engine and lane sequences
are gone. A card that cannot be opened stops the load with the failing
step logged.

Stream admission still counts each stream's full bytes, so the carveout
only leaves more memory free than admission assumes. Off by default.
Kernel mode setting, no display or desktop session on the card, access to
the card node (video group or a container device), and the check that
confirms it. The skip note now names the discrete-GPU case too.
@urtho

urtho commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

carveout-cold-prompt.zip

Cold-prompt receipt inputs:

  • coldw.py (warmed client, the reported medians),
  • cold.py (no warm-up request),
  • arrays.json (the exact 2k/8k/32k/64k token-id arrays with their sha256s)

@plotarmordev

Copy link
Copy Markdown
Contributor

Partial receipt from a second DGX Spark (GB10, kernel 6.17.0-1029-nvidia, driver 580.173.02, options nvidia_drm modeset=1 in modprobe.d), built at 596765f2:

  • Off (the default): Nemotron 3.5 Lightning 4-bit @ d9d758fb with the release 1.0.2 sm121 kernels gives the same token hashes as main on 6 sampled/greedy requests, each repeated.
  • On: this Spark doesn't meet step 2 of the recipe (it boots graphical.target with gdm on seat0), and both tf-cuda-test carveout and TF_CUDA_CARVEOUT=1 stop with DumbBufferRefused and the recipe's hint, at load time rather than falling back. So that path isn't covered here; it would need the box switched to multi-user.target.

@urtho

urtho commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the receipt. The off path matching main is the part that matters most.

The on path stopping is by design. The carveout is all or nothing: it takes the full ~1.75 GiB of the display reservation or refuses the load, and never runs with a partial carveout or quietly without it. On a box booted into graphical.target, gdm's framebuffers already use part of that reservation. The driver then refuses the full-size dumb buffer, which is the DumbBufferRefused you saw. b33cb06 rewords the recipe to say that a stock DGX OS install needs step 2, and adds a way to try it without rebooting.

If you have time to cover the on path:

  1. sudo systemctl isolate multi-user.target (isolate graphical.target brings gdm back).
  2. Check that sudo fuser -v /dev/dri/card0 lists no display server, and that cat /sys/module/nvidia_drm/parameters/fbdev prints N. With fbdev on, the console framebuffer also takes part of the reservation; the receipts ran with fbdev=0.
  3. tf-cuda-test carveout.

If it still refuses with gdm stopped and fbdev=0, that points to driver 580 (the receipts ran on 595.91.07), and I'd like to hear about it.

@plotarmordev

Copy link
Copy Markdown
Contributor

Follow-up to my partial receipt: the carveout-on path, now on the same Spark set up per the recipe (kernel 6.17.0-1029-nvidia, driver 580.173.02, nvidia_drm modeset=Y, multi-user.target, every card0-* connector disconnected), built at 596765f2, Nemotron 3.5 Lightning 4-bit @ d9d758fb, release 1.0.2 sm121 kernels, --context 16384 --parallel 4 --no-thinking, in a container with --device /dev/dri/card0.

tf-cuda-test carveout:

PASS carveout: 1792 MiB from /dev/dri/card0 registered DEVICEMAP|IOMEMORY at 0xecc4c0000000, MemAvailable moved 0 MiB
PASS host write -> device copy -> host: 1 MiB equal
PASS kernel write -> host read through the mapping: 262144 floats equal
RESULT carveout 1024 MiB copies GB/s: into 60, out of 60, device->device 122; axpy GB/s reading x from the carveout 236, from device memory 250
PASS bandwidth probe over 1024 MiB

Serving, off / on / off / on, each a fresh process:

off on off on
12 requests (2 prompts × top_k omitted/0/20, sampled, each twice): token hashes same same same same
decode, 256 greedy tokens (tok/s, two runs) 146.6, 146.6 147.8, 147.7 149.1, 149.2 148.5, 148.5
/health active bytes 19,316,671,216 19,212,861,680 19,316,671,216 19,212,861,680

With the carveout the log shows display carveout: 1792 MiB from /dev/dri/card0; KV planes go there first, and active device memory is 103,809,536 bytes (99 MiB) lower, which is these 4 streams' KV planes at a 16K window; a longer window or more streams would move more, up to the 1,792 MiB. Decode speed is within run-to-run noise here.

One thing I hit on the way: these Sparks shipped an /etc/modprobe.d file setting nvidia-drm modeset=0, which overrides the driver package's modeset=1. Step 1 of the recipe already covers that case ("remove any modeset=0 line"); just noting that systemctl get-default and the connectors looked right while modeset was still N, so step 1 is worth checking first.

@ashhart
ashhart merged commit e4e4385 into ashhart:main Oct 10, 2026
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @urtho, and thanks to @plotarmordev for both receipts. This is merged into main (e4e4385) with your
seven commits as they were, and it ships in the next release, documented as experimental (c75a5ce).

We gated the default path on a GB10. With TF_CUDA_CARVEOUT unset, the four release prompts (story, code, facts and
long, 256 greedy tokens, drafted and "draft": false) gave the same tokens as 1.0.4 in two rounds. Decode and cold
prompts from 2k to 32k tokens ran within 1% of 1.0.4, and device memory is the same to the byte. We didn't run the
carveout itself. It needs multi-user.target, fbdev=0 and the card node, and we're not changing our Spark's setup
for it, so the recipe calls it experimental and points to your receipts. Your plane-by-plane snapshot and restore
are also what the new CUDA prompt cache (#467) copies, so a carved KV plane is saved like any other.

otarkhan pushed a commit to otarkhan/TensorFold that referenced this pull request Oct 10, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
bertholomus added a commit to bertholomus/TensorFold that referenced this pull request Nov 10, 2026
TF_CUDA_CARVEOUT_SOURCE=attic takes the carveout from spark-attic's atticd
instead of the card. atticd holds the GB10 display reservation and lends it in
whole 2 MiB slices, as file descriptors the engine imports
(cuMemImportFromShareableHandle) and maps with CUDA's virtual memory calls,
resolved the way arena.Vmm resolves them. The loan is a Carveout like the
card's, so take, give, bytes, freeBytes and every caller's KV placement work
unchanged. close unmaps the range and closes the socket, and atticd has the
slices back.

Opt-in and explicit: TF_CUDA_CARVEOUT=1 (or --carveout) still turns the
carveout on, and the source defaults to drm. With drm the card path is byte for
byte as it was: its defaults, messages and all-or-nothing rule. An unknown
source is refused. The attic source keeps the same rule: without
TF_CUDA_CARVEOUT_MIB it borrows atticd's longest free run, with it exactly that
many MiB in whole slices, and anything short of that stops the load.
TENSORFOLD_ATTIC_SOCK (default /run/spark-attic/attic.sock) and
TENSORFOLD_ATTIC_KEY (else the first line of /etc/spark-attic/key) point it at
atticd. Both places that open a carveout honour the switch: Nemotron's native
engine and tensorfold run. docs/recipes/cuda.md describes it.

Host tests: the source switch; a fake atticd over a socket pair (requests byte
for byte, a descriptor beside its reply, refusals and malformed replies that
leak no descriptor, a timeout, no daemon); the sizing rule; the key from the
environment or the key file.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next recipe is what this is for; Ash's TensorFold.
bertholomus added a commit to bertholomus/TensorFold that referenced this pull request Nov 10, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

The settings are read through platform/environment.zig, which refuses
malformed values: TF_CUDA_CARVEOUT_SOURCE picks the source (commit 1), and the
TF_DRM_CARD card and the atticd socket and key follow its rules here too.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. docs/recipes/cuda.md and flash-next-cuda.md describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
bertholomus added a commit to bertholomus/TensorFold that referenced this pull request Nov 12, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
bertholomus added a commit to bertholomus/TensorFold that referenced this pull request Nov 17, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
bertholomus added a commit to bertholomus/TensorFold that referenced this pull request Nov 17, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
bertholomus added a commit to bertholomus/TensorFold that referenced this pull request Nov 17, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
ashhart pushed a commit to bertholomus/TensorFold that referenced this pull request Nov 21, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
ashhart pushed a commit to bertholomus/TensorFold that referenced this pull request Nov 21, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
ashhart pushed a commit to bertholomus/TensorFold that referenced this pull request Nov 21, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
ashhart pushed a commit to bertholomus/TensorFold that referenced this pull request Nov 23, 2026
TF_CUDA_CARVEOUT=1 puts Flash Next's KV caches in the display carveout too: a
contiguous cache holds it one at a time, as many whole planes of a full window
as fit (cuda_carve.zig) - the keys and values of the first attention layers
(both or neither), then indexer keys, then pooled keys. A shorter cache takes
the same planes, each smaller, so it fits too and never needs more device
memory than a full window. The DeltaNet states, the n-gram tail, the MTP
head's cache and the pool's pages stay in device memory.

The memory budget counts the planes out of device memory: Loaded.carved_bytes
joins the room cuda_streams.zig counts the streams in (kv_pool.streamsRoom),
which the grown streams, the shared page pool, a KV ledger's plan and the kept
prompt cache are sized from. So pages or streams admitted grow by about the
lent bytes. Nothing is counted when another cache may hold the carveout while
the first stream runs: --slide's learner, a page test, or every stream on
pages. The carveout opens before the checkpoint load finishes, so a refusal
keeps the page cache as any other refusal does. The startup log names the
planes, their bytes and the bytes counted.

Flash Next makes the same two calls the CLI and Nemotron make: carveout.zig's
requested(Settings) reads every row through the settings table, TF_DRM_CARD
included, and Carveout.from opens the source the request names and logs a
refusal once. The daemon's rows are read only while the daemon is the source,
and the card's only while the card is. cuda_carve.zig holds no opener of its
own.

Opt-in and off by default: without TF_CUDA_CARVEOUT nothing changes. One rank:
--tp 2 with the carveout is refused (FlashNextCarveoutUnsupported). Nemotron's
placement and the card source are unchanged. Only the planes' addresses change,
not the math.

Host tests: the plane sizes against seqBytes; the plan at 2,044 MiB, at
1,792 MiB, at a short window and with no room; every cache size up to the
window takes the window's planes from an empty carveout, in order; a cache's
planes by part; and the pool gaining the carved planes' whole pages (135 pages
of 512 tokens for 2,032 MiB at 30,784 bytes a token) while the prompt cache
stays at its budget. Test fixtures that build an Engine field by field set
carve = null. cuda_lanes.zig and cuda_prompt.zig stay under the 600-line limit:
an unused import goes, the layer-map test moves to cuda_prompt_test.zig, and
the engine closes the carveout. docs/recipes/cuda.md and flash-next-cuda.md
describe it.

Credits: urtho wrote cuda.Carveout and its spans (ashhart#487), which this builds on;
coolbho3k had the idea of the display carveout as KV room; ezoushen and BadAd84
put display KV into the GLM recipe; Kindling's dispramd introduced the lending
protocol atticd speaks; plotarmordev gave receipts on a second Spark; Mia's
Qwen3.8-Flash-Next work, her checkpoint and settings, is what this is for;
Ash's TensorFold.
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.

CUDA (GB10): KV caches in the display controller's reserved memory

3 participants