1
votes

I have host files (say h_A.cpp, etc) which can be compiled by host compiler (g++), device files (say d_A.cu, etc) to be compiled by device compiler (nvcc) and host-device files i.e., host functions, kernel call, etc (say h_d_A.cu) to be compiled by device compiler (nvcc).

Device side compilation

nvcc -arch=sm_20 -dc d_A.cu -o d_A.o $(INCLUDES)

/* -dc since the file may call / have relocatable device functions */

Host side compilation

g++ -c h_A.cpp -o h_A.o $(INCLUDES, FLAGS)

Device Linkage as suggested here

nvcc -arch=sm_20 -dlink d_A.o -o link.o

/* Linkage due to relocatable device functions */

I am using Makefile for the project. Now, the query i have is, how do i form the final executable? I have tried,

1. g++ h_A.o link.o –L<path> -lcudart
Error: relocation 0 has invalid symbol index 10
2. g++ h_A.o link.o –lcudadevrt –L<path> –lcudart
Error: undefined reference to phase2(int*, int) //where phase2 is my __global__ kernel.
1
You cannot link the cudadevrt library against architectures < sm_35, see Compiling CUDA with dynamic parallelism fallback - multiple architectures/compute capability. - Vitality
This recent question External calls are not supported - CUDA could be useful to you. - Vitality
@JackOLantern That question answers how to compile and link the -rdc device files. But my conern is i am not able to form the final executable which is combination of Host and Device code. Thanks for cudadevrt pointer. - Itachi
Concerning the second post I linked too, I apologize but for some reasons I missed to read the first part of your post. - Vitality

1 Answers

1
votes

Sorry, Found out the problem i missed to include device objects while forming the final executable.

corrected syntax.

g++ h_A.o d_A.o link.o –L<path> -lcudart