Visible to Intel only — GUID: GUID-BC0F5DE9-976C-46F7-BF8F-023681810C0F
Visible to Intel only — GUID: GUID-BC0F5DE9-976C-46F7-BF8F-023681810C0F
Ahead of Time Compilation
Ahead of Time (AOT) Compilation is a helpful feature for your development lifecycle or distribution time. The AOT feature provides the following benefits when you know beforehand what your target device is going to be at application execution time:
- No additional compilation time is done when running your application.
- No just-in-time (JIT) bugs encountered due to compilation for the target. Any bugs should be found during AOT and resolved.
- Your final code, executing on the target device, can be tested as-is before you deliver it to end-users.
A program built with AOT compilation for specific target device(s) will not run on different device(s). You must detect the proper target device at runtime and report an error if the targeted device is not present. The use of exception handling with an asynchronous exception handler is recommended.
SYCL supports AOT compilation for the following targets: Intel® CPUs, Intel® Processor Graphics, and Intel® FPGA.
OpenMP supports AOT compilation for the following targets: Intel® Processor Graphics.
Prerequisites
To target a GPU with the AOT feature, you must have the OpenCL™ Offline Compiler (OCLOC) tool installed. OCLOC can generate binaries that use OpenCL™ (SYCL only) or the Intel® oneAPI Level Zero (Level Zero) backend.
Linux
OCLOC is not packaged with the Linux version of Intel® oneAPI DPC++/C++ Compiler and must be installed separately. To install OCLOC, you need to install the GPU drivers (whether or not you have an Intel GPU on your system). Refer to the Installation Guides for instructions.
Windows
OCLOC is packaged with the Windows version of Intel® oneAPI DPC++/C++ Compiler.
Requirements for Accelerators
GPUs:
- Intel® UDH Graphics for 11th generation Intel processors or newer
- Intel® Iris® Xe graphics
- Intel® Arc™ graphics
- Intel® Data Center GPU Flex Series
- Intel® Data Center GPU Max Series
AOT Compilation Supported Options for OpenMP
Use the following options to target a specific device for AOT compilation:
- -fopenmp-targets=<target> to specify the device target
- -Xs to pass options to the backend tool
-Xs or -Xopenmp-target-backend=spir64_gen allows you to specify a general device target option.
When using Ahead of Time (AOT) compilation, the options passed with -Xs are not compiler options, but rather options to pass to OCLOC.
AOT Compilation Supported Options for SYCL
Use the following options to target a specific device for AOT compilation:
- -fsycl-targets=<target>, to specify the device target
- -Xs, to pass options to the backend tool
-Xs is a general device target option. If there are multiple targets desired (example: -fsycl-targets=spir64_gen,spir64_x86_64) the options specified with -Xs apply to all targets. This is not desired for multiple targets. You can use -Xsycl-target-backend=spir64_gen <option> and -Xsycl-target-backend=spir64_x86_64 <option> to add specificity.
When using Ahead of Time (AOT) compilation, the options passed with -Xs are not compiler options.
To see a list of the options you can pass with -Xs when using AOT, specify -fsycl-help=gen, -fsycl-help=x86_64, or -fsycl-help=fpga on the command line.
Use AOT for the Target Device (Intel® CPUs)
Use the following option arguments to specify Intel® CPUs as the target device for AOT compilation:
- -fsycl-targets=spir64_x86_64
- -Xs "-march=<arch>", where <arch> is one of the following:
Switch Display Name avx Intel® Advanced Vector Extensions (Intel® AVX)
avx2 Intel® Advanced Vector Extensions 2 (Intel® AVX2)
avx512 Intel® Advanced Vector Extensions 512 (Intel® AVX-512)
sse4.2 Intel® Streaming SIMD Extensions 4.2 (Intel® SSE4.2)
The following examples tell the compiler to generate code that uses Intel® AVX2 instructions:
Linux
icpx -fsycl -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" main.cppWindows
icx -fsycl /EHsc -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" main.cpp
Build an Application with Multiple Source Files for CPU Targeting
Compile your normal files (with no SYCL kernels) to create host objects. Then compile the file with the kernel code and link it with the rest of the application.
Linux
icpx -fsycl -fsycl-targets=spir64_gen -Xs "-device *"-c main.cpp
icpx -fsycl -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" mandel.cpp main.o
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xs "-device *" -c main.cpp
icx -fsycl /EHsc -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" mandel.cpp main.obj
Use AOT for Integrated Graphics (Intel® GPU)
Use the following option arguments to specify Intel® GPU as the target device for AOT compilation:
OpenMP and SYCL
Use of -Xs is a general-purpose option, any arguments supplied with -Xs will be applied to all offline compilation invocations.
- -Xs "-device <arch>" option, where <arch> is the target device.
OpenMP
- -fopenmp-targets=spir64_gen
- -fopenmp-device-code-split=<value> to perform an OpenMP device code split. The <value> is:
- per_kernel (device code module is created for each OpenMP kernel)
SYCL
- -fsycl-targets=spir64_gen
- -fsycl-device-code-split=<value> option to perform SYCL device code split. The <value> can be:
- per_kernel (device code module is created for each SYCL kernel)
- per_source (device code module is created for each source (translation unit))
- off (no device code split)
- auto (use heuristic to select the best way of splitting device code)
NOTE:The default is auto
- -fsycl-device-code-split option to perform SYCL device code split in the auto mode (use heuristic to distribute device code across modules)
To see the complete list of supported target device types for your installed version of OCLOC, run:
ocloc compile --help
To find supported devices look for -device <device_type> in the help.
If multiple target devices are listed in the compile command, the Intel® oneAPI DPC++/C++ Compiler compiles for each of these targets and creates a fat-binary that contains all the device binaries produced this way.
Examples of supported -device patterns:
OpenMP for Linux
- To compile for a single target, using skl as an example, use:
icpx -fiopenmp -fopenmp-targets=spir64_gen -Xs "-device skl" vector-add.cpp
- To compile for two targets, using skl and icllp as examples, use:
icpx -fiopenmp -fopenmp-targets=spir64_gen -Xs "-device skl,icllp" vector-add.cpp
- To compile for all the targets known to OCLOC, use:
icpx -fiopenmp -fopenmp-targets=spir64_gen -Xs "-device *" vector-add.cpp
Or
icpx -fiopenmp -fopenmp-targets=spir64_gen -Xopenmp-target-backend=spir64_gen "-device *" vector-add.cpp
SYCL for Linux
- To compile for a single target, using skl as an example, use:
icpx -fsycl -fsycl-targets=spir64_gen -Xs "-device skl" vector-add.cpp
- To compile for two targets, using skl and icllp as examples, use:
icpx -fsycl -fsycl-targets=spir64_gen -Xs "-device skl,icllp" vector-add.cpp
- To compile for all the targets known to OCLOC, use:
icpx -fsycl -fsycl-targets=spir64_gen -Xs "-device *" vector-add.cpp
Windows
- To compile for a single target, using skl as an example, use:
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xs "-device skl" vector-add.cpp
- To compile for two targets, using skl and icllp as examples, use:
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xs "-device skl,icllp" vector-add.cpp
- To compile for all the targets known to OCLOC, use:
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xs "-device *" vector-add.cpp
Or
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device *" vector-add.cpp
Build an Application with Multiple Source Files for GPU Targeting
Compile your normal files (with no SYCL kernels) to create host objects. Then compile the file with the kernel code and link it with the rest of the application.
Linux
icpx -fsycl -fsycl-targets=spir64_gen -c main.cpp
icpx -fsycl -fsycl-targets=spir64_gen -Xs "-device *" mandel.cpp main.o
or
icpx -fsycl -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device *" mandel.cpp main.o
icx -fsycl -fsycl-targets=spir64_gen -c -EHsc main.cpp
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xs "-device *" mandel.cpp main.obj
or
icx -fsycl /EHsc -fsycl-targets=spir64_gen -Xsycl-target-backend=spir64_gen "-device *" mandel.cpp main.obj
Use AOT in Microsoft Visual Studio
You can use Microsoft Visual Studio for compiling and linking. Set the following flags to use AOT compilation for CPU or GPU:
CPU:
- To compile, in the dialog box, select: Configuration Properties > DPC++ > General > Specify SYCL offloading targets for AOT compilation.
- To link, in the dialog box, select: Configuration Properties > Linker > General > Specify CPU Target Device for AOT compilation.
GPU:
- To compile, in the dialog box, select: Configuration Properties > DPC++ > General > Specify SYCL offloading targets for AOT compilation.
- To link, in the dialog box, select: Configuration Properties > Linker > General > Specify GPU Target Device for AOT compilation.