与 CUDA 代码链接时出错:`__cudaRegisterLinkedBinary_ 的多个定义

Error linking with CUDA code: multiple definitions of `__cudaRegisterLinkedBinary_

我有一些 CUDA 代码正在编译到 .a 库中,还有一些(与 CUDA 相关的)常规 C++ 代码用于使用它的应用程序。一切都在进行中间链接。

现在,在一台机器上(使用 CUDA 8.0 RC)构建成功,但在另一台机器上(使用 Maxwell 而不是 Kepler 卡,以防万一)我得到:

/tmp/tmpxft_00001796_00000000-2_ktkernels_intermediate_link.reg.c:25: multiple definition of `__cudaRegisterLinkedBinary_66_tmpxft_00007a5f_00000000_16_cuda_device_runtime_compute_52_cpp1_ii_8b1a5d37'
CMakeFiles/tester.dir/tester_intermediate_link.o:/tmp/tmpxft_0000180b_00000000-2_tester_intermediate_link.reg.c:4: first defined here
collect2: error: ld returned 1 exit status
CMakeFiles/tester.dir/build.make:1766: recipe for target 'bin/tester' failed
make[2]: *** [bin/tester] Error 1

我实际上开始从编译成调用库代码的二进制文件中删除文件 - 只有当我删除所有文件时链接才会成功。

我的问题:

备注:

  • Under what circumstances is it possible for such inconsistent behavior to occur?

如果您在单个应用程序中尝试多个设备 linkages。

  • Can this possibly be the result of the "second linking" for the library and for the binary?

几乎毫无疑问。

  • What can I do to determine exactly what is actually in conflict (e.g. what symbols to look for in )?

冲突是运行时在设备 link 阶段生成的样板的多个定义,运行时用于将设备代码加载到上下文中 API。

  • If nothing is actually conflicting, what should I do to avoid this?

冲突是真实的。避免涉及正确 linking 单独编译的设备代码。除此之外,我无法确切地告诉您如何修复它,因为您选择不告诉我们您在做什么。