The standard convention seems to be to give CUDA source-code files a .cu
extension, to distinguish them from C files with a .c
extension. What's the corresponding convention for CUDA-specific header files? Is there one?
Asked
Active
Viewed 3.0k times
28

Wladimir Palant
- 56,865
- 12
- 98
- 126

Brooks Moses
- 9,267
- 2
- 33
- 57
2 Answers
42
Some people (including the CUDA SDK) use .cuh
for CUDA header files, and if you're including device code in the header then perhaps this may help. However really there is no special meaning attached to the extension of the header file (unlike for the source file where it determines which compiler to use) so personally I stick with .h
.

Brooks Moses
- 9,267
- 2
- 33
- 57

Tom
- 20,852
- 4
- 42
- 54
-
Thanks! In some cases I do have device code in the header, and I'd like to make that clear in the file extension so that people won't include it in non-CUDA source files, so .cuh sounds like the right answer for that. (This is also an environment that distinguishes C++ .hpp headers from C .h ones, so there's local precedent.) Otherwise, yeah, .h makes sense. – Brooks Moses Mar 07 '10 at 06:07
-
2When you work with the Linux Version of Eclipse it is indeed very important what extension the include file has. With a `.h` extension Eclipse does not format correctly the content. I had this issue almost 2 years till I realized that it may be due to a wrong extension. Changing the extension to `.cuh` solved my problem and Eclipse now finally formats correctly the include file. Up Mister Tom :-) – Peter VARGA Mar 09 '17 at 16:57
5
No - just use .h
for header files. The CUDA source files have a different suffix to make lt easy to ensure that the various source files in a build get compiled with the right compiler (think makefile rules).

Brooks Moses
- 9,267
- 2
- 33
- 57

Paul R
- 208,748
- 37
- 389
- 560
-
18In my opinion, it is good habit to use a different extensions for headers that have CUDA specific code. This way, you can avoid people trying to include them in regular C++ files. – shinjin Jan 18 '13 at 05:45