cuda runtime_error ai_generated true

RuntimeError: CUDA error: operation not permitted when stream is capturing

ID: cuda/cuda-graphs-capture-error

Also available as: JSON · Markdown
78%Fix Rate
82%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
12 active

Root Cause

CUDA Graphs capture mode does not allow certain operations (memory allocation, CPU sync, conditional branching).

generic

Workarounds

  1. 88% success Pre-allocate all tensors before graph capture
    static_input = torch.empty(..., device='cuda'); with torch.cuda.graph(g): output = model(static_input)
  2. 85% success Move CPU operations and conditionals outside the captured region
  3. 80% success Use torch.compiler.cudagraph_mark_step_begin() for torch.compile integration
    torch._inductor.config.triton.cudagraph_trees = True

Dead Ends

Common approaches that don't work:

  1. Disable CUDA Graphs and accept the performance loss 65% fail

    CUDA Graphs provide 10-30% speedup for small kernels; worth fixing the capture issue

  2. Wrap every operation in a separate graph 78% fail

    Creates excessive overhead from multiple graph launches; defeats the purpose of graphing