彻底解决低版本boost在新版CUDA下编译出错的问题

解决marian在Ubuntu上的编译问题:

在安装了boost 1.58 - 1.65左右的版本时,编译会报错:

In file included from /usr/local/cuda-10.2/include/cuda_runtime.h:115:0,
                 from <command-line>:0:
/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^

这个问题坑在没有给出引用/usr/local/cuda-10.2/include/cuda_runtime.h的文件,止步于:

from <command-line>:0:

第一步:

使用make VERBOSE=1 重新编译,得到下面信息:

/usr/local/cuda-10.2/bin/nvcc -M -D__CUDACC__ marian/src/tensors/gpu/tensor_operators.cu -o marian/build/src/CMakeFiles/marian_cuda.dir/tensors/gpu/marian_cuda_generated_tensor_operators.cu.o.NVCC-depend -m64 -DBLAS_FOUND=1 -DMKL_FOUND=1 -DCUDA_FOUND -DUSE_NCCL --default-stream per-thread -O3 -g --use_fast_math -gencode=arch=compute_60,code=sm_60 -gencode=arch=compute_61,code=sm_61 -gencode=arch=compute_70,code=sm_70 -gencode=arch=compute_70,code=compute_70 -ccbin /usr/bin/cc -std=c++11 -Xcompiler -fPIC -Xcompiler -Wno-unused-result -Xcompiler -Wno-deprecated -Xcompiler -Wno-pragmas -Xcompiler -Wno-unused-value -Xcompiler -Werror -Xcompiler -msse2 -Xcompiler -msse3 -Xcompiler -msse4.1 -Xcompiler -msse4.2 -Xcompiler -mavx -Xcompiler -mavx2 -DNVCC -I/usr/local/cuda-10.2/include -I/opt/intel/compilers_and_libraries_2019.1.144/linux/mkl/include -Imarian/src -Imarian/src/. -Imarian/src/3rd_party -Imarian/src/3rd_party/SQLiteCpp/include -Imarian/src/3rd_party/sentencepiece -Imarian/src/3rd_party/fbgemm/include -Imarian/build/local/include
In file included from /usr/local/cuda-10.2/include/cuda_runtime.h:115:0,
                 from <command-line>:0:
/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^
/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^
CMake Error at marian_cuda_generated_tensor_operators.cu.o.Release.cmake:215 (message):
  Error generating
  marian/build/src/CMakeFiles/marian_cuda.dir/tensors/gpu/./marian_cuda_generated_tensor_operators.cu.o

第二步:

在nvcc后加上 -v 选项,重新执行上面的nvcc编译指令,得到下面输出:

"/usr/bin"/cc -std=c++11 -D__CUDA_ARCH__=600 -E -x c++  -DCUDA_DOUBLE_MATH_FUNCTIONS -D__CUDACC__ -D__NVCC__  -fPIC -Wno-unused-result -Wno-deprecated -Wno-pragmas -Wno-unused-value -Werror -msse2 -msse3 -msse4.1 -msse4.2 -mavx -mavx2 -O3 -I"/usr/local/cuda-10.2/include" -I"/opt/intel/compilers_and_libraries_2019.1.144/linux/mkl/include" -I"marian/src" -I"marian/src/." -I"marian/src/3rd_party" -I"marian/src/3rd_party/SQLiteCpp/include" -I"marian/src/3rd_party/sentencepiece" -I"marian/src/3rd_party/fbgemm/include" -I"marian/build/local/include" "-I/usr/local/cuda-10.2/bin/../targets/x86_64-linux/include"    -D "__CUDACC__" -D "BLAS_FOUND=1" -D "MKL_FOUND=1" -D "CUDA_FOUND" -D "USE_NCCL" -D "NVCC" -D__CUDACC_VER_MAJOR__=10 -D__CUDACC_VER_MINOR__=2 -D__CUDACC_VER_BUILD__=89 -DCUDA_API_PER_THREAD_DEFAULT_STREAM=1 -include "cuda_runtime.h" -m64 -g -gdwarf-2 "marian/src/tensors/gpu/tensor_operators.cu" -o "/tmp/tmpxft_00004b67_00000000-7_tensor_operators.compute_60.cpp1.ii" 

