DPCPP CPP Compiler - Get Started Guide - 2024.2 767258 824361
DPCPP CPP Compiler - Get Started Guide - 2024.2 767258 824361
++/C++ Compiler
Get Started with the Intel® oneAPI DPC++/C++ Compiler
Contents
Chapter 1: Get Started with the Intel® oneAPI DPC++/C++ Compiler
Get Started on Linux* ................................................................................4
Get Started on Windows* ...........................................................................7
Compile and Execute Sample Code ............................................................ 10
2
Get Started with the Intel® oneAPI DPC++/C++ Compiler 1
Find More
NOTE
Explore the complete list of oneAPI code samples in the oneAPI Samples Catalog (GitHub*). These
samples were designed to help you develop, offload, and optimize multiarchitecture applications
targeting CPUs, GPUs, and FPGAs.
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 SYCL* and OpenMP*
offload, programming for various target accelerators, and
introductions to the Intel® oneAPI libraries.
Intel® oneAPI DPC++/C++ Explore Intel® oneAPI DPC++/C++ Compiler features and setup and
Compiler Developer Guide and get more detailed information about compiler options, attributes, and
Reference more.
• Intel® oneAPI Data Parallel C+ Ask questions and find answers in the Intel® oneAPI Data Parallel C+
+ Forum + and Intel® C++ Compiler forums.
• Intel® C++ Compiler Forum
Intel® oneAPI DPC++/C++ Explore tutorials, training materials, and other Intel® oneAPI
Compiler Documentation DPC++/C++ Compiler documentation.
SYCL Specification Version 1.2.1 The SYCL specification, explains how SYCL integrates OpenCL devices
PDF with modern C++.
The GNU* C++ Library - Using The GNU* C++ Library documentation on using dual ABI.
Dual ABI
Layers for Yocto* Project Add oneAPI components to a Yocto project build using the meta-intel
layers.
3
1 Get Started with the Intel® oneAPI DPC++/C++ Compiler
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.
Intel optimizations, for Intel compilers or other products, may not optimize to the same degree for non-Intel
products.
NOTE
The Unified Directory Layout was implemented in 2024.0. If you have multiple toolkit versions
installed, the Unified layout ensures that your development environment contains the correct
component versions for each installed version of the toolkit.
The directory layout used before 2024.0, the Component Directory Layout, is still supported on new
and existing installations.
For detailed information about the Unified layout, including how to initialize the environment and
advantages with the Unified layout, refer to Use the setvars and oneapi-vars Scripts with Linux.
Compiler environment variables must first be configured if using the compiler from a Command Line
Interface (CLI). Environment variables are set up with a script called setvars in the Component Directory
Layout or oneapi-vars in the Unified Directory Layout. By default, changes to your environment made by
sourcing the setvars.sh or oneapi-vars.sh script apply only to the terminal session in which the
environment script was sourced. You must source the script for each new terminal session.
Detailed instructions on using the setvars.sh or oneapi-vars.sh script are found in Use the setvars and
oneapi-vars Scripts with Linux.
Optionally use one-time setup for setvars.sh as described in Use Modulefiles with Linux*.
4
Get Started with the Intel® oneAPI DPC++/C++ Compiler 1
• To use an NVIDIA GPU, install the oneAPI for NVIDIA GPUs plugin from Codeplay.
icx-cl is the
Microsoft-
compatible variant
of icx.
NOTE On Linux,
icx-cl is
experimental and
requires the
Microsoft Visual
Studio Package.
Invoke the compiler on the command line using the following syntax:
5
1 Get Started with the Intel® oneAPI DPC++/C++ Compiler
For example:
icpx hello-world.cpp
For SYCL compilation, use the -fsycl option with the C++ driver:
If you are targeting an AMD or NVIDIA GPU, refer to the corresponding Codeplay plugin get started guide for
detailed compilation instructions:
• oneAPI for AMD GPUs Get Started Guide
• oneAPI for NVIDIA GPUs Get Started Guide
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
return 0;
}
6
Get Started with the Intel® oneAPI DPC++/C++ Compiler 1
3. If you are not using one-time setup for setvars.sh, set environment variables by sourcing setvars:
source <install-dir>/setvars.sh
Unified Directory Layout
source <install-dir>/<toolkit-version>/oneapi-vars.sh
For information about the <install-dir> location for Component or Unified layout on system-wide or
private installations, refer to Using the setvars and oneapi-vars Scripts with Linux*.
4. From the terminal window, issue the following command to compile hello-world.cpp:
hello-world
Which outputs:
Hello, world!
You can direct and control compilation with compiler options. For example, you can create the object file and
output the final binary in two steps:
1. Compile hello-world.cpp:
icpx hello-world.cpp -c
The -c option prevents linking at this step.
2. Use the icpx compiler to link the resulting application object code and output an executable:
7
1 Get Started with the Intel® oneAPI DPC++/C++ Compiler
To develop and run applications for Intel GPUs you must first install the latest Intel GPU drivers.
icx-cl is the
Microsoft-
compatible variant
of icx.
NOTE On Linux,
icx-cl is
experimental and
requires the
Microsoft Visual
Studio Package.
Invoke the compiler on the command line using the following syntax:
8
Get Started with the Intel® oneAPI DPC++/C++ Compiler 1
To invoke the compiler using the command line from within Microsoft Visual Studio, open a command prompt
and enter your compilation command. For example:
icx hello-world.cpp
For SYCL compilation, use the -fsycl option with the C++ driver:
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.
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.
9
1 Get Started with the Intel® oneAPI DPC++/C++ 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.
#include <iostream>
int main()
{
std::cout << "Hello, world!\n";
return 0;
}
2. Compile hello-world.cpp:
icx hello-world.cpp
3. Now you have an executable called hello-world.exe which can be run and will give immediate
feedback:
hello-world.exe
Which outputs:
Hello, world!
You can direct and control compilation with compiler options. For example, you can create the object file and
output the final binary in two steps:
1. Compile hello-world.cpp:
10
Get Started with the Intel® oneAPI DPC++/C++ Compiler 1
Sample Project Description
OpenMP Offload Sample
The OpenMP* Offload sample demonstrates some
of the new OpenMP Offload features supported by
the Intel® oneAPI DPC++/C++ Compiler.
Base: Vector Add Sample
The Vector Add sample is the equivalent of a 'Hello,
World!' sample for data parallel programs. Building
and running the code sample verifies that your
development environment is set up correctly and
demonstrates the use of the core features of DPC+
+.
Matrix Multiply Sample
The Matrix Multiply sample is a simple program that
multiplies together two large matrices and verifies
the results. This program is implemented in two
ways: Using Data Parallel C++ (DPC++) and using
OpenMP (OMP).
Adaptive Noise Reduction Sample
The Adaptive Noise Reduction sample is a DPC++
reference design that demonstrates a highly
optimized image sensor adaptive noise reduction
(ANR) algorithm on an FPGA.
NOTE Explore the complete list of oneAPI code samples in the oneAPI Samples Catalog (GitHub*).
These samples were designed to help you develop, offload, and optimize multiarchitecture applications
targeting CPUs, GPUs, and FPGAs.
Next Steps
• Use the latest oneAPI Code Samples and follow along with the Intel® oneAPI Training Resources.
• Explore the Intel® oneAPI DPC++/C++ Compiler Developer Guide and Reference on the Intel® Developer
Zone.
11