Get Started with the Intel® oneAPI DPC++/C++ Compiler

The Intel® oneAPI DPC++/C++ Compiler provides optimizations that help your applications to run faster on Intel® 64 and IA-32 (Windows* and Linux* only) architectures, with support for the latest C, C++, and DPC++ language standards (including C++17). This compiler produces optimized code that can run significantly faster by taking advantage of the ever-increasing core count and vector register width in Intel® Xeon® processors and compatible processors. The Intel® Compiler will help you boost application performance through superior optimizations and Single Instruction Multiple Data (SIMD) vectorization, integration with Intel® Performance Libraries, and by leveraging the OpenMP* 5.0/5.1 parallel programming model.

The Intel® oneAPI DPC++/C++ Compiler compiles C++-based SYCL* source files for a wide range of compute accelerators.

The Intel® oneAPI DPC++/C++ Compiler is part of the Intel® oneAPI Toolkits.

Before You Begin

Windows*

The compiler integrates into the following versions of Microsoft Visual Studio*:

For full functionality within Visual Studio, including debugging and development, Visual Studio Community Edition or higher is required. Visual Studio Express Edition allows only command-line builds. For all versions, Microsoft C++ support must be selected as part of the Visual Studio install. For Visual Studio 2017 and later, you must use a custom install to select this option.

You typically do not need to set the environment variables on Windows, as the compiler command-line window sets these variables for you automatically. If you need to set the environment variables, run the environment script as described in the suite-specific Get Started documentation.

<install_dir> is the installation directory. By default, it is C:\Program Files (x86)\Intel\oneAPI.

Linux*

Before you can use the compiler, you must first set the environment variables by sourcing the environment script using the initialization utility to initialize all the tools in one step:

  1. Determine your installation directory,<install_dir>:
    1. If your compiler was installed in the default location by a root user or sudo user, the compiler will be installed under/opt/intel/oneapi. In this case, <install_dir>is /opt/intel/oneapi.
    2. For non-root users, your home directory under intel/oneapi is used. In this case, <install_dir> will be $HOME/intel/oneapi.
    3. For cluster or enterprise users, your admin team may have installed the compilers on a shared network file system. Check with your local admin staff for the location of installation (<install_dir>).
  2. Source the environment-setting script for your shell:
    1. bash: source <install_dir>/setvars.sh intel64
    2. csh/tcsh: source <install_dir>/setvars.csh intel64
  3. If you want to use the 32bit ia32 compiler instead of the default 64bit compiler, replace intel64 in the source command above with ia32. For example:
    1. bash: source <install_dir>/setvars.sh ia32
    2. csh/tcsh: source <install_dir>/setvars.csh ia32

Compile and Execute SYCL Code

Use these steps to compile and execute SYCL code.

  1. The following is a sample SYCL program, captured in the file simple-sycl-app.cpp:
    #include <CL/sycl.hpp>
    
    int main() {
      // Creating SYCL queue
      cl::sycl::queue Queue;
    
      // Creating buffer of 4 ints
      cl::sycl::buffer<cl::sycl::cl_int, 1> Buffer(4);
    
      // Size of index space for kernel
      cl::sycl::range<1> NumOfWorkItems{Buffer.get_count()};
    
      // Submitting command group to queue
      Queue.submit([&](cl::sycl::handler &cgh) {
        // Getting write only access to the buffer on a device
        auto Accessor = Buffer.get_access<cl::sycl::access::mode::write>(cgh);
        // Executing kernel
        cgh.parallel_for<class FillBuffer>(
            NumOfWorkItems, [=](cl::sycl::id<1> WIid) {
              // Fill buffer with indexes
              Accessor[WIid] = (cl::sycl::cl_int)WIid.get(0);
            });
      });
    
      // Getting read only access to the buffer on the host
      const auto HostAccessor = Buffer.get_access<cl::sycl::access::mode::read>();
    
      // Check that the results are correct
      bool MismatchFound = false;
      for (size_t I = 0; I < Buffer.get_count(); ++I) {
        if (HostAccessor[I] != I) {
          std::cout << "The result is incorrect for element: " << I
                    << " , expected: " << I << " , got: " << HostAccessor[I]
                    << std::endl;
          MismatchFound = true;
        }
      }
    
      if (!MismatchFound) {
        std::cout << "The results are correct!" << std::endl;
      }
    
      return MismatchFound;
    }
    
  2. To build the simple-sycl-app, use:
    dpcpp simple-sycl-app.cpp -o simple-sycl-app
  3. To run the simple-sycl-app, use:
    ./simple-sycl-app

    You will see the following output: The results are correct!

