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

- **ID:** `cuda/nvrtc-cannot-open-source-file-cuda`
- **Domain:** cuda
- **Category:** build_error
- **Error Code:** `NVRTC_ERROR_COMPILATION`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

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.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CUDA 11.7 | active | — | — |
| CUDA 12.0 | active | — | — |
| CUDA 12.2 | active | — | — |

## Workarounds

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.** (85% success)
   ```
   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.** (80% success)
   ```
   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.
   ```

## Dead Ends

- **** — Reinstalling PyTorch doesn't fix missing CUDA headers because it ships with its own CUDA runtime but not the full toolkit headers. (60% fail)
- **** — Setting CUDA_HOME to a non-existent directory is a common mistake that doesn't resolve the include path. (80% fail)
