Using CMake with the compiler on Linux is supported. When you are using CMake, the compiler is enabled using the icx (variant) binary. You may need to set your CC/CXX or CMAKE_C_COMPILER /CMAKE_CXX_COMPILER string to icx/icpx. For example:
cmake -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx …
Using CMake with the compiler on Windows is supported. When you are using CMake, the compiler is enabled using the icx (variant) binary. You may need to set your CC/CXX or CMAKE_C_COMPILER /CMAKE_CXX_COMPILER string to icx. The supported generator in the Windows environment is Ninja. For example:
cmake -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -GNinja …
Use the following steps to enable the compiler for your project:
cmake_minimum_required(VERSION 3.23.0)
And:
find_package(IntelDPCPP REQUIRED)
The second snippet enables the compiler. The heterogeneous compilation configuration package (IntelDPCPPConfig.cmake) is shipped with the compiler. The package directory is found in the parent directory of the icx bin directory.
CMake is supported on the Windows and Linux command line. The following CMakeLists.txt builds the DPC++ application in simple.cpp for either Windows or Linux with the minimum supported CMake version for each platform.
if (CMAKE_HOST_WIN32) # need at least CMake 3.23 for IntelLLVM support of IntelDPCPP package on Windows cmake_minimum_required(VERSION 3.23) else() # CMake 3.20.5 is the minimum recommended for IntelLLVM on Linux cmake_minimum_required(VERSION 3.20.5) endif() project(simple-dpcpp LANGUAGES CXX) find_package(IntelDPCPP REQUIRED) add_executable(simple simple.cpp)
The minimum required CMake version for Linux is 3.20.5. For Windows the minimum required version is 3.23.0. The project CMake directive tells CMake the name of this project and that it uses C++. Projects that also use C, Fortran, or other languages can list the languages used them in the LANGUAGES parameter.
The find_package directive, tells CMake to use the IntelDPCPP module distributed with the oneAPI distribution. IntelDPCPP is in CMake's search path after running setvars.sh on Linux or setvars.bat on Windows. The IntelDPCPP module sets the compiler and linker flags required to build a project with DPC++.
The add_executable directive tells CMake which source files to use to build the simple application.
An example simple.cpp that works with the above CMakeLists.txt is:
#include <iostream> #include <CL/sycl.hpp> #include <cmath> int main(int argc, char* argv[]) { sycl::queue queue; std::cout << "Using " << queue.get_device().get_info<sycl::info::device::name>() << std::endl; // Compute the first n_items values in a well known sequence constexpr int n_items = 16; int *items = sycl::malloc_shared<int>(n_items, queue); queue.parallel_for(sycl::range<1>(n_items), [items] (sycl::id<1> i) { double x1 = pow((1.0 + sqrt(5.0))/2, i); double x2 = pow((1.0 - sqrt(5.0))/2, i); items[i] = round((x1 - x2)/sqrt(5)); }).wait(); for(int i = 0 ; i < n_items ; ++i) { std::cout << items[i] << std::endl; } free(items, queue); return 0; }
To build and run the simple application, put the CMakeLists.txt and simple.cpp in the same directory. Build the application in a subdirectory of the project using the appropriate compiler for your platform.
Linux
mkdir build cd build cmake -G Ninja -DCMAKE_CXX_COMPILER=icpx .. cmake --build . ./simple
Windows
mkdir build cd build cmake -G Ninja -DCMAKE_CXX_COMPILER=icx .. cmake –build . .\simple.exe
The Linux Makefile generator is known to work with Intel oneAPI compilers and CMake. Other build generators may work, but have not been thoroughly tested.