Builds (compiles and links) a program executable from the program source or binary.
cl_int clBuildProgram(cl_program program, cl_uint num_devices, const cl_device_id *device_list, const char *options, void (CL_CALLBACK *pfn_notify)( cl_program program, void *user_data), void *user_data)
The program object.
A pointer to a list of devices associated with
device_listis a NULL value, the program executable is built for all devices associated with
programfor which a source or binary has been loaded. If
device_listis a non-NULL value, the program executable is built for devices specified in this list for which a source or binary has been loaded.
The number of devices listed in
A pointer to a null-terminated string of characters that describes the build options to be used for building the program executable. Certain options are ignored when
programis created with IL. The list of supported options is described below.
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_notifyis not NULL,
clBuildProgramdoes not need to wait for the build to complete and can return immediately once the build operation can begin. The build operation can begin if the context, program whose sources are being compiled and linked, list of devices and build options specified are all valid and appropriate host and device resources needed to perform the build are available. If
clBuildProgramdoes not return until the build 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.
Passed as an argument when
user_datacan be NULL.
Builds (compiles & links) a program executable from the program source or binary for all the devices or a specific device(s) in the OpenCL context associated with
OpenCL allows program executables to be built using the source or the binary.
clBuildProgram must be called for
program created using either
clCreateProgramWithBinary to build the program executable for one or more devices associated with
program is created with
clCreateProgramWithBinary, then the program binary must be an executable binary (not a compiled binary or library).
clBuildProgram does not return until the build 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.
The compiler options are categorized as pre-processor options, options for math intrinsics, options that control optimization and miscellaneous options. This specification defines a standard set of options that must be supported by the OpenCL C compiler when building program executables online or offline. These may be extended by a set of vendor- or platform specific options.
These options control the OpenCL C preprocessor which is run on each program source before actual compilation.
-D options are processed in the order they are given in the
options argument to
- -D name
nameas a macro, with definition 1.
- -D name=definition
The contents of
definitionare tokenized and processed as if they appeared during translation phase three in a '#define' directive. In particular, the definition will be truncated by embedded newline characters.
- -I dir
Add the directory
dirto the list of directories to be searched for header files.
These options control compiler behavior regarding floating-point arithmetic. These options trade off between speed and correctness.
Treat double precision floating-point constant as single precision constant.
This option controls how single precision and double precision denormalized numbers are handled. If specified as a build option, the single precision denormalized numbers may be flushed to zero; double precision denormalized numbers may also be flushed to zero if the optional extension for double precsion is supported. This is intended to be a performance hint and the OpenCL compiler can choose not to flush denorms to zero if the device supports single precision (or double precision) denormalized numbers.
This option is ignored for single precision numbers if the device does not support single precision denormalized numbers i.e.
CL_FP_DENORMbit is not set in
This option is ignored for double precision numbers if the device does not support double precision or if it does support double precison but not double precision denormalized numbers i.e.
CL_FP_DENORMbit is not set in
This flag only applies for scalar and vector single precision floating-point variables and computations on these floating-point variables inside a program. It does not apply to reading from or writing to image objects.
-cl-fp32-correctly-rounded-divide-sqrtbuild option to
clCompileProgramallows an application to specify that single precision floating-point divide (x/y and 1/x) and sqrt used in the program source are correctly rounded. If this build option is not specified, the minimum numerical accuracy of single precision floating-point divide and sqrt are as defined in section 7.4 of the OpenCL specification.
This build option can only be specified if the
CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRTis set in
CL_DEVICE_SINGLE_FP_CONFIG(as defined in in the table of allowed values for
clGetDeviceInfo) for devices that the program is being build.
clCompileProgramwill fail to compile the program for a device if the
-cl-fp32-correctly-rounded-divide-sqrtoption is specified and
CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRTis not set for the device.
These options control various sorts of optimizations. Turning on optimization flags makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.
This option disables all optimizations. The default is optimizations are enabled.
The following options control compiler behavior regarding floating-point arithmetic. These options trade off between performance and correctness and must be specifically enabled. These options are not turned on by default since it can result in incorrect output for programs which depend on an exact implementation of IEEE 754 rules/specifications for math functions.
a * b + cto be replaced by a
a * b + cwith reduced accuracy. For example, some OpenCL devices implement
madas truncate the result of
a * bbefore adding it to
Allow optimizations for floating-point arithmetic that ignore the signedness of zero. IEEE 754 arithmetic specifies the distinct behavior of
-0.0values, which then prohibits simplification of expressions such as
-clfinite-mathonly). This option implies that the sign of a zero result isn’t significant.
Allow optimizations for floating-point arithmetic that (a) assume that arguments and results are valid, (b) may violate IEEE 754 standard and (c) may violate the OpenCL numerical compliance requirements as defined in section 7.4 for single precision and double precision floating-point, and edge case behavior in section 7.5. This option includes the
Allow optimizations for floating-point arithmetic that assume that arguments and results are not NaNs or ±∞. This option may violate the OpenCL numerical compliance requirements defined in section 7.4 for single precision and double precision floating point, and edge case behavior in section 7.5.
Sets the optimization options
-cl-unsafe-math-optimizations. This allows optimizations for floating-point arithmetic that may violate the IEEE 754 standard and the OpenCL numerical compliance requirements defined in the specification in section 7.4 for single-precision and double precision floating-point, and edge case behavior in section 7.5. This option also relaxes the precision of commonly used math functions (refer to table 7.2 defined in section 7.4). This option causes the preprocessor macro
FAST_RELAXED_MATHto be defined in the OpenCL program.
This requires that the global work-size be a multiple of the work-group size specified to
clEnqueueNDRangeKernel. Allow optimizations that are made possible by this restriction.
Warnings are diagnostic messages that report constructions which are not inherently erroneous but which are risky or suggest there may have been an error. The following language independent options do not enable specific warnings but control the kinds of diagnostics produced by the OpenCL compiler.
Inhibit all warning messages.
Make all warnings into errors.
The following option controls the version of OpenCL C that the compiler accepts.
Determine the OpenCL C language version to use. A value for this option must be provided. Valid values are:
CL1.1- Support all OpenCL C programs that use the OpenCL C language features defined in section 6 of the OpenCL 1.1 specification.
CL1.2- Support all OpenCL C programs that use the OpenCL C language features defined in section 6 of the OpenCL 1.2 specification.
CL2.0- Support all OpenCL C programs that use the OpenCL C language features defined in section 6 of the OpenCL 2.0 specification.
clCompileProgram with the
-cl-std=CL1.1 option will fail to compile the program for any devices with
CL_DEVICE_OPENCL_C_VERSION = OpenCL C 1.0.
clCompileProgram with the
-cl-std=CL1.2 option will fail to compile the program for any devices with
CL_DEVICE_OPENCL_C_VERSION = OpenCL C 1.0 or OpenCL C 1.1.
clCompileProgram with the
-cl-std=CL2.0 option will fail to compile the program for any devices with
CL_DEVICE_OPENCL_C_VERSION = OpenCL C 1.0, OpenCL C 1.1, or OpenCL C 1.2.
–cl-std build option is not specified, the highest OpenCL C 1.x language version supported by each device is used when compiling the program for each device.
Applications are required to specify the
–cl-std=CL2.0 option if they want to compile or build their programs with OpenCL C 2.0.
- -x spir
Indicates that the binary is in SPIR format.
Specifies the version of the SPIR specification that describes the format and meaning of the binary. For example, if the binary is as described in SPIR version 1.2, then
-spir-std=1.2must be specified. Failing to specify these compile options may result in implementation defined behavior.
This option allows the compiler to store information about the arguments of a kernel(s) in the program executable. The argument information stored includes the argument name, its type, the address and access qualifiers used. Refer to description of
clGetKernelArgInfoon how to query this information.
This option can currently be used to generate additional errors for the built-in functions that allow you to enqueue commands on a device (refer to section 6.13.17).
This specification defines a standard set of linker options that must be supported by the OpenCL C compiler when linking compiled programs online or offline. These linker options are categorized as library linking options and program linking options. These may be extended by a set of vendor- or platform-specific options.
The following options can be specified when creating a library of compiled binaries.
Create a library of compiled binaries specified in
Allows the linker to modify the library behavior based on one or more link options (described in Program Linking Options, below) when this library is linked with a program executable. This option must be specified with the
The following options can be specified when linking a program executable.
The linker may apply these options to all compiled program objects specified to
The linker may apply these options only to libraries which were created with the
OpenCL programs are compiled and linked to support the following:
Separate compilation and link stages. Program sources can be compiled to generate a compiled binary object and linked in a separate stage with other compiled program objects to the program exectuable.
Embedded headers. In OpenCL 1.0 and 1.1, the
-Ibuild option could be used to specify the list of directories to be searched for headers files that are included by a program source(s). OpenCL 1.2 extends this by allowing the header sources to come from program objects instead of just header files.
Libraries. The linker can be used to link compiled objects and libraries into a program executable or to create a library of compiled binaries.
CL_SUCCESS if the function is executed successfully.
Otherwise, it returns one of the following errors:
programis not a valid program object.
device_listis NULL and
num_devicesis greater than zero, or if
device_listis not NULL and
pfn_notifyis NULL but
user_datais not NULL.
CL_INVALID_DEVICEif OpenCL devices listed in
device_listare not in the list of devices associated with
programis created with
clCreateProgramWithBinaryand devices listed in
device_listdo not have a valid program binary loaded.
CL_INVALID_BUILD_OPTIONSif the build options specified by
CL_INVALID_OPERATIONif the build of a program executable for any of the devices listed in
device_listby a previous call to
programhas not completed.
programis created with
clCreateProgramWithSourceand a compiler is not available i.e.
CL_DEVICE_COMPILER_AVAILABLEspecified in the table of OpenCL Device Queries for
clGetDeviceInfois set to
CL_BUILD_PROGRAM_FAILUREif there is a failure to build the program executable. This error will be returned if
clBuildProgramdoes not return until the build has completed.
CL_INVALID_OPERATIONif there are kernel objects attached to
programrequires independent forward progress of sub-groups but one or more of the devices listed in
device_listdoes not return
CL_OUT_OF_RESOURCESif there is a failure to allocate resources required by the OpenCL implementation on the device.
CL_OUT_OF_HOST_MEMORYif there is a failure to allocate resources required by the OpenCL implementation on the host.