# CUDA error: stream-order violation during graph launch (cudaErrorStreamOrderViolation)

- **ID:** `cuda/stream-order-violation-cuda-graph`
- **Domain:** cuda
- **Category:** runtime_error
- **Error Code:** `cudaErrorStreamOrderViolation`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

A CUDA graph is launched on a stream that has pending operations from a different stream or graph, violating the implicit ordering constraints when using CUDA graph capturing.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CUDA 11.7 | active | — | — |
| CUDA 12.2 | active | — | — |
| PyTorch 2.1 | active | — | — |
| PyTorch 2.3 | active | — | — |

## Workarounds

1. **Ensure all operations on the target stream are synchronized before launching a graph. Use `torch.cuda.synchronize()` or stream synchronization primitives before `cudaGraphLaunch`.** (85% success)
   ```
   Ensure all operations on the target stream are synchronized before launching a graph. Use `torch.cuda.synchronize()` or stream synchronization primitives before `cudaGraphLaunch`.
   ```
2. **Re-capture the graph on a dedicated stream that is not used for other operations, ensuring no cross-stream dependencies.** (90% success)
   ```
   Re-capture the graph on a dedicated stream that is not used for other operations, ensuring no cross-stream dependencies.
   ```

## Dead Ends

- **** — The error is about stream synchronization, not parallelism; adding workers can introduce more streams and worsen the violation. (90% fail)
- **** — This removes the performance benefit but does not fix the underlying stream management; the error may reappear if graphs are re-enabled. (60% fail)
