Adding Intel oneAPI toolkits to GitHub actions
While having access to the latest top secret Intel CPU and GPU hardware is one of the benefits of preparing science and engineering applications for the upcoming Aurora supercomputer, much of the open-source code for these applications is hosted in public repositories on GitHub, GitLab, Bitbucket, or similar services.
Adding Intel oneAPI compilers and toolkits to the CI pipelines for such projects can help catch many issues at the source as they are introduced during the development cycle. Fortunately this is easier than you might think.
This gist demonstrates how to add the Intel oneAPI DPC++ compiler and oneMKL library to GitHub actions for a project using CMake.
First, the oneAPI DPC++ compiler and oneMKL must be installed on the runner. For Ubuntu, this can be done using apt in a manner similar to an installation on your local machine. Notice that only the specific components needed are installed to avoid long build times.
name: CI
on:
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: add oneAPI to apt
shell: bash
run: |
cd /tmp
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
- name: install oneAPI dpcpp compiler
shell: bash
run: |
sudo apt update
sudo apt install intel-oneapi-compiler-dpcpp-cpp
- name: install oneAPI MKL library
shell: bash
run: |
sudo apt install intel-oneapi-mkl-devel
Second, it is important to sourcesetvars.sh
at the beginning of each step which uses the compilers or toolkits to ensure all necessary paths and environment variables are set.
- name: configure
shell: bash
run: |
source /opt/intel/oneapi/setvars.sh
cmake -S . -B build \
-DCMAKE_BUILD_TYPE="RelWithDebInfo" \
-DCMAKE_INSTALL_PREFIX=install \
-DCMAKE_CXX_COMPILER=dpcpp \
-DCMAKE_C_COMPILER=icx \
-DIntelDPCPP_DIR="/opt/intel/oneapi/compiler/latest/linux/cmake/SYCL" \
-DMKL_ROOT="/opt/intel/oneapi/mkl/latest" \
-DTBB_ROOT="/opt/intel/oneapi/tbb/latest"
- name: build
shell: bash
run: |
source /opt/intel/oneapi/setvars.sh
cmake --build build
- name: test
shell: bash
run: |
source /opt/intel/oneapi/setvars.sh
export SYCL_DEVICE_FILTER=opencl.cpu
ctest --test-dir build --output-on-failure
Finally, the CMakeLists.txt file at the top of the source tree contains the following:
enable_language(CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
list(APPEND CMAKE_MODULE_PATH "${IntelDPCPP_DIR}")
find_package(IntelDPCPP REQUIRED)
find_package(MKL REQUIRED)
Notice the path to the DPC++ CMake package file must be added to CMAKE_MODULE_PATH
.
Adding Intel oneAPI compilers and toolkits to the automated workflows for your open-source project is easier than you might think. Hopefully this helps with sharing your next great software project with the world.
Good luck and happy coding!