Visible to Intel only — GUID: GUID-D5F28668-A119-4094-8ABD-D2C3803659EB
Visible to Intel only — GUID: GUID-D5F28668-A119-4094-8ABD-D2C3803659EB
Use a Third-Party Compiler as a Host Compiler for SYCL Code
There are three basic rules to use multiple different compilers with the Intel® oneAPI DPC++/C++ Compiler to compile SYCL* code:
- Host code can be compiled with any compiler.
- Source files that contain device code must be compiled with the Intel® oneAPI DPC++/C++ Compiler.
- Linking of the final program must be done with the Intel® oneAPI DPC++/C++ Compiler.
The following example shows application of these rules when mixing compilers with the Intel® oneAPI DPC++/C++ Compiler:
- michigan.cpp may contain host and device code:
icpx -fsycl -c michigan.cpp
- erie.cpp contains host code only:
g++ -c erie.cpp
- ontario.cpp contains host code only:
ifx -c ontario.f90
- huron.cpp contains host code only:
icx -c huron.cpp
- superior.cpp may contain host and device code:
icpx -fsycl -c superior.cpp
- Final linkage is done using the Intel® oneAPI DPC++/C++ Compiler
icpx -fsycl -o greatlakes.out michigan.o superior.o huron.o erio.o ontario.o
External Compiler Options
The compiler has two options that let you use an external compiler to perform host-side compilation. The options are:
- fsycl-host-compiler: Tells the compiler to use the specified compiler for host compilation of the performed offloading compilation.
- fsycl-host-compiler-options: Passes options to the compiler specified by the option fsycl-host-compiler.
The following example shows how to use a host compiler to generate the host objects and perform the final linkage. The example compiles a SYCL program using the GNU C++ Compiler (g++) for host code and the Intel® oneAPI DPC++/C++ Compiler (icpx -fsycl) for SYCL code. In the example:
- a.cpp contains SYCL code
- b.cpp contains SYCL code
- main.cpp contains C++ code
Follow the Get Started with the Intel® oneAPI Base Toolkit for Linux guide to set up the build environment:
NOTE:The build environment requires GCC version 5.1 or above to be installed and accessible.source /opt/intel/oneapi/setvars.sh
- Set up the SYCL headers location:
export INCLUDEDIR=<Location of SYCL headers>
- Use -fsycl-host-compiler to tell the compiler to use a third-party compiler to perform the host compilation. Device compilation will be performed with the Intel® oneAPI DPC++/C++ Compiler. This step will create fat objects that contain device and host code:
icpx -fsycl -fsycl-host-compiler=g++ a.cpp -o a.o icpx -fsycl -fsycl-host-compiler=g++ b.cpp -o b.o
- Compile other C++ code (or non-SYCL code) using G++:
g++ -std=c++17 main.cpp -c -fPIC -I$INCLUDEDIR
- Perform the final link to create an executable:
icpx -fsycl main.o a.o b.o -o finalexe.exe