Skip to content

Report the CUDA backend's pinned host memory in /metrics - #541

Merged
ashhart merged 1 commit into
ashhart:mainfrom
GustavBlack:report-pinned-memory
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
GustavBlack:report-pinned-memory

Conversation

@GustavBlack

Copy link
Copy Markdown
Contributor

One-commit change for #538.

The CUDA runtime already tracks pinned host bytes (memory.zig's host_bytes, held and freed by
HostBuffer) and exposes them in Usage — but readMemory dropped them (cache hardcoded 0, the
host count never left the engine). The Python engine's memory_snapshot reports device active /
cache / peak (MLX freed-buffer cache semantics for cache), so pinned host memory gets its own
field rather than reusing cache:

  • engine_api.zig: Memory gains pinned: u64 = 0.
  • native/cuda.zig: readMemory fills .pinned = u.host.
  • server/metrics.zig: tensorfold:pinned_memory_bytes beside the device pair, same "only where
    the backend counts it (CUDA)" wording; the render test asserts the gauge is absent when memory is
    unknown and reports its value when given.

Validated on a GB10 (aarch64, from-source build at f8fe17d in the pinned container): metrics
tests pass (5/5), and the served /metrics emits all three gauges live — 19.3 GiB device,
19.5 GiB peak, 111,936 B pinned on a freshly served Nemotron checkpoint. (Developed with AI
assistance on our 2×GB10 bring-up testbed; authorship is mine.)

The CUDA runtime tracks pinned host bytes (memory.zig's host_bytes, held and
freed by HostBuffer) and exposes them in Usage, but readMemory dropped them:
cache was hardcoded 0 and the host count never left the engine. api.Memory
gains pinned, readMemory fills it, and /metrics emits tensorfold:pinned_memory_bytes
beside the device pair (cache keeps its MLX meaning: freed device buffers,
per the Python engine's memory_snapshot). The render test asserts the gauge
absent when memory is unknown and its value when reported.

The last of the device/pinned-memory items CHANGELOG.md (1.0.0 section) lists
as planned.

Fixes ashhart#538
@plotarmordev

Copy link
Copy Markdown
Contributor

Receipt from a DGX Spark (GB10, Nemotron 3.5 Lightning 4-bit @ d9d758fb, release 1.0.2 sm121 kernels): with this PR (6ba30338) /metrics shows tensorfold:pinned_memory_bytes 111936 next to device 19,316,671,216 B / peak 19,505,140,464 B, the same as your numbers. main and another main-based build show only the two device gauges. The reply hashes are the same as main's.

@ashhart
ashhart merged commit 2d02054 into ashhart:main Oct 10, 2026
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you @GustavBlack. Merged into main (2d02054): /metrics reports tensorfold:pinned_memory_bytes on CUDA (79,168 bytes on a GB10 serving Nemotron here). That closes #538 and the last memory item #537 asked about. It ships in the next release.

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.

3 participants