Skip to content

Commit abff6a6

Browse files
committed
Build cached Intel native CPU toolchain in CI
1 parent c9f83fe commit abff6a6

2 files changed

Lines changed: 128 additions & 41 deletions

File tree

.github/workflows/sycl-ci.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,40 @@ env:
1414
ADAPTIVECPP_TAG: v25.10.0
1515

1616
jobs:
17+
prepare-sycl-linux-x86-toolchain:
18+
name: prepare-linux-x86_64-toolchain
19+
runs-on: ubuntu-latest
20+
timeout-minutes: 360
21+
22+
defaults:
23+
run:
24+
shell: bash
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Setup Ninja
30+
uses: seanmiddleditch/gha-setup-ninja@v6
31+
32+
- name: Setup ccache
33+
uses: hendrikmuhs/ccache-action@v1.2
34+
with:
35+
key: ccache-${{ github.job }}-${{ env.INTEL_LLVM_TAG }}
36+
max-size: 8G
37+
38+
- name: Restore Intel toolchain cache
39+
uses: actions/cache@v4
40+
with:
41+
path: ${{ runner.temp }}/intel-nativecpu-toolchain/install
42+
key: intel-nativecpu-toolchain-${{ env.INTEL_LLVM_TAG }}-v1
43+
44+
- name: Prepare Intel native_cpu toolchain
45+
run: python3 ./scripts/ci/sycl_x86_setup.py linux-x86_64
46+
1747
build-sycl-linux-x86:
1848
name: linux-x86_64 / ${{ matrix.build_type }}
1949
runs-on: ubuntu-latest
50+
needs: prepare-sycl-linux-x86-toolchain
2051
timeout-minutes: 360
2152
strategy:
2253
fail-fast: true
@@ -43,6 +74,12 @@ jobs:
4374
key: ccache-${{ github.job }}-${{ matrix.build_type }}
4475
max-size: 2G
4576

77+
- name: Restore Intel toolchain cache
78+
uses: actions/cache@v4
79+
with:
80+
path: ${{ runner.temp }}/intel-nativecpu-toolchain/install
81+
key: intel-nativecpu-toolchain-${{ env.INTEL_LLVM_TAG }}-v1
82+
4683
- name: Prepare platform settings
4784
run: python3 ./scripts/ci/sycl_x86_setup.py linux-x86_64
4885

scripts/ci/sycl_x86_setup.py

Lines changed: 91 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,26 @@
2121
)
2222

2323

