• 10/30/2018
  • Public Content
Contents

Use Built-In Functions

OpenCL™ offers a library of built-in functions, including vector variants. For details, see the OpenCL specification.
Using built-in functions is typically more efficient than using their manual implementation in OpenCL code. Consider the following code example:
__kernel void Foo(const __global float* a,                           const __global float* b,                           __global float* c) {   int tid = get_global_id(0);   c[tid] = 1/sqrt(a[tid] + b[tid]); }
The following code uses the
rsqrt
built-in to implement the same example:
__kernel void Foo(const __global float* a,                           const __global float* b,                           __global float* c) {   int tid = get_global_id(0);   c[tid] = rsqrt(a[tid] + b[tid]); }
Consider 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)
Use specialized built-in versions like
math
,
integer
, and
geometric
built-ins, where possible, as the specialized built-ins work faster than their manually-computed counterparts. For example, when the
x
value for
xy
is ≥0, use
powr
instead of
pow
.

See Also

The OpenCL™ 1.2 Specification at

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