Ahead of Time (AOT) Compilation is a helpful feature for your development lifecycle or distribution time. It benefits you when you know beforehand what your target device is going to be at application execution time. The AOT feature provides the following benefits:
A program built with AOT compilation for a specific target device will not run on a non-specific device. 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 (Gen9 or above), and Intel® FPGA.
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™ 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. Refer to Install OpenCL™ Offline Compiler (OCLOC) for details.
Windows
OCLOC is packaged with the Windows version of Intel® oneAPI DPC++/C++ Compiler.
Use the following options to target a specific device for AOT compilation:
-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 the following option arguments to specify Intel® CPUs as the target device for AOT compilation:
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
dpcpp -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" main.cppWindows
dpcpp-cl /EHsc -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" main.cpp
Build an Application with Multiple Source Files for CPU Targeting
Method 1: 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
dpcpp -c main.cpp
dpcpp -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" mandel.cpp main.o
dpcpp-cl -c /EHsc main.cpp
dpcpp-cl /EHsc -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" mandel.cpp main.obj
Method 2: Compile the file with the kernel code and create a fat object. Then compile the rest of the files and linking to create a fat executable:
Linux
dpcpp -c -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" mandel.cpp
dpcpp main.cpp mandel.o -fsycl-targets=spir64_x86_64 -Xs "-march=avx2"
dpcpp-cl -c /EHsc -fsycl-targets=spir64_x86_64 -Xs "-march=avx2" mandel.cpp
dpcpp-cl /EHsc main.cpp mandel.obj -fsycl-targets=spir64_x86_64 -Xs "-march=avx2"
Use the following option arguments to specify Intel® GPU as the target device for AOT compilation:
Switch | Display Name |
---|---|
skl | 6th generation Intel® Core™ processor (Skylake with Intel® Processor Graphics Gen9) |
kbl | 7th generation Intel® Core™ processor (Kaby Lake with Intel® Processor Graphics Gen9) |
cfl | 8th generation Intel® Core™ processor (Coffee Lake with Intel® Processor Graphics Gen9) |
glk | Gemini Lake with Intel® Processor Graphics Gen9 |
icllp | 10th generation Intel® Core™ processor (Ice Lake with Intel® Processor Graphics Gen11) |
tgllp | 11th generation Intel® Core™ processor (Tiger Lake with Intel® Processor Graphics Gen12) |
dg1 | Intel® Iris® Xe MAX graphics |
Gen9 | Intel® Processor Graphics Gen9 |
Gen11 | Intel® Processor Graphics Gen11 |
Gen12LP | Intel® Processor Graphics Gen12 (Lower Power) |
adls | 12th generation Intel® Core™ processor (Alder Lake S with Intel® Processor Graphics Gen12.2) |
aldp | 12th generation Intel® Core™ processor (Alder Lake P with Intel® Processor Graphics Gen12.2) |
To see the complete list of supported target device types for your installed version of OCLOC, run:
ocloc compile --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:
Linux
dpcpp -fsycl-targets=spir64_gen -Xs "-device skl" vector-add.cpp
dpcpp -fsycl-targets=spir64_gen -Xs "-device skl,icllp" vector-add.cpp
dpcpp -fsycl-targets=spir64_gen -Xs "-device *" vector-add.cpp
dpcpp-cl /EHsc -fsycl-targets=spir64_gen -Xs "-device skl" vector-add.cpp
dpcpp-cl /EHsc -fsycl-targets=spir64_gen -Xs "-device skl,icllp" vector-add.cpp
dpcpp-cl /EHsc -fsycl-targets=spir64_gen -Xs "-device *" vector-add.cpp
Build an Application with Multiple Source Files for GPU Targeting
Method 1: 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
dpcpp -c main.cpp
dpcpp -fsycl-targets=spir64_gen -Xs "-device *" mandel.cpp main.o
dpcpp-cl -c /EHsc main.cpp
dpcpp-cl /EHsc -fsycl-targets=spir64_gen -Xs "-device *" mandel.cpp main.obj
Method 2: Compile the file with the kernel code and create a fat object. Then compile the rest of the files and linking to create a fat executable:
Linux
dpcpp -c -fsycl-targets=spir64_gen mandel.cpp
dpcpp main.cpp mandel.o -fsycl-targets=spir64_gen -Xs "-device *"
dpcpp-cl -c /EHsc -fsycl-targets=spir64_gen mandel.cpp
dpcpp-cl /EHsc main.cpp mandel.obj -fsycl-targets=spir64_gen -Xs "-device *"
You can use Microsoft Visual Studio for compiling and linking. Set the following flags to use AOT compilation for CPU or GPU:
CPU:
GPU: