# 运行时错误：CUDA错误：在异步操作中遇到了非法内存访问

- **ID:** `cuda/tensor-memory-not-contiguous`
- **领域:** cuda
- **类别:** runtime_error
- **错误码:** `cudaErrorIllegalAddress`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

将一个非连续张量传递给需要连续内存的CUDA内核，导致越界或未对齐访问。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CUDA 11.8 | active | — | — |
| PyTorch 2.1.0 | active | — | — |
| cuDNN 8.9.2 | active | — | — |

## 解决方案

1. ```
   Ensure tensors are contiguous before passing to CUDA kernels: `tensor = tensor.contiguous()`. For PyTorch, add `.contiguous()` after operations like `.transpose()` or `.view()`.
   ```

## 无效尝试

- **** — The error is about memory access pattern, not capacity. (85% 失败率)
- **** — The error is unrelated to device assignment. (90% 失败率)
