Skip to content

Commit 883f1ba

Browse files
committed
Add SYCL backend integration
1 parent 60c1097 commit 883f1ba

22 files changed

Lines changed: 710 additions & 120 deletions
Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
name: Setup SYCL toolchain
2+
description: Prepare AdaptiveCpp and compiler settings for ITLabAI SYCL CI.
3+
4+
inputs:
5+
phase:
6+
description: Either prepare or build.
7+
required: true
8+
cache-hit:
9+
description: actions/cache cache-hit output for the AdaptiveCpp toolchain.
10+
default: "false"
11+
12+
runs:
13+
using: composite
14+
steps:
15+
- name: Setup MSVC environment
16+
if: ${{ runner.os == 'Windows' }}
17+
uses: ilammy/msvc-dev-cmd@v1
18+
19+
- name: Install macOS toolchain dependencies
20+
if: ${{ runner.os == 'macOS' && inputs.phase == 'build' }}
21+
shell: bash
22+
run: brew install adaptivecpp libomp ninja
23+
24+
- name: Configure macOS toolchain environment
25+
if: ${{ runner.os == 'macOS' && inputs.phase == 'build' }}
26+
shell: bash
27+
run: |
28+
{
29+
echo "ITLABAI_CC=$(xcrun --find clang)"
30+
echo "ITLABAI_CXX=$(xcrun --find clang++)"
31+
echo "ITLABAI_CMAKE_PREFIX_PATH=$(brew --prefix adaptivecpp);$(brew --prefix libomp)"
32+
echo "ITLABAI_OPENMP_ROOT=$(brew --prefix libomp)"
33+
} >> "${GITHUB_ENV}"
34+
35+
- name: Install Linux toolchain dependencies
36+
if: ${{ runner.os == 'Linux' && (inputs.phase == 'build' || inputs.cache-hit != 'true') }}
37+
shell: bash
38+
run: |
39+
sudo apt-get update
40+
sudo apt-get install -y \
41+
build-essential \
42+
ccache \
43+
clang-18 \
44+
cmake \
45+
libboost-context-dev \
46+
libboost-fiber-dev \
47+
libboost-filesystem-dev \
48+
libboost-system-dev \
49+
libboost-test-dev \
50+
libclang-18-dev \
51+
libomp-18-dev \
52+
llvm-18-dev \
53+
ninja-build \
54+
python3
55+
56+
- name: Build Linux AdaptiveCpp
57+
if: ${{ runner.os == 'Linux' && inputs.phase == 'prepare' && inputs.cache-hit != 'true' }}
58+
shell: bash
59+
env:
60+
ACPP_INSTALL_DIR: ${{ runner.temp }}/adaptivecpp-install
61+
ACPP_SOURCE_DIR: ${{ runner.temp }}/AdaptiveCpp
62+
ACPP_BUILD_DIR: ${{ runner.temp }}/AdaptiveCpp-build
63+
ACPP_ARCHIVE_DIR: ${{ runner.temp }}/archives
64+
run: |
65+
mkdir -p "${ACPP_ARCHIVE_DIR}" "${ACPP_BUILD_DIR}" "${ACPP_INSTALL_DIR}"
66+
archive="${ACPP_ARCHIVE_DIR}/AdaptiveCpp-${ADAPTIVECPP_TAG}.tar.gz"
67+
curl -L "https://github.com/AdaptiveCpp/AdaptiveCpp/archive/refs/tags/${ADAPTIVECPP_TAG}.tar.gz" -o "${archive}"
68+
69+
tar -xzf "${archive}" -C "${RUNNER_TEMP}"
70+
extracted_dir="$(find "${RUNNER_TEMP}" -maxdepth 2 -type f -path '*/AdaptiveCpp-*/CMakeLists.txt' -print | head -n 1)"
71+
rm -rf "${ACPP_SOURCE_DIR}" "${ACPP_BUILD_DIR}"
72+
mv "$(dirname "${extracted_dir}")" "${ACPP_SOURCE_DIR}"
73+
mkdir -p "${ACPP_BUILD_DIR}"
74+
75+
cmake -S "${ACPP_SOURCE_DIR}" -B "${ACPP_BUILD_DIR}" -G Ninja \
76+
-DCMAKE_BUILD_TYPE=Release \
77+
-DCMAKE_INSTALL_PREFIX="${ACPP_INSTALL_DIR}" \
78+
-DCMAKE_C_COMPILER=/usr/bin/clang-18 \
79+
-DCMAKE_CXX_COMPILER=/usr/bin/clang++-18 \
80+
-DLLVM_DIR=/usr/lib/llvm-18/lib/cmake/llvm \
81+
-DClang_DIR=/usr/lib/llvm-18/lib/cmake/clang \
82+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
83+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
84+
cmake --build "${ACPP_BUILD_DIR}" --target install --parallel
85+
86+
- name: Configure Linux toolchain environment
87+
if: ${{ runner.os == 'Linux' && inputs.phase == 'build' }}
88+
shell: bash
89+
run: |
90+
{
91+
echo "ITLABAI_CC=/usr/bin/clang-18"
92+
echo "ITLABAI_CXX=/usr/bin/clang++-18"
93+
echo "ITLABAI_CMAKE_PREFIX_PATH=${RUNNER_TEMP}/adaptivecpp-install"
94+
echo "ITLABAI_OPENMP_ROOT=/usr/lib/llvm-18"
95+
} >> "${GITHUB_ENV}"
96+
echo "${RUNNER_TEMP}/adaptivecpp-install/bin" >> "${GITHUB_PATH}"
97+
98+
- name: Locate Windows LLVM toolchain
99+
if: ${{ runner.os == 'Windows' }}
100+
shell: pwsh
101+
run: |
102+
function Get-ShortPath($Path) {
103+
$resolvedPath = (Resolve-Path $Path).Path
104+
$shortPath = & $env:ComSpec /d /c "for %I in (`"$resolvedPath`") do @echo %~sI"
105+
if ($LASTEXITCODE -ne 0 -or [string]::IsNullOrWhiteSpace($shortPath)) {
106+
throw "Failed to resolve short path for $resolvedPath"
107+
}
108+
return $shortPath.Trim()
109+
}
110+
111+
$clangCl = Get-Command clang-cl.exe -ErrorAction SilentlyContinue
112+
if (-not $clangCl -and $env:ProgramFiles) {
113+
$programFilesClang = Join-Path $env:ProgramFiles 'LLVM/bin/clang-cl.exe'
114+
if (Test-Path $programFilesClang) {
115+
$clangCl = Get-Item $programFilesClang
116+
}
117+
}
118+
if (-not $clangCl -and $env:VCToolsInstallDir) {
119+
$vcToolsRoot = Resolve-Path (Join-Path $env:VCToolsInstallDir '../..')
120+
$vsClang = Join-Path $vcToolsRoot 'Llvm/x64/bin/clang-cl.exe'
121+
if (Test-Path $vsClang) {
122+
$clangCl = Get-Item $vsClang
123+
}
124+
}
125+
if (-not $clangCl) {
126+
throw 'clang-cl.exe was not found. Install the Visual Studio LLVM/Clang toolset on the Windows runner.'
127+
}
128+
129+
$clangClPath = $clangCl.Source
130+
if (-not $clangClPath) {
131+
$clangClPath = $clangCl.FullName
132+
}
133+
$clangBin = Split-Path $clangClPath -Parent
134+
$clangClShortPath = Get-ShortPath $clangClPath
135+
136+
"ITLABAI_CC=$clangClShortPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
137+
"ITLABAI_CXX=$clangClShortPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
138+
"ITLABAI_ACPP_CPU_CXX=$clangClShortPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
139+
"$clangBin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
140+
141+
- name: Configure Windows toolchain environment
142+
if: ${{ runner.os == 'Windows' && inputs.phase == 'build' }}
143+
shell: pwsh
144+
run: |
145+
"ITLABAI_CMAKE_PREFIX_PATH=$env:RUNNER_TEMP\adaptivecpp-install" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
146+
"$env:RUNNER_TEMP\adaptivecpp-install\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
147+
148+
- name: Install Windows Ninja
149+
if: ${{ runner.os == 'Windows' && (inputs.phase == 'build' || inputs.cache-hit != 'true') }}
150+
shell: pwsh
151+
run: |
152+
if (-not (Get-Command ninja.exe -ErrorAction SilentlyContinue)) {
153+
choco install ninja --yes --no-progress
154+
}
155+
156+
- name: Build Windows AdaptiveCpp
157+
if: ${{ runner.os == 'Windows' && inputs.phase == 'prepare' && inputs.cache-hit != 'true' }}
158+
shell: pwsh
159+
env:
160+
ACPP_INSTALL_DIR: ${{ runner.temp }}\adaptivecpp-install
161+
ACPP_SOURCE_DIR: ${{ runner.temp }}\AdaptiveCpp
162+
ACPP_BUILD_DIR: ${{ runner.temp }}\AdaptiveCpp-build
163+
ACPP_ARCHIVE_DIR: ${{ runner.temp }}\archives
164+
run: |
165+
New-Item -ItemType Directory -Force -Path $env:ACPP_ARCHIVE_DIR,$env:ACPP_BUILD_DIR,$env:ACPP_INSTALL_DIR | Out-Null
166+
$archive = Join-Path $env:ACPP_ARCHIVE_DIR "AdaptiveCpp-$env:ADAPTIVECPP_TAG.tar.gz"
167+
Invoke-WebRequest "https://github.com/AdaptiveCpp/AdaptiveCpp/archive/refs/tags/$env:ADAPTIVECPP_TAG.tar.gz" -OutFile $archive
168+
169+
Remove-Item $env:ACPP_SOURCE_DIR,$env:ACPP_BUILD_DIR -Recurse -Force -ErrorAction SilentlyContinue
170+
tar -xzf $archive -C $env:RUNNER_TEMP
171+
$extractedAcpp = Get-ChildItem $env:RUNNER_TEMP -Directory | Where-Object { $_.Name -like 'AdaptiveCpp-*' } | Select-Object -First 1
172+
Move-Item $extractedAcpp.FullName $env:ACPP_SOURCE_DIR
173+
New-Item -ItemType Directory -Force -Path $env:ACPP_BUILD_DIR | Out-Null
174+
175+
cmake -S $env:ACPP_SOURCE_DIR -B $env:ACPP_BUILD_DIR -G Ninja `
176+
"-DCMAKE_BUILD_TYPE=Release" `
177+
"-DCMAKE_INSTALL_PREFIX=$env:ACPP_INSTALL_DIR" `
178+
"-DCMAKE_C_COMPILER=$env:ITLABAI_CC" `
179+
"-DCMAKE_CXX_COMPILER=$env:ITLABAI_CXX" `
180+
-DCMAKE_C_COMPILER_LAUNCHER=ccache `
181+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
182+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
183+
184+
cmake --build $env:ACPP_BUILD_DIR --target install --parallel
185+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }

.github/workflows/sycl-ci.yml

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
name: SYCL CI
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
concurrency:
8+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
9+
cancel-in-progress: true
10+
11+
env:
12+
ADAPTIVECPP_TAG: v25.10.0
13+
ADAPTIVECPP_CACHE_VERSION: v4
14+
ACPP_TARGETS: omp.library-only
15+
16+
jobs:
17+
prepare-sycl-toolchain:
18+
name: prepare ${{ matrix.platform }}
19+
runs-on: ${{ matrix.runner }}
20+
timeout-minutes: 180
21+
strategy:
22+
fail-fast: true
23+
matrix:
24+
platform:
25+
- linux-x86_64
26+
- linux-arm64
27+
- windows-x86_64
28+
include:
29+
- platform: linux-x86_64
30+
runner: ubuntu-latest
31+
- platform: linux-arm64
32+
runner: ubuntu-24.04-arm
33+
- platform: windows-x86_64
34+
runner: windows-2022
35+
36+
steps:
37+
- uses: actions/checkout@v4
38+
39+
- name: Setup ccache
40+
uses: hendrikmuhs/ccache-action@v1.2
41+
with:
42+
key: ccache-${{ github.job }}-${{ matrix.platform }}
43+
max-size: 4G
44+
45+
- name: Restore or save AdaptiveCpp toolchain cache
46+
id: sycl-toolchain-cache
47+
uses: actions/cache@v4
48+
with:
49+
path: |
50+
${{ runner.temp }}/AdaptiveCpp
51+
${{ runner.temp }}/AdaptiveCpp-build
52+
${{ runner.temp }}/adaptivecpp-install
53+
${{ runner.temp }}/archives
54+
key: sycl-toolchain-${{ matrix.platform }}-${{ env.ADAPTIVECPP_TAG }}-${{ env.ADAPTIVECPP_CACHE_VERSION }}
55+
56+
- name: Prepare SYCL toolchain
57+
uses: ./.github/actions/setup-sycl-toolchain
58+
with:
59+
phase: prepare
60+
cache-hit: ${{ steps.sycl-toolchain-cache.outputs.cache-hit }}
61+
62+
build-sycl:
63+
name: ${{ matrix.platform }} ${{ matrix.build_type }}
64+
needs: prepare-sycl-toolchain
65+
runs-on: ${{ matrix.runner }}
66+
timeout-minutes: 180
67+
strategy:
68+
fail-fast: true
69+
matrix:
70+
platform:
71+
- linux-x86_64
72+
- linux-arm64
73+
- macos-arm64
74+
- windows-x86_64
75+
build_type:
76+
- Debug
77+
- Release
78+
include:
79+
- platform: linux-x86_64
80+
runner: ubuntu-latest
81+
- platform: linux-arm64
82+
runner: ubuntu-24.04-arm
83+
- platform: macos-arm64
84+
runner: macos-15
85+
- platform: windows-x86_64
86+
runner: windows-2022
87+
88+
steps:
89+
- uses: actions/checkout@v4
90+
with:
91+
submodules: true
92+
93+
- name: Setup ccache
94+
uses: hendrikmuhs/ccache-action@v1.2
95+
with:
96+
key: ccache-${{ github.job }}-${{ matrix.platform }}-${{ matrix.build_type }}
97+
max-size: 4G
98+
99+
- name: Restore AdaptiveCpp toolchain cache
100+
if: runner.os != 'macOS'
101+
uses: actions/cache/restore@v4
102+
with:
103+
path: |
104+
${{ runner.temp }}/AdaptiveCpp
105+
${{ runner.temp }}/AdaptiveCpp-build
106+
${{ runner.temp }}/adaptivecpp-install
107+
${{ runner.temp }}/archives
108+
key: sycl-toolchain-${{ matrix.platform }}-${{ env.ADAPTIVECPP_TAG }}-${{ env.ADAPTIVECPP_CACHE_VERSION }}
109+
fail-on-cache-miss: true
110+
111+
- name: Setup SYCL toolchain
112+
uses: ./.github/actions/setup-sycl-toolchain
113+
with:
114+
phase: build
115+
116+
- name: Configure
117+
if: runner.os != 'Windows'
118+
shell: bash
119+
run: |
120+
cmake -S . -B "build/${{ matrix.build_type }}" -G Ninja \
121+
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }} \
122+
-DCMAKE_C_COMPILER="${ITLABAI_CC}" \
123+
-DCMAKE_CXX_COMPILER="${ITLABAI_CXX}" \
124+
-DCMAKE_PREFIX_PATH="${ITLABAI_CMAKE_PREFIX_PATH}" \
125+
-DOpenMP_ROOT="${ITLABAI_OPENMP_ROOT}" \
126+
-DITLABAI_ENABLE_SYCL=ON \
127+
-DACPP_TARGETS="${ACPP_TARGETS}" \
128+
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
129+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
130+
131+
- name: Configure
132+
if: runner.os == 'Windows'
133+
shell: pwsh
134+
run: |
135+
cmake -S . -B "build/${{ matrix.build_type }}" -G Ninja `
136+
"-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}" `
137+
"-DCMAKE_C_COMPILER=$env:ITLABAI_CC" `
138+
"-DCMAKE_CXX_COMPILER=$env:ITLABAI_CXX" `
139+
"-DCMAKE_PREFIX_PATH=$env:ITLABAI_CMAKE_PREFIX_PATH" `
140+
"-DITLABAI_ENABLE_SYCL=ON" `
141+
"-DACPP_TARGETS=$env:ACPP_TARGETS" `
142+
"-DACPP_CPU_CXX=$env:ITLABAI_ACPP_CPU_CXX" `
143+
-DCMAKE_C_COMPILER_LAUNCHER=ccache `
144+
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
145+
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
146+
147+
- name: Build
148+
run: cmake --build "build/${{ matrix.build_type }}" --target SYCL_Example run_test --parallel
149+
150+
- name: Test
151+
run: ctest --test-dir "build/${{ matrix.build_type }}" --output-on-failure -R '^(UnitTests|SYCL\.Example)$'

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.20)
33
project(ITLabAI)
44

