42. Device graphs and zero-copy buffers
Note: This feature is planned and not available in
coax0. The syntax shown follows the Coax specification and may change before it's built. This is roadmap R23 (spec stage 11).
An iterative solver launches the same few kernels many times per step. R23 lets a program capture that launch sequence once and replay it, and lets buffers cross library boundaries without copies when ownership allows. Psionic already replays CUDA graphs and leases DLPack views through its own library code. This chapter covers the language forms that make those checked programs instead of library conventions. Chapter 17 and chapter 20 introduce the plan.
What this chapter will cover
- Capturing a bounded launch sequence with fixed, admitted bindings.
- Bounded dynamic scalars, such as an iteration count or a tolerance.
- Device-side loops where a target allows them, and the host-driven fallback.
- Importing another component's buffer as a view, and refusing use after release.
- Transfers as explicit, counted effects.
Outline
- Many small launches. Show the launch pattern of one contact solver iteration and its measured launch overhead.
- Capture. A device program holds the launches, immutable bindings and bounded scalars. Uncompiled sketch:
// Sketch only: no syntax is accepted yet.solve :: #device_graph (iterations: bounded(64), tolerance: f32) { for 0..iterations-1 { contact_pass(); if residual() < tolerance break; }}- Device loops and the fallback. Where the target runs a device-side exit test, the loop stays on the device. Where it can't, the host iterates. Results are identical, and the report says which path ran.
- Imported buffers. A view states layout, placement, lifetime and synchronization. A use after the exporter releases the buffer is refused.
- Transfers are effects. Every host–device copy is an R11 effect that
coax explaincounts. A step that reads state back without saying so fails its transfer budget. - Psionic's first consumers. CUDA graph replay and leased DLPack views move from library effects to the language form.
The consumer and the gate
The consumers are the OpenAgents Metaverse Engine's contact solver (Metaverse Engine chapter 22) and a policy reading observations (Metaverse Engine chapter 34). The gate:
- The solver's iterations replayed as one device program equal the unrolled launches bit for bit.
- A policy reads simulated observations through a shared buffer with zero recorded copies.
- A use after the exporter released the buffer is refused.
Done when
- R23 has shipped with the gate above.
- The chapter's examples run under
check-examples.sh, including the refused use-after-release fixture with its exit status. - Chapters 17 and 20 link here and state what shipped.
Dependencies
- R3 ownership (chapter 6, chapter 15), R9 GPU interfaces (chapter 17), R11 effects and R15 strict profiles (chapter 32).
- Chapter 40 for placement.