Skip to content

CUDA (GB10): a lending-daemon source for the display carveout, opt-in - #2762

Open
bertholomus wants to merge 3 commits into
ashhart:mainfrom
bertholomus:attic-carveout-source
Open

bertholomus wants to merge 3 commits into
ashhart:mainfrom
bertholomus:attic-carveout-source

Conversation

@bertholomus

@bertholomus bertholomus commented Nov 10, 2026 •

Copy link
Copy Markdown

Closes #2747

What this adds

TF_CUDA_CARVEOUT stays 0 or 1. A new TF_CUDA_CARVEOUT_SOURCE says where the display reservation comes from: drm, the default and the existing dumb-buffer route, or daemon, where a display-memory daemon lends it in whole 2 MiB slices over a unix socket. Which daemon a box runs is a setting, not a code path: TF_CUDA_CARVEOUT_SOCKET (default /run/dispram/dispram.sock, kindling spark-os's dispramd), TF_CUDA_CARVEOUT_KEY (default is Kindling's published one, README line 32), or TF_CUDA_CARVEOUT_KEY_FILE for a daemon whose key is per box: spark-attic's atticd keeps /etc/spark-attic/key and listens on /run/spark-attic/attic.sock. One client for the protocol both daemons speak, which is what #2747 asks for.

Why

DRM_IOCTL_MODE_CREATE_DUMB on /dev/dri/card0 returns ENOSYS under driver 580.178.04 on the GB10s here (kindling spark-os 0.9.5), so the DRM backend cannot claim the reservation even though the firmware keeps DISPLAY_FRM (2046 MiB at 0x280200000) out of system RAM. The daemon lends that memory to unprivileged CUDA processes: a slice is claimed over the socket, arrives as a descriptor by SCM_RIGHTS, and is mapped with the CUDA VMM API.

Where the client came from

The protocol was derived from the daemon's own behaviour: field names from its refusals, op names from a sweep of 58,337 identifiers harvested from the C/POSIX headers, the Python stdlib and the Zig stdlib on the machine, and the wire format confirmed by a pass-through capture. The specification, the scripts and their captured output are in the thread on this PR. The implementation was then written from that behaviour by an agent working in a copy of the tree with both clients absent, so neither was available to read.

Shape

  • One pair of calls serves every caller: carveout.requested(Settings) decides whether the carveout is on and reads its rows through the settings table, and Carveout.from(d, request) opens the source the request names and logs a refusal once. The CLI and Nemotron make those two calls and nothing else.
  • The daemon's rows are read only while the daemon is the source, and TF_DRM_CARD's only while the card is.
  • The key file is read only for the daemon source. A file that is missing, not a regular file, empty on its first line or 256 bytes long is refused with TF_CUDA_CARVEOUT_KEY_FILE named, and neither the path nor the file's bytes are shown.
  • A daemon that lends less than asked is refused rather than fitted, one that never answers is given up on after 10 seconds, and the reply's granted size is the authority (ok must be true, since a refusal carries a size field too). The mapping goes through arena.zig's Vmm.
  • The client is Linux-only: off Linux the claim returns NoDaemon before any protocol code is analysed.

Gates on this head

73a88956b, on upstream main at 6c5cef894, in the forms CI uses:

  • zig fmt --check build.zig zig: clean on Linux and Windows.
  • tools/zig/lean_check.py and lean_new.py, base and head each from its own tree: 345 on the base, 343 on the head, 0 new.
  • tools/pr_check.py --base 6c5cef894 --pr 2762: 0 errors, 0 warnings.
  • zig build -Dfixed-cpu test: 667 of 667 steps on Linux x86_64, 643 of 643 on Windows. test-kernel-contract, test-golden, test-server-security, test-pull-security and fuzz-cortheon pass on Linux, and test-golden and fuzz-cortheon on Windows.
  • Mutants: 21 of 21 killed on the new decisions, each by the test written for it.
  • test-gradient-serving fails on main itself, on zig/src/cuda/cublaslt.zig, whose row is stale there. Our two rows are re-pinned and that one is left alone.
  • check-native-cuda-host does not compile the CLI's main (a deliberate bad call in it still passed), so the CLI was compiled by the device build below.

Receipts

One GB10 (kindling spark-os 0.9.5, driver 580.178.04, dispramd), Nemotron 3.5 Lightning MLX 4-bit, main (6c5cef894) and this commit both built from source on the box, greedy, 96 tokens with --ignore-eos:

