Skip to content

Commit 2136eb1

Browse files
authored
Add SYCL support (#284)
1 parent 60c1097 commit 2136eb1

25 files changed

Lines changed: 820 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/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ jobs:
226226
- name: Upload coverage reports to Codecov
227227
uses: codecov/codecov-action@v4.0.1
228228
with:
229+
fail_ci_if_error: true
229230
token: ${{ secrets.CODECOV_TOKEN }}
230231
slug: embedded-dev-research/ITLabAI
231232

0 commit comments

Comments
 (0)