Search code examples
ccudanvccobject-files

cuda separate compilation "undefined methods"


I'm having problems using separate compilation with cuda c. I have 2 files. nsim.cu and methods.cu.

in my methods.cu files, i have all my kernel functions "_ _global _ _" and my nsim.cu calls these functions. my problem is that when trying to call the methods in my object files, I get an

error : "identifier "MyMethod" is undefined"

heres how I am using nvcc:

NVCC= /usr/local/cuda-5.5/bin/nvcc
NVCCFLAGS= -arch=sm_35 -dc
LIBS= -lglut -lGL -lcurand
OBJECTS = nsim.o methods.o

go:
    rm -f ${OBJECTS}
    ${NVCC} ${NVCCFLAGS} methods.cu ${LIBS}
    ${NVCC} ${NVCCFLAGS} nsim.cu ${LIBS}
    ${NVCC} ${NVCCFLAGS} ${OBJECTS} -o nsim

nsim.cu contains my main method, and is where the errors are being thrown at compile time

thank you for any input!


Solution

  • I fixed my problem by moving all of my device functions into seperate object files, then compiling with the lcudadebrt library. my new makefile looks like this:

    NVCC= /usr/local/cuda-5.5/bin/nvcc
    NVCCFLAGS= -arch=sm_35 
    LIBS= -lglut -lGL -lcurand -lcudadevrt
    OBJECTS = nsim.o cuda0.o cuda1.o cuda2.o cuda3.o cuda4.o
    
    go:
        rm -f ${OBJECTS}
        ${NVCC} ${NVCCFLAGS} -dc cuda0.cu ${LIBS}
        ${NVCC} ${NVCCFLAGS} -dc cuda1.cu ${LIBS}
        ${NVCC} ${NVCCFLAGS} -dc cuda2.cu ${LIBS}
        ${NVCC} ${NVCCFLAGS} -dc cuda3.cu ${LIBS}
        ${NVCC} ${NVCCFLAGS} -dc cuda4.cu ${LIBS}
        ${NVCC} ${NVCCFLAGS} -dc nsim.cu ${LIBS}
        ${NVCC} ${NVCCFLAGS} ${OBJECTS} -o nsim ${LIBS}