【问题标题】:using other c++ compiler to compile the CUDA code使用其他 c++ 编译器编译 CUDA 代码
【发布时间】:2013-09-04 04:10:57
【问题描述】:

我有一个由 nvcc 编译的 CUDA (*.cu) 代码,它在 GPU 中运行良好。但是 nvcc 不支持某些 c++11 功能,并且某些 3rd 方 c++ 库不能与 nvcc 一起使用。我想知道是否可以使用 gcc 或其他商业 c++ 编译器编译 .cu 代码?谢谢。

【问题讨论】:

  • 如果这些 C++11 功能仅出现在 .cu 文件的主机部分中,我建议将该代码分离到一个单独的文件中,该文件直接使用主机编译器构建。您可能还想通过注册开发者网站为您使用的 C++11 功能提交功能请求(C+11 添加了许多不同的功能,我假设您的代码只需要其中的几个)
  • 我认为您的第一条评论就是我想要的。但是有几行代码使用 C++11,这对算法的其余部分至关重要。看来我无法将它与主代码分开:(
  • 检查this中的单独编译。

标签: c++ cuda nvcc


【解决方案1】:

nvcc 支持显式指定它使用的主机编译器,以及特定于主机编译器的选项。您可以在 nvcc 选项 -ccbin-Xcompiler 上找到文档以了解详细信息。

http://docs.nvidia.com/cuda/cuda-compiler-driver-nvcc/index.html#nvcc-command-options

例如,我将 nvcc 与 Intel 编译器和 Intel MKL 绑定如下。

$ nvcc -ftz true -ccbin icpc -Xcompiler "-Wall -Wno-long-long -ansi -pedantic -ansi-alias -parallel -fopenmp -openmp-link=static -static-intel -wd10237" -O2 -Xcompiler "-O2"   -gencode arch=compute_20,code=sm_20 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -Ilib -c -o test/triangle.o test/triangle.cu
$ nvcc -ftz true -ccbin icpc -Xcompiler "-Wall -Wno-long-long -ansi -pedantic -ansi-alias -parallel -fopenmp -openmp-link=static -static-intel -wd10237" -O2 -Xcompiler "-O2"  -Ilib -Llib test/triangle.o lib/KTiming.o -lpthread -lm /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_intel_lp64.a /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_intel_thread.a /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_core.a /opt/intel/composer_xe_2013.1.117/mkl/lib/intel64/libmkl_core.a -lcublas -lcurand -lcusparse -o test/triangle

【讨论】:

  • 值得注意的是,英特尔编译器仅在 64 位 Linux 上的 CUDA 5.0 或更高版本中受支持。
  • 谢谢。我在 linux 64 位操作系统中安装了 cuda5.5,我尝试了第一个编译命令,但它报告“nvcc 致命:未指定输入文件;使用选项 --help 获取更多信息 /opt/cuda5/include/host_config.h(72 ): 灾难性错误: #error 指令: -- 不支持的 ICC 配置!仅支持 Linux x86_64 上的 ICC 12.1!#error -- 不支持的 ICC 配置!仅支持 Linux x86_64 上的 ICC 12.1!"
  • 官方cuda5.5只支持Icc 12.1。您可以在 /opt/cuda5/include/host_config.h(72) 中注释掉 #error。到目前为止,我还没有任何编译失败。
  • 哦...我在集群中运行编译,一切都由 IT 安装。我无权修改代码 :( 不过还是谢谢
  • 其实我也是。我将 ..../cuda-5.5 复制到我家并定义了$CUDA_HOME 并在我的.bashrc 中添加了$PATH,LD_LIBRARY_PATH。然后我就可以完全控制 cuda-5.5
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-20
  • 2014-03-23
  • 2012-06-04
  • 2014-05-19
  • 1970-01-01
相关资源
最近更新 更多