Mixing CUDA and C++

Hello,

Another programming tutorial coming up...

CUDA
For those who don't know CUDA is an Nvidia library/tool for allowing you to run programs on a graphics card. A bit like OpenCL but more proprietary. It allows you to run lots of lightweight threads in parallel which can speed up tasks like Vector maths but is limited in terms memory access.

C++
Programming language.... nuff said.

Mixing
You might want to integrate CUDA into an existing program to speed up certain parts by performing tasks in parallel. When mixing together make sure you wrap your CUDA code (typically in a .cu file) with functions declared in a header (.h) which doesn't mention any CUDA primitives or types atall.


Steps
1. Separate out raw C++ code from CUDA code so that there is essentially a wrapper around everything CUDA related
2. Compile CUDA related stuff with NVCC and the rest with g++
3. Link with NVCC

You can use NVCC to compile C/C++ code but it doesn't seem to recognise all the flags g++ uses and gives errors
You can't link with g++ as it won't have all the CUDA primitives and symbols (which is sensible)

cuda_code.h is contains handles and contains nothing CUDA related!!

# My makefile
OBJECTS = cpp_code.o cuda_code.o
LINKEROPTIONS = -lm -lGL
NVCCOPTIONS = -arch sm_11
program : $(OBJECTS)
nvcc $(OBJECTS) -o program $(LINKEROPTIONS)
cpp_code.o : cpp_code.cc cpp_code.h
g++ -c dep1.cc
cuda_code.o : cuda_code.cu cuda_code.h
nvcc -c cuda_code.cu $(NVCCOPTIONS)


Notes
Tutorial aimed at more experienced programmers using linux


For those who are into programming i'd urge you to look at CUDA its pretty cool ;-)
Comments
10
man, i dunno wtf this shit is but:

you're the true awesomener of the awesomeners.

YES!

xx<3
I have codes for some hacks, can you compile them for me ?
Even a noob with no exp can compile them LoL, whether they'll have errors or not is down to the code/libraries etc though :{{{}
Parent
Well I dont have the tools for it.
Parent
GPU based hacks would be awesome, you could process information for every client in the game at the same time...
Parent
Why on earth would you need to do that in paralell? Don't think there'd be much gain from that, the bus overhead would be far too high
Parent
Such a useful tutorial. Nice contribution.
kurwa take me this hax pls
kinda wrong site for this dont you think
not quite sure where the tutorial part is. you pasted a makefile :o
Back to top