• 2019 Update 4
  • 03/20/2019
  • Public Content
Contents

Using Built-In Functions

OpenCL™ software technology offers a library of built-in functions, including vector variants. Using the built-in functions is typically more efficient than implementing them manually in OpenCL code. For example, consider the following code example:
int tid = get_global_id(0); c[tid] = 1/sqrt(a[tid] + b[tid]);
The following code uses the built-in rsqrt function to implement the same example more efficiently:
int tid = get_global_id(0); c[tid] = rsqrt(a[tid] + b[tid]);
See other examples of simple expressions and built-ins based equivalents below:
dx * fCos + dy * fSin == dot( (float2)(dx, dy),(float2)(fCos, fSin)) x * a - b == mad(x, a, -b) sqrt(dot(x, y)) == distance(x,y)
The only exception is using mul24 as it involves redundant overflow-handling logic:
int iSize = x*y;//prefer general multiplication, not mul24(x,y);
Also use specialized built-in versions where possible. For example, when the
x
value for
xy
is
≥0
, use
powr
instead of
pow
.
See Also
The OpenCL 2.0 C Specification at https://www.khronos.org/registry/cl/specs/opencl-2.0-openclc.pdf

Product and Performance Information

1

Intel's compilers may or may not optimize to the same degree for non-Intel microprocessors for optimizations that are not unique to Intel microprocessors. These optimizations include SSE2, SSE3, and SSSE3 instruction sets and other optimizations. Intel does not guarantee the availability, functionality, or effectiveness of any optimization on microprocessors not manufactured by Intel. Microprocessor-dependent optimizations in this product are intended for use with Intel microprocessors. Certain optimizations not specific to Intel microarchitecture are reserved for Intel microprocessors. Please refer to the applicable product User and Reference Guides for more information regarding the specific instruction sets covered by this notice.

Notice revision #20110804