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

Using Buffers and Images Appropriately

On both CPU and Intel® Graphics devices, buffers usually perform better than images: more data transfers per read or write operation for buffers with much lower latency.
If your algorithm does not require linear data interpolation or specific border modes, consider using buffers instead of images. Still, if your legacy code uses images, or if you want to use the linear interpolation ability of the sampler, consider using the
cl_khr_image2d_from_buffer
extension which offers creating zero copy image aliases for the buffers.
To improve performance on the Intel Graphics, do the following:
  • Consider using images if you need linear interpolation between pixel values.
  • Consider using images for irregular access patterns. For example, use buffers when processing in memory (in row-major) order. Yet prefer image2D and texture sampling your access pattern is other than simple linear. For example, a kernel that reads diagonally or generally irregular positions.
  • Use local memory for explicit caching of data values rather than relying on sampler’s caches, as the caches do not support image
    write
    operations.
  • Notice however, that for (even mildly large) look-up tables the regular global memory is preferable over local memory.
  • Use constant samplers to be able to specify and optimize the sampling behavior in compile time.
  • Consider using the
    CL_ADDRESS_CLAMP_NONE
    as it is the fastest addressing mode, and use
    CL_ADDRESS_CLAMP_TO_EDGE
    rather than
    CL_ADDRESS_CLAMP
    .
In general, image2D sampling on the Intel Graphics offers:
  • Free type conversions. For example,
    uchar4
    to
    uint4
    (unavailable on CPU).
  • Automatic handling image boundaries (slower on the CPU).
  • Fast bilinear sampling (works slow on CPU; may vary between devices).
Notice that images are software-emulated on a CPU. So, make sure to choose the fastest interpolation mode that meets your needs. Specifically:
  • Nearest-neighbor filtering works well for most (interpolating) kernels.
  • Linear filtering might decrease CPU device performance.
See Also

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