Add SYCL support #119
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| 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 }}/ninja_install | |
| ${{ runner.temp }}/archives | |
| key: sycl-toolchain-${{ matrix.platform }}-${{ env.ADAPTIVECPP_TAG }}-v2 | |
| - 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 2 -type f -path '*/AdaptiveCpp-*/CMakeLists.txt' -print | head -n 1)" | |
| extracted_dir="$(dirname "${extracted_dir}")" | |
| 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' | |
| $ninjaDir = Join-Path $env:RUNNER_TEMP 'ninja_install' | |
| $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 | |
| } | |
| $clangCl = Get-Command clang-cl.exe -ErrorAction SilentlyContinue | |
| if (-not $clangCl -and $env:ProgramFiles) { | |
| $programFilesClang = Join-Path $env:ProgramFiles 'LLVM/bin/clang-cl.exe' | |
| if (Test-Path $programFilesClang) { | |
| $clangCl = Get-Item $programFilesClang | |
| } | |
| } | |
| if (-not $clangCl -and $env:VCToolsInstallDir) { | |
| $vcToolsRoot = Resolve-Path (Join-Path $env:VCToolsInstallDir '../..') | |
| $vsClang = Join-Path $vcToolsRoot 'Llvm/x64/bin/clang-cl.exe' | |
| if (Test-Path $vsClang) { | |
| $clangCl = Get-Item $vsClang | |
| } | |
| } | |
| if (-not $clangCl) { | |
| throw 'clang-cl.exe was not found. Install the Visual Studio LLVM/Clang toolset on the Windows runner.' | |
| } | |
| $clangClPath = $clangCl.Source | |
| if (-not $clangClPath) { | |
| $clangClPath = $clangCl.FullName | |
| } | |
| $clangBin = Split-Path $clangClPath -Parent | |
| $clangCxxPath = Join-Path $clangBin 'clang++.exe' | |
| if (-not (Test-Path $clangCxxPath)) { | |
| throw "clang++.exe was not found next to $clangClPath. Install the Visual Studio LLVM/Clang toolset on the Windows runner." | |
| } | |
| $env:PATH = "$clangBin;$ninjaDir;$env:PATH" | |
| $acppConfig = Join-Path $installDir 'lib/cmake/AdaptiveCpp/adaptivecpp-config.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=$clangClPath", | |
| "-DCMAKE_CXX_COMPILER=$clangClPath" | |
| ) | |
| 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=$clangClPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| "ITLABAI_CXX=$clangClPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| "ITLABAI_ACPP_CPU_CXX=$clangCxxPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append | |
| "ITLABAI_CMAKE_PREFIX_PATH=$installDir" | 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 | |
| "$clangBin" | 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", | |
| "-DACPP_CPU_CXX=$env:ITLABAI_ACPP_CPU_CXX" | |
| ) | |
| 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 } | |
| } |