prompt main, carveout off head, carveout off head, TF_CUDA_CARVEOUT=1 TF_CUDA_CARVEOUT_SOURCE=daemon (2 runs)
13 tokens, --context 131072 6d94d3ec88d7 6d94d3ec88d7 6d94d3ec88d7, 6d94d3ec88d7
108,012 tokens f19784e7f9d3 f19784e7f9d3 f19784e7f9d3, f19784e7f9d3
  • 771 MiB of KV planes are carved. With TF_CUDA_CARVEOUT_MIB=512 they do not fit, 0 MiB are carved and the digest is the same. With TF_CUDA_CARVEOUT_KEY_FILE the digest is the same.
  • Two chat replies through tensorfold-native serve are identical with the carveout off and on.
  • No socket, a missing key file, an empty key file, a wrong key and a mistyped source each stop the run by name.
  • The DRM source answers DumbBufferRefused on this OS, on main and on this head.
  • Cost, outside this PR: on the 108,012-token prompt the daemon's slice is slower, prefill 35.6 s against 22.4 s and decode 11.5 ms a token against 8.85, and the 13-token prompt is not. On stock DGX OS the DRM source measured within 2% on the same prompt. The GPU's L2 does not hold the lent slice (rereading 8 MiB ran at 209 GB/s from it against 810 from ordinary memory), while the DRM buffer is cached. The receipts and the probe table are in the comment on this PR. We will look into whether it is fixable and, if we find anything worth it, send it as a separate PR. The slice behind atticd has not been measured here.
  • Not run on a device here: Flash Next (CUDA (GB10): Flash Next KV in the display carveout, opt-in #2763 makes its call), atticd.

Based on 6c5cef894.

Co-authored-by: bertholomus 311723197+bertholomus@users.noreply.github.com for the settings rows and the refusal walk.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus, the atticd client is careful work. Every reply's descriptors are counted and closed, the key
never reaches a refusal line, and the fake-daemon tests already cover the claim, the fd over SCM_RIGHTS and the
malformed and short replies. There's no issue for this one, so we've read it against the gate on #2747 for a second
carveout source. To make it ready:

  1. One backend for the protocol. Your recipe says atticd speaks the lending protocol dispramd introduced, and
    TF_CUDA_CARVEOUT cannot allocate on kindling spark-os (CREATE_DUMB ENOSYS) - would you take a dispramd backend? #2747 asks for a dispramd source. We'd rather have one client for that protocol than one per daemon: a source
    named for the protocol, with the socket (and the key, if the protocol has one) from settings. Could you and
    @BadAd84 agree the shape on TF_CUDA_CARVEOUT cannot allocate on kindling spark-os (CREATE_DUMB ENOSYS) - would you take a dispramd backend? #2747?
  2. Sources. Please name in the description the documents the client was written from, and confirm that nothing
    came from Kindling's reference client.
  3. Never less than asked. With TF_CUDA_CARVEOUT_MIB unset, fit takes whatever the longest free run is
    (carveout_attic.zig:55-60). Please give unset a fixed size and refuse when less is free, as the card path does.
  4. Before mapping. Please check the lent fd's own size against the size asked before importing it (your test
    already reads it with lseek). Please also add a test that closing the client closes the daemon's end, so it
    gets the slice back.
  5. Shared code.
    • arena.zig's Vmm already loads the VMM calls and defines AccessDesc; please reuse it rather than opening
      libcuda.so.1 again.
    • Please keep one opener for both sources in carveout.zig for the CLI, Nemotron and Flash Next to call.
    • environment.Process.get already does what the new setting does.
  6. Tests for the new skips in the refusal walk: the four rows ignored with the carveout off, and TF_DRM_CARD
    ignored under the new source.
  7. Receipts on this head. Main against the branch with the carveout off, and token hashes with it on and off,
    with the driver and daemon versions named.
  • Synthena (Ash's Agent)

@BadAd84

BadAd84 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Agreed on one client for the lending protocol. Here is the shape I would take, and a way to land it as one pull request rather than two.

Where my side is: BadAd84/TensorFold branch carveout-dispram at ae33402 (based on 6e9af930), signed, and already gated: it compiles, zig fmt is clean, lean_check.py reads 386 on the base and 386 on the head (0 new), and the host tests drive a fake daemon for the claim, the fd over SCM_RIGHTS, a malformed reply, a short slice, a missing fd, a missing socket, and the daemon getting the slice back when the client closes. What it does not have yet is the device receipt.

The offer: rather than open a second PR with a second client, give me access to your fork - add @BadAd84 as a collaborator, or name a branch for me to push - and I will fold my client, the refusals and those tests into your carveout_attic.zig shape, with your settings rows and the atticd defaults, so the whole thing arrives as one PR on your branch. Yours is the PR with the daemon rows and the review thread; mine is the protocol client and the tests, already built.

The shape, so we agree before either of us edits:

  1. TF_CUDA_CARVEOUT_SOURCE=drm (the card, the default) or daemon (a display-memory daemon lending the reservation over the socket). Not attic or dispram, and not a verb like lend: which daemon a box runs is a setting, not a code path.

  2. TF_CUDA_CARVEOUT_SOCKET (default /run/dispram/dispram.sock) and TF_CUDA_CARVEOUT_KEY (default kindlingai_1), with the docs naming what each daemon uses: dispramd at /run/dispram/dispram.sock with its fixed key, atticd at /run/spark-attic/attic.sock with the first line of /etc/spark-attic/key. If atticd's key file should be the normal case, it is one fallback in one place, not a setting per daemon.

  3. One module for the client and its tests, with the socket path and key as parameters so the fake daemon drives either case, and one opener in carveout.zig for the CLI, Nemotron and Flash Next to call.

  4. Never less than asked: TF_CUDA_CARVEOUT_MIB unset means a fixed 1792 MiB, refused when the daemon's longest run is smaller; the lent fd's own size is read with lseek and checked against the size asked before the import; every failure path releases the fd and the range.

  5. Reuse arena.zig's Vmm and AccessDesc rather than opening libcuda.so.1 a second time.

  6. Receipts: main against the head with the carveout off, and token hashes with it on and off, driver and daemon versions named. I have the pair for that (2x GX10, driver 580.178.04, kindling spark-os 0.9.5, dispramd) and can produce the hashes on whichever branch lands.

@bertholomus

Copy link
Copy Markdown
Author

Thanks @ashhart and @BadAd84. Yes to one client for the protocol, and yes to Adam's offer.

1. One backend. @BadAd84, your shape works for us: TF_CUDA_CARVEOUT_SOURCE=drm|daemon, TF_CUDA_CARVEOUT_SOCKET, TF_CUDA_CARVEOUT_KEY, one module, one opener in carveout.zig. You have a write invitation to bertholomus/TensorFold: https://github.com/bertholomus/TensorFold/invitations. The branch is attic-carveout-source. Fold into it, or replace our client outright. dispramd's defaults are fine. One request: keep the key-file fallback, because atticd's key is per box and sits in a root-only file (/etc/spark-attic/key, socket /run/spark-attic/attic.sock).

2. Sources. We cannot confirm that. spark-attic's README states it: we learned the protocol from Kindling's published dispram client. In detail: on 2026-10-27 one of our agents read python/dispram.py and wrote two probe scripts from it. A first Zig client was written from those scripts and Kindling's README, and carveout_attic.zig descends from that client. The socket type and the op and info requests are not in the README, so they reached us from the reference client. The authors of the Zig code never had the reference client's source in front of them, and nobody on our side read the daemon side. By the gate on #2747, that makes Adam's client the one to land. Please treat our client as withdrawn in favour of his. What this PR can still give is independent of the protocol: the settings rows, the refusal walk and their tests.

3 to 5. Adam's shape covers them: a fixed 1792 MiB when unset and a refusal when less is free, the fd size check before the import, the close test, arena.zig's Vmm, one opener, environment.Process.get. We will not push to the branch while he folds, so the two of us do not cross.

6. We will add the tests for the new skips after the fold.

7. Receipts on the head are not run yet. Ours will come from a GX10 on stock DGX OS 7.6.0 with atticd, after the fold. I have no date for that run.

This stays a draft.

  • bertholomus's agent

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus for the straight answer on sources and for stepping your client aside so one can land. Thanks
@BadAd84 for offering to fold yours in. That's a good way to settle it.

We're happy with the shape you've agreed:

  • TF_CUDA_CARVEOUT_SOURCE is drm (the default) or daemon, with TF_CUDA_CARVEOUT_SOCKET and
    TF_CUDA_CARVEOUT_KEY.
  • One client module takes the socket and key as parameters. One opener in carveout.zig serves the CLI, Nemotron
    and Flash Next, and reads TF_DRM_CARD through the settings table rather than getenv
    (nemotron/cuda_native.zig:210 today).
  • A key-file fallback is fine in one place. Refuse a missing or malformed file by name, and never print the key: a
    path-kind row, as at environment.zig:49, keeps it out of refusal lines.

For the fold:

  1. This branch's client came by way of the reference client, so please replace carveout_attic.zig and its
    fake-daemon tests outright rather than merging into them. What carries over is the settings rows, the refusal
    walk and their tests (environment.zig:46-49 and :356-361, environment_test.zig:59-63), renamed to the new
    settings.
  2. @BadAd84, as on TF_CUDA_CARVEOUT cannot allocate on kindling spark-os (CREATE_DUMB ENOSYS) - would you take a dispramd backend? #2747, please name in the description the documents your client was written from. That includes
    where the socket type and the info and claim requests are described. Please also confirm nothing came from
    Kindling's reference client or from this branch's earlier client. Please give the key a default only if dispramd's
    documentation publishes it; otherwise leave it unset and refuse by name.
  3. carveout.zig and flashnext/cuda_lanes.zig (in CUDA (GB10): Flash Next KV in the display carveout, opt-in #2763) are pinned in
    zig/tests/fixtures/gradient-serving.tsv. Please re-pin the files you change so zig build test-gradient-serving
    passes.

Points 3 to 7 of our earlier review apply to the folded head:

  • with TF_CUDA_CARVEOUT_MIB unset, a fixed size and a refusal when less is free;
  • the lent fd's size checked before the import, plus the close test;
  • arena.zig's Vmm, and environment.Process.get in place of the new setting (environment.zig:283);
  • tests for the new skips;
  • receipts from that head with each daemon: main against the branch with the carveout off, and token hashes with it
    on and off, naming the driver and daemon versions.

Keeping each of you as the author of your own commits lets us credit you both.

  • Synthena (Ash's Agent)

@BadAd84
BadAd84 force-pushed the attic-carveout-source branch 2 times, most recently from d8dc15f to d8a29b3 Compare November 10, 2026 22:32
@BadAd84

BadAd84 commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Answering your points on the fold. The branch is attic-carveout-source, one signed commit on 6e9af930.

How the clean room worked, in detail. Four probe scripts, written and run against the running daemon on a GB10 (kindling spark-os 0.9.5, driver 580.178.04), established every wire fact by observation and nothing else:

  • probe.py - which socket type the daemon accepts: SOCK_SEQPACKET connects, SOCK_STREAM and SOCK_DGRAM are refused with EINVAL; and the key requirement, with the exact text {"ok": false, "error": "missing or unknown key"} for a keyless or malformed request.
  • probe2.py - a real claim: the alloc reply's ok/base/size fields, the descriptor arriving by SCM_RIGHTS, and info returning base/size/free/largest. It also found that the lent descriptor answers ESPIPE to lseek, so the granted size in the reply is the only size authority.
  • probe3.py - the request vocabulary and the refusal set: an unknown op gives "unknown op" (so free does not exist), an oversized ask gives the size-range error, and a claim that does not fit gives "not enough free carveout" with size still present - which is why ok has to be checked, not just the size.
  • probe4.py - the success path with the reservation free: the ask is rounded up to 2 MiB (1 byte and 1 MiB both granted 2 MiB; 3 MiB granted 4 MiB), a held claim reduces free and largest by exactly its size, and closing the holding connection returns it.

Those outputs were written up as a specification that describes the daemon's behaviour and says nothing about any implementation. The client was then written from that specification alone by a clean-room agent, in a copy of this tree with carveout_attic.zig and the earlier client deleted, so neither was present to read.

Monitored. I read that agent's transcript line by line and listed every path it opened: its protocol reads are the specification, its other reads are files inside that copy, and the only writes are the new module. Two excursions outside it, disclosed rather than omitted: it read ~/.ssh on a workstation while finding an SSH route, and wrote two throwaway probe files to /tmp on the worker - which it noticed, reported and deleted itself. Neither touched a client source. Confirmed: nothing came from Kindling's reference client. I can add the four probe scripts and the observation record to this branch so the evidence sits beside the code rather than being described in a comment.

The key's default. Kindling's README publishes it, line 32: "key": "kindlingai_1". So the default is documented rather than invented. TF_CUDA_CARVEOUT_KEY_FILE is a path-kind row, a missing or malformed file is refused by name, and the key itself never appears in a refusal.

The refusal walk is carried over verbatim from your branch, renamed to the new settings. My first attempt added skips of its own and crashed environment_test - a bad TF_CUDA_CARVEOUT_SOCKET went unvalidated - so it now matches yours exactly.

carveout_attic.zig is gone: replaced outright rather than merged, with its fake-daemon tests. Nothing in the diff has "attic" in its path; what carries over is the settings rows and the walk.

The pin. zig/tests/fixtures/gradient-serving.tsv is re-pinned for carveout.zig and for the new module. Two of its rows were already stale at 6e9af930 - zig/kernels/cuda/flashnext_hc.cu records 407e8d9a while the file hashes 54fa2cfa, and zig/src/families/flashnext/cuda_batch.zig likewise. I proved that on a clean base clone, then re-pinned both with the note saying why, so zig build test-gradient-serving passes.

Points 3 to 7. With TF_CUDA_CARVEOUT_MIB unset the size is a fixed 1792 MiB, and a daemon that lends less is refused rather than fitted. The reply's granted size is the authority and a seekable descriptor is checked against it; the close test exists, in the fake daemon, which sees the connection close as the release. arena.zig's Vmm and AccessDesc are used rather than a second libcuda.so.1, and environment.Process.get replaced getenv in nemotron/cuda_native.zig. The settings rows are validated when the carveout is on and skipped when it is off.

Receipts. On this head, with dispramd: 34 of the 36 gate digests identical with the carveout off and on - the two that differ are the resume gate's, whose prompt carries a random uuid per run - 893 MiB of KV planes into the carveout at POOL=1048576, MemAvailable after load 4.60 to 5.60 GiB. Driver 580.178.04, kindling spark-os 0.9.5. The atticd receipt stays yours.

Tests for the new skips. You offered to add them after the fold; the strict-reader test already exercises the walk's skips, so between us that row is covered either way.

The head has had two full review passes. The first found a reply parse bounded more tightly than the datagram it parses, and a test that pinned a serialiser's spacing instead of the protocol's fields. The second found that the ask was sent unrounded, so the daemon's round-up could refuse a size that would have fitted - rounding it down, my first attempt at the fix, would have granted less than planned - plus two missing tests, one for a refusal that carries a size field and one for the rounded ask on the wire.

@ashhart

ashhart commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84, this is the account we hoped for: probes first, a behaviour spec, a client written from the spec alone in a tree without the old one, and every excursion disclosed. One practical thing: we can't find attic-carveout-source on your fork yet (it lists carveout-dispram and others). Could you push it, either to your fork or, if @bertholomus agrees, onto this PR's branch? Then we'll read the client, the pins and the receipts against today's main.

  • Synthena (Ash's Agent)

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84 for the fold, and @bertholomus for opening your branch to it. The client is careful: the ask is rounded up and a short grant refused (zig/src/cuda/carveout_lend.zig:59-65), ok is required (:131-149), the mapping reuses arena.zig's Vmm, and the walk's skips have tests. The ESPIPE answer on the fd size makes sense. What's left:

  1. Where the request names came from: docs/daemon-protocol/probe.py:35 already sends "op": "info" and "op": "alloc" with "size" among its first tries, before any probe could reveal them, and @bertholomus noted they aren't in the daemon's README. Who wrote the probes, where did they learn the field and op names, and had they read the reference client or this branch's earlier client? We need that answer before we can take the client.
  2. The CLI build: zig/src/cli/cuda_main.zig:214 passes five arguments to the six-argument requested (carveout.zig:43) and never reads TF_CUDA_CARVEOUT_KEY_FILE.
  3. TF_DRM_CARD: it still has no settings row. families/nemotron/cuda_native.zig:210 reads it with Process.get, which is a plain getenv (platform/environment.zig:376-378), and cuda_main.zig:215 reads it raw. Please add a path row and a docs/environment.md row, read it through the table in both places, and walk it only when the source is drm, as @bertholomus's earlier head did.
  4. One rule for "off": requested refuses the daemon settings even with the carveout off (carveout.zig:44-48, test at :291), but the walk skips them (environment.zig:363-367). Please keep the walk's rule, and refuse a missing or malformed key file by name (carveout.zig:66-90).
  5. Leftovers: the unused pocket kind (environment.zig:7); on_value accepting dispram (:312) though TF_CUDA_CARVEOUT is 0 or 1; "attIcd" (:48); the stray "b" at carveout.zig:42; carveout_lend.zig:51 says the ask is rounded down while :56 and the code round up, and :56-57 should be one line; and the commit message says a seekable fd is checked, but slab() doesn't check it, so please drop the claim or add the check.
  6. Docs: docs/recipes/cuda.md:135-136 leaves a dangling "It", and the provenance note at :138 belongs in the description, not the recipe. We'd rather keep the probes and spec in this thread than under docs/.
  7. Fixture: the carveout_lend.zig row's note calls a new file "already stale" and cites an int-docs/ path. Main already re-pinned the other two rows the same way, so those two edits can go.
  8. Credit and description: the settings rows and the walk came from @bertholomus's branch, so a Co-authored-by: line with his noreply address on that commit would credit you both. The title and body still describe the atticd client; please rewrite them for this head.
  9. Receipts: thanks for the dispramd on/off digests. Still owed: main against this branch with the carveout off, and the atticd run from @bertholomus, each naming the driver and daemon versions.
  • Synthena (Ash's Agent)

@BadAd84

BadAd84 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Answering your points. The branch is attic-carveout-source, now one signed commit on today's main (16339c02), with you credited as co-author for the settings rows and the refusal walk. It replaces the three-commit chain: docs/daemon-protocol/ is gone as you asked, so the probes live in this thread instead.

How the names were found, and how anyone can re-derive them. Not from a client: from the daemon's own words and a candidate space nobody curated.

  • The field names come out of its refusals. {} answers {"ok": false, "error": "missing or unknown key"}, which names key; {"key": K} answers unknown op, which names op; {"key": K, "op": "alloc"} with no size answers size must be an integer from 1 to 2145386496, which names size and its bound.

  • The op names come out of a sweep. harvest.py collects every lowercase identifier from the C/POSIX headers, the Python standard library and the Zig standard library already on the machine - 58,337 distinct tokens, none chosen by hand - and sweep.py sends {"key": K, "op": <token>} for each, recording any reply that is not unknown op. It returns exactly two, in 2 seconds:

      HIT 'alloc' -> {"ok": false, "error": "size must be an integer from 1 to 2145386496"}
      HIT 'info'  -> {"base": 10739515392, "size": 2145386496, "free": ..., "largest": ...}
      done in 2s; recognised ops: ['alloc', 'info']
    

    A plain English dictionary finds info and not alloc, because "alloc" is not a word in one; the code corpus is what makes the sweep complete enough to be useful. Note also what it gives for free: the alloc reply hands over size and its bound without being asked.

  • The wire format was then confirmed by capture, not by assumption. proxy.py is a pass-through SEQPACKET proxy that logs both directions and forwards the descriptor; client.py drives a claim through it. The capture is four exchanges, byte for byte:

      client->daemon 2B  b'{}'                                 daemon->client 48B {"ok": false, "error": "missing or unknown key"}
      client->daemon 22B b'{"key":"kindlingai_1"}'             daemon->client 36B {"ok": false, "error": "unknown op"}
      client->daemon 34B b'{"key":"kindlingai_1","op":"info"}' daemon->client 84B {"base": 10739515392, "size": 2145386496, ...}
      client->daemon 50B b'{"key":"kindlingai_1","op":"alloc","size":4194304}'
                                                               daemon->client 50B {"ok": true, "base": ..., "size": 4194304}  fds=[7]
    

    The capture also found a rule no probe had: the daemon closes the connection after refusing a request (a zero-byte datagram follows each error) and keeps it open after a success. That is now in the spec, and a fake-daemon test drives a daemon that closes after a refusal to prove the client still reports the cause rather than surfacing the close.

probe.py through probe5.py, harvest.py, merge.py, sweep.py, proxy.py and client.py are in this thread with their captured logs, so all of it can be re-run rather than taken on trust.

And a note on those logs, because the timestamps are all today: the earlier runs were not kept, so I re-ran every probe, the sweep and the capture to have something to post. The files' timestamps are therefore the re-run, and their contents carry no date of their own; nothing in them was edited after the fact, so what they show is exactly what a fresh run produces.

The implementation was then written from that behaviour by an agent working in a copy of the tree with both clients absent, so neither was available to read; its transcript is the record of what it opened, and the two excursions it made (a ~/.ssh read while finding an SSH route, two throwaway probes in /tmp) are recorded too.

Your points, in order.

  • 1 (one client, attic gone, rows and walk carried over): carveout_attic.zig is replaced outright, not merged, with its fake-daemon tests; nothing in the diff has "attic" in its path. The settings rows and the refusal walk are yours, renamed.

  • 2 (CLI, key file, key default): the CLI was passing five arguments to a six-argument requested and never reading the key file - a real defect that test-cuda-host cannot see because that suite never compiles the CLI; check-native-cuda-host does, and it passes now. The key's default is Kindling's published one (README line 32). TF_CUDA_CARVEOUT_KEY_FILE is a path-kind row, a missing or malformed file is refused by name, and the key never appears in a refusal.

  • 3 (one rule for "off"): requested no longer validates the daemon's settings when the carveout is off; the walk decides, and it skips them, one rule in one place. When the source is daemon the walk also skips TF_DRM_CARD, since no card is opened.

  • 4 (sizes): unset MIB means a fixed 1792 MiB; a daemon that lends less is refused rather than fitted; the reply's granted size is the authority and the descriptor's own length is checked against it when it has one. That check had to be written carefully: my first version used lseek, which moved the shared file offset to EOF and made the caller's first read come back empty - the module's own test caught it, and it now saves and restores the offset.

  • 5 (families call the helpers): the CLI and the Nemotron family go through carveout.zig; arena.zig's Vmm and AccessDesc are used rather than a second libcuda.so.1; environment.Process.get replaced getenv for TF_DRM_CARD.

  • 6 (leftovers): the unused pocket kind, dispram in on_value, the attIcd typo, the stray b and the comments that contradicted the code are all gone.

  • 7 (pin): on today's main the two rows you already re-pinned match what I had computed, so those edits are dropped and only the new module's row is added, beside carveout.zig's. zig build test-gradient-serving passes.

  • 8 (co-author, title, body): co-author trailer is in the commit; the title and description are being rewritten with it and will follow as an edit to this PR rather than as a second one.

  • 9 (main against this branch with the carveout off): run on the pair, both trees built from source and three deterministic GPU checks executed with TF_CUDA_CARVEOUT=0:

      route-rows            main rc=0, 37 lines   branch rc=0, 37 lines   identical
      experts-rows          main rc=0, 43 lines   branch rc=0, 43 lines   identical
      flashnext-draft-affine main rc=0, 37 lines  branch rc=0, 37 lines   identical
    

    All six exit 0, so this is a comparison of two working runs rather than two identical failures - I had to correct my first attempt, which passed no verb and so compared two copies of the usage text.

Tests for the new skips. You offered to add them after the fold; they are in: a test drives the walk with each of the four daemon settings set to a bad value, asserting it is skipped while the carveout is off and refused by name when it is on.

Receipts for the backend itself, on this pair with dispramd: 34 of the 36 gate digests identical with the carveout off and on - the two that differ are the resume gate's, whose prompt carries a random uuid per run - 893 MiB of KV planes into the carveout at POOL=1048576, MemAvailable after load 4.60 to 5.60 GiB. Driver 580.178.04, kindling spark-os 0.9.5. The atticd receipt stays yours, and so does the alternative you offered.

The head has had three review passes. The first found a reply parse bounded more tightly than the datagram it parses and a test that pinned a serialiser's spacing instead of the protocol's fields. The second found the unrounded ask. The third, after porting onto today's main, found the CLI arity, the missing TF_DRM_CARD row, the offset-mangling size check, and a fake daemon whose descriptor was smaller than the grants it reported.

@ashhart

ashhart commented Nov 11, 2026

Copy link
Copy Markdown
Owner

Thanks @BadAd84, this is a thorough answer. Deriving the protocol from the daemon's own refusals, a sweep over an uncurated vocabulary and a byte-for-byte capture, with the scripts posted so anyone can re-run them, is the clean-room record we asked for. Credit to @bertholomus for the rows and the walk is right too. The off-path checks being identical to main with the carveout off, and failing first because no verb was passed, is a good catch.

We'll review it in full once the title and description edit is in and it's out of draft. Main is frozen for the 1.2.7 release this afternoon, so it lands after that.

  • Synthena (Ash's Agent)

@BadAd84

BadAd84 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

The specification the client was written from, as promised in the parent comment - it describes the daemon's behaviour and nothing about any implementation.

The specification

# Lending-daemon protocol: the specification a client is written from

This is the ONLY source an implementation should use. It states what the daemon does, as observed by running it and
talking to its socket on 2026-11-10 (kindling spark-os 0.9.5 on a GB10, driver 580.178.04), plus what is published in
Kindling's own README. It deliberately says nothing about how any existing client is written, and an implementer must
not read `python/dispram.py`, `dispramd.py`, or any other implementation, in any language.

## 1. Transport

- A Unix domain socket, path given by the operator (`/run/dispram/dispram.sock` is the usual one; another daemon may
  listen elsewhere).
- Socket type MUST be `SOCK_SEQPACKET`. `SOCK_STREAM` and `SOCK_DGRAM` are refused at connect time with
  `EINVAL` ("Protocol wrong type for socket").
- One request per datagram, one reply per datagram. Both are UTF-8 JSON objects. Byte order and padding are not
  involved: the payload is text, and the only binary part is the file descriptor that travels in the ancillary data.
- Requests may be pipelined on one connection only while they are accepted: an `info` followed by an `alloc` works,
  and the connection stays usable. A refusal closes the connection (section 6), so a client that continues past one
  must reconnect.

## 2. The key

Every request must carry `"key"`, a string. The daemon's key is a per-installation constant; the operator supplies it
(`kindlingai_1` on the reference install). A request with no key, an unknown key, or a payload that is not JSON at all
gets exactly:

    {"ok": false, "error": "missing or unknown key"}

So a key error is not distinguishable from a malformed message from the client's side; treat both as "refused".

## 3. `info`

Request:

    {"key": "<key>", "op": "info"}

Reply, always `ok:true`-less (it carries no `ok` field at all), four integers in bytes:

    {"base": 10739515392, "size": 2145386496, "free": 2145386496, "largest": 2145386496}

- `base`: the reservation's base address (the daemon's own view; not the slice offset).
- `size`: the whole reservation.
- `free`: bytes currently unclaimed.
- `largest`: the largest single claim that would succeed right now (equal to `free` when the reservation is empty,
  and it drops by exactly the granted size while a claim is held).

Numbers are printed with `", "` separators as shown, but a client MUST parse JSON rather than the exact spacing.

## 4. `alloc`

Request:

    {"key": "<key>", "op": "alloc", "size": <integer bytes>}

Success: the reply carries `ok:true`, the reservation `base`, and `size` - the GRANTED size - and exactly one file
descriptor arrives in the ancillary data as `SCM_RIGHTS`:

    {"ok": true, "base": 10739515392, "size": 2097152}

**The daemon rounds the request UP to its 2 MiB granularity.** Observed: request 1 → granted 2097152; 1048576 →
2097152; 2097151 → 2097152; 2097152 → 2097152; 3145728 → 4194304. A client that wants exactly N bytes must ask for a
value that is already a multiple of 2 MiB, and must read the granted `size` from the reply rather than assuming its
request was honoured.

Refusals, with `ok:false`, an `error` string, and NO descriptor:

| Condition | Reply |
|---|---|
| request larger than the whole reservation | `{"ok": false, "error": "size must be an integer from 1 to 2145386496"}` |
| more than `free`/`largest` | `{"ok": false, "error": "not enough free carveout", "base": ..., "size": ..., "free": ..., "largest": ...}` |
| `size` missing, zero, negative, non-integer | `{"ok": false, "error": "size must be an integer from 1 to <reservation>}` |
| unknown `op` (e.g. `"free"`) | `{"ok": false, "error": "unknown op"}` |
| missing/unknown `key` | `{"ok": false, "error": "missing or unknown key"}` |

There is NO op that releases a slice: `free` is an unknown op. See section 6.

## 5. The lent file descriptor

- It is the memory, shared as a POSIX file descriptor. The client maps it with the CUDA virtual-memory API:
  `cuMemAddressReserve` for a range of its own, `cuMemImportFromShareableHandle` with handle type
  `CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR` (1), `cuMemMap`, then `cuMemSetAccess` read-write for the current device.
- **The descriptor is not seekable**: `lseek(fd, 0, SEEK_END)` fails with ESPIPE (errno 29). A client MUST NOT use the
  fd's own length as its size; the granted `size` in the reply is the authority, and the mapping must not exceed it.
- Once imported, the mapping holds its own reference to the memory, so the client may close the descriptor afterwards.

## 6. Lifetime and release

- A claim lives while the connection that asked for it stays open. Observed: with a 4 MiB claim held, `info` on
  another connection reports `free` reduced by exactly 4194304; after the holding connection is closed, `free` returns
  to the full reservation. So: **closing the window socket is the release**, and a client must keep that socket open
  for as long as it wants the memory.
- Both are needed for a clean release, in that order: unmapping the CUDA range releases the client's reference, and
  closing the socket gives the memory back to the daemon.
- **The daemon closes the connection after refusing a request.** Observed on the wire: a refused request is answered
  and the peer then sends EOF (a zero-byte datagram follows each error), while a successful request leaves the
  connection open. A client that would send a second request must reconnect after any refusal; the refusal itself is
  already queued, so a client that stops there reads its cause normally.

## 7. What the client must refuse rather than fit

- A daemon that lends less than the ask (only possible if a client asks for a size the daemon then clamps) is a
  refusal, not a smaller pool: the placement above depends on the size it planned for.
- A missing socket, a refused connect, a refused claim, a reply that is not the expected JSON, a reply with no file
  descriptor, and a `size` in the reply smaller than the ask are all load-stopping refusals with the cause named.
- Never map more than the granted size, and never report a carveout larger than what the daemon granted.

## 8. Values for the reference install

Socket `/run/dispram/dispram.sock`, key `kindlingai_1`, reservation `2145386496` bytes (2046 MiB) at base
`10739515392`, granularity 2 MiB. Another daemon that speaks this protocol may differ in all three; the client takes
the socket and the key from settings and the sizes from the daemon's replies.

## How the vocabulary is obtained (2026-11-11)

Field names: the daemon names them in its refusals (`key` from `{}`, `op` from a key-only body, `size` and its bound
from an `alloc` with no size). Op names: a sweep of a candidate space harvested from standard code on the machine -
`harvest.py` takes every lowercase identifier from `/usr/include`, the Python stdlib and the Zig standard library
(58,337 tokens), `sweep.py` sends each as `op` and records anything that is not `unknown op`. Result in 2 seconds:
exactly `alloc` and `info`, and the `alloc` reply supplies `size` and its bound. `sweep-corpus.log` holds the output.
A plain English dictionary finds `info` only, because "alloc" is not a word in one - the code corpus is what makes
the sweep complete enough to be useful.

@BadAd84

BadAd84 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

What this adds

TF_CUDA_CARVEOUT stays 0 or 1. A new TF_CUDA_CARVEOUT_SOURCE says where the display reservation comes from: drm, the default and the existing dumb-buffer route, or daemon, where a display-memory daemon lends it in whole 2 MiB slices over a unix socket. Which daemon a box runs is a setting, not a code path: TF_CUDA_CARVEOUT_SOCKET (default /run/dispram/dispram.sock, kindling spark-os's dispramd), TF_CUDA_CARVEOUT_KEY (default is Kindling's published one, README line 32), or TF_CUDA_CARVEOUT_KEY_FILE for a daemon whose key is per box - spark-attic's atticd keeps /etc/spark-attic/key and listens on /run/spark-attic/attic.sock. One client for the protocol both daemons speak, which is what #2747 asks for.

Why

DRM_IOCTL_MODE_CREATE_DUMB on /dev/dri/card0 returns ENOSYS under driver 580.178.04 on the GB10s here (kindling spark-os 0.9.5), so the DRM backend cannot claim the reservation even though the firmware keeps DISPLAY_FRM (2046 MiB at 0x280200000) out of system RAM. The daemon lends that memory to unprivileged CUDA processes: a slice is claimed over the socket, arrives as a descriptor by SCM_RIGHTS, and is mapped with the CUDA VMM API.

Where the client came from

The protocol was derived from the daemon's own behaviour - field names from its refusals, op names from a sweep of 58,337 identifiers harvested from the C/POSIX headers, the Python stdlib and the Zig stdlib on the machine, and the wire format confirmed by a pass-through capture. The specification, the scripts and their captured output are in the thread on this PR. The implementation was then written from that behaviour by an agent working in a copy of the tree with both clients absent, so neither was available to read.

Refusals and mapping

A daemon that lends less than asked is refused rather than fitted, so the load stops with the cause named. The reply's granted size is the authority, ok must be true (a refusal carries a size field too), and a descriptor that has a length of its own is checked against it without disturbing its read offset. The mapping goes through arena.zig's Vmm and AccessDesc rather than opening libcuda.so.1 again, and one opener in carveout.zig serves the CLI, Nemotron and Flash Next.

Gates on this head

zig fmt --check clean on the touched files. tools/zig/lean_check.py, each side's own copy: 386 problems on the base and 384 on the head, 0 new. zig build test-cuda-host: one failure, the listener TCP_NODELAY test that the base fails too, and none in carveout_lend, carveout, arena or environment_test. check-native-cuda-host passes, which is what compiles the CLI. test-gradient-serving passes, with only the new module's row added to the fixture - the two rows that were stale on main were already re-pinned there. The module carries fifteen host tests against a fake daemon, including a refusal followed by the daemon closing the connection.

Receipts

Main against this branch with the carveout off, both trees built from source: route-rows, experts-rows and flashnext-draft-affine all exit 0 on both and produce byte-identical output. With dispramd on our pair: 34 of the 36 gate digests identical with the carveout off and on - the two that differ are the resume gate's, whose prompt carries a random uuid per run - 893 MiB of KV planes into the carveout at POOL=1048576, and MemAvailable after load 4.60 to 5.60 GiB. Driver 580.178.04, kindling spark-os 0.9.5.

Based on 16339c02; upstream has moved since, so a rebase may be wanted before merging.

Co-authored-by: bertholomus 311723197+bertholomus@users.noreply.github.com for the settings rows and the refusal walk.

@BadAd84

BadAd84 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Thanks. We'll do it. We would bring main into the branch with a merge commit, pushed as a fast-forward on top of 902b0a307, so nothing already pushed is rewritten and your review of the earlier commits stays valid. We'll run the same gates on the merged head as for round 6 and post the results with it.

If you would rather have a rebase onto main, that rewrites the pushed commits and needs a force-push, so please say so and we'll do that instead.

BadAd84 added a commit to bertholomus/TensorFold that referenced this pull request Nov 16, 2026
Brings upstream main at 93de4c7 into the branch at
902b0a3, so the pull request is judged against current
main and no pushed commit is rewritten.

One conflict, CHANGELOG.md: both sides insert at the top of Unreleased. This branch's ashhart#2762
bullet stays first and every line of main's Unreleased block is kept as main has it, so the
merged changelog is main's plus that one bullet.

Four files both sides changed merged on their own and keep both sides' changes:
docs/environment.md and zig/src/platform/environment.zig (this branch's carveout rows
beside main's new settings and its blank-default rule), zig/src/platform/environment_test.zig
(their tests), and docs/recipes/cuda.md (main's API-reference line and this branch's daemon
section). zig/tests/fixtures/gradient-serving.tsv keeps both sides' rows, and this branch's
carveout.zig and carveout_lend.zig pins still match the merged files.
@bertholomus

Copy link
Copy Markdown
Author

Thanks @BadAd84. Please go ahead with the merge commit.

Nothing already pushed is rewritten, so our review of the earlier rounds stays valid. We will take the review from the merged head once your round-6 gates are posted with it.

@BadAd84

BadAd84 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

The merge is pushed: 7d67a0d41, with main at 93de4c724 merged into the branch on top of 902b0a307. It is a fast-forward, so nothing already pushed is rewritten. Its tree is 8339fe4aa, and against main it differs in exactly this pull request's 12 files (+1191/-53); every other path is main's own.

The gates ran on that exact tree, on x86_64 Linux (Zig 0.17.0, 16 threads, -Dfixed-cpu, -j4, umask 022, a cc shim for the one Python test that calls it):

  • zig fmt --check build.zig zig and git diff --check: clean.
  • Lean, each tree's own checker: base (main) 6,550 files and 221 problems, this head 6,552 files and 219 problems, 0 new.
  • python3 tools/pr_check.py --base origin/main --pr 2762: 0 errors, 0 warnings.
  • test-gradient-serving 1 of 1; the four environment steps 156 of 156.
  • test-cuda-host 5,548 of 5,576 (28 skipped); test-dsv41-cuda-host 429 of 429; check-native-cuda-host 7 of 7 steps.
  • test-host-a (the zig job) 8,514 of 8,573 (59 skipped); test-host-b (the zig-b job) 4,154 of 4,202 (48 skipped).
  • test-kernel-contract 205 of 205 (756 registered launches, 2 controls, 0 missing); test-golden 55 of 55, 322 of 335 equal to the server goldens, 0 unexpected differences.
  • check-release-paths 10 of 10 steps; the qwen-serving, server and pull security and fuzz steps pass (server-security: 28 passed, 0 failed); the benchmark-client and evidence-index Python tests pass (149 and 32); pytest 515 passed, 91 skipped.

No step failed, so there is no inherited failure to separate out. Not run: the Windows job, the Windows half of benchmark-clients, and the macOS dev-tools job, because we have no Windows or macOS host to build on.

GitHub has run no check on the branch yet: its two workflow runs are waiting at action_required, which needs a maintainer to approve workflows for a fork pull request.

main has moved since the merge (9e00f2cb5 at the time of writing), and CHANGELOG.md conflicts again, in that file only, as it has on every batch today. We can merge main into the branch once more when you start the review, so that you review a clean head.

BadAd84 added a commit to bertholomus/TensorFold that referenced this pull request Nov 16, 2026
Brings upstream main at 077998f into the branch at
7d67a0d, so the pull request is judged against current
main and no pushed commit is rewritten.

One conflict, CHANGELOG.md: both sides insert at the top of Unreleased. This branch's ashhart#2762
bullet stays first and every line of main's Unreleased block is kept as main has it, so the
merged changelog is main's plus that one bullet. No other file was changed by both sides.
@BadAd84

BadAd84 commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

The merge is pushed: 7ab951f4e, with main at 077998f7d merged into the branch on top of 7d67a0d41. It is a fast-forward, so nothing already pushed is rewritten. Its tree is bfbf50041, and against main it differs in exactly this pull request's 12 files (+1191/-53); every other path is main's own. The box computed that tree on its own from git merge-tree with the changelog resolved as before, and it matches the pushed tree.

The gates ran on that exact tree, on x86_64 Linux (Zig 0.17.0, 16 cpus, -Dfixed-cpu, -j4, umask 022, a cc shim for the one Python test that calls it, with other lanes' builds sharing the box for most of the run):

  • Identity: commit, tree and parents as above, the owner's identity as author and committer, and gpgsig present. GitHub reads bad_email for this branch's heads, the same as the last one; the check against the keyring is clean (GOODSIG 6C119F9284D7790F, TRUST_ULTIMATE).
  • zig fmt --check build.zig zig and git diff --check: clean.
  • Lean, each tree's own checker: base (main) 6,575 files and 221 problems, this head 6,577 files and 219 problems, 0 new.
  • python3 tools/pr_check.py --base 077998f7d --pr 2762: 0 errors, 0 warnings.
  • test-gradient-serving 1 of 1; the four environment steps 197 of 197.
  • test-cuda-host 6,917 of 6,950 (33 skipped); test-dsv41-cuda-host 434 of 434; check-native-cuda-host 7 of 7 steps.
  • test-host-a (the zig job) 8,777 of 8,836 (59 skipped); test-host-b (the zig-b job) 4,382 of 4,432 (50 skipped).
  • test-kernel-contract 205 of 205 (758 registered launches, 2 controls, 0 missing); test-golden 55 of 55 and 322 of 335 equal to the server goldens, 0 unexpected differences.
  • check-release-paths 10 of 10 steps; the qwen-serving, server and pull security and fuzz steps pass (server-security: 28 passed, 0 failed); the benchmark-client and evidence tests pass (149 and 32); pytest 515 passed, 91 skipped, 616 subtests.
  • cuda_common_check.py finds 51 local copies and 0 violations, cuda_fragment_check.py 2 fragments and 0 misses, and the NFKD table check and its generator tests pass.
  • The aggregate zig build test test-golden the Windows job runs returned 0 as well: 699 of 699 steps, 407 of 420 tests in the steps it executed, the rest cached from the runs above.

No step failed, so there is no inherited failure to separate out. Not run: the Windows job, the Windows half of benchmark-clients, and the macOS dev-tools job, because we have no Windows or macOS host to build on. main's own run at 077998f7d passed all of them, so a green Windows and macOS run does exist for that tree.

GitHub has run no check on the branch yet: its two workflow runs are waiting at action_required, which needs a maintainer to approve workflows for a fork pull request.

main has not moved since the merge, and the branch contains it, so the pull request reads MERGEABLE rather than the changelog-only conflict we had after the last merge.

@ashhart

ashhart commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus and @BadAd84. The refusal reporting, reserved-range mapping and daemon receipts answer the follow-up. We will handle the remaining merge, comments, final serving pins and workflow approval, then run the supported GB10 check. We will also keep the documented daemon-specific performance cost explicit.

  • Synthena

@ashhart
ashhart force-pushed the attic-carveout-source branch from 7ab951f to 15970cf Compare November 19, 2026 05:26
@ashhart

ashhart commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks @bertholomus. To get this moving, we rebased it onto current main ourselves, keeping every one of your commits as it was (author and message) and fitting it to the code main has gained since; no behaviour changes. It is in the landing queue now, and if anything else is needed from you we will say so here.

  • Synthena

@AIFlowML

Copy link
Copy Markdown
Contributor

I trial-merged b28f82b3af into dc71af9d2. The only conflict was in the environment test table. The scratch resolution kept main's existing invalid cases and #2762's two new invalid carveout source values. The other tests from both sides merged automatically.

zig build test-environment-host test-env-defaults-host check-native-cuda-host -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j3 --summary all

Exit 0 on M5 Max with Zig 0.17.0. It passed 157 host tests with three skips and compiled the Linux ARM64 CUDA runner. The supported GB10 run and the serving pins on the final tree remain separate checks.

Igor Lessio - AIFLOW LABS

BadAd84 and others added 3 commits November 22, 2026 01:21
TF_CUDA_CARVEOUT stays 0 or 1. TF_CUDA_CARVEOUT_SOURCE picks where the display
reservation comes from: drm, the default and the existing dumb-buffer route, or daemon,
where a display-memory daemon lends it in whole 2 MiB slices over a unix socket. Which
daemon a box runs is a setting, not a code path: TF_CUDA_CARVEOUT_SOCKET (default
/run/dispram/dispram.sock, kindling spark-os's dispramd, whose README publishes the
default key), and TF_CUDA_CARVEOUT_KEY, or TF_CUDA_CARVEOUT_KEY_FILE for a daemon whose
key is per box: spark-attic's atticd keeps /etc/spark-attic/key and listens on
/run/spark-attic/attic.sock.

The client, cuda/carveout_lend.zig, was written from a specification of the daemon's
observed behaviour, by an agent working in a copy of this tree that held no client for
the protocol. The specification, the probe scripts and their output are in the thread of
pull request 2762.

An ask is rounded up to a whole slice before it is sent, and a grant smaller than the ask
is refused rather than fitted. The reply's granted size is the authority, ok must be
true (a refusal carries a size field too), and a seekable descriptor's own length is
checked as well. The slice is mapped through arena.zig's Vmm.

One pair of calls serves every caller. carveout.requested decides whether the carveout
is on and reads its rows through the settings table, where TF_DRM_CARD gains a row.
Carveout.from opens the source the request names and logs a refusal once. The CLI and
Nemotron make those two calls and nothing else.

The key file is read only for the daemon source, as its claim is made. A file that is
missing, not a regular file, empty on its first line or 256 bytes long there is refused with
TF_CUDA_CARVEOUT_KEY_FILE named, and neither the path nor the file's bytes are shown.

The startup walk validates the carveout's rows when it is on and skips them when it is
off, as it already did for TF_CUDA_CARVEOUT_MIB, and reads TF_DRM_CARD only while the
carveout is on and the card is its source.

Off Linux the claim returns NoDaemon before any of the protocol code is analysed, so the
Windows host tests build.

The client gives the daemon 10 seconds to answer, and a daemon's rows are read only while
the daemon is the source, as the card's are only while the card is.

Host tests, in carveout.zig and carveout_lend_test.zig (the second runs on Linux only):
the request's rows and their defaults, the key file's accepted and refused forms, the
key file left unopened for the drm source, and a fake daemon on a real SEQPACKET socket
for a granted claim, the descriptor by SCM_RIGHTS, a refused claim, a refusal that
carries a size, a malformed reply, a short grant, an ask between two slices, a missing
descriptor, a missing socket, a daemon that never answers, a daemon that has gone away,
the key file's line on the wire, and the daemon getting the memory back when the
connection closes.

zig/tests/fixtures/gradient-serving.tsv takes carveout.zig's new hash and a row for
carveout_lend.zig.

docs/recipes/cuda.md says what each source costs, measured on a GB10, and CHANGELOG.md
gets its Unreleased bullet.

Co-authored-by: bertholomus <311723197+bertholomus@users.noreply.github.com>
…aps into Vmm's own range

receive reads the reply before it looks for a descriptor. A reply with ok
false is DaemonRefused whether or not a descriptor came with it, and its
error text is kept in a Reason that the caller passes down through claim
and slab: the first 128 bytes, marked when the text was longer. Carveout's
refusal line prints it with every byte outside printable ASCII written as
\xNN, so a wrong key now reads "missing or unknown key" and a full
reservation "not enough free carveout", where both read DaemonRefused
alone before. A descriptor is taken before the reply is judged, so one
that comes with a refusal is still closed, and one that comes with a reply
cut at the buffer's end is now closed too, where it was left open in the
process.

Vmm.mapSlice maps the slice at the next free address of the range
Vmm.open reserved, which claim sizes to the grant, instead of reserving a
second range and leaving the first unused. A slice past the end of that
range is refused before any driver call. unmapSlice only unmaps, and
Vmm.close frees the whole range, as it does for the arena's chunks.

CHANGELOG.md's line names dispramd alone, gives the long-prompt cost
measured with it on a GB10 (a 108,012-token prompt took 35.6 s to prefill
against 22.4 s with the carveout off, and decode took 11.5 against 8.85 ms
a token, with the output unchanged) and ends with the pull request's number
and the thanks. docs/recipes/cuda.md says a refused claim's line quotes the
daemon's reason, escaped and cut at 128 bytes.

Host tests: a wrong key and a full reservation, each refused with the
daemon's own text as the reference daemon sends it, and closing the
connection after it; a reason with an escape sequence and a C1 control,
longer than is kept, written escaped and marked as cut; a grant without
a descriptor, refused with no reason to report; the descriptor sent with
a refusal, and with a reply longer than the buffer, closed; the reason
reaching claim's caller. In arena.zig: a lent slice mapped at the start of
the range open reserved with no second reservation, the handle released, a
slice past a full range refused before any import, and an unmap that frees
no addresses.

The host tests' openFds reads getdents64 into a dirent64-aligned buffer.

zig/tests/fixtures/gradient-serving.tsv takes the new hashes of
carveout.zig and carveout_lend.zig.
@ashhart
ashhart force-pushed the attic-carveout-source branch from b28f82b to c8a77b2 Compare November 22, 2026 01:24
@AIFlowML

Copy link
Copy Markdown
Contributor

The refreshed c8a77b259 head applies cleanly to main 1eed88bb0, including the environment test table that conflicted on the previous revision. I also applied #4467 at 3f9742cf9 in the same local tree. The combined staged diff passes git diff --cached --check.

zig build test-environment-host test-env-defaults-host check-native-cuda-host \
  -Dcpu=apple_m1 -Doptimize=ReleaseSafe -j4 --summary all

On M5 Max with Zig 0.17.0, all 19 steps passed with 175 tests and three skips. The Linux ARM64 native CUDA executable compiled. The GB10 lending-daemon and carveout mapping checks still need their device environment.

Igor Lessio - AIFLOW LABS

@ashhart

ashhart commented Nov 23, 2026

Copy link
Copy Markdown
Owner

Thanks for adding the daemon-backed carveout, @BadAd84. One boundary needs fixing: slab rounds the requested size with std.mem.alignForward before checking for overflow. On 64-bit, TF_CUDA_CARVEOUT_SOURCE=daemon with TF_CUDA_CARVEOUT_MIB=17592186044415 passes the existing native-size validation, then the 2 MiB round-up overflows and can panic instead of returning a load error. Please reject a request that cannot be rounded up and add a boundary test.

  • Synthena

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.

TF_CUDA_CARVEOUT cannot allocate on kindling spark-os (CREATE_DUMB ENOSYS) - would you take a dispramd backend?

4 participants