CLLINKPROGRAM(3clc)
๐ CLLINKPROGRAM ๐
okay bestie, welcome to the OpenCL Manual page for clLinkProgram โจ this one lives in section 3clc and it's literally the moment where all your little compiled program objects and libraries get smooshed together into one executable. it's giving glow-up ๐
๐ธ NAME ๐ธ
clLinkProgram โ links a set of compiled program objects and libraries for all the devices (or one specific device, no judgement) in the OpenCL context, and creates an executable. yes queen, the final boss of the build pipeline ๐
cl_program clLinkProgram(cl_context context, cl_uint num_devices,
const cl_device_id *device_list,
const char *options,
cl_uint num_input_programs,
const cl_program *input_programs,
void (CL_CALLBACK *pfn_notify) (cl_program program, void *user_data),
void *user_data, cl_int *errcode_ret);
โจ PARAMETERS โจ
here's the whole cast, no one's getting cut ๐ฌ
contextโ must be a valid OpenCL context. non-negotiable, babe.device_listโ a pointer to a list of devices that are incontext. ifdevice_listisNULL, the link happens for all devices associated withcontextthat have a compiled object available. ifdevice_listis non-NULL, the compile is performed for the devices in this list that have a source loaded. (yes, that's what the page says โ copy it verbatim energy ๐ซถ)num_devicesโ how many devices are indevice_list. the headcount ๐งฎoptionsโ a pointer to a null-terminated string of characters describing the link options used to build the program executable. for the full list of supported compiler and linker options, go peek atclBuildProgram(3clc)โ it's the receipts ๐num_input_programsโ the number of programs in the array thatinput_programspoints to.input_programsโ an array of program objects that are compiled binaries or libraries, and they're getting linked into the program executable. for each device indevice_list, or ifdevice_listisNULLthen the list of devices associated withcontext, these are the possible situations:- all programs specified by
input_programscontain a compiled binary or library for the device. in this case, a link is performed to generate a program executable for this device. slay โ - none of the programs contain a compiled binary or library for that device. in this case, no link is performed and there will be no program executable generated for this device. it's giving ghosted ๐ป
- all other cases will return a
CL_INVALID_OPERATIONerror. and that's on periodt ๐ซ
- all programs specified by
pfn_notifyโ a function pointer to a notification routine. this notification routine is a callback function that an application can register, and it gets called when the program executable has been built (successfully or unsuccessfully โ either way, she calls ๐).
if pfn_notify is not NULL, clLinkProgram does not need to wait for the linker to complete and can return immediately once the linking operation can begin. once the linker has completed, the pfn_notify callback function is called, which returns the program object returned by clLinkProgram. the application can then query the link status and log for this program object. heads up: this callback function may be called asynchronously by the OpenCL implementation, so it is the application's responsibility to make sure the callback function is thread-safe. protect your threads, bestie ๐งต๐
if pfn_notify is NULL, clLinkProgram does not return until the linker has completed. no skipping ahead โ
user_dataโ will be passed as an argument whenpfn_notifyis called.user_datacan beNULL. lowkey the chillest param here.
๐ NOTES ๐
clLinkProgram creates a new program object that contains this executable. you can query that executable binary with clGetProgramInfo(3clc)(program, CL_PROGRAM_BINARIES, ...) and you can hand it over to clCreateProgramWithBinary(3clc) to create a new program object. it's giving โจrecycling eraโจ
the devices associated with the returned program object will be the list of devices specified by device_list, or if device_list is NULL it'll be the list of devices associated with context.
the linking operation can begin if the context, the list of devices, the input programs and the linker options specified are all valid, and the appropriate host and device resources needed to perform the link are available. if the linking operation can begin, clLinkProgram returns a valid non-zero program object. ๐ฏ
๐ ERRORS ๐
if pfn_notify is NULL, the errcode_ret will be set to CL_SUCCESS if the link operation was successful, and CL_LINK_FAILURE if there is a failure to link the compiled binaries and/or libraries.
if pfn_notify is not NULL, clLinkProgram does not have to wait until the linker completes and can return CL_SUCCESS in errcode_ret if the linking operation can begin. the pfn_notify callback function will return a CL_SUCCESS or CL_LINK_FAILURE depending on whether the linking operation was successful or not.
otherwise clLinkProgram returns a NULL program object with an appropriate error in errcode_ret. the application should query the linker status of this program object to check if the link was successful or not. here's the full roster of errors that can be returned, don't skip any ๐ซฃ:
CL_INVALID_CONTEXTifcontextis not a valid context.CL_INVALID_VALUEifdevice_listisNULLandnum_devicesis greater than zero, or ifdevice_listis notNULLandnum_devicesis zero.CL_INVALID_VALUEifnum_input_programsis zero andinput_programsisNULL, or ifnum_input_programsis zero andinput_programsis notNULL, or ifnum_input_programsis not zero andinput_programsisNULL.CL_INVALID_PROGRAMif programs specified ininput_programsare not valid program objects.CL_INVALID_VALUEifpfn_notifyisNULLbutuser_datais notNULL.CL_INVALID_DEVICEif OpenCL devices listed indevice_listare not in the list of devices associated withcontext.CL_INVALID_LINKER_OPTIONSif the linker options specified byoptionsare invalid.CL_INVALID_OPERATIONif the compilation or build of a program executable for any of the devices listed indevice_listby a previous call toclCompileProgram(3clc)orclBuildProgram(3clc)for program has not completed.CL_INVALID_OPERATIONif the rules for devices containing compiled binaries or libraries as described in theinput_programsargument above are not followed.CL_LINKER_NOT_AVAILABLEif a linker is not available, i.e.CL_DEVICE_LINKER_AVAILABLEspecified in the table of allowed values forparam_nameforclGetDeviceInfo(3clc)is set toCL_FALSE.CL_LINK_PROGRAM_FAILUREif there is a failure to link the compiled binaries and/or libraries.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.
๐ SPECIFICATION ๐
OpenCL Specification[1] โ the source of truth, the blueprint, the origin story ๐
๐ SEE ALSO ๐
clGetDeviceInfo(3clc) โ go read it, it's right there, bestie ๐ซถ
โ๏ธ AUTHORS โ๏ธ
The Khronos Group โ the icons who wrote all this down ๐
ยฉ๏ธ COPYRIGHT ยฉ๏ธ
Copyright ยฉ 2007-2011 The Khronos Group Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and/or associated documentation files (the "Materials"), to deal in the Materials without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Materials, and to permit persons to whom the Materials are furnished to do so, subject to the condition that this copyright notice and permission notice shall be included in all copies or substantial portions of the Materials.
๐ NOTES ๐
- OpenCL Specification โ page 142, section 5.6.3 - Separate Compilation and Linking of Programs. that's the exact page, go look it up ๐
and that's the whole page, no cap ๐ this was the CLLINKPROGRAM(3clc) manpage from The Khronos Group, dated 01/14/2021, and honestly? she ate. go link something iconic โจ๐ฆ๐
๐ฆ where this page comes from
- ubuntu jammy: opencl-1.2-man-doc 1.0~svn33624-5 ยท other
- ubuntu noble: opencl-1.2-man-doc 1.0~svn33624-5 ยท other
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms