Under The Wire

Under The Wire
Showing posts with label CUDA. Show all posts
Showing posts with label CUDA. Show all posts

Wednesday, April 15, 2009

Integrate a CUDA kernel in your projects

Recently I told you how to setup a Virtual Machine with VirtualBox running openSUSE (Yeah, this time I spelled it right).

As I wrote on the previous post all the mess was due to a project with nVidia CUDA, porting some data intensive tasks on the GPU.

Working on an existing project I had some troubles integrating the new code with the existing sources editing the makefile.

To build your executable with a CUDA kernel you have to do this:

  • Compile CUDA sources with nvcc (You have to install CUDA toolkit to have it), generating an object file.
    Be sure that when you include functions headers from your C project into the CUDA sources you state that what you are importing is C code. To do that use extern “C” {#incude “whateverYouWant.h”} and it will be fine.
    $ nvcc --compiler-options -fno-strict-aliasing -I. -I/opt/cuda/NVIDIA_CUDA_SDK/common/inc -I/opt/cuda/include -o objectCUDA.o -c SOURCE.cu
  • Compile the project C code with gcc, producing the object files, as you do usually.
  • Link all together, using gcc. Be sure that you link all the required libraries.
    gcc -o EXECUTABLE object1.o object2.o objectCUDA.o -L/opt/cuda/lib -lcudart -L/opt/cuda/NVIDIA_CUDA_SDK/lib -lcutil

With this tips you should be able to edit easily your project makefile and have all the things working.


Read more...

  © Blogger template 'Minimalist E' by Ourblogtemplates.com 2008

Back to TOP