第三步:

继续在cc后加上 -v选项,重新执行上面的cc编译指令,得到下面输出:

/usr/libexec/gcc/x86_64-unknown-linux-gnu/5.4.0/cc1plus -E -quiet -v -I /usr/local/cuda-10.2/include -I /opt/intel/compilers_and_libraries_2019.1.144/linux/mkl/include -I marian/src -I marian/src/. -I marian/src/3rd_party -I marian/src/3rd_party/SQLiteCpp/include -I marian/src/3rd_party/sentencepiece -I marian/src/3rd_party/fbgemm/include -I marian/build/local/include -I /usr/local/cuda-10.2/bin/../targets/x86_64-linux/include -imultiarch x86_64-linux-gnu -D_GNU_SOURCE -D __CUDA_ARCH__=600 -D CUDA_DOUBLE_MATH_FUNCTIONS -D __CUDACC__ -D __NVCC__ -D __CUDACC__ -D BLAS_FOUND=1 -D MKL_FOUND=1 -D CUDA_FOUND -D USE_NCCL -D NVCC -D __CUDACC_VER_MAJOR__=10 -D __CUDACC_VER_MINOR__=2 -D __CUDACC_VER_BUILD__=89 -D CUDA_API_PER_THREAD_DEFAULT_STREAM=1 -include cuda_runtime.h marian/src/tensors/gpu/tensor_operators.cu -o /tmp/tmpxft_00004b67_00000000-7_tensor_operators.compute_60.cpp1.ii -msse2 -msse3 -msse4.1 -msse4.2 -mavx -mavx2 -m64 -mtune=generic -march=x86-64 -std=c++11 -Wno-unused-result -Wno-deprecated -Wno-pragmas -Wno-unused-value -Werror -fPIC -g -gdwarf-2 -fworking-directory -O3

…

In file included from /usr/local/cuda-10.2/include/cuda_runtime.h:115:0,
                 from <command-line>:0:
/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^
/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^

第四步:

由于cc1plus已经加上了-v参数,最后的输出也并未比最开始多出有用信息,故只能使用strace来打印出所有系统调用。在上面命令前加上strace,并重新执行,得到下面信息:

