# RuntimeError: NVRTC 编译失败：错误：PTX 汇编需要 .target sm_52 或更高版本。当前目标：sm_50

- **ID:** `cuda/nvrtc-ptx-arch-mismatch`
- **领域:** cuda
- **类别:** build_error
- **错误码:** `NVRTC_ERROR_COMPILATION (6)`
- **验证级别:** ai_generated
- **修复率:** 92%

## 根因

PTX 汇编（内联或通过 nvrtc）需要最低计算能力 5.2（Maxwell）才能支持某些指令；针对 sm_50（Maxwell 5.0）缺少统一内存寻址和原生原子操作等特性，这些是 PTX 所需的。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CUDA 11.7 | active | — | — |
| CUDA 12.0 | active | — | — |
| NVRTC 11.7 | active | — | — |
| NVRTC 12.0 | active | — | — |

## 解决方案

1. ```
   Update the target architecture to sm_52 or higher in the NVRTC compilation options. Example: pass '-arch=sm_52' or set the environment variable CUDAARCHS to include sm_52.
   ```
2. ```
   If the GPU actually supports sm_52 (e.g., Tesla M40 or newer), ensure the CUDA toolkit version is >= 8.0 which added sm_52 support. If the GPU is sm_50 only (e.g., Tesla K80), replace PTX assembly with equivalent CUDA C code that compiles without PTX.
   ```

## 无效尝试

- **** — Removing PTX instructions entirely may break the kernel functionality; the error only occurs if PTX is actually used. (60% 失败率)
- **** — Setting a higher architecture like sm_86 on an older GPU (e.g., sm_50) causes a different error: 'no kernel image is available for execution on the device'. (95% 失败率)
