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

ID 767253
Date 3/31/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

Use a Third-Party Compiler as a Host Compiler for SYCL Code

This content describes the steps needed to use an external host compiler (G++) along with the Intel® oneAPI DPC++/C++ Compiler.

In this example, you will use a host compiler to generate the host objects and perform the final link. The host compiler needs to know where to find the required headers and libraries. Follow the example instructions to build a SYCL program using a G++ Compiler (g++) for host code and an Intel® oneAPI DPC++/C++ Compiler (icpx -fsycl) for SYCL code.

Linux

This example includes the following:

  • a.cpp: SYCL code
  • b.cpp: SYCL code
  • main.cpp: 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.

    source /opt/intel/oneapi/setvars.sh
  2. Set up the headers and library locations:
    export LIBDIR=<Location of libsycl.so>
    export INCLUDEDIR=<Location of SYCL headers>
  3. Build the objects for your device:
    icpx -fsycl -c a.cpp -fPIC -o a.o
    icpx -fsycl -c b.cpp -fPIC -o b.o
  4. Create the integration header files (used by the host compiler):
    icpx -fsycl -fsycl-device-only -Xclang -fsycl-int-header=a_host.h a.cpp
    icpx -fsycl -fsycl-device-only -Xclang -fsycl-int-header=b_host.h b.cpp
  5. Create the host objects:
    g++ -std=c++17 -c a.cpp -o a_host.o -include a_host.h -fPIC -I$INCLUDEDIR
    g++ -std=c++17 -c b.cpp -o b_host.o -include b_host.h -fPIC -I$INCLUDEDIR
  6. Compile other C++ code (or non-SYCL code) using G++:
    g++ -std=c++17 main.cpp -c -fPIC -I$INCLUDEDIR
  7. Create a device object:
    icpx -fPIC -fsycl -fsycl-link a.o b.o -o device.o
  8. Optional step. Create an archive libuser.a that contains the necessary host and device objects:

    ar -rcs libuser.a a_host.o b_host.o device.o
  9. Perform the final link to create a final.exe executable:
    g++ main.o a_host.o b_host.o device.o -L$LIBDIR -lOpenCL -lsycl -o finalexe.exe 
  10. Optional step. Build the final.exe with an archive:

    g++ main.o -Wl,--whole-archive libuser.a -Wl,--no-whole-archive -L$LIBDIR -lOpenCL -lsycl -o finalexe.exe

Windows

Windows is not supported in this release.

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.