Note

The SYCL host device is not fully supported.

Specify a SYCL Device (optional)

To specify the device, SYCL provides the abstract cl::sycl::device_selector class, which you can subclass to define how the runtime selects the device. The method operator() of the SYCL device_selector is an abstract member function, which takes a reference to a SYCL device and returns an integer score. This abstract member function can be implemented in a derived class and provide a logic for selecting a SYCL device. The SYCL runtime uses the device with the highest returned score. This object can be passed to the cl::sycl::queue and cl::sycl::device constructors.

This example illustrates how to use the device_selector to create a device and queue objects that are bound to a GPU:

#include <CL/sycl.hpp>

int main() {
  class NEOGPUDeviceSelector : public cl::sycl::device_selector {
  public:
    int operator()(const cl::sycl::device &Device) const override {
      using namespace cl::sycl::info;

      const std::string DeviceName = Device.get_info<device::name>();
      const std::string DeviceVendor = Device.get_info<device::vendor>();

      return Device.is_gpu() && (DeviceName.find("HD Graphics NEO") != std::string::npos);
    }
  };

  NEOGPUDeviceSelector Selector;
  try {
    cl::sycl::queue Queue(Selector);
    cl::sycl::device Device(Selector);
  } catch (cl::sycl::invalid_parameter_error &E) {
    std::cout << E.what() << std::endl;
  }
}

Note

You can specify the SYCL device used for execution with one of the following device selectors:
  • cl::sycl::intel::fpga_selector
  • cl::sycl::intel::fpga_emulator_selector
  • cl::sycl::cpu_selector
  • cl::sycl::gpu_selector

Use the Command Line on Windows

Follow these steps to invoke the compiler using the command line from within Microsoft Visual Studio:

  1. Open a command prompt in Microsoft Visual Studio.
  2. Invoke the compiler.
    • For C/C++ source files: icx [options] file1 [file2...] [/link link_options]
    • For DPC++ source files: dpcpp-cl [options] file1 [file2...] [/link link_options]
    • For DPC++ source files (Intel® oneAPI HPC Toolkit only): icx -fsycl [options] file1 [file2...] [/link link_options]

      Note

      To enable unnamed SYCL lambda kernel support with Intel® oneAPI HPC Toolkit, add the -fsycl-unnamed-lambda option.

Intel® C++ Compiler Classic is included as part of the Intel® oneAPI HPC and IoT Toolkits. Use the following command to invoke the classic compiler from the command line:

For more information about invoking the Intel® C++ Classic compiler, see Invoking the Compiler

Use the Command Line on Linux

Use one of the following commands to invoke the compiler from the command line on Linux:

Intel® C++ Compiler Classic is included as part of the Intel® oneAPI HPC and IoT Toolkits. Use the following command to invoke the classic compiler from the command line:

For more information about invoking the Intel® C++ Classic compiler, see Invoking the Compiler

Use Microsoft Visual Studio on Windows

Project Support for the Intel® DPC++/C++ Compiler in Microsoft Visual Studio

New Microsoft Visual Studio projects for DPC++ are automatically configured to use the Intel® oneAPI DPC++/C++ Compiler.

New Microsoft Visual C++* (MSVC) projects must be manually configured to use the Intel® oneAPI DPC++/C++ Compiler.

Note

.NET-based CLR C++ project types are not supported by the Intel® oneAPI DPC++/C++ Compiler. The specific project types will vary depending on your version of Visual Studio, for example: CLR Class Library, CLR Console App, or CLR Empty Project.

Use the Intel® DPC++/C++ Compiler in Microsoft Visual Studio

Note

