Create an OpenCL program object.
The OpenCL program object encapsulates the following components:
Your OpenCL program source.
The latest successfully built program executable.
The build options.
The build log.
A list of devices the program is built for.
The program object is loaded with the kernel source code,
then the code is compiled for the devices attached to the context.
All kernel functions must be identified in the application source
__kernel qualifier. OpenCL applications
can also include functions that you can call from your kernel functions.
Load the OpenCL C kernel source and create an OpenCL program
object from it.
To create a program object, use the
// Create OpenCL program
program = clCreateProgramWithSource(context, device, “<kernel source>”);
if (program == NULL)
There are different options for building OpenCL programs:
You can create a program object directly
from the source code of an OpenCL application and compile it at
runtime. Do this at application start-up to save compute resources
while the application is running.
If you can cache the binary between application invocations,
compile the program object at platform start-up.
To avoid compilation overhead at runtime, you can
build a program object with a previously built binary.
Note Applications with pre-built program objects are not portable
across platforms and driver versions.
Creating a program object from a binary is a similar process
to creating a program object from source code, except that you must
supply the binary for each device that you want to execute the kernel
on. Use the
to do this.
clGetProgramInfo() function to
obtain the binary after you have generated it.