I’ve written an OpenCL kernel in a .cl file. It attempts to #include several headers.
Its compilation fails, since the included header files are “not found”.
I am aware that clBuildProgram can take the -I dir option, which adds the directory dir to the list of directories to be searched for the header files.
In the khronus site forum this post http://www.khronos.org/message_boards/viewtopic.php?f=37&t=2535 talks about the issue.
They propose to use clCreateProgramWithSource which specifies all sources (including .h files).
I have a questions regarding this issue:
- Which option is better? (
clBuildProgramvs.clCreateProgramWithSource, as described above) - If I use
clCreateProgramWithSourcehow does the compiler know what to include? I mean, which source stands for which included file name? - If I use
clBuildProgramand there are several directories with include files, how do I specify them?
OpenCL requires you use
clCreateProgramWithSource()followed byclBuildProgram().ClCreateProgramWithSource()creates and returns acl_programobject.That
cl_programobject is input intoclBuildProgram().clBuildProgram()allows you to specify compiler options which include the include filedirectories. In your case, for header file includes, it will be something like the string:
The compiler used is the internal OpenCL compiler in the OpenCL SDK you are using. So if you
are using AMD’s SDK, the AMD OpenCL compiler that is part of their OpenCL SDK will be used. Likewise for Nvidia or Intel.
Its important to check the OpenCL status code for ALL OpenCL function calls.
This is mandatory for
clCreateProgramWithSource()andclBuildProrgam()to getany compiler errors or messages. There is a whole other bit code to write
to get the size of the messages and then retrieve the messages themselves.