C Specification
To compile a program’s source for all the devices or a specific device(s) in the OpenCL context associated with the program, call the function
// Provided by CL_VERSION_1_2
cl_int clCompileProgram(
cl_program program,
cl_uint num_devices,
const cl_device_id* device_list,
const char* options,
cl_uint num_input_headers,
const cl_program* input_headers,
const char** header_include_names,
void (CL_CALLBACK* pfn_notify)(cl_program program, void* user_data),
void* user_data);
| clCompileProgram is missing before version 1.2. |
Parameters
-
program is the program object that is the compilation target.
-
device_list is a pointer to a list of devices associated with program. If device_list is a
NULLvalue, the compile is performed for all devices associated with program. If device_list is a non-NULLvalue, the compile is performed for devices specified in this list. -
num_devices is the number of devices listed in device_list.
-
options is a pointer to a null-terminated string of characters that describes the compilation options to be used for building the program executable. If options is a
NULLpointer then it will have the same result as the empty string. Certain options are ignored when program is created with IL. The list of supported options is as described in Compiler Options. -
num_input_headers specifies the number of programs that describe headers in the array referenced by input_headers.
-
input_headers is an array of program embedded headers created with clCreateProgramWithSource.
-
header_include_names is an array that has a one to one correspondence with input_headers. Each entry in header_include_names specifies the include name used by source in program that comes from an embedded header. The corresponding entry in input_headers identifies the program object which contains the header source to be used. The embedded headers are first searched before the headers in the list of directories specified by the
-Icompile option (as described in Preprocessor options). If multiple entries in header_include_names refer to the same header name, the first one encountered will be used. -
pfn_notify is a function pointer to a notification routine. The notification routine is a callback function that an application can register and which will be called when the program executable has been built (successfully or unsuccessfully). If pfn_notify is not
NULL, clCompileProgram does not need to wait for the compiler to complete and can return immediately once the compilation can begin. Any state changes of the program object that result from calling clCompileProgram (e.g. compile status or log) will be observable from this callback function. The compilation can begin if the context, program whose sources are being compiled, list of devices, input headers, programs that describe input headers and compiler options specified are all valid and appropriate host and device resources needed to perform the compile are available. If pfn_notify isNULL, clCompileProgram does not return until the compiler has completed. This callback function may be called asynchronously by the OpenCL implementation. It is the application’s responsibility to ensure that the callback function is thread-safe. -
user_data will be passed as an argument when pfn_notify is called. user_data can be
NULL.
Description
The pre-processor runs before the program sources are compiled.
The compiled binary is built for all devices associated with program or
the list of devices specified.
The compiled binary can be queried using clGetProgramInfo(program,
CL_PROGRAM_, …) and can be passed to clCreateProgramWithBinary
to create a new program object.
If program was created using clCreateProgramWithIL, then num_input_headers, input_headers, and header_include_names are ignored.
For example, consider the following program source:
#include <foo.h>
#include <mydir/myinc.h>
__kernel void
image_filter (int n, int m,
__constant float *filter_weights,
__read_only image2d_t src_image,
__write_only image2d_t dst_image)
{
...
}
This kernel includes two headers foo.h and mydir/myinc.h. The following describes how these headers can be passed as embedded headers in program objects:
cl_program foo_pg = clCreateProgramWithSource(context,
1, &foo_header_src, NULL, &err);
cl_program myinc_pg = clCreateProgramWithSource(context,
1, &myinc_header_src, NULL, &err);
// lets assume the program source described above is given
// by program_A and is loaded via clCreateProgramWithSource
cl_program input_headers[2] = { foo_pg, myinc_pg };
char * input_header_names[2] = { foo.h, mydir/myinc.h };
clCompileProgram(program_A,
0, NULL, // num_devices & device_list
NULL, // compile_options
2, // num_input_headers
input_headers,
input_header_names,
NULL, NULL); // pfn_notify & user_data
clCompileProgram returns CL_SUCCESS if the function is executed
successfully.
Otherwise, it returns one of the following errors:
-
CL_INVALID_if program is not a valid program object.PROGRAM -
CL_INVALID_if device_list isVALUE NULLand num_devices is greater than zero, or if device_list is notNULLand num_devices is zero. -
CL_INVALID_if num_input_headers is zero and header_include_names or input_headers are notVALUE NULLor if num_input_headers is not zero and header_include_names or input_headers areNULL. -
CL_INVALID_if pfn_notify isVALUE NULLbut user_data is notNULL. -
CL_INVALID_if device in device_list is not in the list of devices associated with program.DEVICE -
CL_INVALID_if the compiler options specified by options are invalid.COMPILER_ OPTIONS -
CL_INVALID_if the compilation or build of a program executable for any of the devices listed in device_list by a previous call to clCompileProgram or clBuildProgram for program has not completed.OPERATION -
CL_COMPILER_if a compiler is not available, i.e.NOT_ AVAILABLE CL_DEVICE_specified in the Device Queries table is set toCOMPILER_ AVAILABLE CL_FALSE. -
CL_COMPILE_if there is a failure to compile the program source. This error will be returned if clCompileProgram does not return until the compile has completed.PROGRAM_ FAILURE -
CL_INVALID_if there are kernel objects attached to program.OPERATION -
CL_INVALID_if program has no source or IL available, i.e. it has not been created with one ofOPERATION -
clCreateProgramWithIL or clCreateProgramWithILKHR
-
clCreateProgramWithBinary where
-x spiris present in options, if thecl_khr_extension is supported.spir -
clCreateProgramWithSource
-
-
CL_OUT_if there is a failure to allocate resources required by the OpenCL implementation on the device.OF_ RESOURCES -
CL_OUT_if there is a failure to allocate resources required by the OpenCL implementation on the host.OF_ HOST_ MEMORY
Document Notes
For more information, see the OpenCL Specification
This page is extracted from the OpenCL Specification. Fixes and changes should be made to the Specification, not directly.