'\" t .\" Title: clCompileProgram .\" Author: The Khronos Group .\" Generator: DocBook XSL Stylesheets v1.79.1 .\" Date: 02/03/2019 .\" Manual: OpenCL Manual .\" Source: The Khronos Group .\" Language: English .\" .TH "CLCOMPILEPROGRAM" "3clc" "02/03/2019" "The Khronos Group" "OpenCL Manual" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" clCompileProgram \- Compiles a program\(cqs source for all the devices or a specific device(s) in the OpenCL context associated with program\&. .SH "" .HP \w'cl_int\ clCompileProgram('u .BI "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" ");" .SH "PARAMETERS" .PP \fI program \fR .RS 4 The program object that is the compilation target\&. .RE .PP \fI device_list \fR .RS 4 A pointer to a list of devices associated with \fIprogram\fR\&. If \fIdevice_list\fR is a NULL value, the compile is performed for all devices associated with program\&. If \fIdevice_list\fR is a non\-NULL value, the compile is performed for devices specified in this list\&. .RE .PP \fI num_devices \fR .RS 4 The number of devices listed in \fIdevice_list\fR\&. .RE .PP \fIoptions\fR .RS 4 A pointer to a null\-terminated string of characters that describes the compilation options to be used for building the program executable\&. The list of supported options is as described below\&. .RE .PP \fInum_input_headers\fR .RS 4 Specifies the number of programs that describe headers in the array referenced by \fIinput_headers\fR\&. .RE .PP \fIinput_headers\fR .RS 4 An array of program embedded headers created with \fBclCreateProgramWithSource\fR(3clc)\&. .RE .PP \fIheader_include_names\fR .RS 4 An array that has a one to one correspondence with \fIinput_headers\fR\&. Each entry in \fIheader_include_names\fR specifies the include name used by source in \fIprogram\fR that comes from an embedded header\&. The corresponding entry in \fIinput_headers\fR identifies the program object which contains the header source to be used\&. The embedded headers are first searched before the headers in the list of directories specified by the \(enI compile option (as described in section 5\&.6\&.4\&.1)\&. If multiple entries in \fIheader_include_names\fR refer to the same header name, the first one encountered will be used\&. .RE .PP \fI pfn_notify \fR .RS 4 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 \fIpfn_notify\fR is not NULL, \fBclCompileProgram\fR does 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\&. If \fIpfn_notify\fR is NULL, \fBclCompileProgram\fR does not return until the compiler has completed\&. This callback function may be called asynchronously by the OpenCL implementation\&. It is the application\(cqs responsibility to ensure that the callback function is thread\-safe\&. .RE .PP \fI user_data \fR .RS 4 Passed as an argument when \fIpfn_notify\fR is called\&. \fIuser_data\fR can be NULL\&. .RE .SH "NOTES" .PP Compiles a program\(cqs source for all the devices or a specific device(s) in the OpenCL context associated with \fIprogram\fR\&. The pre\-processor runs before the program sources are compiled\&. The compiled binary is built for all devices associated with \fIprogram\fR or the list of devices specified\&. The compiled binary can be queried using \fBclGetProgramInfo\fR(3clc)(\fIprogram\fR, \fBCL_PROGRAM_BINARIES\fR, \&.\&.\&.) and can be specified to \fBclCreateProgramWithBinary\fR(3clc) to create a new program object\&. Compiler Options.PP 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.PP These options control the OpenCL C preprocessor which is run on each program source before actual compilation\&. .PP \-D options are processed in the order they are given in the options argument to \fBclBuildProgram\fR or or \fBclCompileProgram\fR\&. .PP \-D name .RS 4 Predefine \fIname\fR as a macro, with definition 1\&. .RE .PP \-D name=definition .RS 4 The contents of \fIdefinition\fR are tokenized and processed as if they appeared during translation phase three in a `#define\*(Aq directive\&. In particular, the definition will be truncated by embedded newline characters\&. .RE .PP \-I dir .RS 4 Add the directory \fIdir\fR to the list of directories to be searched for header files\&. .RE Math Intrinsics Options These options control compiler behavior regarding floating\-point arithmetic\&. These options trade off between speed and correctness\&. .PP \-cl\-single\-precision\-constant .RS 4 Treat double precision floating\-point constant as single precision constant\&. .RE .PP \-cl\-denorms\-are\-zero .RS 4 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 precsion 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\&. .sp This option is ignored for single precision numbers if the device does not support single precision denormalized numbers i\&.e\&. \fBCL_FP_DENORM\fR bit is not set in \fBCL_DEVICE_SINGLE_FP_CONFIG\fR\&. .sp This option is ignored for double precision numbers if the device does not support double precision or if it does support double precison but \fBCL_FP_DENORM\fR bit is not set in \fBCL_DEVICE_DOUBLE_FP_CONFIG\fR\&. .sp 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\&. .RE .PP \-cl\-fp32\-correctly\-rounded\-divide\-sqrt .RS 4 The \-cl\-fp32\-correctly\-rounded\-divide\-sqrt build option to \fBclBuildProgram\fR or \fBclCompileProgram\fR allows an application to specify that single precision floating\-point divide (x/y and 1/x) and sqrt used in the program source are correctly rounded\&. If this build option is not specified, the minimum numerical accuracy of single precision floating\-point divide and sqrt are as defined in section 7\&.4 of the OpenCL specification\&. .sp This build option can only be specified if the \fBCL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT\fR is set in \fBCL_DEVICE_SINGLE_FP_CONFIG\fR (as defined in in the table of allowed values for \fIparam_name\fR for \fBclGetDeviceInfo\fR(3clc)) for devices that the program is being build\&. \fBclBuildProgram\fR or \fBclCompileProgram\fR will fail to compile the program for a device if the \-cl\-fp32\-correctly\-rounded\-divide\-sqrt option is specified and \fBCL_FP_CORRECTLY_ROUNDED_DIVIDE_SQRT\fR is not set for the device\&. .RE Optimization Options.PP 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\&. .PP \-cl\-opt\-disable .RS 4 This option disables all optimizations\&. The default is optimizations are enabled\&. .RE .PP 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\&. .PP \-cl\-mad\-enable .RS 4 Allow a * b + c to be replaced by a mad\&. The mad computes a * b + c with reduced accuracy\&. For example, some OpenCL devices implement mad as truncate the result of a * b before adding it to c\&. .RE .PP \-cl\-no\-signed\-zeros .RS 4 Allow optimizations for floating\-point arithmetic that ignore the signedness of zero\&. IEEE 754 arithmetic specifies the distinct behavior of +0\&.0 and \-0\&.0 values, which then prohibits simplification of expressions such as x+0\&.0 or 0\&.0*x (even with \-clfinite\-math only)\&. This option implies that the sign of a zero result isn\*(Aqt significant\&. .RE .PP \-cl\-unsafe\-math\-optimizations .RS 4 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\-zeros and \-cl\-mad\-enable options\&. .RE .PP \-cl\-finite\-math\-only .RS 4 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\&. .RE .PP \-cl\-fast\-relaxed\-math .RS 4 Sets the optimization options \-cl\-finite\-math\-only and \-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\&. .RE 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\&. .PP \-w .RS 4 Inhibit all warning messages\&. .RE .PP \-Werror .RS 4 Make all warnings into errors\&. .RE Options Controlling the OpenCL C Version The following option controls the version of OpenCL C that the compiler accepts\&. .PP \-cl\-std= .RS 4 Determine the OpenCL C language version to use\&. A value for this option must be provided\&. Valid values are: .sp CL1\&.1 \- Support all OpenCL C programs that use the OpenCL C language features defined in section 6 of the OpenCL 1\&.1 specification\&. .sp CL1\&.2 \(en Support all OpenCL C programs that use the OpenCL C language features defined in section 6 of the OpenCL 1\&.2 specification\&. .RE .PP Calls to \fBclBuildProgram\fR or \fBclCompileProgram\fR with the \-cl\-std=CL1\&.1 option will fail to compile the program for any devices with \fBCL_DEVICE_OPENCL_C_VERSION\fR = OpenCL C 1\&.0\&. Calls to \fBclBuildProgram\fR or \fBclCompileProgram\fR with the \-cl\-std=CL1\&.2 option will fail to compile the program for any devices with \fBCL_DEVICE_OPENCL_C_VERSION\fR = OpenCL C 1\&.0 or OpenCL C 1\&.1\&. .PP If the \-cl\-std build option is not specified, the \fBCL_DEVICE_OPENCL_C_VERSION\fR is used to select the version of OpenCL C to be used when compiling the program for each device\&. Options for Querying Kernel Argument Information .PP \-cl\-kernel\-arg\-info .RS 4 This option allows the compiler to store information about the arguments of a kernel(s) in the program executable\&. The argument information stored includes the argument name, its type, the address and access qualifiers used\&. Refer to description of \fBclGetKernelArgInfo\fR(3clc) on how to query this information\&. .RE Linker Options This specification 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\&. These may be extended by a set of vendor\- or platform\-specific options\&. Library Linking Options The following options can be specified when creating a library of compiled binaries\&. .PP \-create\-library .RS 4 Create a library of compiled binaries specified in \fIinput_programs\fR argument to \fBclLinkProgram\fR(3clc)\&. .RE .PP \-enable\-link\-options .RS 4 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 \(encreate\-library option\&. .RE Program Linking Options The following options can be specified when linking a program executable\&. .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \-cl\-denorms\-are\-zero .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \-cl\-no\-signed\-zeroes .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \-cl\-unsafe\-math\-optimizations .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \-cl\-finite\-math\-only .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} \-cl\-fast\-relaxed\-mat .RE The linker may apply these options to all compiled program objects specified to \fBclLinkProgram\fR(3clc)\&. The linker may apply these options only to libraries which were created with the \(enenable\-link\-option\&. Separate Compilation and Linking of Programs.PP OpenCL 1\&.2 extends how programs are compiled and linked to support the following: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} 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\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} Embedded headers\&. In OpenCL 1\&.0 and 1\&.1, the \(enI build 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\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} Libraries\&. The linker can be used to link compiled objects and libraries into a program executable or to create a library of compiled binarie .RE .SH "ERRORS" .PP \fBclCompileProgram\fR returns CL_SUCCESS if the function is executed successfully\&. Otherwise, it returns one of the following errors: .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_PROGRAM if \fIprogram\fR is not a valid program object\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_VALUE if \fIdevice_list\fR is NULL and \fInum_devices\fR is greater than zero, or if \fIdevice_list\fR is not NULL and \fInum_devices\fR is zero\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_VALUE if \fInum_input_headers\fR is zero and \fIheader_include_names\fR or \fIinput_headers\fR are not NULL or if \fInum_input_headers\fR is not zero and \fIheader_include_names\fR or \fIinput_headers\fR are NULL\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_VALUE if \fIpfn_notify\fR is NULL but \fIuser_data\fR is not NULL\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_DEVICE if OpenCL devices listed in \fIdevice_list\fR are not in the list of devices associated with \fIprogram\fR\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_COMPILER_OPTIONS if the compiler options specified by \fIoptions\fR are invalid\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_OPERATION if the compilation or build of a program executable for any of the devices listed in \fIdevice_list\fR by a previous call to \fBclCompileProgram\fR or \fBclBuildProgram\fR for \fIprogram\fR has not completed\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_COMPILER_NOT_AVAILABLE if a compiler is not available i\&.e\&. \fBCL_DEVICE_COMPILER_AVAILABLE\fR specified in in the table of allowed values for \fIparam_name\fR for \fBclGetDeviceInfo\fR(3clc) is set to \fBCL_FALSE\fR\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_COMPILE_PROGRAM_FAILURE if there is a failure to compile the program source\&. This error will be returned if \fBclCompileProgram\fR does not return until the compile has completed\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_OPERATION if there are kernel objects attached to \fIprogram\fR\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_INVALID_OPERATION if program has no source i\&.e\&. it has not been created with \fBclCreateProgramWithSource\fR(3clc)\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_OUT_OF_RESOURCES if there is a failure to allocate resources required by the OpenCL implementation on the device\&. .RE .sp .RS 4 .ie n \{\ \h'-04'\(bu\h'+03'\c .\} .el \{\ .sp -1 .IP \(bu 2.3 .\} CL_OUT_OF_HOST_MEMORY if there is a failure to allocate resources required by the OpenCL implementation on the host\&. .RE .SS "Example" .PP For example, consider the following program source: .TS tab(:); l. T{ #include #include __kernel void image_filter (int n, int m, __constant float *filter_weights, __read_only image2d_t src_image, __write_only image2d_t dst_image) { \&.\&.\&. } T} .TE .sp 1 .PP 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: .TS tab(:); l. T{ 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\(cqs 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] = { \(lqfoo\&.h\(rq, \(lqmydir/myinc\&.h\(rq }; 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 T} .TE .sp 1 .SH "SPECIFICATION" .PP \m[blue]\fBOpenCL Specification\fR\m[]\&\s-2\u[1]\d\s+2 .SH "SEE ALSO" .PP \fBclGetDeviceInfo\fR(3clc) .SH "AUTHORS" .PP \fBThe Khronos Group\fR .SH "COPYRIGHT" .br Copyright \(co 2007-2011 The Khronos Group Inc. .br 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. .sp .SH "NOTES" .IP " 1." 4 OpenCL Specification .RS 4 \%page 139, section 5.6.3 - Separate Compilation and Linking of Programs .RE