1

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.
Itachi
  • 1,383
  • 11
  • 22
  • You cannot link the `cudadevrt` library against architectures `< sm_35`, see [Compiling CUDA with dynamic parallelism fallback - multiple architectures/compute capability](http://stackoverflow.com/questions/20896136/compiling-cuda-with-dynamic-parallelism-fallback-multiple-architectures-comput). – Vitality Jan 07 '14 at 08:33
  • This recent question [External calls are not supported - CUDA](http://stackoverflow.com/questions/20884562/external-calls-are-not-supported-cuda/20900595#comment31372285_20900595) could be useful to you. – Vitality Jan 07 '14 at 08:37
  • @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 Jan 07 '14 at 09:09
  • Concerning the second post I linked too, I apologize but for some reasons I missed to read the first part of your post. – Vitality Jan 07 '14 at 12:12

1 Answers1

1

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
Itachi
  • 1,383
  • 11
  • 22