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?

Thanks!

 

 

 

8 post / 0 nuovi
Ultimo contenuto
Per informazioni complete sulle ottimizzazioni del compilatore, consultare l'Avviso sull'ottimizzazione

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

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?

THanks,

Aaron

 

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

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,

Aaron

Any ideas on how to resolve this?  Any workarounds?

Thanks,

Aaron

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
...";

sprintf(kernelSource,kernelSource2,BUFFER_SIZE);

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.

 

 

Lascia un commento

Eseguire l'accesso per aggiungere un commento. Non siete membri? Iscriviti oggi