NVRTC_ERROR_COMPILATION cuda build_error ai_generated true

运行时错误:NVRTC 编译失败:错误:无法打开源文件 'cuda.h'

RuntimeError: NVRTC compilation failed: error: cannot open source file 'cuda.h'

ID: cuda/nvrtc-cannot-open-source-file-cuda

其他格式: JSON · Markdown 中文 · English
85%修复率
88%置信度
1证据数
2023-08-10首次发现

版本兼容性

版本状态引入弃用备注
CUDA 11.7 active
CUDA 12.0 active
CUDA 12.2 active

根因分析

NVRTC(CUDA 运行时编译)库无法找到 CUDA 头文件,因为 CUDA 包含路径未正确设置或未安装 CUDA 工具包。

English

The NVRTC (CUDA runtime compilation) library cannot find the CUDA header files because the CUDA include path is not set correctly or the CUDA toolkit is not installed.

generic

官方文档

https://docs.nvidia.com/cuda/nvrtc/index.html

解决方案

  1. Install the full CUDA toolkit (e.g., version 12.2) and set the CUDA_PATH environment variable to the installation directory. For Ubuntu: wget https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda_12.2.0_535.54.03_linux.run; sudo sh cuda_12.2.0_535.54.03_linux.run --toolkit --silent --toolkitpath=/usr/local/cuda-12.2; export CUDA_PATH=/usr/local/cuda-12.2; export CPATH=$CUDA_PATH/include:$CPATH; then retry NVRTC compilation.
  2. If using conda, install the cuda-toolkit package: conda install -c nvidia cuda-toolkit=12.2. This places headers in the conda environment's include directory, which NVRTC can find automatically.

无效尝试

常见但无效的做法:

  1. 60% 失败

    Reinstalling PyTorch doesn't fix missing CUDA headers because it ships with its own CUDA runtime but not the full toolkit headers.

  2. 80% 失败

    Setting CUDA_HOME to a non-existent directory is a common mistake that doesn't resolve the include path.