Headers in CUDA C ?

Hello,

Suppose I want to write somewhat larger kernels in CUDA C… do I still need to use header files to split up my code ?

Also will nvcc understand that *.h belongs to *.cu ?

Bye,
Skybuck.

I tried it and it returned the following:

nvcc fatal : Don’t know what to do with ‘O:/CUDA C/test CorewarSimulator/unit_TInstruction_version_001.h’

Tool completed with exit code -1

:)

Maybe *.cu needs something special like *.hcu ? or *.hpp ? or *.hppcu ?

Ok I guess *.h cannot be compiled seperately which makes somewhat sense ;) (except for templates maybe)

So *.cu should probably include *.h and then compile *.cu and then it will automatically find *.h and return any errors in *.h

But being able to syntax check *.h directly would have been nice… now I need to select *.cu first a little bit more cumbersome ;) :)

Hmmm, headers are kinda annoying, a bad feature of c/c++.

It’s starting to annoy me to have to save *.h, then select *.cu, then compile that. When multiple files open selecting the wrong one is pretty easy, and after every compile step this procedure has to be repeated which is many seconds lost per day ;)

Maybe it’s possible to work around it…

I think it was with ifdefs that’s usually what headers do and include is just a copy & paste excercise for the compiler.

So it’s probably ok to write conceptually something like:

#ifndef myunit.cu
#define myunit.cu

header + code here.

#endif

That should probably do the trick ;) :)

mhmm looking good! :thumbup:

There was a guy back in 2008 who was dealing with this kind of advanced programming concepts:

http://cboard.cprogramming.com/faq-board/31408-faq-header-files-include-statements.html

Hmm it needs a little bit of extra trickery it seems.

Otherwise circular references would exist which can’t be solved.

It can be stuffed into one *.cu file but it will need something like this:

(file: my_unit.cu)

#ifndef my_unit_h
#define my_unit_h

// header code

#endif my_unit_h

#ifndef my_unit_cu
#define my_unit_cu

// implementation code

#endif mu_unit_cuu

That seems to solve it ! ;)

then in other units/files simply write:

#include “my_unit.cu”