我需要编译一个使用cmake动态并行的CUDA代码。 代码是:
#include <stdio.h>
__global__ void childKernel() {
printf("Hello ");
}
__global__ void parentKernel() {
childKernel<<<1,1>>>();
cudaDeviceSynchronize();
printf("World!\n");
}
int main(int argc, char **argv){
parentKernel<<<1, 1>>>();
return 0;
}
并且cmake如下:
cmake_minimum_required(VERSION 2.8)
find_package(CUDA QUIET REQUIRED)
include_directories(/usr/include)
include_directories(/usr/local/cuda/lib)
include_directories(/usr/local/cuda-8.0/lib)
include_directories(/usr/local/cuda/include)
include_directories(/usr/local/cuda-8.0/include)
set(CUDA_SEPARABLE_COMPILATION ON)
find_package(CUDA QUIET REQUIRED)
set(CUDA_PROPAGATE_HOST_FLAGS OFF)
set(
CUDA_NVCC_FLAGS
${CUDA_NVCC_FLAGS};
-arch=compute_35 -rdc=true -lcudadevrt
)
cuda_add_executable(
prova
test.cu
)
我试图直接用nvcc传递-arch=compute_35 -rdc=true -lcudadevrt
来编译代码并且编译完美,但是当
我尝试用cmake编译它返回以下错误:
CMakeFiles/prova.dir/prova_intermediate_link.o: In function `__cudaRegisterLinkedBinary_66_tmpxft_00001101_00000000_13_cuda_device_runtime_compute_62_cpp1_ii_8b1a5d37':
link.stub:(.text+0xcc): undefined reference to `__fatbinwrap_66_tmpxft_00001101_00000000_13_cuda_device_runtime_compute_62_cpp1_ii_8b1a5d37'
link.stub:(.text+0xd0): undefined reference to `__fatbinwrap_66_tmpxft_00001101_00000000_13_cuda_device_runtime_compute_62_cpp1_ii_8b1a5d37'
collect2: error: ld returned 1 exit status
CMakeFiles/prova.dir/build.make:200: recipe for target 'prova' failed
make[2]: *** [prova] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/prova.dir/all' failed
make[1]: *** [CMakeFiles/prova.dir/all] Error 2
Makefile:83: recipe for target 'all' failed
make: *** [all] Error 2
答案 0 :(得分:1)
您看到的未定义符号在libcudadevrt.a
中定义。我看到你告诉CMake链接到它,但似乎编译器找不到它。在命令行上尝试:
VERBOSE=1 make
并检查输出以查看您是否正在搜索/usr/local/cuda/lib64
库。
这可能不相关,但我也注意到您指示CMake在/usr/local/cuda/lib
和/usr/local/cuda-8.0/lib
搜索头文件。这是不正确的,因为这些目录只包含库。
答案 1 :(得分:1)
感谢您的回答,我尝试使用Tegra X2(compute_62)的正确计算功能,并且我检查了详细make的输出,并找到了以下输出:
CMakeFiles/prova.dir/prova_generated_test.cu.o CMakeFiles/prova.dir/prova_intermediate_link.o -o prova -rdynamic /usr/local/cuda-8.0/lib64/libcudart_static.a -lpthread -ldl -lrt
链接器似乎试图搜索/usr/local/cuda-8.0/lib64/libcudart_static.a而不是libcudadevrt.a