integrate cuda with application

I have an application and I want to change one of its function to cuda implementation. How to do it to not influence the original application. Can I compile this function into a DLL?

You can compile a CPU function that launches a kernel into an object file and link it with the rest of the application.

Paulius

Is like the following?

In application:

{

function()

}

In another file: f1

function()

{

kernle<<…>>>()

}

Then nvcc f1 and link them?

Thanks!

Yeah… and also, if your app. is written in C/C++ then, you can compile whole of your app. with ‘nvcc’ itself (basically nvcc will call your C/C++ compiler for those C/C++ codes).

Else, what you are thinking is perfectly right.

I use a makefile to compile my application. If I want to use the method teju suggested, how to write the new makefile?

Here’s a simple makefile (formatting is messed up since tabs/spaces don’t survive the post).

As you can see, I use nvcc to compile a file with the kernel and its launcher function into an object file. I then use mpicc (since this is an MPI app that uses CUDA) to compile the C++ file and link in the object file (mpicc is also a compiler driver, using host’s C++ compiler for actual compilation).

Look at the nvcc documentation on information how to pass parameters to the host C/C++ compiler.

Paulius

multi: kernel.o test.cpp
mpicc -I/usr/local/cuda/include -L /usr/local/cuda/lib -lcudart test.cpp kernel.o -o multi
kernel.o: kernel.cu
nvcc -c --ptxas-options=-v -maxrregcount=32 kernel.cu
clean:
rm -f *.o
scrub: clean
rm -f multi

Thank you very much.

I try it, but doesn’t wok.

I have two files:

file1: kernel and its launcher function

file2: main function to call the launcher function

To file1 I use the command you mentioned:

nvcc -c --ptxas-options=-v -maxrregcount=32 kernel.cu

the error is:

“/usr/include/c++/4.2.1/x86_64-suse-linux/bits/gthr-default.h”, line 92: error:

      function "__gthrw_pthread_once" was referenced but not defined

static __typeof(pthread_once) __gthrw_pthread_once attribute ((weakref(“pthread_once”)));

The reason for those errors are due to not mentioning the location where your CUDA header files are located. (Basically the ‘-I’ option which comes with ‘nvcc’)
Here’s the correct sequence of commands for the example you have provided.

Compile file1:
nvcc --compiler-bindir “” -I “” -c -o file1.obj file1

Compile file2:
nvcc --compiler-bindir “” -I “” -c -o file1.obj file1

Link them: (produces an executable named ‘a.exe’)
nvcc --compiler-bindir “” -I “” -o a.exe file1.obj file2.obj

gcc is in my search path so I try

nvcc -I “/usr/local/cuda2.0/include/” -c -o test.o test.cu

The error still exists.

I attach this two files. It’s the sdk example matMulGPU. I separate it inot main.c and matMulGPU.cu

Could you try it?

Thanks!

Thanks.

It works. I login one computer but use the nvcc coming from another computer.

Now I can link them together.