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)
program
-
The program object.
device_list
-
A pointer to a list of devices associated with
program
. Ifdevice_list
is a NULL value, the program executable is built for all devices associated withprogram
for which a source or binary has been loaded. Ifdevice_list
is a non-NULL value, the program executable is built for devices specified in this list for which a source or binary has been loaded. num_devices
-
The number of devices listed in
device_list
. options
-
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
program
is created with IL. The list of supported options is described below. pfn_notify
-
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. Ifpfn_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 application’s responsibility to ensure that the callback function is thread-safe. user_data
-
Passed as an argument when
pfn_notify
is called.user_data
can 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 program
.
OpenCL allows program executables to be built using the source or the binary.
clBuildProgram
must be called for program
created using either 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.
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.
clBuildProgram
returns CL_SUCCESS
if the function is executed successfully.
Otherwise, it returns one of the following errors:
-
CL_INVALID_PROGRAM
ifprogram
is not a valid program object. -
CL_INVALID_VALUE
ifdevice_list
is NULL andnum_devices
is greater than zero, or ifdevice_list
is not NULL andnum_devices
is zero. -
CL_INVALID_VALUE
ifpfn_notify
is NULL butuser_data
is not NULL. -
CL_INVALID_DEVICE
if OpenCL devices listed indevice_list
are not in the list of devices associated withprogram
. -
CL_INVALID_BINARY
ifprogram
is created withclCreateProgramWithBinary
and devices listed indevice_list
do not have a valid program binary loaded. -
CL_INVALID_BUILD_OPTIONS
if the build options specified byoptions
are invalid. -
CL_INVALID_OPERATION
if the build of a program executable for any of the devices listed indevice_list
by a previous call toclBuildProgram
forprogram
has not completed. -
CL_COMPILER_NOT_AVAILABLE
ifprogram
is created withclCreateProgramWithSource
and a compiler is not available i.e.CL_DEVICE_COMPILER_AVAILABLE
specified in the table of OpenCL Device Queries forclGetDeviceInfo
is set toCL_FALSE
. -
CL_BUILD_PROGRAM_FAILURE
if there is a failure to build the program executable. This error will be returned ifclBuildProgram
does not return until the build has completed. -
CL_INVALID_OPERATION
if there are kernel objects attached toprogram
. -
CL_INVALID_OPERATION
ifprogram
was not created withclCreateProgramWithSource
,clCreateProgramWithIL
, orclCreateProgramWithBinary
. -
CL_INVALID_OPERATION
if theprogram
requires independent forward progress of sub-groups but one or more of the devices listed indevice_list
does not returnCL_TRUE
for theCL_DEVICE_SUBGROUP_INDEPENDENT_FORWARD_PROGRESS
query. -
CL_OUT_OF_RESOURCES
if there is a failure to allocate resources required by the OpenCL implementation on the device. -
CL_OUT_OF_HOST_MEMORY
if there is a failure to allocate resources required by the OpenCL implementation on the host.