The opencl™ specification
Содержание:
Notes on Textures, Formats, and Targets
There is a well-defined list of OpenGL texture usages (“targets”) that can be shared:
- An OpenCL (1D, 2D, 3D) image object can be created from the regular OpenGL (1D, 2D, 3D) texture.
- A 2D OpenCL image can be created from single face of an OpenGL cubemap texture.
- An OpenCL 1D or 2D image array can be created from an OpenGL 1D or 2D texture array.
Refer to Table 9.4 in the The OpenCL Extension Specification, Version 1.2 that describes the list of GL texture internal formats and the corresponding image formats in OpenCL. These are the most important four-channel formats, such as GL_RGBA8 or GL_RGBA32F, for which the mapping is guaranteed.
Textures created with other OpenGL internal formats may also have a mapping to a CL image format. So, if such mappings exist (they are implementation-specific), the clCreateFromGLTexture succeeds; otherwise it fails with CL_INVALID_IMAGE_FORMAT_DESCRIPTOR.
Note that single-channel textures are generally not supported for sharing.
Also note that OpenGL depth (depth-stencil) buffer sharing is subject for separate cl_khr_depth_images and cl_khr_gl_depth_images extensions, which we do not cover in this tutorial.
Finally, multi-sampled (MSAA) textures, both color and depth, are subject for cl_khr_gl_msaa_sharing (which requires cl_khr_gl_depth_images support from the implementation).
2018
18.1
Overview
- Support of Intel Advanced Vector Extensions 512 (Intel AVX-512) ISA on Intel Xeon Platinum processor (formerly code name Skylake)
- Support for vectorization width 16 for the environment and configuration file variable CL_CONFIG_CPU_VECTORIZER_MODE, as well as for OpenCL C optional kernel attribute intel_vec_len_hint
- Support for OpenCL Kernel debugging on Linux* OS with GDB*
- Improved coexistence support with Intel Graphics Compute Runtime for OpenCL Driver when both are installed.
- Changed the platform name returned via clGetPlatformInfo(…) OpenCL API call with CL_PLATFORM_NAME bitflag to “Intel(R) CPU Runtime for OpenCL(TM) Applications”
- New environment variable CL_CONFIG_CPU_TARGET_ARCH. It generates code exclusively for a given target CPU architecture. Allows only lowering the instruction set level supported by CPU:
Allowed values are:
|
skx |
Generates code for processors that support Intel Advanced Vector Extensions 512 (Intel AVX-512) Foundation instructions, Intel AVX-512 Conflict Detection instructions, Intel AVX-512 Doubleword and Quadword instructions, Intel AVX-512 Byte and Word instructions and Intel AVX-512 Vector Length Extensions for Intel processors, and the instructions enabled with core-avx2. |
|
core-avx2 |
Generates code for processors that support Intel Advanced Vector Extensions 2 (Intel AVX2), Intel AVX, SSE4.2 SSE4.1, SSE3, SSE2, SSE, and SSSE3 instructions. |
|
corei7-avx |
Generates code for processors that support Intel Advanced Vector Extensions (Intel AVX), Intel SSE4.2, SSE4.1, SSE3, SSE2, SSE, and SSSE3 instructions. |
|
corei7 |
Generates code for processors that support Intel SSE4.2 Efficient Accelerated String and Text Processing instructions. May also generate code for Intel SSE4 Vectorizing Compiler and Media Accelerator, Intel SSE3, SSE2, SSE, and SSSE3 instructions. |
- Fixed an issue with user functions not being inlined in programs created using clCreateProgramWithIL(…) OpenCL API call
- Fixed incorrectly reported CL_DEVICE_MAX_COMPUTE_UNITS for multi-socket Intel Xeon systems (reported on forum https://software.intel.com/en-us/forums/opencl/topic/702240)
- Fixed incompatibility with Intel Threading Building Blocks (Intel TBB) max_allowed_parallelism parameter
- Fixed an issue with CL_DRIVER_VERSION returning incorrect driver version
- Improved OpenCL C compiler diagnostics
- Minor bug fixes
- Updated the compiler infrastructure to LLVM* version 6.0
- Intel CPU Runtime for OpenCL Applications 18.1 supports CPU only. For Intel Xeon Phi coprocessor support, use the version 14.2. For more information, see OpenCL runtime entry and release notes on the OpenCL driver page at: /content/www/us/en/develop/articles/opencl-drivers.html .
Creating the Interoperability-Capable OpenCL Context
Since OpenCL memory objects are created from OpenGL objects, we need some sort of shared OpenCL-OpenGL context. To avoid implicit copying via host, it is important to create OpenCL context for the same underlying device that drives the OpenGL context as well.
Via clGetGLContextInfoKHR, you can enumerate all OpenCL devices capable of sharing with the OpenGL context you are willing to interop. First, you need to set up additional context parameters:
For the fastest interoperability, it is important to select a device currently associated with the given OpenGL context (CL_CURRENT_DEVICE_FOR_GL_CONTEXT_KHR flag for the clGetGLContextInfoKHR).
Notice that there are potentially many more OpenCL devices that can potentially share the data with the OpenGL context (e.g. via copies). In the code example below, we use clGetGLContextInfoKHR with CL_DEVICES_FOR_GL_CONTEXT_KHR to enumerate all interoperable devices:
This tutorial supports selecting the platform and device to run (refer to the section on controlling the sample), so after identifying the available devices (that support cl_khr_gl_sharing) for the requested platform, the “OpenGL-shared” OpenCL context is created along with a queue for the selected device:
Once we established a shared OpenCL-OpenGL context we can implement sharing using one of three basic ways described below:
OpenCL-OpenGL Interoperability API
OpenCL-OpenGL interoperability is implemented as a Khronos extension to OpenCL . The name of this extension is cl_khr_gl_sharing, and it should be listed among the supported extensions queried for the platform and the device.
The interfaces (API) for this extension are provided in the cl_gl.h header.
Just as with other vendor extension APIs, the clGetExtensionFunctionAddressForPlatform function should be used to provide pointers to the actual functions of the specific OpenCL platform. Following is the full list of functions for the extension and a short description for each:
|
Function |
Description |
|---|---|
|
Queries the devices associated with the OpenGL context |
|
|
Creates an OpenCL buffer object from the OpenGL buffer object |
|
|
Creates an OpenCL image object from the OpenGL texture object |
|
|
Creates an OpenCL 2D image object from the OpenGL render buffer |
|
|
Queries type and name for the OpenGL object used to create the OpenCL memory object |
|
|
Gets additional information (target and mipmap level) about the GL texture object associated with a memory object |
|
|
Acquires OpenCL memory objects from OpenGL |
|
|
Releases OpenCL memory objects to OpenGL |
2014
14.2 (deprecated)
- Added support for offline kernel compilation and kernel binary distribution on Intel Xeon Phi coprocessors. With this release, on both Intel Xeon Phi coprocessor and Intel CPU, the kernel binary is the final executable binary in contrast to the previous release, where the kernel binary on Intel Xeon Phi coprocessor was an intermediate code.
- Improved kernel invocation time on Intel Xeon Phi coprocessor device in case of batching kernel commands into in-order queues
- Optimized compiler vectorizer
- New feature — User logger for API tracing and debugging functional failures in OpenCL applications
- New environment variable
- SPIR is now conformant on Intel Xeon Phi coprocessor
- Bug fixes
14.1 (deprecated)
Develop OpenCL Applications
Tools to develop OpenCL applications for Intel Processors
Intel oneAPI: DPC++ Compiler
- DPC++/SYCL programs can run SYCL kernels by way of underlying OpenCL implementations.
- OpenCL-C kernels can also be directly ingested and run by a SYCL runtime. Users of the OpenCL C++ API wrapper may find the SYCL specification particularly appealing.
- As of article publication, this compiler is in Beta.
Intel System Studio
- For compilation, cross-platform, IoT, power considerate development, and performance analysis.
- OpenCL development tools component:
- Develop OpenCL applications targeting Intel Xeon Processors, Intel Core Processors, and/or Intel Graphics Technology.
- Develop applications with expanded IDE functionality, debug, and analysis tools.
- Earlier versions of the SDK contain an experimental OpenCL 2.1 implementation. Intel CPU Runtime for OpenCL Applications 18.1 was intended as a replacement for the experimental implementation.
- OpenCL development tools component:
- Visit the Intel System Studio portal
Intel SDK for OpenCL Applications
- Standalone distribution of Intel System Studio: OpenCL Tools component.
- Develop OpenCL Applications targeting Intel Xeon Processors, Intel Core Processors, and/or Intel Graphics Technology.
- Develop applications with expanded IDE functionality, debug, and analysis tools.
- Note: Some debug and analysis features have been removed from recent versions of the SDK.
- Earlier versions of the SDK contain an experimental OpenCL 2.1 implementation suitable for development testing on CPU OpenCL targets. Intel CPU Runtime for OpenCL Applications 18.1 was intended as a replacement for that experimental implementation.
- See release notes, requirements, and download links through the Intel SDK for OpenCL Applications portal.
Intel FPGA SDK for OpenCL Software Technology
- Build OpenCL Applications and OpenCL kernels for Intel FPGA devices.
- See release notes, requirements, and download links through the SDK’s portal webpage.
- For OpenCL runtimes and required system drivers, visit Download Center for FPGAs.
Intel Distribution of OpenVINO toolkit
-
The Intel Distribution of OpenVINO toolkit is available for vision and deep learning inference. It benefits from OpenCL acceleration for each of these components:
- Intel Deep Learning Deployment Toolkit
- OpenCV
- OpenVX*
- The Intercept Layer for Debugging and Analyzing OpenCL Applications (clIntercept) can intercept, report, and modify OpenCL API calls.
- No application-level modifications nor OpenCL implementation modifications are necessary.
- clIntercept functionality can supplement removed functionality from recent releases of the Intel SDK for OpenCL Applications.
Driver/Runtime Packages Available
GPU/CPU Driver Packages
- (Also automatically shipped with Windows graphics drivers)
CPU-only Runtime Packages
OpenCL Runtime for Intel Core and Intel Xeon Processors
Intel SDK for OpenCL Applications 2017 R2 for Linux (64-bit)
This is a standalone release for customers who do not need integration with the Intel Media Server Studio. It provides components to develop OpenCL applications for Intel processors.
Visit https://software.intel.com/en-us/intel-opencl to download the version for your platform. For details check out the Release Notes.
Intel SDK for OpenCL Applications 2017 R2 for Windows* (64-bit)
This is a standalone release for customers who do not need integration with the Intel Media Server Studio. The standard Windows graphics driver packages contains the driver and runtime library components necessary to run OpenCL applications. This package provides components for OpenCL development.
Visit https://software.intel.com/en-us/intel-opencl to download the version for your platform. For details check out the Release Notes.
OpenCL 2.0 GPU/CPU driver package for Linux* (64-bit)
The intel-opencl-r5.0 (SRB5.0) Linux driver package enables OpenCL 1.2 or 2.0 on the GPU/CPU for the following Intel processors:
- Intel 5th, 6th or 7th generation Core processor
- Intel Celeron Processor J3000 Series with Intel HD Graphics 500 (J3455, J3355), Intel Pentium Processor J4000 Series with Intel HD Graphics 505 (J4205), Intel Celeron Processor N3000 Series with Intel HD Graphics 500 (N3350, N3450), Intel Pentium Processor N4000 Series with Intel HD Graphics 505 (N4200)
- Intel Xeon v4, or Intel Xeon v5 Processors with Intel Graphics Technology (if enabled by OEM in BIOS and motherboard)
Installation Instructions. Scripts to automate install and additional install documentation available here.
Intel validates the intel-opencl-r5.0 driver on CentOS 7.2 and 7.3 when running the following 64-bit kernels:
- Linux 4.7 kernel patched for OpenCL
- Linux 4.4 kernel patched for Intel Media Server Studio 2017 R3
Although Intel validates and provides technical support only for the above Linux kernels on CentOS 7.2 and 7.3, other distributions may be adapted by utilizing our generic operating system installation steps as well as MSS 2017 R3 installation steps.
In addition: Intel also validates Ubuntu 16.04.2 when running the following 64-bit kernel:
•Ubuntu 16.04.2 default 4.8 kernel
Ubuntu 16.04 with the default kernel works fairly well but some core features (i.e. device enqueue, SVM memory coherency, VTune support) won’t work without kernel patches. This configuration has been minimally validated to prove that it is viable to suggest for experimental use, but it is not fully supported or certified.
Supported OpenCL devices:
- Intel graphics (GPU)
- CPU
For detailed information please see the driver package Release Notes.
Previous Linux driver packages:
| Intel intel-opencl-r4.1 (SRB4.1) Linux driver package | Installation instructions | Release Notes |
| Intel intel-opencl-r4.0 (SRB4) Linux driver package | Installation instructions | Release Notes |
| SRB3.1 Linux driver package | Installation instructions | Release Notes |
For Linux drivers covering earlier platforms such as 4th generation Intel Core processor please see the versions of Media Server Studio in the Driver Support Matrix.
OpenCL Driver for Iris graphics and Intel HD Graphics for Windows* OS (64-bit and 32-bit)
The standard Intel graphics drivers for Windows* include components needed to run OpenCL* and Intel Media SDK applications on processors with Intel Iris Graphics or Intel HD Graphics on Windows* OS.
You can use the Intel Driver Update Utility to automatically detect and update your drivers and software. Using the latest available graphics driver for your processor is usually recommended.
Supported OpenCL devices:
- Intel graphics (GPU)
- CPU
For the full list of Intel Architecture processors with OpenCL support on Intel Graphics under Windows*, refer to the Release Notes.
2014
14.2 (deprecated)
- Added support for offline kernel compilation and kernel binary distribution on Intel Xeon Phi coprocessors. With this release, on both Intel Xeon Phi coprocessor and Intel CPU, the kernel binary is the final executable binary in contrast to the previous release, where the kernel binary on Intel Xeon Phi coprocessor was an intermediate code.
- Improved kernel invocation time on Intel Xeon Phi coprocessor device in case of batching kernel commands into in-order queues
- Optimized compiler vectorizer
- New feature — User logger for API tracing and debugging functional failures in OpenCL applications
- New environment variable
- SPIR is now conformant on Intel Xeon Phi coprocessor
- Bug fixes
14.1 (deprecated)
2016
16.1.2
Overview:
- New optional __attribute__((intel_vec_len_hint(<uint>)))
- This attribute can be used to provide a hint to the compiler that the kernel will perform best if vectorized to the specified vector length.
- You can specify one of the following lengths for this attribute:
uint Description The compiler uses heuristics to decide whether to vectorize the kernel,
and if so, which vector length to use. This is the default behavior.1 No vectorization is performed by the compiler. Explicit vector data types
in kernels are left intact.4 Disables heuristics and vectorizes to the length of 4 respectively. 8 Disables heuristics and vectorizes to the length of 8 respectively.
- New OpenCL C predefined macro __INTEL_OPENCL_CPU_<CPUSIGN>
- This macro can be used to fine tune the kernel for a specific CPU device microarchitecture. <CPUSIGN> is the CPU signature of a device.
- You can specify one of the following values for this macro:
Macro Intel Microarchitectures __INTEL_OPENCL_CPU_SKL__ Intel microarchitecture code name Skylake __INTEL_OPENCL_CPU_SKX__ Intel microarchitecture code name
Skylake on Intel Xeon processor family__INTEL_OPENCL_CPU_BDW__ Intel microarchitecture code name
Broadwell__INTEL_OPENCL_CPU_BDW_XEON__ Intel microarchitecture code name Broadwell on Intel Xeon processor family __INTEL_OPENCL_CPU_HSW__ Intel microarchitecture code name Haswell __INTEL_OPENCL_CPU_HSW_XEON__ Intel microarchitecture code name Haswell on Intel Xeon processor family __INTEL_OPENCL_CPU_IVB__ Intel microarchitecture code name Ivy Bridge __INTEL_OPENCL_CPU_IVB_XEON__ Intel microarchitecture code name Ivy Bridge on Intel Xeon processor family __INTEL_OPENCL_CPU_SNB__ Intel microarchitecture code name Sandy Bridge __INTEL_OPENCL_CPU_SNB_XEON__ Intel microarchitecture code name Sandy Bridge on Intel Xeon processor family __INTEL_OPENCL_CPU_WST__ Intel microarchitecture code name Westmere __INTEL_OPENCL_CPU_WST_XEON__ Intel microarchitecture code name Westmere on Intel Xeon processor family __INTEL_OPENCL_CPU_UNKNOWN__ Unknown microarchitecture
- Improved heuristics for choosing local size when ndrange is enqueued to the
command queue that was created with
CL_QUEUE_THREAD_LOCAL_EXEC_ENABLE_INTEL property (extension
https://www.khronos.org/registry/OpenCL/extensions/intel/cl_intel_thread_local_exec.
txt). - A fix for a previous issue where an incorrect library was loaded when running on Intel
microarchitecture code name Skylake.
16.1.1
Overview:
- Fix for the known incompatibility issue with the CPU Kernel Debugger from the Intel SDK for OpenCL Applications 2016 R2 and the CPU only runtime package version 16.1.
- Performance optimizations:
- Compiler vectorizer heuristic tuning for a set of workloads
- Workgroup fusion optimization improvements
- Performance enhancements of the vload()/vstore() built-in functions
- Fix for the issue reported on the forum (): vectorizer produces incorrect code on SSE42 architectures when using the samplerless read_imagef() built-in function with image2d_t and int2 coordinates as arguments.
- cl_khr_gl_sharing extension was disabled due to incompatibility with the Microsoft* Basic Display Adapter. To use this extension, please install OpenCL Driver for Intel Iris Graphics and HD Graphics for Windows* OS from . The driver package includes the OpenCL Runtime package for CPUs.
- Due to performance bug Threading Building Blocks (TBB) library was downgraded from 4.2,Interface version 7001, Oct 2 2013″ to 4.2, Interface version 7005 , Jun 1 2014
16.1
Overview:
- Support for Intel Core 6th generation and Xeon v4 processors (former Intel microarchitecture codename Broadwell)
- Support for OpenCL 2.0 specification
- Improved cross-CPU support of pre-compiled kernel binary in Runtime:
- Enables loading pre-generated kernel binaries that saves OpenCL program build time. For more information, see https://software.intel.com/en-us/node/540584
- Enables generating a JIT binary for target CPU model by the Intel SDK for OpenCL — Offline Compiler. For more information, see https://software.intel.com/en-us/node/539388
- Bug and memory leak fixes.
- Compiler infrastructure was updated to LLVM version 3.6.2
Driver/Runtime Packages Available
GPU/CPU Driver Packages
- (Also automatically shipped with Windows graphics drivers)
CPU-only Runtime Packages
OpenCL Runtime for Intel Core and Intel Xeon Processors
Intel SDK for OpenCL Applications 2017 R2 for Linux (64-bit)
This is a standalone release for customers who do not need integration with the Intel Media Server Studio. It provides components to develop OpenCL applications for Intel processors.
Visit https://software.intel.com/en-us/intel-opencl to download the version for your platform. For details check out the Release Notes.
Intel SDK for OpenCL Applications 2017 R2 for Windows* (64-bit)
This is a standalone release for customers who do not need integration with the Intel Media Server Studio. The standard Windows graphics driver packages contains the driver and runtime library components necessary to run OpenCL applications. This package provides components for OpenCL development.
Visit https://software.intel.com/en-us/intel-opencl to download the version for your platform. For details check out the Release Notes.
OpenCL 2.0 GPU/CPU driver package for Linux* (64-bit)
The intel-opencl-r5.0 (SRB5.0) Linux driver package enables OpenCL 1.2 or 2.0 on the GPU/CPU for the following Intel processors:
- Intel 5th, 6th or 7th generation Core processor
- Intel Celeron Processor J3000 Series with Intel HD Graphics 500 (J3455, J3355), Intel Pentium Processor J4000 Series with Intel HD Graphics 505 (J4205), Intel Celeron Processor N3000 Series with Intel HD Graphics 500 (N3350, N3450), Intel Pentium Processor N4000 Series with Intel HD Graphics 505 (N4200)
- Intel Xeon v4, or Intel Xeon v5 Processors with Intel Graphics Technology (if enabled by OEM in BIOS and motherboard)
Installation Instructions. Scripts to automate install and additional install documentation available here.
Intel validates the intel-opencl-r5.0 driver on CentOS 7.2 and 7.3 when running the following 64-bit kernels:
- Linux 4.7 kernel patched for OpenCL
- Linux 4.4 kernel patched for Intel Media Server Studio 2017 R3
Although Intel validates and provides technical support only for the above Linux kernels on CentOS 7.2 and 7.3, other distributions may be adapted by utilizing our generic operating system installation steps as well as MSS 2017 R3 installation steps.
In addition: Intel also validates Ubuntu 16.04.2 when running the following 64-bit kernel:
•Ubuntu 16.04.2 default 4.8 kernel
Ubuntu 16.04 with the default kernel works fairly well but some core features (i.e. device enqueue, SVM memory coherency, VTune support) won’t work without kernel patches. This configuration has been minimally validated to prove that it is viable to suggest for experimental use, but it is not fully supported or certified.
Supported OpenCL devices:
- Intel graphics (GPU)
- CPU
For detailed information please see the driver package Release Notes.
Previous Linux driver packages:
| Intel intel-opencl-r4.1 (SRB4.1) Linux driver package | Installation instructions | Release Notes |
| Intel intel-opencl-r4.0 (SRB4) Linux driver package | Installation instructions | Release Notes |
| SRB3.1 Linux driver package | Installation instructions | Release Notes |
For Linux drivers covering earlier platforms such as 4th generation Intel Core processor please see the versions of Media Server Studio in the Driver Support Matrix.
OpenCL Driver for Iris graphics and Intel HD Graphics for Windows* OS (64-bit and 32-bit)
The standard Intel graphics drivers for Windows* include components needed to run OpenCL* and Intel Media SDK applications on processors with Intel Iris Graphics or Intel HD Graphics on Windows* OS.
You can use the Intel Driver Update Utility to automatically detect and update your drivers and software. Using the latest available graphics driver for your processor is usually recommended.
Supported OpenCL devices:
- Intel graphics (GPU)
- CPU
For the full list of Intel Architecture processors with OpenCL support on Intel Graphics under Windows*, refer to the Release Notes.
Method 1: Texture Sharing via clCreateFromGLTexture
This method is the most efficient, allowing direct OpenGL-texture to OpenCL-image sharing with the help of clCreateFromGLTexture. This approach also allows modifying the content of the texture in place. Following are the required steps:
- Creating OpenGL 2D texture the regular way:
- Creating the OpenCL image corresponding to the texture (once):
Note the CL_MEM_WRITE_ONLY flag that allows fast discarding of the data. Use CL_MEM_READ_WRITE if your kernel requires reading the current texture context. Also, remove the _write_only qualifier for the image access in the kernel in that case.
- Acquiring the ownership via clEnqueueAcquireGLObjects:
- Executing the OpenCL kernel that alters the image:
- Releasing the ownership via clEnqueueReleaseGLObjects:
In this approach, the relation between OpenCL image and OpenGL texture is specified just once, and only acquire/release calls are used to pass ownership of the resources between APIs, thus providing zero-copy goodness for the actual texture data. However, the number of texture formats and usages for which this sharing is possible is rather limited.
Заключение
- Не позволяет описывать процессы с точностью до такта (но ведь от этого мы и хотели уйти!)
- Неприменим на маленьких чипах: инфраструктура отъедает огромное количество ресурсов.
https://youtube.com/watch?v=ythPvAPB4iI
Arria 10Stratix 10
https://youtube.com/watch?v=ObqtwoVy5RQ
Полезные ссылки
- Исходники примера и автосгеренеренный Verilog-код
- Altera SDK for OpenCL: Overview
- Altera SDK for OpenCL: Getting Started Guide
- Harnessing the Power of FPGAs using Altera’s OpenCL Compiler: очень большая презентация (>100 слайдов) для тех кто любит картинки смотреть 🙂
- Altera SDK for OpenCL: Programming Guide
- Altera SDK for OpenCL: Optimization Guide
- Altera SDK for OpenCL: Best Practices Guide
Update