CLCOMPILEPROGRAM(3clc)
π clCompileProgram(3clc) β OpenCL Manual π
okay bestie, gather round. This is the clCompileProgram page, and she is long, so we're doing part 1. No cap.
β¨ NAME β¨
clCompileProgram β compiles a program's source for all the devices or a specific device(s) in the OpenCL context associated with program. That's the whole vibe.
cl_int clCompileProgram(cl_program program, cl_uint num_devices,
const cl_device_id *device_list,
const char *options, cl_uint num_input_headers,
const cl_program *input_headers,
const char **header_include_names,
void (CL_CALLBACK *pfn_notify)( cl_program program, void *user_data),
void *user_data);
πΈ PARAMETERS πΈ
programβ the program object that is the compilation target. She's the main character here.device_listβ pointer to a list of devices associated withprogram. Ifdevice_listisNULL, the compile runs for all devices associated withprogram. Ifdevice_listis a non-NULLvalue, the compile runs for the devices specified in this list.num_devicesβ the number of devices listed indevice_list.optionsβ pointer to a null-terminated string of characters describing the compilation options used for building the program executable. The list of supported options is below, bestie.num_input_headersβ number of programs that describe headers in the array referenced byinput_headers.input_headersβ an array of program embedded headers created withclCreateProgramWithSource(3clc).header_include_namesβ array with a one-to-one correspondence withinput_headers. Each entry specifies the include name used by source inprogramthat comes from an embedded header. The corresponding entry ininput_headersidentifies the program object containing the header source to be used. Embedded headers are searched first before the headers in the list of directories specified by theβIcompile option (as described in section 5.6.4.1). If multiple entries inheader_include_namesrefer to the same header name, the first one encountered will be used.pfn_notifyβ 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). Ifpfn_notifyis notNULL,clCompileProgramdoes not need to wait for the compiler to complete and can return immediately once the compilation can begin. The compilation can begin if the context, program whose sources are being compiled, list of devices, input headers, programs that describe input headers and compiler options specified are all valid and appropriate host and device resources needed to perform the compile are available. Ifpfn_notifyisNULL,clCompileProgramdoes not return until the compiler 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 whenpfn_notifyis called.user_datacan beNULL.
π¦ NOTES π¦
clCompileProgram compiles a program's source for all devices or a specific device(s) in the OpenCL context associated with program. The pre-processor runs before the program sources are compiled. The compiled binary is built for all devices associated with program or the list of devices specified. The compiled binary can be queried using clGetProgramInfo(3clc)(program, CL_PROGRAM_BINARIES, ...) and can be specified to clCreateProgramWithBinary(3clc) to create a new program object.
Compiler Options. 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.
π Preprocessor 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 clBuildProgram or or clCompileProgram.
-D nameβ Predefinenameas a macro, with definition1.-D name=definitionβ The contents ofdefinitionare tokenized and processed as if they appeared during translation phase three in a#definedirective. In particular, the definition will be truncated by embedded newline characters.-I dirβ Add the directorydirto the list of directories to be searched for header files.
π Math Intrinsics Options π
These options control compiler behavior regarding floating-point arithmetic. These options trade off between speed and correctness.
-cl-single-precision-constantβ Treat double precision floating-point constant as single precision constant.-cl-denorms-are-zeroβ 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 precision 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_DENORM bit is not set in CL_DEVICE_SINGLE_FP_CONFIG.
This option is ignored for double precision numbers if the device does not support double precision or if it does support double precision but CL_FP_DENORM bit is not set in CL_DEVICE_DOUBLE_FP_CONFIG.
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-sqrtβ The-cl-fp32-correctly-rounded-divide-sqrtbuild option toclBuildProgramorclCompileProgramallows an application to specify that single precision floating-point divide (x/yand1/x) andsqrtused in the program source are correctly rounded. If this build option is not specified, the minimum numerical accuracy of single precision floating-point divide andsqrtare as defined in section 7.4 of the OpenCL specification.
This build option can only be specified if the CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT is set in CL_DEVICE_SINGLE_FP_CONFIG (as defined in the table of allowed values for param_name for clGetDeviceInfo(3clc)) for devices that the program is being build. clBuildProgram or clCompileProgram will fail to compile the program for a device if the -cl-fp32-correctly-rounded-divide-sqrt option is specified and CL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT is not set for the device.
β¨ Optimization Options β¨
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.
-cl-opt-disableβ 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.
-cl-mad-enableβ Allowa * b + cto be replaced by amad. Themadcomputesa * b + cwith reduced accuracy. For example, some OpenCL devices implementmadas truncate the result ofa * bbefore adding it toc.-cl-no-signed-zerosβ Allow optimizations for floating-point arithmetic that ignore the signedness of zero. IEEE 754 arithmetic specifies the distinct behavior of+0.0and-0.0values, which then prohibits simplification of expressions such asx+0.0or0.0*x(even with-clfinite-mathonly). This option implies that the sign of a zero result isn't significant.-cl-unsafe-math-optimizationsβ 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-cl-no-signed-zerosand-cl-mad-enableoptions.-cl-finite-math-onlyβ 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.-cl-fast-relaxed-mathβ Sets the optimization options-cl-finite-math-onlyand-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 causes the preprocessor macro__FAST_RELAXED_MATH__to be defined in the OpenCL program.
πΈ Options to Request or Suppress Warnings πΈ
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 languageindependent options do not enable specific warnings but control the kinds of diagnostics produced by the OpenCL compiler.
-wβ Inhibit all warning messages.-Werrorβ Make all warnings into errors.
π Options Controlling the OpenCL C Version π
The following option controls the version of OpenCL C that the compiler accepts.
-cl-std=β Determine the OpenCL C language version to use. A value for this option must be provided. Valid values are:CL1.1β bestie, this one supports all the OpenCL C programs that use the OpenCL C language features defined in section 6 of the OpenCL 1.1 specification. periodt. β¨CL1.2β same energy, but for the OpenCL C language features defined in section 6 of the OpenCL 1.2 specification. slay. π
okay so listen π calls toclBuildProgramorclCompileProgramwith the-cl-std=CL1.1option will fail to compile the program for any devices withCL_DEVICE_OPENCL_C_VERSION= OpenCL C 1.0. and calls toclBuildProgramorclCompileProgramwith the-cl-std=CL1.2option will fail to compile the program for any devices withCL_DEVICE_OPENCL_C_VERSION= OpenCL C 1.0 or OpenCL C 1.1. like it's just not gonna happen, no cap π
If the -cl-std build option is not specified, the CL_DEVICE_OPENCL_C_VERSION is used to select the version of OpenCL C to be used when compiling the program for each device. it just picks for u, main character behavior fr π«Ά
πΈ Options for Querying Kernel Argument Information πΈ
-cl-kernel-arg-infoβ this lets the compiler stash info about the arguments of a kernel(s) inside the program executable. and what info exactly?? the argument name, its type, the address and access qualifiers used. so if u wanna know, go check the description ofclGetKernelArgInfo(3clc)for how to query all that. iykyk π
π Linker Options π
okay so this spec 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. and they may be extended by a set of vendor- or platform-specific options, because of course they can π
π Library Linking Options π
the following options can be specified when creating a library of compiled binaries.
-create-libraryβ create a library of compiled binaries specified in theinput_programsargument toclLinkProgram(3clc). literally what it says on the tin β¨-enable-link-optionsβ 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-create-libraryoption. it's a package deal bestie, no solo acts π
π« Program Linking Options π«
the following options can be specified when linking a program executable.
-cl-denorms-are-zero-cl-no-signed-zeroes-cl-unsafe-math-optimizations-cl-finite-math-only-cl-fast-relaxed-mat
The linker may apply these options to all compiled program objects specified to clLinkProgram(3clc). The linker may apply these options only to libraries which were created with the -enable-link-option. so likeβ¦ it may. it also may not. the suspense is real π
π¦ Separate Compilation and Linking of Programs π¦
OpenCL 1.2 extends how 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. two whole moments, iconic π
- 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. glow up fr π - Libraries. The linker can be used to link compiled objects and libraries into a program executable or to create a library of compiled binarie
π ERRORS π
clCompileProgram returns CL_SUCCESS if the function is executed successfully. otherwise, it returns one of the following errors β buckle up bestie, it's a list π
CL_INVALID_PROGRAMifprogramis not a valid program object.CL_INVALID_VALUEifdevice_listisNULLandnum_devicesis greater than zero, or ifdevice_listis notNULLandnum_devicesis zero.CL_INVALID_VALUEifnum_input_headersis zero andheader_include_namesorinput_headersare notNULLor ifnum_input_headersis not zero andheader_include_namesorinput_headersareNULL.CL_INVALID_VALUEifpfn_notifyisNULLbutuser_datais notNULL.CL_INVALID_DEVICEif OpenCL devices listed indevice_listare not in the list of devices associated withprogram.CL_INVALID_COMPILER_OPTIONSif the compiler 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 toclCompileProgramorclBuildProgramforprogramhas not completed.CL_COMPILER_NOT_AVAILABLEif a compiler is not available i.e.CL_DEVICE_COMPILER_AVAILABLEspecified in in the table of allowed values forparam_nameforclGetDeviceInfo(3clc)is set toCL_FALSE.CL_COMPILE_PROGRAM_FAILUREif there is a failure to compile the program source. This error will be returned ifclCompileProgramdoes not return until the compile has completed.CL_INVALID_OPERATIONif there are kernel objects attached toprogram.CL_INVALID_OPERATIONifprogramhas no source i.e. it has not been created withclCreateProgramWithSource(3clc).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.
β¨ Example β¨
for example, consider the following program source:
#include <foo.h>
#include <mydir/myinc.h>
__kernel void image_filter (int n, int m, __constant float *filter_weights,
__read_only image2d_t src_image,
__write_only image2d_t dst_image) {
...
}
This kernel includes two headers foo.h and mydir/myinc.h. The following describes how these headers can be passed as embedded headers in program objects:
cl_program foo_pg = clCreateProgramWithSource(context, 1,
&foo_header_src, NULL, &err);
cl_program myinc_pg = clCreateProgramWithSource(context, 1,
&myinc_header_src, NULL, &err);
// letβs assume the program source described above is given
// by program_A and is loaded via clCreateProgramWithSource
cl_program input_headers[2] = { foo_pg, myinc_pg };
char * input_header_names[2] = { "foo.h", "mydir/myinc.h" };
clCompileProgram(program_A,
0, NULL, // num_devices & device_list
NULL, // compile_options
2, // num_input_headers
input_headers,
input_header_names,
NULL, NULL); // pfn_notify & user_data
π SPECIFICATION π
OpenCL Specification[1]
π SEE ALSO π
π«Ά AUTHORS π«Ά
The Khronos Group
π 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 139, section 5.6.3 - Separate Compilation and Linking of Programs
and that's the whole page bestie, we ate and left no crumbs π this was brought to u by The Khronos Group, dated 01/14/2021, and it lives in the man page CLCOMPILEPROGRAM(3clc) β go forth and compile responsibly π
π¦ 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