我需要编译一个使用 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