Skip to main content

Module capture

Module capture 

Source
Expand description

Stream-capture modeling — a CPU-side model of CUDA stream capture.

CUDA lets a program record a sequence of asynchronous operations issued into a stream and turn them into a graph via cudaStreamBeginCapture / cudaStreamEndCapture. During capture, every operation enqueued on the stream becomes a graph node, and inter-stream dependencies introduced through events (cudaEventRecord / cudaStreamWaitEvent) become graph edges — this is how a captured graph reconstructs the fork / join parallelism of multi-stream code.

This module provides a pure-CPU model of that mechanism. No GPU is required: it is a state machine that tracks per-stream capture status, records the operations issued into each captured stream, threads dependencies through events, and finally emits a ComputeGraph. The resulting graph can then be analysed, optimised, and (on real hardware) lowered to a driver graph exactly like a hand-built graph.

§State machine

                begin_capture(s)
    None  ───────────────────────────▶  Active
     ▲                                     │
     │  end_capture(s) -> ComputeGraph     │  record_*/wait_event
     └─────────────────────────────────────┘
                                           │
              (illegal op, e.g. join cycle)│
                                           ▼
                                      Invalidated

A captured stream that is forced into the Invalidated state (for example, because a join would have introduced a cycle, or because an operation was issued on a stream that was never begun) can no longer be ended successfully: StreamCapture::end_capture returns an error and the partially-built graph is discarded.

Structs§

CaptureEvent
Opaque identifier for an event used to thread cross-stream dependencies.
StreamCapture
A CPU-side model of one or more concurrently-capturing CUDA streams.

Enums§

CaptureStatus
Capture status of a single stream, mirroring cudaStreamCaptureStatus.