{
  "id": "cuda/thrust-vector-alloc-failure",
  "signature": "terminate called after throwing an instance of 'thrust::system::system_error' what():  after cudaGetLastError: an illegal memory access was encountered",
  "signature_zh": "terminate 调用后抛出 'thrust::system::system_error' 实例：what():  after cudaGetLastError: 遇到非法内存访问",
  "regex": "thrust::system::system_error.*cudaGetLastError.*illegal memory access",
  "domain": "cuda",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "Thrust algorithms (e.g., thrust::sort, thrust::reduce) internally launch CUDA kernels; an illegal memory access occurs when a device vector is accessed out of bounds or a host pointer is passed to a device-side operation, causing a kernel crash that Thrust reports as a system_error.",
  "root_cause_type": "generic",
  "root_cause_zh": "Thrust 算法（如 thrust::sort、thrust::reduce）内部启动 CUDA 内核；当设备向量越界访问或主机指针被传递给设备端操作时，会发生非法内存访问，导致内核崩溃，Thrust 将其报告为 system_error。",
  "versions": [
    {
      "version": "CUDA 11.8",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "CUDA 12.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Thrust 1.17.2",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "Thrust 2.1.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Resetting the device (cudaDeviceReset) does not fix the root cause; the illegal access will recur on the next Thrust call.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Increasing the device vector size arbitrarily may mask the out-of-bounds access but does not guarantee correctness; the real bug is in the algorithm logic.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Use cuda-memcheck or compute-sanitizer to pinpoint the exact illegal memory access location. Example: run the program with compute-sanitizer --tool memcheck ./my_program, then fix the out-of-bounds index.",
      "success_rate": 0.9,
      "how": "Use cuda-memcheck or compute-sanitizer to pinpoint the exact illegal memory access location. Example: run the program with compute-sanitizer --tool memcheck ./my_program, then fix the out-of-bounds index.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Ensure all device vectors are properly sized and that host pointers are not accidentally passed to Thrust algorithms. Use thrust::device_vector for device data and thrust::host_vector for host data. Example: change thrust::sort(host_ptr, host_ptr+N) to thrust::sort(d_vec.begin(), d_vec.end()).",
      "success_rate": 0.85,
      "how": "Ensure all device vectors are properly sized and that host pointers are not accidentally passed to Thrust algorithms. Use thrust::device_vector for device data and thrust::host_vector for host data. Example: change thrust::sort(host_ptr, host_ptr+N) to thrust::sort(d_vec.begin(), d_vec.end()).",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Use cuda-memcheck or compute-sanitizer to pinpoint the exact illegal memory access location. Example: run the program with compute-sanitizer --tool memcheck ./my_program, then fix the out-of-bounds index.",
    "Ensure all device vectors are properly sized and that host pointers are not accidentally passed to Thrust algorithms. Use thrust::device_vector for device data and thrust::host_vector for host data. Example: change thrust::sort(host_ptr, host_ptr+N) to thrust::sort(d_vec.begin(), d_vec.end())."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://thrust.github.io/doc/group__cuda.html",
  "official_doc_section": null,
  "error_code": "cudaErrorIllegalAddress (77)",
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.8,
  "resolvable": "partial",
  "first_seen": "2023-08-22",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}