{
  "id": "cuda/stream-capture-invalid-scope",
  "signature": "RuntimeError: CUDA error: operation not permitted when stream is capturing (streamCaptureInvalidated)",
  "signature_zh": "运行时错误：CUDA错误：流正在捕获时不允许操作（streamCaptureInvalidated）",
  "regex": "operation not permitted when stream is capturing",
  "domain": "cuda",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "A CUDA graph capture is in progress on a stream, but an operation (e.g., memory allocation, host-side sync) that is invalid during capture was attempted, invalidating the capture.",
  "root_cause_type": "generic",
  "root_cause_zh": "流上正在进行CUDA图捕获，但尝试了捕获期间无效的操作（例如内存分配、主机端同步），导致捕获失效。",
  "versions": [
    {
      "version": "CUDA 12.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "PyTorch 2.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "NVIDIA Driver 535.129.03",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "This disables cuDNN heuristics but does not fix the capture violation; the error will reoccur if capture is attempted again.",
      "fail_rate": 0.92,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Thread configuration is unrelated to capture validity; the error is about operations allowed during capture.",
      "fail_rate": 0.98,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Move all memory allocations and host-device synchronization outside the capture scope. Example: pre-allocate tensors before calling torch.cuda.CUDAGraph.begin_capture(), and use torch.cuda.synchronize() only after capture ends.",
      "success_rate": 0.88,
      "how": "Move all memory allocations and host-device synchronization outside the capture scope. Example: pre-allocate tensors before calling torch.cuda.CUDAGraph.begin_capture(), and use torch.cuda.synchronize() only after capture ends.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use cudaStreamBeginCapture with cudaStreamCaptureModeGlobal to allow more operations, but ensure no host-side blocking calls occur during capture. In PyTorch, wrap the capture in a context manager that defers any print or sleep calls.",
      "success_rate": 0.8,
      "how": "Use cudaStreamBeginCapture with cudaStreamCaptureModeGlobal to allow more operations, but ensure no host-side blocking calls occur during capture. In PyTorch, wrap the capture in a context manager that defers any print or sleep calls.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Move all memory allocations and host-device synchronization outside the capture scope. Example: pre-allocate tensors before calling torch.cuda.CUDAGraph.begin_capture(), and use torch.cuda.synchronize() only after capture ends.",
    "Use cudaStreamBeginCapture with cudaStreamCaptureModeGlobal to allow more operations, but ensure no host-side blocking calls occur during capture. In PyTorch, wrap the capture in a context manager that defers any print or sleep calls."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__STREAM.html",
  "official_doc_section": null,
  "error_code": "cudaErrorStreamCaptureInvalidated",
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.81,
  "resolvable": "true",
  "first_seen": "2024-09-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}