Get Started with the
Intel® oneAPI
DPC++/C++ Compiler
Intel® oneAPI
DPC++/C++
CompilerThe
Intel® oneAPI
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.
DPC++/C++
CompilerThe
Intel® oneAPI
compiles C++-based SYCL* source files for a wide range of compute accelerators.
DPC++/C++
CompilerThe
Intel® oneAPI
is part of the
Intel® oneAPI Toolkits.
DPC++/C++
CompilerBefore You Begin
Windows*
The compiler integrates into the following versions of Microsoft Visual Studio*:
- Visual Studio 2022
- Visual Studio 2019
- Visual Studio 2017
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:
- Determine your installation directory,<install_dir>:
- 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.
- For non-root users, your home directory underintel/oneapiis used. In this case,<install_dir>will be$HOME/intel/oneapi.
- 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>).
- Source the environment-setting script for your shell:
- bash:source <install_dir>/setvars.sh intel64
- csh/tcsh:source <install_dir>/setvars.csh intel64
- If you want to use the 32bit ia32 compiler instead of the default 64bit compiler, replaceintel64in the source command above withia32. For example:
- bash:source <install_dir>/setvars.sh ia32
- csh/tcsh:source <install_dir>/setvars.csh ia32
Compile and Execute SYCL Code
Use these steps to compile and execute SYCL code.
- The following is a sample SYCL program, captured in the filesimple-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; }
- To build thesimple-sycl-app, use:dpcpp simple-sycl-app.cpp -o simple-sycl-app
- To run thesimple-sycl-app, use:./simple-sycl-appYou will see the following output:The results are correct!
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;
}
}
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:
- Open a command prompt in Microsoft Visual Studio.
- 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]To enable unnamed SYCL lambda kernel support with Intel® oneAPI HPC Toolkit, add the 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 C/C++ source files:icl [options] file1 [file2...] [/link link_options]
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:
- For C/C++ source files:{icx|icpx} [options] file1 [file2...]
- For DPC++ source files:dpcpp [options] file1 [file2...]
- For DPC++ source files (Intel® oneAPI HPC Toolkit only):icpx -fsycl [options] file1 [file2...]To enable unnamed SYCL lambda kernel support with Intel® oneAPI HPC Toolkit, add the 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 C/C++ source files:{icc|icpc} [options] file1 [file2...]
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.
.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
Exact steps may vary depending on the version of Microsoft Visual Studio in use.
- Create a Microsoft Visual C++ (MSVC) project or open an existing project.
- InSolution Explorer, select the project(s) to build with the Intel® oneAPI DPC++/C++ Compiler.
- OpenProject > Properties.
- In the left pane, expand theConfiguration Propertiescategory and select theGeneralproperty page.
- In the right pane change thePlatform Toolsetto the compiler you want to use:
- For DPC++, selectIntel(R) oneAPI DPC++ Compilerto invokedpcpp-cl.
- For C/C++, there are two toolsets.SelectIntel C++ Compiler <major version>(example 2021) to invokeicx.SelectIntel C++ Compiler <major.minor>(example 19.2) to invokeicl.Alternatively, you can specify a compiler version as the toolset for all supported platforms and configurations of the selected project(s) by selectingProject > Intel Compiler > Use Intel oneAPI DPC++/C++ Compiler.
- Rebuild, using eitherBuild > Project only > Rebuildfor a single project orBuild > Rebuild Solutionfor 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:
- Select a project, then go toTools > Options > Intel Compilers and Libraries > <compiler> > Compilers, where <compiler> values areC++orDPC++.
- Use theSelected Compilerdrop-down menu to select the appropriate version of the compiler.
- SelectOK.
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:
- Select your project in Microsoft Visual Studio.
- Right-click and selectIntel 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.
- Start Eclipse
- SelectHelp > Install New Software
- SelectAddto open the Add Site dialog
- SelectArchive, browse to the directory<install_dir>/compiler/<version>/linux/ide_support, select the .zip file that starts withcom.intel.dpcpp.compiler, then selectOK
- Select the options beginning with Intel, selectNext, then follow the installation instructions
- When asked if you want to restart Eclipse*, selectYes
Build a new project or open an existing project.
- Open Existing Project or Create New Project on Eclipse
- Right click onProject > Properties > C/C++ Build > Tool chain Editor
- SelectIntel DPC++/C++ Compilerfrom the right panel
Set build configurations.
- Open Existing Project on Eclipse
- Right click onProject > Properties > C/C++ Build > Settings
- Create or manage build configurations in the right panel
Next Steps
- Use the latest oneAPI Code Samples and follow along with the Intel® oneAPI Training Resources.
- Explore theIntel® oneAPIDeveloper Guide and Reference on the Intel® Developer Zone.DPC++/C++Compiler
Find More
Content
| Description and Links
|
---|---|
Visit the Release Notes page for known issues and the most up-to-date information.
| |
Provides details on the
Intel® oneAPI
programming model, including details about
DPC++/C++ CompilerDPC++ Intel® oneAPI libraries.
| |
Explore
Intel® oneAPI
features and setup and get more detailed information about compiler options, attributes, and more.
DPC++/C++ Compiler | |
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
| |
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.