链接时突然收到maxrregcount警告和未定义的引用错误

Suddenly getting maxrregcount warnings and undefined reference errors when linking

本文关键字:未定义 引用 错误 警告 maxrregcount 突然 链接      更新时间:2023-10-16

我维护 C+=-flavored CUDA API 包装器库。库的当前提交是相对经过良好测试的,有一些示例程序和相当多的用户。但是,最近某个时候(不能确切地说出何时(,并且没有提交任何新内容,我现在在我的示例程序的"dlink"阶段收到NVCC警告,例如:

/path/to/nvcc /path/to/cuda-api-wrappers/examples/modified_cuda_samples/vectorAdd/vectorAdd.cu -dc -o /path/to/cuda-api-wrappers/CMakeFiles/vectorAdd.dir/examples/modified_cuda_samples/vectorAdd/./vectorAdd_generated_vectorAdd.cu.o -ccbin /opt/gcc-5.4.0/bin/gcc -m64 -gencode arch=compute_52,code=compute_52 --std=c++11 -Xcompiler -Wall -O3 -DNDEBUG -DNVCC -I/path/to/cuda/include -I/path/to/cuda-api-wrappers/src
/path/to/nvcc -gencode arch=compute_52,code=compute_52 --std=c++11 -Xcompiler -Wall -O3 -DNDEBUG -m64 -ccbin /opt/gcc-5.4.0/bin/gcc -dlink /export/path/to/cuda-api-wrappers/CMakeFiles/vectorAdd.dir/examples/modified_cuda_samples/vectorAdd/./vectorAdd_generated_vectorAdd.cu.o /path/to/cuda/lib64/libcublas_device.a -o /export/path/to/cuda-api-wrappers/CMakeFiles/vectorAdd.dir/./vectorAdd_intermediate_link.o
@O@ptxas info    : 'device-function-maxrregcount' is a BETA feature
@O@ptxas info    : 'device-function-maxrregcount' is a BETA feature
@O@ptxas info    : 'device-function-maxrregcount' is a BETA feature
... this repeats many times ...

但眨眼的脸确实总结了。这已经很奇怪了,因为我没有明确使用任何测试版功能。

/opt/gcc-5.4.0/bin/g++   -Wall -Wpedantic -O2 -DNDEBUG  -L/path/to/cuda/lib64 -rdynamic CMakeFiles/vectorAdd.dir/examples/modified_cuda_samples/vectorAdd/vectorAdd_generated_vectorAdd.cu.o CMakeFiles/vectorAdd.dir/vectorAdd_intermediate_link.o  -o examples/bin/vectorAdd lib/libcuda-api-wrappers.a -Wl,-Bstatic -lcudart_static -Wl,-Bdynamic -lpthread -ldl -lrt -lnvToolsExt -Wl,-Bstatic -lcudadevrt -Wl,-Bdynamic 
CMakeFiles/vectorAdd.dir/vectorAdd_intermediate_link.o: In function `__cudaRegisterLinkedBinary_25_cublas_compute_70_cpp1_ii_f0559976':
link.stub:(.text+0xe0): undefined reference to `__fatbinwrap_25_cublas_compute_70_cpp1_ii_f0559976'
CMakeFiles/vectorAdd.dir/vectorAdd_intermediate_link.o: In function `__cudaRegisterLinkedBinary_25_xerbla_compute_70_cpp1_ii_cd7f3ad3':
link.stub:(.text+0x190): undefined reference to `__fatbinwrap_25_xerbla_compute_70_cpp1_ii_cd7f3ad3'
CMakeFiles/vectorAdd.dir/vectorAdd_intermediate_link.o: In function `__cudaRegisterLinkedBinary_23_nrm2_compute_70_cpp1_ii_8edbce95':
link.stub:(.text+0x240): undefined reference to `__fatbinwrap_23_nrm2_compute_70_cpp1_ii_8edbce95'
... more udnefined reference errors here ...

我的问题:为什么会发生这种情况,我该如何规避/避免/解决它?

笔记:

  • 我正在使用可分离的编译
  • 我在使用 CUDA 9.1 和 SM 5.2 设备(没有 7.0(时遇到这些特定错误。
  • CMakeLists.txt就在这里。
  • 我显然在建造之前清理CMakeCache.txt
  • 这在GNU/Linux Mint 18.3和Fedora 26上都发生在我身上。在第一台机器上,已经完成了一些apt-get dist-upgrade,现在GCC已经升级到5.5.0版本,以防万一。在第二台机器上 - 我知道确实没有变化;相同的编译器和 CUDA 版本。

部分答案/解决方法:

此问题似乎仅在涉及libcublas时才发生。如果我从-dlink阶段命令行中删除/path/to/cuda/lib64/libcublas_device.a,所有警告和错误都会消失(包括后期阶段(。事实上,我的包装库忘记了 cublas,不知道为什么 CMake 要添加它;它不在$CUDA_LIBRARIES.另请参阅:

为什么 CMake 强制使用具有可分离编译的 libcublas?