Expand description
Await GPU work as a memory descriptor.
A GPU stream stores a sequence number into a word of host-visible memory behind its work; that word is to device completion what a file descriptor is to I/O readiness. This crate makes it a first-class awaitable source and supplies the pieces around it:
CompletionLine/MemoryDescriptor: one 64-byte line of eight completion words, and one word reaching one sequence number.WaitPlan/WaitBands: how a host waits (block, poll, or park on the word with a status backstop), optionally after sleeping to a predicted completion; typed, parsed once.PointTable: the deadline estimator (min of recent exact residuals per readback point, late wakes censored downward).CompletionPort+wait: the per-backend port and the async driver that runs a plan.Executor+Reactor: a small single-threaded executor whose idle sleeps to the earliest predicted deadline, then parks on the completion line; ready tasks run between waits.ExecutorKind+resolve: the selectable executor (naive,gpu-reactor,io-uring) with a declared fallback chain, a coded warning, and an opt-in strict refusal.Error/ErrorCode: coded errors, one append-only registry.
The core is no_std + alloc and forbids unsafe. Vendor code sits behind features in
backend (cuda, hip, metal, wordwait) and hosts in host (std, tokio,
io-uring). See the README for measured numbers and the safety model.
Modules§
- backend
- Vendor backends, each behind its cargo feature. This is the only place
unsafeis allowed: every block carries aSAFETY:comment, and every public item is safe to call. - host
- Hosts: the clocks, timers and idles a binary picks. The core never names one.
Macros§
Structs§
- Alarmed
- The reactor’s sleep future (its
Timer). - Band
- One band:
planruns fromfrom_rowsrows up to the next band’s edge. - Bands
- The bands, in edge order (module invariants).
- Completion
Line - A 64-byte aligned line of completion words.
- Deadline
Plan - The deadline fields.
- DurNs
- A duration in nanoseconds.
- Error
- A coded error: an
ErrorCodeand its arguments. - Executor
- A single-threaded FILL executor over tasks of type
F. - Executor
Caps - What a host offers the executors, probed once.
- Fallback
- One link of the declared fallback chain.
- Host
Caps - What a host offers, probed once at boot by the host (never by the core).
- Manual
Clock - A clock that moves only when told to; clones share it.
- Manual
Timer - The
Timerof oneManualClock; it fires only when that clock moves. - Memory
Descriptor - One awaitable completion: word
slotoflinereachingtarget. Sequence numbers increase by one per store, so “reached” isword >= targetin wrapping order (a later store that lands before the waiter looks still completes it). - MonoNs
- Monotonic nanoseconds from a host-chosen origin.
- Point
Estimate - One readback point’s residual estimate (a ring of the last samples).
- Point
Table - The estimates of every readback point a host has waited at, keyed by
K(the host’s point identity, e.g. a call site). Runtime measurement, not a decision input. - Reactor
- The reactor of one executor: registrations made by the futures it hands out.
- Ready
- The future of
Reactor::ready. - Resolution
- A resolved setting: what was asked, what runs, and the warning when they differ.
- Resolved
- The plan a host runs, and the coded warning when a fallback was taken.
- RunStats
- What a
Executor::rundid: the work it ran and the idle it measured. - Slot
- The slot of a word in a
CompletionLine(0..LINE_WORDS, checked once at construction). - Step
Rows - The rows of the current decode step: written once per step by the router that launches it, read by every wait of the host that owns the bands. 0 until the first step.
- Wait
Plan - How a host waits at a readback point.
- Wait
Report - What one wait did, for the estimator (
outcome) and the host’s counters.
Enums§
- Capability
- A host capability a park needs.
- Error
Code - The identity of an
Error: append-only, a number is never reused. - Executor
Kind - How a waiting thread runs a wait.
- Outcome
- What one wait observed at its readback point.
- Park
- How the rest of a wait is spent.
- Park
Kind - A park’s kind, without its fields.
- Strictness
- Whether a setting may fall back when its value is unavailable.
- Turn
- What one
Reactor::turndid. - Wait
Kind - How one wait ended.
Constants§
- BANDS_
MAX - The most bands a plan may state.
- FALLBACKS
- the whole chain, as data. The executor never chooses;
WaitPlan::resolvewalks this table once at boot. The chain ends atQueryPoll, which needs nothing and runs on every host;Block, the vendor’s blocking wait, is the conservative arm a plan may name (declared, not a default). - LINE_
WORDS - Completion words per line.
- WINDOW_
MAX - The largest
windowa deadline plan may state.
Traits§
- Clock
- The host’s monotonic clock: the core’s only time source.
- Completion
Port - One wait on device work, implemented per backend (the core names no vendor).
queryanswers at once; the others take time and are awaited: a host that runs them on the waiting thread returns a ready future, an executor’s pend. Errors are the port’s own type and pass throughwaitunchanged. - Declared
- A setting value with a declared fallback chain.
- Idle
- How an executor’s thread idles when no task is ready: the host’s blocking primitives. Only the executor calls these, and only between task polls.
- Timer
- The host’s sleep. A host that runs a wait inline returns a future that is ready on its first poll (it slept already); an executor’s timer pends until its deadline.
Functions§
- block_
on - Run one future to completion on an executor of its own; see
Executor::run. - reached
- Whether word
slotoflinehas reachedtargetin wrapping sequence order. - resolve
- Resolve
requestedagainstcaps: walk the declared chain while the value cannot run. - run_
inline - Poll
futonce with a no-op waker: for hosts whose every future is ready on the first poll (a thread that sleeps and parks inline). A pending poll is a bug in such a host, reported asPendedInlinenamingsite, never a hang. - wait
- Run
planoverport.sleep_nsis the point’s estimate (PointTable::sleep_ns) and is used only whenplan.predictis set. - yield_
now - Yield to the executor once: the task is woken at once and runs again after every other ready task had its turn (cooperative slicing of CPU work between waits).