You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CUDA 11.5中使用Thrust时nvcc编译报错问题咨询

问题背景

最初编译包含<algorithm>的代码时出现错误,添加-std=c++14编译选项(如nvcc -std=c++14 test1.cu)后问题解决。但引入<thrust/extrema.h>时,再次出现相同报错。

代码示例

#include <algorithm>
#include <thrust/extrema.h> // 移除该行可正常编译
int main(){
    return 0;
}

报错信息

/usr/include/c++/11/bits/std_function.h:435:145: error: parameter packs not expanded with ‘...’:
435 | function(_Functor&& __f)
| ^
/usr/include/c++/11/bits/std_function.h:435:145: note: ‘_ArgTypes’
/usr/include/c++/11/bits/std_function.h:530:146: error: parameter packs not expanded with ‘...’:
530 | operator=(_Functor&& __f)
| ^
/usr/include/c++/11/bits/std_function.h:530:146: note: ‘_ArgTypes’

环境版本

  • Ubuntu 22.04.1 LTS
  • CUDA编译工具11.5(V11.5.119)
  • gcc 11.3.0
  • g++ 11.3.0

问题原因

这是CUDA 11.5与GCC 11.x之间的兼容性问题:

  1. GCC 11.x的C标准库实现里,std::function的部分模板代码依赖C14及以上的语法特性。CUDA 11.5的Thrust库在引入头文件时,会强制将主机端代码的编译标准回退到C++11,直接覆盖你手动指定的-std=c++14选项。
  2. 单独包含<algorithm>时,-std=c++14能让GCC以C14标准编译,避开C11模式下std::function的模板展开错误;但引入<thrust/extrema.h>后,Thrust的内部配置会修改编译标准,导致主机端代码又切换回C++11模式,触发GCC 11.x在该模式下的语法报错。

内容的提问来源于stack exchange,提问作者Kaz

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 20:00:47