# CUDA 错误：图启动期间流顺序违规 (cudaErrorStreamOrderViolation)

- **ID:** `cuda/stream-order-violation-cuda-graph`
- **领域:** cuda
- **类别:** runtime_error
- **错误码:** `cudaErrorStreamOrderViolation`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

CUDA 图在具有来自不同流或图的未决操作的流上启动，违反了使用 CUDA 图捕获时的隐式排序约束。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CUDA 11.7 | active | — | — |
| CUDA 12.2 | active | — | — |
| PyTorch 2.1 | active | — | — |
| PyTorch 2.3 | active | — | — |

## 解决方案

1. ```
   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.
   ```

## 无效尝试

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