OpenCL* for CPU
Ask questions and share information on Intel® SDK for OpenCL™ Applications and OpenCL™ implementations for Intel® CPU
Announcements
This forum covers OpenCL* for CPU only. OpenCL* for GPU questions can be asked in the GPU Compute Software forum. Intel® FPGA SDK for OpenCL™ questions can be ask in the FPGA Intel® High Level Design forum.
1663 Discussions

Passing #defines in as build options

ABoxe
Beginner
277 Views

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!

 

 

 

0 Kudos
7 Replies
Yuri_K_Intel
Employee
277 Views
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
ABoxe
Beginner
277 Views

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

 

Yuri_K_Intel
Employee
277 Views
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
ABoxe
Beginner
277 Views

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

ABoxe
Beginner
277 Views

Any ideas on how to resolve this?  Any workarounds?

Thanks,

Aaron

Jeffrey_M_Intel1
Employee
277 Views

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?

ABoxe
Beginner
277 Views

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.

 

 

Reply