Exact steps may vary depending on the version of Microsoft Visual Studio in use.
  1. Create a Microsoft Visual C++ (MSVC) project or open an existing project.
  2. In Solution Explorer, select the project(s) to build with the Intel® oneAPI DPC++/C++ Compiler.
  3. Open Project > Properties .
  4. In the left pane, expand the Configuration Properties category and select the General property page.
  5. In the right pane change the Platform Toolset to the compiler you want to use:
    • For DPC++, select Intel® oneAPI DPC++ Compiler to invoke dpcpp-cl.
    • For C/C++, there are two toolsets.

      Select Intel C++ Compiler <major version> (example 2021) to invoke icx.

      Select Intel C++ Compiler <major.minor> (example 19.2) to invoke icl.

      Alternatively, you can specify a compiler version as the toolset for all supported platforms and configurations of the selected project(s) by selecting Project > Intel Compiler > Use Intel oneAPI DPC++/C++ Compiler.

  6. Rebuild, using either Build > Project only > Rebuild for a single project or Build > Rebuild Solution for a solution.

Select Compiler Version

If you have multiple versions of the Intel® oneAPI DPC++/C++ Compiler installed, you can select which version you want from the Compiler Selection dialog box:

  1. Select a project, then go to Tools > Options > Intel Compilers and Libraries > <compiler> > Compilers, where <compiler> values are C++ or DPC++.
  2. Use the Selected Compiler drop-down menu to select the appropriate version of the compiler.
  3. Select OK.

Switch Back to the Microsoft Visual Studio C++ Compiler

If your project is using the Intel® oneAPI DPC++/C++ Compiler, you can choose to switch back to the Microsoft Visual C++ compiler:

  1. Select your project in Microsoft Visual Studio.
  2. Right-click and select Intel Compiler > Use Visual C++ from the context menu.

This action updates the solution file to use the Microsoft Visual Studio C++ compiler. All configurations of affected projects are automatically cleaned unless you select Do not clean project(s). If you choose not to clean projects, you will need to rebuild updated projects to ensure all source files are compiled with the new compiler.

Use the Eclipse* CDT on Linux

Follow these steps to invoke the compiler from within the Eclipse* CDT.

Install the Intel® Compiler Eclipse CDT plugin.

  1. Start Eclipse
  2. Select Help > Install New Software
  3. Select Add to open the Add Site dialog
  4. Select Archive, browse to the directory <install_dir>/compiler/<version>/linux/ide_support, select the .zip file that starts with com.intel.dpcpp.compiler, then select OK
  5. Select the options beginning with Intel, select Next, then follow the installation instructions
  6. When asked if you want to restart Eclipse*, select Yes

Build a new project or open an existing project.

  1. Open Existing Project or Create New Project on Eclipse
  2. Right click on Project > Properties > C/C++ Build > Tool chain Editor
  3. Select Intel DPC++/C++ Compiler from the right panel

Set build configurations.

  1. Open Existing Project on Eclipse
  2. Right click on Project > Properties > C/C++ Build > Settings
  3. Create or manage build configurations in the right panel

Next Steps

Find More

Content

Description and Links

Release Notes

Visit the Release Notes page for known issues and the most up-to-date information.

Intel® oneAPI Programming Guide

Provides details on the Intel® oneAPI DPC++/C++ Compiler programming model, including details about DPC++, programming for various target accelerators, and introductions to the Intel® oneAPI libraries.

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

Explore Intel® oneAPI DPC++/C++ Compiler features and setup and get more detailed information about compiler options, attributes, and more.

SYCL Specification Version 1.2.1 PDF

The SYCL Specification PDF, explains how SYCL integrates OpenCL devices with modern C++: https://www.khronos.org/registry/SYCL/specs/sycl-1.2.1.pdf

SYCL Overview site

An overview of SYCL: https://www.khronos.org/sycl/

The GNU* C++ Library

Using dual ABI: https://gcc.gnu.org/onlinedocs/libstdc++/manual/using_dual_abi.html

Layers for Yocto* Project

Add oneAPI components to a Yocto project build using the meta-intel layers.

Notices and Disclaimers

Intel technologies may require enabled hardware, software or service activation.

No product or component can be absolutely secure.

Your costs and results may vary.

© Intel Corporation. Intel, the Intel logo, and other Intel marks are trademarks of Intel Corporation or its subsidiaries. Other names and brands may be claimed as the property of others.

No license (express or implied, by estoppel or otherwise) to any intellectual property rights is granted by this document.

The products described may contain design defects or errors known as errata which may cause the product to deviate from published specifications. Current characterized errata are available on request.

Intel disclaims all express and implied warranties, including without limitation, the implied warranties of merchantability, fitness for a particular purpose, and non-infringement, as well as any warranty arising from course of performance, course of dealing, or usage in trade.