C Specification
To create a program object for a context and load binary bits into that object, call the function
// Provided by CL_VERSION_1_0
cl_program clCreateProgramWithBinary(
cl_context context,
cl_uint num_devices,
const cl_device_id* device_list,
const size_t* lengths,
const unsigned char** binaries,
cl_int* binary_status,
cl_int* errcode_ret);
Parameters
-
context must be a valid OpenCL context.
-
device_list is a pointer to a list of devices that are in context. device_list must be a non-
NULLvalue. The binaries are loaded for devices specified in this list. -
num_devices is the number of devices listed in device_list.
-
lengths is an array of the size in bytes of the program binaries to be loaded for devices specified by device_list.
-
binaries is an array of pointers to program binaries to be loaded for devices specified by device_list. For each device given by device_list[i], the pointer to the program binary for that device is given by binaries[i] and the length of this corresponding binary is given by lengths[i]. lengths[i] cannot be zero and binaries[i] cannot be a
NULLpointer. -
binary_status returns whether the program binary for each device specified in device_list was loaded successfully or not. It is an array of num_devices entries and returns
CL_SUCCESSin binary_status[i] if binary was successfully loaded for device specified by device_list[i]; otherwise returnsCL_INVALID_if lengths[i] is zero or if binaries[i] is aVALUE NULLvalue orCL_INVALID_in binary_status[i] if program binary is not a valid binary for the specified device. If binary_status isBINARY NULL, it is ignored. -
errcode_ret will return an appropriate error code. If errcode_ret is
NULL, no error code is returned.
Description
The devices associated with the program object will be the list of devices specified by device_list. The list of devices specified by device_list must be devices associated with context.
The program binaries specified by binaries will be loaded into the program object. They contain bits that describe one of the following:
-
a program executable to be run on the device(s) associated with context,
-
a compiled program for device(s) associated with context, or
-
a library of compiled programs for device(s) associated with context.
The program binary can consist of either or both:
-
Device-specific code and/or,
-
Implementation-specific intermediate representation (IR) which will be converted to the device-specific code.
OpenCL allows applications to create a program object using the program source or binary and build appropriate program executables. This can be very useful as it allows applications to load program source and then compile and link to generate a program executable online on its first instance for appropriate OpenCL devices in the system. These executables can now be queried and cached by the application. The cached executables can be read and loaded by the application, which can help significantly reduce the application initialization time.
If the cl_khr_ extension is supported, clCreateProgramWithBinary
can be used to load a SPIR binary.
Once a program object has been created from a SPIR binary, clBuildProgram
can be called to build a program executable or clCompileProgram can be
called to compile the SPIR binary.
clCreateProgramWithBinary returns a valid non-zero program object and
errcode_ret is set to CL_SUCCESS if the program object is created
successfully.
Otherwise, it returns a NULL value with one of the following error values
returned in errcode_ret:
-
CL_INVALID_if context is not a valid context.CONTEXT -
CL_INVALID_if device_list isVALUE NULLor num_devices is zero. -
CL_INVALID_if any device in device_list is not in the list of devices associated with context.DEVICE -
CL_INVALID_if lengths or binaries isVALUE NULLor if any entry in lengths[i] is zero or binaries[i] isNULL. -
CL_INVALID_if an invalid program binary was encountered for any device. binary_status will return specific status for each device.BINARY -
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.