To build (compile & link) a program executable, call the function
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);
program is the program object.
device_list is a pointer to a list of devices associated with program. If device_list is a
NULLvalue, the program executable is built for all devices associated with program for which a source or binary has been loaded. If device_list is a non-
NULLvalue, the program executable is built for devices specified in this list for which a source or binary has been loaded.
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 build options to be used for building the program executable. The list of supported options is described in Compiler Options. If the program was created using clCreateProgramWithBinary and options is a
NULLpointer, the program will be built as if options were the same as when the program binary was originally built. If the program was created using clCreateProgramWithBinary and options string contains anything other than the same options in the same order (whitespace ignored) as when the program binary was originally built, then the behavior is implementation defined. Otherwise, if options is a
NULLpointer then it will have the same result as the empty string.
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, clBuildProgram does 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 pfn_notify is
NULL, clBuildProgram does not return until the build has completed. This callback function may be called asynchronously by the OpenCL implementation. It is the applications 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
The program executable is built from the program source or binary for all the devices, or a specific device(s) in the OpenCL context associated with program. OpenCL allows program executables to be built using the source or the binary. clBuildProgram must be called for program created using clCreateProgramWithSource, clCreateProgramWithIL or clCreateProgramWithBinary to build the program executable for one or more devices associated with program. If program is created with clCreateProgramWithBinary, then the program binary must be an executable binary (not a compiled binary or library).
The executable binary can be queried using clGetProgramInfo(program,
CL_PROGRAM_BINARIES, …) and can be specified to
clCreateProgramWithBinary to create a new program object.
CL_SUCCESS if the function is executed
Otherwise, it returns one of the following errors:
CL_INVALID_PROGRAMif program is not a valid program object.
CL_INVALID_VALUEif device_list is
NULLand num_devices is greater than zero, or if device_list is not
NULLand num_devices is zero.
CL_INVALID_VALUEif pfn_notify is
NULLbut user_data is not
CL_INVALID_DEVICEif any device in device_list is not in the list of devices associated with program.
CL_INVALID_BINARYif program is created with clCreateProgramWithBinary and devices listed in device_list do not have a valid program binary loaded.
CL_INVALID_BUILD_OPTIONSif the build options specified by options are invalid.
CL_COMPILER_NOT_AVAILABLEif program is created with clCreateProgramWithSource and a compiler is not available i.e.
CL_DEVICE_COMPILER_AVAILABLEspecified in the Device Queries table is set to
CL_BUILD_PROGRAM_FAILUREif there is a failure to build the program executable. This error will be returned if clBuildProgram does not return until the build has completed.
CL_INVALID_OPERATIONif the build of a program executable for any of the devices listed in device_list by a previous call to clBuildProgram for program has not completed.
CL_INVALID_OPERATIONif there are kernel objects attached to program.
CL_INVALID_OPERATIONif program was not created with clCreateProgramWithSource, clCreateProgramWithIL or clCreateProgramWithBinary.
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.
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.
Copyright (c) 2014-2020 Khronos Group. This work is licensed under a Creative Commons Attribution 4.0 International License.