# CUDA 错误：不支持的执行亲和性 (cudaErrorUnsupportedExecAffinity)

- **ID:** `cuda/cuda-error-unsupported-exec-affinity`
- **领域:** cuda
- **类别:** runtime_error
- **错误码:** `cudaErrorUnsupportedExecAffinity (802)`
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

应用程序请求的内核执行亲和性（例如通过 cudaLaunchAttributeCooperative 或 cudaFuncAttributeMaxDynamicSharedMemorySize）不受当前 GPU 架构或驱动程序版本支持。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| CUDA 12.3 | active | — | — |
| CUDA 12.5 | active | — | — |
| NVIDIA Driver 545.23.06 | active | — | — |
| NVIDIA Driver 550.54.10 | active | — | — |
| PyTorch 2.4.0 | active | — | — |

## 解决方案

1. ```
   Check GPU compute capability and remove unsupported launch attributes. For example, cooperative launch requires sm >= 70: `deviceProp.major * 10 + deviceProp.minor >= 70`.
   ```
2. ```
   Upgrade to a driver that supports the required execution affinity (e.g., driver 550.54.10 or newer for CUDA 12.5 features).
   ```
3. ```
   Fall back to a non-cooperative launch by setting `cudaLaunchAttributeCooperative` to 0: `cudaLaunchConfig config; config.attrs[cudaLaunchAttributeCooperative] = 0;`
   ```

## 无效尝试

- **** — The error is about execution affinity attributes, not shared memory limits; increasing shared memory may cause other issues but does not resolve the affinity problem. (85% 失败率)
- **** — Synchronous execution does not affect launch attributes; the affinity check happens before the kernel is queued, regardless of blocking mode. (90% 失败率)
