Passing #defines in as build options

Passing #defines in as build options

I would like to pass some compile time constants in as build options:

eg:  "-D BUFFER_SIZE=512"

and then I would like to declare the following variable in my kernel:

local buffer[BUFFER_SIZE]; 

When I try this, (visual studio 2012) I get errors. Is there a way of doing this with the intel SDK and 

visual studio integration?





8 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Aaron,

Could you please rephrase your question? What exactly are you trying to do and what errors do you get?

My understanding is that you should just pass "-D BUFFER_SIZE=512" as a compiler option to clBuildProgram (or clCompileProgram) and this macro will be defined in your kernel so you can use it. And I don't see any relation to Visual Studio.


THanks, Yuri. Visual Studio does static checking on opencl file

when compiling C/C++ code. And it doesn't know about the compiler option passed to clBuildProgram.

So it flags

local buffer[BUFFER_SIZE]; 

as an error.

I would like the visual studio plugin to somehow know about the clBuildProgram complier options.

Is this clearer?




Yes, thanks.

You should be able to set the necessary build options in 'Project properies'->'Intel SDK for OpenCL Applications'->'General'->'additional build options': -D BUFFER_SIZE=512

Please, let me know if that works for you.


Thanks, Yuri. Unfortunately, that will not work.

I would like to build different programs using the same kernel code, but with different configurations of #defines.

For example:

Program 1:  kernel1  with  BUFFER_SIZE=512

Program2: kernel1 with BUFFER_SIZE=1028

Also, when I tried your suggestion, I got CL_INVALID_KERNEL errors.  So, it doesn't actually work :(


Thanks again,


Any ideas on how to resolve this?  Any workarounds?



You could consider your kernel source as a string and build it from values defined in the host program.

That is,  

char *kernelSource2 ="
local buffer[%d]; \n


program = clCreateProgramWithSource(context, 1,
                            (const char **) & kernelSource, NULL, &err); 


Will this work for what you are trying to do?

Ok, ok, my bad here. Yuri's suggestion does work.

1) Right click on .cl file and add a command line parameter D BUFFER_SIZE=512

2) pass the same parameter in when calling clBuildProgram

Now, the compiler is happy, and the visual studio plugin is happy.



Leave a Comment

Please sign in to add a comment. Not a member? Join today