CMakeLists /可重定位设备链接步骤(cudaRegisterLinkedBinary错误)

时间:2018-09-26 16:16:18

标签: cmake cuda

即使在列出并尝试链接CMakeLists中的CUDA库之后,也会出现“未定义引用`__cudaRegisterLinkedBinary ...”的错误。

上一个问题建议执行“ 可重定位的设备代码链接”(See Here),因为在此编译中需要重定位的设备代码。有没有一种方法可以执行通过CMake(又名CMakeLists命令)链接的可重定位设备代码?

CMake: 3.9.6
CUDA: 9.0
GCC / G ++: 7.1.0
Ubuntu 16.04

编辑::添加CMakeLists.txt

CMakeLists.txt:

cmake_minimum_required(VERSION 3.1)
project(sigma_cuda_pkg)

set(CMAKE_CUDA_HOST_COMPILER "/usr/bin/nvcc")
set(CUDA_TOOLKIT_ROOT_DIR /usr/local/cuda-9.0)
set(CUDA_SEPARABLE_COMPILATION ON)

find_package(CUDA 9.0 REQUIRED)

set(LIB_TYPE STATIC)
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS}; -arch=sm_61 -rdc=true -lcudart -lcudadevrt -lcuda)

find_library(SIGMA_LIBRARY sigma HINTS /lib)

file(GLOB SOURCES_SIGMA_C "src/*.c")
file(GLOB SOURCES_SIGMA_CPP "src/*.cpp")
file(GLOB SOURCES_SIGMA_CUDA "src/*.cu")


include_directories(
include
/usr/local/cuda-9.0/include
/usr/include/eigen3
)

CUDA_INCLUDE_DIRECTORIES(
include
/usr/local/cuda-9.0/include
/usr/include/eigen3
)

CUDA_ADD_LIBRARY(sigma_cuda_pkg_lib  ${LIB_TYPE} ${SOURCES_SIGMA_C} ${SOURCES_SIGMA_CPP} ${SOURCES_SIGMA_CUDA})


CUDA_COMPILE(SIGMA_MAIN_CU_O src/main.cu OPTIONS -G)
CUDA_COMPILE(SIGMA_A_CU_O src/alpha.cu OPTIONS -G)
CUDA_COMPILE(SIGMA_A_ERROR_CU_O src/alpha_errors.cu OPTIONS -G)
CUDA_COMPILE(SIGMA_A_COMPARE_CU_O src/alpha_compare.cu OPTIONS -G)

CUDA_ADD_EXECUTABLE(sigma_cuda_pkg_node src/main.cu ${SIGMA_A_CU_O} ${SIGMA_A_ERROR_CU_O} ${SIGMA_A_COMPARE_CU_O} OPTIONS -G)
set_target_properties(sigma_cuda_pkg_node PROPERTIES CUDA_RESOLVE_DEVICE_SYMBOLS ON)

target_link_libraries(
sigma_cuda_pkg_node 
sigma_cuda_pkg_lib
m
${CUDA_LIBRARIES} 
)

多种结果错误,格式如下:

undefined reference to `__cudaRegisterLinkedBinary_43_tmpxft_0000081d_00000000_6_sigmaB_cpp1_ii_633f8803'

1 个答案:

答案 0 :(得分:0)

在添加具有C ++头文件的C ++源文件后,其中的函数在CUDA源文件中定义,CUDA_ADD_EXECUTABLE现在看起来像:

CUDA_ADD_EXECUTABLE(sigma_cuda_pkg_node src/main.cpp src/main.cu ${SOURCES_SIGMA_CUDA} OPTIONS -G)

不要忘记删除-G标志(用于调试)以优化性能(使用-DCMAKE_BUILD_TYPE=Release变量)。

项目成功构建。