cuda
runtime_error
ai_generated
true
RuntimeError: CUDA error: operation not permitted when stream is capturing
ID: cuda/cuda-graphs-capture-error
78%Fix Rate
82%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 12 | active | — | — | — |
Root Cause
CUDA Graphs capture mode does not allow certain operations (memory allocation, CPU sync, conditional branching).
genericWorkarounds
-
88% success Pre-allocate all tensors before graph capture
static_input = torch.empty(..., device='cuda'); with torch.cuda.graph(g): output = model(static_input)
-
85% success Move CPU operations and conditionals outside the captured region
-
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:
-
Disable CUDA Graphs and accept the performance loss
65% fail
CUDA Graphs provide 10-30% speedup for small kernels; worth fixing the capture issue
-
Wrap every operation in a separate graph
78% fail
Creates excessive overhead from multiple graph launches; defeats the purpose of graphing