55
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
6+
option(ITLABAI_ENABLE_SYCL "Build SYCL example and helper targets" OFF)
67

78
option(ENABLE_STATISTIC_TENSORS "Enable statistic tensors" OFF)
89

@@ -83,4 +84,7 @@ endforeach()
8384
add_subdirectory(app)
8485
add_subdirectory(include)
8586
add_subdirectory(src)
87+
if(ITLABAI_ENABLE_SYCL)
88+
add_subdirectory(app/SYCL)
89+
endif()
8690
add_subdirectory(test)

app/Graph/graph_build.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ int main(int argc, char* argv[]) {
4040
options.par_backend = ParBackend::kOmp;
4141
} else if (backend_str == "kokkos") {
4242
options.par_backend = ParBackend::kKokkos;
43+
} else if (backend_str == "sycl") {
44+
options.par_backend = ParBackend::kSycl;
4345
} else {
4446
std::cerr << "Unknown parallel backend: " << backend_str
4547
<< ". Using default (Threads)." << '\n';

app/SYCL/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
find_package(AdaptiveCpp CONFIG REQUIRED)
2+
3+
add_executable(SYCL_Example
4+
sycl_example.cpp
5+
)
6+
target_link_libraries(SYCL_Example PRIVATE layers_lib AdaptiveCpp::acpp-rt)
7+
8+
if(WIN32)
9+
target_sources(SYCL_Example PRIVATE sycl_kernel.cpp)
10+
target_compile_definitions(SYCL_Example PRIVATE _USE_MATH_DEFINES ITLABAI_HAS_SYCL)
11+
else()
12+
add_library(SYCL_Example_kernel OBJECT sycl_kernel.cpp)
13+
target_compile_definitions(SYCL_Example_kernel PRIVATE ITLABAI_HAS_SYCL)
14+
target_link_libraries(SYCL_Example_kernel PRIVATE AdaptiveCpp::acpp-rt TBB_unified Kokkos_imported)
15+
add_sycl_to_target(TARGET SYCL_Example_kernel SOURCES
16+
sycl_kernel.cpp
17+
)
18+
target_sources(SYCL_Example PRIVATE $<TARGET_OBJECTS:SYCL_Example_kernel>)
19+
endif()
20+
21+
add_test(NAME SYCL.Example COMMAND SYCL_Example)
22+
set_tests_properties(SYCL.Example PROPERTIES
23+
LABELS "sycl;smoke"
24+
TIMEOUT 60
25+
)

0 commit comments

Comments
 (0)