[Bug已解决] arch_id.h: error: template constraint not satisfied 编译报错:CUDA 架构不匹配解决方案
一、报错长什么样
当你在编译一个 PyTorch 的自定义 CUDA 扩展(.cu 文件),或者在 pip install 某些带 CUDA 算子的仓库(比如 detectron2、xformers、flash-attn 的源码编译版本)时,可能会看到类似这样的报错:
/path/to/torch/include/c10/cuda/CUDAGuard.h: ...
/usr/local/cuda/include/arch_id.h: error: template constraint not satisfied
或者更常见地,编译器(nvcc)直接报:
arch_id.h(...) : error: template constraint not satisfied
这个错误不是你的 Python 代码写错了,而是 nvcc 在编译 CUDA 代码时,遇到了「目标 GPU 架构(__CUDA_ARCH__)与某个模板约束不匹配」的情况。换句话说:你让编译器为一个它不认识的、或不支持的 GPU 计算能力(Compute Capability)去生成代码,于是 PyTorch 内部的 arch_id.h 里那段根据架构选择实现
转载自 CSDN-专业IT技术社区
原文链接:https://blog.csdn.net/weixin_52908342/article/details/162906030


![[Bug已解决] arch_id.h: error: template constraint not satisfied 编译报错:CUDA 架构不匹配解决方案封面图](https://i-blog.csdnimg.cn/img_convert/0cc5974d937dd2605871c07d07d22640.png?x-oss-process=image/resize,m_fixed,h_300)

