cudaErrorIllegalAddress cuda runtime_error ai_generated true

RuntimeError: CUDA error: an illegal memory access was encountered in an asynchronous operation

ID: cuda/tensor-memory-not-contiguous

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-09-15First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
CUDA 11.8 active
PyTorch 2.1.0 active
cuDNN 8.9.2 active

Root Cause

A non-contiguous tensor was passed to a CUDA kernel that requires contiguous memory, causing out-of-bounds or misaligned access.

generic

中文

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

Official Documentation

https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__TYPES.html

Workarounds

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

中文步骤

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

Dead Ends

Common approaches that don't work:

  1. 85% fail

    The error is about memory access pattern, not capacity.

  2. 90% fail

    The error is unrelated to device assignment.