Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference

ID 767253
Date 3/22/2024
Public
Document Table of Contents

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:

  1. Host code can be compiled with any compiler.
  2. Source files that contain device code must be compiled with the Intel® oneAPI DPC++/C++ Compiler.
  3. 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:

  1. michigan.cpp may contain host and device code:
    icpx -fsycl -c michigan.cpp
    
  2. erie.cpp contains host code only:
    g++ -c erie.cpp                 
    
  3. ontario.cpp contains host code only:
    ifx -c ontario.f90              
    
  4. huron.cpp contains host code only:
    icx -c huron.cpp                
    
  5. superior.cpp may contain host and device code:
    icpx -fsycl -c superior.cpp     
    
  6. 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 
    
Mixing the use of another SYCL* compiler with the Intel® oneAPI DPC++/C++ Compiler is not currently supported.

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
  1. 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.

    Component directory layout:

    source /opt/intel/oneapi/setvars.sh

    Unified directory layout:

    source /opt/intel/oneapi/<toolkit_version>/oneapi-vars.sh

  2. Set up the SYCL headers location:
    export INCLUDEDIR=<Location of SYCL headers>
  3. 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
  4. Compile other C++ code (or non-SYCL code) using G++:
    g++ -std=c++17 main.cpp -c -fPIC -I$INCLUDEDIR
  5. Perform the final link to create an executable:
    icpx -fsycl main.o a.o b.o -o finalexe.exe