Possibility to auto-include headers?

Hello,

I have an automatic build process which creates a C# wrapper around my CUDA code.
Since I’m working also in the driver API i need to decorate each kernel with an
extern “C” global keyword.

For that reason I created a header-file in which I have defined this macro

#define kernel extern “C” global

to be used in every CUDA code to make life a little easier.
Also I have defined a lot of different method and constants. The problem is that I
always have to type the #include. Is there a way that the #include is done automatically?
At least in some config or as command line when I call NVCC?

Thanks
Martin

The nvcc manual (provided in the GPU Computing Toolkit) shows sample nvcc output when run with the -v option, and apparently cudafe (called by nvcc) has an option “–preinclude”. As a quick test, I modified the vectorAdd program, changing this line:

int n = 50000;

to this:

int n = VECTOR_SIZE;

I then created a header file called vector_size_header.h with the following contents:

#define VECTOR_SIZE (50000)

and invoked nvcc like this:

nvcc -c -I"C:\NVIDIA_GPU_Computing SDK_4.0\C\common\inc" --cudafe-options="--preinclude vector_size_header.h" -v vectorAdd.cu

Compilation was successful with the --preinclude option above, and as expected, fails due to an undefined VECTOR_SIZE without it.

I’m not aware of documentation for cudafe options and I don’t know how stable that option is across CUDA versions. Perhaps there are other issues lurking, but maybe this will work for you.

Jeremy

Hi Jeremy,

thanks for the answer. The method works quite fine for me. The only problem is that I have installed some parts of my framework in “C:\Program Files” and it seems that the command line parser of NVCC does not recognize white spaces in the command line argument.

Is there any solution to this?

Thanks
Martin

Did you try putting quotes around the path? For nvcc 4.0 on Windows, both of these work for me:

nvcc -c -I"C:\NVIDIA_GPU_Computing SDK_4.0\C\common\inc" vectorAdd.cu

nvcc -c "-IC:\NVIDIA_GPU_Computing SDK_4.0\C\common\inc" vectorAdd.cu

(There is a space in my SDK path - I must have forgotten to change the space between “Computing” and “SDK”, but the quotation marks work for me.)

Hi Jeremy,

of course you are right, wen using the nvcc only I did this. But in this special situation I have to call nvcc which in turn calls cudafe.
Through the commandline argument

–cudafe-options=“–preinclude vector_size_header.h”

which is delegated to cudafe. Since internally nvcc call cudafe.exe it seems that it’s not possible to hand over arguments with a white space in it.
I have tried to escape with different methods, also of course using “…” in various combinations, escaping it with \ but nothing worked.

Thanks
Martin

Sorry - I misunderstood. I wasn’t able to coerce nvcc into passing the path with spaces to cudafe either!

Looking at the nvcc manual again, it looks like nvcc has its own --preinclude option. For my test example, I can compile the file with this command:

nvcc -c -I"C:\NVIDIA_GPU_Computing SDK_4.0\C\common\inc" --pre-include ".\path with spaces\vector_size_header.h" -v vectorAd

d.cu

Do you need to preinclude with cudafe instead of nvcc?

If you really need cudafe to process a path with spaces, maybe the best approach would be to create a redirect header with this:

// File: redirect_header.h

#include "my path with spaces in it/my_header.h"

and then put this file in some (any?) directory without spaces. Then, your nvcc command would be something like:

--cudafe-options="--preinclude C:\Temp\redirect_header.h"

This worked for the simple example that I tried.

Hi Jeremy,

your suggestions worked perfectly. Sometimes I think I’m too stupid to read the docs.

Thanks
Martin