Reputation: 21
I need to compile a CUDA code that use a dynamic parallelism with cmake. The code is:
#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;
}
and the cmake is the following:
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
)
I have tried to compile the code directly with nvcc passing the -arch=compute_35 -rdc=true -lcudadevrt
and it compiles perfectly, but when
I try to compile with cmake it returns me the following error:
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
Upvotes: 0
Views: 1038
Reputation: 21
Thanks for the answer, I have tried to use the correct compute capability of the Tegra X2 (compute_62), and I have inspected the output of verbose make and I found the following output:
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
It seems that the linker try to search /usr/local/cuda-8.0/lib64/libcudart_static.a but not libcudadevrt.a
Upvotes: 1
Reputation: 21
The undefined symbols you're seeing are defined in libcudadevrt.a
. I see that you're telling CMake to link to it, but it appears the compiler can't find it. Try this on the command line:
VERBOSE=1 make
and inspect the output to see if you're searching /usr/local/cuda/lib64
for libraries.
This may be unrelated, but I also notice that you're instructing CMake to search /usr/local/cuda/lib
and /usr/local/cuda-8.0/lib
for header files. This is incorrect, as these directories contain only libraries.
Upvotes: 1