How does one compile a cuda project with dependancies to c++ class files


I’ve written and run a cuda 6.5 program which runs fine through visual studio on windows but I’m having grief trying to compile it on a remote Linux system (using nvcc).

I’ve gotten simple cuda programs to compile and execute on the remote linux server - as well as simple c++ programs. That said, I’ve been unable to compile my actual cuda program which uses several classes I defined in seperate .cpp files.

My program consists of a file and 3 .cpp files. The file contains the main function and all the program’s gpu run functions. The 3 .cpp files (each with an accompanying .h file) contain classes with strictly cpu functions which are used in’s main function.

My current attempt at compiling on linux has been to try compile the .cpp dependancies beforehand then link the comiled objects while compiling my cuda file:

#PBS -l nodes=1:ppn=1
#PBS -q medium
#PBS -l walltime=00:10:00,

cd /home/jselvan/gpuScriptAttempt2

g++ -c -o ESBTL_Invoker.o ESBTL_Invoker.cpp ESBTL_Invoker.h -I /home/jselvan/ESBTL-1.0-beta01/include/

g++ -c -o cpuArrayManipulationFunctions.o cpuArrayManipulationFunctions.cpp cpuArrayManipulationFunctions.h

g++ -c -o kdTreeFunctions.o kdTreeFunctions.cpp kdTreeFunctions.h

module load nvidia

nvcc -o GPUExecutable.out kdTreeFuntions.o cpuArrayManipulationFunctions.o ESBTL_Invoker.o

To which I get the error message :
nvlink fatal : Could not open input file ‘kdTreeFuntions.o’

removing kdTreeFunctions.o from the nvcc compile line results in the error:
nvlink fatal : Could not open input file ‘cpuArrayManipulationFunctions.o’

I haven’t really used linux for anything major before this so any input or links on how to compile this thing on linux would be greatly appreciated.

dude, spellcheck




The compiler is VERY right about the file not existing, because it was created under a different file name.

I don’t know about the problem with cpuArrayManipulationFunctions.o, because here the names appear to match. Does the file get created the current directory after running g++ ?

Whoops. Switching between visual studio and terminal has resulted in that sort of thing a few times.

Resubmitted and got the new error:
kdTreeFunctions.o: file not recognized: File format not recognized

Any chance you could confirm if this sort of approach should be viable?

All 3 .o files do exist (and were produced) by running the script I listed. Oddly, I think I did have kdTreeFunctions.o spelled correctly before as there are no left over kdTreeFuntions files in the folder - and I haven’t deleted any .o files.

Could it be that you accidentially placed a Windows object file on your Linux PC? I cannot imagine g++ generating object files that are incompatible to be used with nvcc.

I’ll look into it. I only copied .cpp, .cu and .h files onto the linux server - and compiled the .o files there. I’ll try checking if any windows stuff got moved somehow.

No, just plain .cpp, .h and .cu files.

Maybe nvcc can’t compile one file and link with other object files at the same time?
Can you try splitting it in two calls to nvcc:

nvcc -o kernel.o -c
nvcc -o GPUExecutable.out kernel.o kdTreeFuntions.o cpuArrayManipulationFunctions.o ESBTL_Invoker.o

Or compile and link all files at once, e.g.:

nvcc -o GPUExecutable.out *.cpp

Got the files to compile. Not sure what the most correct way to compile them is but I got the c++ files to link by compiling them (and the cu file) separately into object files and then linking the objects together simultaneously.

Script below:

#PBS -l nodes=1:ppn=1
#PBS -q medium
#PBS -l walltime=00:10:00,

module load nvidia

cd /home/jselvan/gpuScriptAttempt2

nvcc -o ESBTL_Invoker.o -dc ESBTL_Invoker.cpp -I /home/jselvan/ESBTL-1.0-beta01/include/

nvcc -o manip.o -dc cpuArrayManipulationFunctions.cpp

nvcc -o kdTreeFunctions.o -dc kdTreeFunctions.cpp

nvcc -o kernel.o -dc

nvcc -o gpuExecutable kernel.o kdTreeFunctions.o manip.o ESBTL_Invoker.o

Thanks for the responses.