…
open("/usr/lib/gcc/x86_64-unknown-linux-gnu/5.4.0/../../../../include/c++/5.4.0/backward/boost/config/compiler/nvcc.hpp", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory)
lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/lib", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
lstat("/usr/lib/gcc", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/lib/gcc/x86_64-unknown-linux-gnu", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/lib/gcc/x86_64-unknown-linux-gnu/5.4.0", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/lib/gcc/x86_64-unknown-linux-gnu/5.4.0/include", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
lstat("/usr/lib/gcc/x86_64-unknown-linux-gnu/5.4.0/include/boost", 0x7fffc8a511d0) = -1 ENOENT (No such file or directory)
open("/usr/lib/gcc/x86_64-unknown-linux-gnu/5.4.0/include/boost/config/compiler/nvcc.hpp", O_RDONLY|O_NOCTTY) = -1 ENOENT (No such file or directory)
lstat("/usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local/include", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local/include/boost", {st_mode=S_IFDIR|0755, st_size=12288, ...}) = 0
lstat("/usr/local/include/boost/config", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local/include/boost/config/compiler", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
lstat("/usr/local/include/boost/config/compiler/nvcc.hpp", {st_mode=S_IFREG|0644, st_size=1246, ...}) = 0
open("/usr/local/include/boost/config/compiler/nvcc.hpp", O_RDONLY|O_NOCTTY) = 5
fstat(5, {st_mode=S_IFREG|0644, st_size=1246, ...}) = 0
read(5, "//  (C) Copyright Eric Jourdanne"..., 1246) = 1246
close(5)                                = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en_US/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale-langpack/en/LC_MESSAGES/cpplib.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/cuda-10.2/include/crt/common_functions.h", O_RDONLY) = 5
fstat(5, {st_mode=S_IFREG|0644, st_size=11839, ...}) = 0
read(5, "/*\n * Copyright 1993-2018 NVIDIA"..., 4096) = 4096
read(5, "tin__ void*   __cdecl memset(voi"..., 4096) = 4096
read(5, "  __THROW; \n#elif defined(_WIN32"..., 8192) = 3647
read(5, "", 4096)                       = 0
write(2, "In file included from \33[01m\33[K/u"..., 602In file included from /usr/local/cuda-10.2/include/cuda_runtime.h:115:0,
                 from <command-line>:0:
/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^
) = 602
write(2, "\33[01m\33[K/usr/local/cuda-10.2/inc"..., 461/usr/local/cuda-10.2/include/crt/common_functions.h:74:24: error: token ""__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."" is not valid in preprocessor expressions
 #define __CUDACC_VER__ "__CUDACC_VER__ is no longer supported.  Use __CUDACC_VER_MAJOR__, __CUDACC_VER_MINOR__, and __CUDACC_VER_BUILD__ instead."
                        ^
) = 461

可以看到在出错前,open的最后一个文件是/usr/local/include/boost/config/compiler/nvcc.hpp,因此可以推断问题和boost。
继续向上回溯,可以找到出错前最后打开的最后一个工程内的文件是marian/src/3rd_party/CLI/Optional.hpp
这个文件中使用了__has_include这个C++11新提供的宏,根据文件是否存在来决定是否include,来实现选择性include。
可能是这个新特性导致编译器无法输出引用/usr/local/cuda-10.2/include/cuda_runtime.h的文件。

解决方案:

由于定位到boost,很容易就能发现是/usr/local/include/boost/config/compiler/nvcc.hpp中使用了__CUDACC_VER__。
这个问题有两中方式解决:
一是升级boost库版本,升级到1.65以上。
二是在CMakeList.txt中CUDA_NVCC_FLAGS中加上-DCLI11_BOOST_OPTIONAL=0,禁止使用boost option

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
在 Windows 10 下编译 Boost 库,需要先安装 Visual Studio 和 Boost 的源代码,具体步骤如下: 1. 安装 Visual Studio:访问 Visual Studio 官网(https://visualstudio.microsoft.com/),下载并安装最新版本的 Visual Studio。 2. 下载 Boost 源代码:访问 Boost 官网(https://www.boost.org/),点击 Download 下载最新版本的 Boost 源代码。将下载后的源代码解压到任意目录下,例如在 C:\ 目录下解压。 3. 打开 Visual Studio 命令提示符:在 Windows 开始菜单中搜索“Visual Studio 命令提示符”,并以管理员身份运行。 4. 进入 Boost 源代码目录:在命令提示符中输入以下命令,进入 Boost 源代码的根目录: ``` cd C:\boost_1_76_0 ``` 这里假设 Boost 源代码解压到了 C:\boost_1_76_0 目录下。 5. 配置编译选项:输入以下命令,配置 Boost编译选项: ``` bootstrap.bat ``` 这个命令将自动检测系统环境,并生成编译所需的文件。 6. 编译 Boost 库:输入以下命令,开始编译 Boost 库: ``` b2.exe --build-type=complete --toolset=msvc-14.2 architecture=x86 address-model=64 install ``` 这个命令将使用 Visual Studio 中的 MSVC 编译编译 Boost 库。其中,--toolset 参数指定编译工具集为 MSVC 14.2,--build-type 参数指定编译类型为 complete,--architecture 参数指定编译架构为 x86,--address-model 参数指定编译的地址模型为 64 位。最后的 install 参数指定将编译结果安装到默认位置。 7. 验证 Boost 库:在 Visual Studio 中创建一个新的 C++ 项目,编写一个测试程序并链接 Boost 库,验证 Boost 库是否成功编译。 以上是在 Windows 10 下编译 Boost 库的基本步骤,具体的编译选项和命令可能会因 Boost 版本和系统环境而有所不同。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值