Skip to content

Add SYCL support

Add SYCL support #108

Workflow file for this run

name: SYCL CI
on:
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
ADAPTIVECPP_TAG: v25.10.0
LLVM_MINGW_VERSION: "20231128"
jobs:
build-sycl:
name: ${{ matrix.platform }}
runs-on: ${{ matrix.runner }}
timeout-minutes: 360
strategy:
fail-fast: true
matrix:
include:
- platform: linux-x86_64
runner: ubuntu-latest
- platform: linux-arm64
runner: ubuntu-24.04-arm
- platform: macos-arm64
runner: macos-15
- platform: windows-x86_64
runner: windows-2022
steps:
- uses: actions/checkout@v4
with:
submodules: true
- name: Setup ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ccache-${{ github.job }}-${{ matrix.platform }}
max-size: 4G
- name: Restore AdaptiveCpp toolchain cache
uses: actions/cache@v4
with:
path: |
${{ runner.temp }}/AdaptiveCpp
${{ runner.temp }}/AdaptiveCpp-build
${{ runner.temp }}/adaptivecpp-install
${{ runner.temp }}/llvm
${{ runner.temp }}/boost_1_87_0
${{ runner.temp }}/ninja_install
${{ runner.temp }}/archives
key: sycl-toolchain-${{ matrix.platform }}-${{ env.ADAPTIVECPP_TAG }}-${{ env.LLVM_MINGW_VERSION }}-v1
- name: Setup MSVC environment
if: runner.os == 'Windows'
uses: ilammy/msvc-dev-cmd@v1
- name: Prepare AdaptiveCpp toolchain
if: runner.os == 'macOS'
shell: bash
run: |
brew install adaptivecpp libomp ninja
echo "ITLABAI_CC=$(xcrun --find clang)" >> "${GITHUB_ENV}"
echo "ITLABAI_CXX=$(xcrun --find clang++)" >> "${GITHUB_ENV}"
echo "ITLABAI_CMAKE_PREFIX_PATH=$(brew --prefix adaptivecpp);$(brew --prefix libomp)" >> "${GITHUB_ENV}"
echo "ITLABAI_OPENMP_ROOT=$(brew --prefix libomp)" >> "${GITHUB_ENV}"
echo "ACPP_TARGETS=omp.library-only" >> "${GITHUB_ENV}"
- name: Prepare AdaptiveCpp toolchain
if: runner.os == 'Linux'
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y \
build-essential \
ccache \
clang-18 \
cmake \
libboost-context-dev \
libboost-fiber-dev \
libboost-filesystem-dev \
libboost-system-dev \
libboost-test-dev \
libclang-18-dev \
libomp-18-dev \
llvm-18-dev \
ninja-build \
python3
install_dir="${RUNNER_TEMP}/adaptivecpp-install"
config="${install_dir}/lib/cmake/AdaptiveCpp/AdaptiveCppConfig.cmake"
archive_dir="${RUNNER_TEMP}/archives"
archive="${archive_dir}/AdaptiveCpp-${ADAPTIVECPP_TAG}.tar.gz"
source_dir="${RUNNER_TEMP}/AdaptiveCpp"
build_dir="${RUNNER_TEMP}/AdaptiveCpp-build"
mkdir -p "${archive_dir}"
if [ ! -f "${archive}" ]; then
curl -L "https://github.com/AdaptiveCpp/AdaptiveCpp/archive/refs/tags/${ADAPTIVECPP_TAG}.tar.gz" -o "${archive}"
fi
if [ ! -f "${config}" ]; then
rm -rf "${source_dir}" "${build_dir}"
mkdir -p "${build_dir}" "${install_dir}"
tar -xzf "${archive}" -C "${RUNNER_TEMP}"
extracted_dir="$(find "${RUNNER_TEMP}" -maxdepth 1 -type d -name 'AdaptiveCpp-*' | head -n 1)"
mv "${extracted_dir}" "${source_dir}"
cmake -S "${source_dir}" -B "${build_dir}" -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX="${install_dir}" \
-DCMAKE_C_COMPILER=/usr/bin/clang-18 \
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-18 \
-DLLVM_DIR=/usr/lib/llvm-18/lib/cmake/llvm \
-DClang_DIR=/usr/lib/llvm-18/lib/cmake/clang \
$(command -v ccache >/dev/null 2>&1 && printf '%s ' -DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache)
cmake --build "${build_dir}" --target install --parallel
fi
echo "ITLABAI_CC=/usr/bin/clang-18" >> "${GITHUB_ENV}"
echo "ITLABAI_CXX=/usr/bin/clang++-18" >> "${GITHUB_ENV}"
echo "ITLABAI_CMAKE_PREFIX_PATH=${install_dir}" >> "${GITHUB_ENV}"
echo "ITLABAI_OPENMP_ROOT=/usr/lib/llvm-18" >> "${GITHUB_ENV}"
echo "ACPP_TARGETS=omp.library-only" >> "${GITHUB_ENV}"
if [ -d "${install_dir}/bin" ]; then
echo "${install_dir}/bin" >> "${GITHUB_PATH}"
fi
- name: Prepare AdaptiveCpp toolchain
if: runner.os == 'Windows'
shell: pwsh
run: |
$archiveDir = Join-Path $env:RUNNER_TEMP 'archives'
$llvmDir = Join-Path $env:RUNNER_TEMP 'llvm'
$ninjaDir = Join-Path $env:RUNNER_TEMP 'ninja_install'
$boostDir = Join-Path $env:RUNNER_TEMP 'boost_1_87_0'
$sourceDir = Join-Path $env:RUNNER_TEMP 'AdaptiveCpp'
$buildDir = Join-Path $env:RUNNER_TEMP 'AdaptiveCpp-build'
$installDir = Join-Path $env:RUNNER_TEMP 'adaptivecpp-install'
New-Item -ItemType Directory -Force -Path $archiveDir | Out-Null
$ninjaArchive = Join-Path $archiveDir 'ninja-win.zip'
if (-not (Test-Path (Join-Path $ninjaDir 'ninja.exe'))) {
if (-not (Test-Path $ninjaArchive)) {
Invoke-WebRequest 'https://github.com/ninja-build/ninja/releases/download/v1.11.1/ninja-win.zip' -OutFile $ninjaArchive
}
Remove-Item $ninjaDir -Recurse -Force -ErrorAction SilentlyContinue
Expand-Archive $ninjaArchive -DestinationPath $ninjaDir
}
$llvmArchive = Join-Path $archiveDir "llvm-mingw-$env:LLVM_MINGW_VERSION.zip"
if (-not (Test-Path (Join-Path $llvmDir 'bin/clang++.exe'))) {
if (-not (Test-Path $llvmArchive)) {
Invoke-WebRequest "https://github.com/mstorsjo/llvm-mingw/releases/download/$env:LLVM_MINGW_VERSION/llvm-mingw-$env:LLVM_MINGW_VERSION-msvcrt-x86_64.zip" -OutFile $llvmArchive
}
Remove-Item $llvmDir -Recurse -Force -ErrorAction SilentlyContinue
Expand-Archive $llvmArchive -DestinationPath $env:RUNNER_TEMP
$extractedLlvm = Get-ChildItem $env:RUNNER_TEMP -Directory | Where-Object { $_.Name -like 'llvm-mingw-*-msvcrt-x86_64' } | Select-Object -First 1
Move-Item $extractedLlvm.FullName $llvmDir
}
$env:PATH = "$($llvmDir)\bin;$ninjaDir;$env:PATH"
if (-not (Test-Path (Join-Path $boostDir 'stage/lib'))) {
$boostArchive = Join-Path $archiveDir 'boost_1_87_0.zip'
if (-not (Test-Path $boostArchive)) {
Invoke-WebRequest 'https://archives.boost.io/release/1.87.0/source/boost_1_87_0.zip' -OutFile $boostArchive
}
Remove-Item $boostDir -Recurse -Force -ErrorAction SilentlyContinue
Expand-Archive $boostArchive -DestinationPath $env:RUNNER_TEMP
Push-Location $boostDir
cmd /c bootstrap.bat clang | Out-Host
cmd /c 'b2.exe --with-context --with-fiber --with-atomic --with-filesystem --with-test toolset=clang address-model=64 variant=release --build-type=complete stage' | Out-Host
Pop-Location
}
$acppConfig = Join-Path $installDir 'lib/cmake/AdaptiveCpp/AdaptiveCppConfig.cmake'
$adaptiveCppArchive = Join-Path $archiveDir "AdaptiveCpp-$env:ADAPTIVECPP_TAG.tar.gz"
if (-not (Test-Path $adaptiveCppArchive)) {
Invoke-WebRequest "https://github.com/AdaptiveCpp/AdaptiveCpp/archive/refs/tags/$env:ADAPTIVECPP_TAG.tar.gz" -OutFile $adaptiveCppArchive
}
if (-not (Test-Path $acppConfig)) {
Remove-Item $sourceDir,$buildDir -Recurse -Force -ErrorAction SilentlyContinue
New-Item -ItemType Directory -Force -Path $buildDir,$installDir | Out-Null
tar -xzf $adaptiveCppArchive -C $env:RUNNER_TEMP
$extractedAcpp = Get-ChildItem $env:RUNNER_TEMP -Directory | Where-Object { $_.Name -like 'AdaptiveCpp-*' } | Select-Object -First 1
Move-Item $extractedAcpp.FullName $sourceDir
$cmakeArgs = @(
'-S', $sourceDir,
'-B', $buildDir,
'-G', 'Ninja',
'-DCMAKE_BUILD_TYPE=Release',
"-DCMAKE_INSTALL_PREFIX=$installDir",
"-DCMAKE_C_COMPILER=$llvmDir/bin/clang.exe",
"-DCMAKE_CXX_COMPILER=$llvmDir/bin/clang++.exe",
"-DBOOST_ROOT=$boostDir",
'-DBoost_COMPILER=-clang17',
'-DBoost_ARCHITECTURE=-x64'
)
if (Get-Command ccache -ErrorAction SilentlyContinue) {
$cmakeArgs += '-DCMAKE_C_COMPILER_LAUNCHER=ccache'
$cmakeArgs += '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache'
}
& cmake @cmakeArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& cmake --build $buildDir --target install --parallel
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}
"ITLABAI_CC=$llvmDir/bin/clang.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"ITLABAI_CXX=$llvmDir/bin/clang++.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"ITLABAI_CMAKE_PREFIX_PATH=$installDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"ITLABAI_OPENMP_ROOT=$llvmDir" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
'ACPP_TARGETS=omp.library-only' | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
"$installDir\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
"$llvmDir\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
"$ninjaDir" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Configure, build and test
if: runner.os != 'Windows'
shell: bash
run: |
for build_type in Debug Release; do
build_dir="build/${build_type}"
cmake_args=(
-S .
-B "${build_dir}"
-G Ninja
-DCMAKE_BUILD_TYPE=${build_type}
-DCMAKE_C_COMPILER=${ITLABAI_CC}
-DCMAKE_CXX_COMPILER=${ITLABAI_CXX}
-DCMAKE_PREFIX_PATH=${ITLABAI_CMAKE_PREFIX_PATH}
-DITLABAI_ENABLE_SYCL=ON
-DACPP_TARGETS=${ACPP_TARGETS}
)
if command -v ccache >/dev/null 2>&1; then
cmake_args+=(
-DCMAKE_C_COMPILER_LAUNCHER=ccache
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
)
fi
if [ -n "${ITLABAI_OPENMP_ROOT:-}" ]; then
cmake_args+=(-DOpenMP_ROOT=${ITLABAI_OPENMP_ROOT})
fi
cmake "${cmake_args[@]}"
cmake --build "${build_dir}" --target SYCL_Example run_test --parallel
ctest --test-dir "${build_dir}" --output-on-failure -R '^UnitTests$'
done
- name: Configure, build and test
if: runner.os == 'Windows'
shell: pwsh
run: |
foreach ($buildType in 'Debug', 'Release') {
$buildDir = "build/$buildType"
$cmakeArgs = @(
'-S', '.',
'-B', $buildDir,
'-G', 'Ninja',
"-DCMAKE_BUILD_TYPE=$buildType",
"-DCMAKE_C_COMPILER=$env:ITLABAI_CC",
"-DCMAKE_CXX_COMPILER=$env:ITLABAI_CXX",
"-DCMAKE_PREFIX_PATH=$env:ITLABAI_CMAKE_PREFIX_PATH",
'-DITLABAI_ENABLE_SYCL=ON',
"-DACPP_TARGETS=$env:ACPP_TARGETS"
)
if (Get-Command ccache -ErrorAction SilentlyContinue) {
$cmakeArgs += '-DCMAKE_C_COMPILER_LAUNCHER=ccache'
$cmakeArgs += '-DCMAKE_CXX_COMPILER_LAUNCHER=ccache'
}
if ($env:ITLABAI_OPENMP_ROOT) {
$cmakeArgs += "-DOpenMP_ROOT=$env:ITLABAI_OPENMP_ROOT"
}
& cmake @cmakeArgs
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& cmake --build $buildDir --target SYCL_Example run_test --parallel
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
& ctest --test-dir $buildDir --output-on-failure -R '^UnitTests$'
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}