24+
def linux_native_cpu_toolchain_root() -> Path:
25+
return Path(require_env("RUNNER_TEMP")) / "intel-nativecpu-toolchain" / "install"
26+
27+
28+
def linux_native_cpu_toolchain_ready(toolchain_root: Path) -> bool:
29+
if not toolchain_root.exists():
30+
return False
31+
compiler_candidates = [
32+
toolchain_root / "bin" / "clang++",
33+
toolchain_root / "bin" / "compiler" / "clang++",
34+
]
35+
has_compiler = any(path.exists() for path in compiler_candidates)
36+
has_runtime = find_file([toolchain_root], "libsycl.so") is not None
37+
has_native_cpu_libspirv = (
38+
find_file([toolchain_root], "remangled-l64-signed_char.libspirv-native_cpu.bc")
39+
is not None
40+
)
41+
return has_compiler and has_runtime and has_native_cpu_libspirv
42+
43+
2444
def configure_platform(platform: str) -> None:
2545
settings = {
2646
"linux-x86_64": {
@@ -62,56 +82,86 @@ def setup_linux_runtime() -> None:
6282
"g++-13",
6383
"gcc-13",
6484
"git",
85+
"libzstd-dev",
86+
"ninja-build",
6587
"python3",
6688
"zstd",
6789
]
6890
)
69-
key_url = "https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB"
70-
key_path = Path(require_env("RUNNER_TEMP")) / "oneapi-intel-key.pub"
71-
armored_key_path = Path(require_env("RUNNER_TEMP")) / "oneapi-archive-keyring.gpg"
72-
download(key_url, key_path)
73-
run(
74-
[
75-
"gpg",
76-
"--dearmor",
77-
"--output",
78-
str(armored_key_path),
79-
str(key_path),
80-
]
81-
)
82-
run(
83-
[
84-
*command_prefix,
85-
"cp",
86-
str(armored_key_path),
87-
"/usr/share/keyrings/oneapi-archive-keyring.gpg",
88-
]
89-
)
90-
run(
91-
[*command_prefix, "tee", "/etc/apt/sources.list.d/oneAPI.list"],
92-
input_text=(
93-
"deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] "
94-
"https://apt.repos.intel.com/oneapi all main\n"
95-
),
96-
)
97-
run([*command_prefix, "apt-get", "update"])
98-
run(
99-
[
100-
*command_prefix,
101-
"apt-get",
102-
"install",
103-
"-y",
104-
"intel-oneapi-compiler-dpcpp-cpp",
105-
]
106-
)
107-
10891
write_env("ITLABAI_GCC_INSTALL_DIR", "/usr/lib/gcc/x86_64-linux-gnu/13")
109-
write_env("SYCL_ROOT", "/opt/intel/oneapi/compiler/latest")
92+
93+
94+
def build_linux_native_cpu_toolchain() -> Path:
95+
toolchain_root = linux_native_cpu_toolchain_root()
96+
if linux_native_cpu_toolchain_ready(toolchain_root):
97+
write_env("SYCL_ROOT", str(toolchain_root))
98+
return toolchain_root
99+
100+
toolchain_base = toolchain_root.parent
101+
source_dir = toolchain_base / "src"
102+
build_dir = toolchain_base / "build"
103+
llvm_tag = require_env("INTEL_LLVM_TAG")
104+
105+
toolchain_base.mkdir(parents=True, exist_ok=True)
106+
if not (source_dir / ".git").exists():
107+
run(
108+
[
109+
"git",
110+
"clone",
111+
"--depth",
112+
"1",
113+
"--branch",
114+
llvm_tag,
115+
"https://github.com/intel/llvm.git",
116+
str(source_dir),
117+
]
118+
)
119+
120+
configure_stamp = build_dir / "CMakeCache.txt"
121+
if not configure_stamp.exists():
122+
build_dir.mkdir(parents=True, exist_ok=True)
123+
run(
124+
[
125+
"python3",
126+
str(source_dir / "buildbot" / "configure.py"),
127+
"-w",
128+
str(toolchain_base),
129+
"-s",
130+
str(source_dir),
131+
"-o",
132+
str(build_dir),
133+
"-t",
134+
"Release",
135+
"--native_cpu",
136+
"--cmake-gen",
137+
"Ninja",
138+
"--use-zstd",
139+
"-DCMAKE_C_COMPILER=gcc-13",
140+
"-DCMAKE_CXX_COMPILER=g++-13",
141+
"-DCMAKE_C_COMPILER_LAUNCHER=ccache",
142+
"-DCMAKE_CXX_COMPILER_LAUNCHER=ccache",
143+
f"-DCMAKE_INSTALL_PREFIX={toolchain_root}",
144+
"-DSYCL_ENABLE_BACKENDS=native_cpu",
145+
"-DSYCL_INCLUDE_TESTS=OFF",
146+
"-DLLVM_INSTALL_UTILS=ON",
147+
]
148+
)
149+
150+
run(["cmake", "--build", str(build_dir), "--target", "sycl-toolchain", "--parallel"])
151+
152+
if not linux_native_cpu_toolchain_ready(toolchain_root):
153+
main_error(
154+
"Intel SYCL native_cpu toolchain build completed, but required files "
155+
"were not installed"
156+
)
157+
158+
write_env("SYCL_ROOT", str(toolchain_root))
159+
return toolchain_root
110160

111161

112162
def prepare_sycl_toolchain() -> Path:
113163
if require_env("RUNNER_OS") == "Linux" and not os.environ.get("TOOLCHAIN_ASSET"):
114-
return Path(require_env("SYCL_ROOT"))
164+
return build_linux_native_cpu_toolchain()
115165

116166
runner_os = require_env("RUNNER_OS")
117167
runner_temp = require_env("RUNNER_TEMP")

0 commit comments

Comments
 (0)