Skip to content

Commit 8f80df0

Browse files
[Github] Use building LLVM as perf-training for CI container (#80713)
This patch adjusts the build process for building the toolchain for the CI container to perform more rigorous perf-training for PGO, particularly building the entirety of LLVM as that is what showed the best results while benchmarking. This patch also splits the job into two stages to avoid timeouts due to the large increase in buildtime. There are a couple other hacks added in here to make things work that we can do away with eventually once we're able to run jobs like this on more powerful self-hosted runners.
1 parent 62838b8 commit 8f80df0

File tree

6 files changed

+139
-58
lines changed

6 files changed

+139
-58
lines changed

.github/workflows/build-ci-container.yml

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: Build CI Container
32

43
permissions:
@@ -19,9 +18,41 @@ on:
1918
- '.github/workflows/containers/github-action-ci/**'
2019

2120
jobs:
22-
build-ci-container:
21+
# TODO(boomanaiden154): Switch this back to a single stage build when we can
22+
# run this on the self-hosted runners and don't have to do it this way to
23+
# avoid timeouts.
24+
build-ci-container-stage1:
2325
if: github.repository_owner == 'llvm'
2426
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout LLVM
29+
uses: actions/checkout@v4
30+
with:
31+
sparse-checkout: .github/workflows/containers/github-action-ci/
32+
- name: Change podman Root Direcotry
33+
run: |
34+
mkdir -p ~/.config/containers
35+
sudo mkdir -p /mnt/podman
36+
sudo chown `whoami`:`whoami` /mnt/podman
37+
cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf
38+
podman info
39+
- name: Build container stage1
40+
working-directory: ./.github/workflows/containers/github-action-ci/
41+
run: |
42+
podman build -t stage1-toolchain --target stage1-toolchain -f stage1.Dockerfile .
43+
- name: Save container image
44+
run: |
45+
podman save stage1-toolchain > stage1-toolchain.tar
46+
- name: Upload container image
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: stage1-toolchain
50+
path: stage1-toolchain.tar
51+
retention-days: 1
52+
build-ci-container-stage2:
53+
if: github.repository_owner == 'llvm'
54+
runs-on: ubuntu-latest
55+
needs: build-ci-container-stage1
2556
permissions:
2657
packages: write
2758
steps:
@@ -38,10 +69,27 @@ jobs:
3869
with:
3970
sparse-checkout: .github/workflows/containers/github-action-ci/
4071

72+
- name: Change podman Root Direcotry
73+
run: |
74+
mkdir -p ~/.config/containers
75+
sudo mkdir -p /mnt/podman
76+
sudo chown `whoami`:`whoami` /mnt/podman
77+
cp ./.github/workflows/containers/github-action-ci/storage.conf ~/.config/containers/storage.conf
78+
podman info
79+
80+
- name: Download stage1-toolchain
81+
uses: actions/download-artifact@v4
82+
with:
83+
name: stage1-toolchain
84+
85+
- name: Load stage1-toolchain
86+
run: |
87+
podman load -i stage1-toolchain.tar
88+
4189
- name: Build Container
4290
working-directory: ./.github/workflows/containers/github-action-ci/
4391
run: |
44-
podman build -t ${{ steps.vars.outputs.container-name-tag }} .
92+
podman build -t ${{ steps.vars.outputs.container-name-tag }} -f stage2.Dockerfile .
4593
podman tag ${{ steps.vars.outputs.container-name-tag }} ${{ steps.vars.outputs.container-name }}:latest
4694
4795
- name: Test Container

.github/workflows/containers/github-action-ci/Dockerfile

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
diff --git a/clang/cmake/caches/BOLT-PGO.cmake b/clang/cmake/caches/BOLT-PGO.cmake
2+
index 1a04ca9a74e5..d092820e4115 100644
3+
--- a/clang/cmake/caches/BOLT-PGO.cmake
4+
+++ b/clang/cmake/caches/BOLT-PGO.cmake
5+
@@ -4,6 +4,8 @@ set(CLANG_BOOTSTRAP_TARGETS
6+
stage2-clang-bolt
7+
stage2-distribution
8+
stage2-install-distribution
9+
+ clang
10+
+ lld
11+
CACHE STRING "")
12+
set(BOOTSTRAP_CLANG_BOOTSTRAP_TARGETS
13+
clang-bolt
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
FROM docker.io/library/ubuntu:22.04 as base
2+
ENV LLVM_SYSROOT=/opt/llvm
3+
4+
FROM base as stage1-toolchain
5+
ENV LLVM_VERSION=17.0.6
6+
7+
RUN apt-get update && \
8+
apt-get install -y \
9+
wget \
10+
gcc \
11+
g++ \
12+
cmake \
13+
ninja-build \
14+
python3 \
15+
git \
16+
curl
17+
18+
RUN curl -O -L https://github.com/llvm/llvm-project/archive/refs/tags/llvmorg-$LLVM_VERSION.tar.gz && tar -xf llvmorg-$LLVM_VERSION.tar.gz
19+
20+
WORKDIR /llvm-project-llvmorg-$LLVM_VERSION
21+
22+
COPY bootstrap.patch /
23+
24+
# TODO(boomanaiden154): Remove the patch pulled from a LLVM PR once we bump
25+
# the toolchain to version 18 and the patch is in-tree.
26+
# TODO(boomanaiden154): Remove the bootstrap patch once we unsplit the build
27+
# and no longer need to explicitly build the stage2 dependencies.
28+
RUN curl https://github.com/llvm/llvm-project/commit/dd0356d741aefa25ece973d6cc4b55dcb73b84b4.patch | patch -p1 && cat /bootstrap.patch | patch -p1
29+
30+
RUN mkdir build
31+
32+
RUN cmake -B ./build -G Ninja ./llvm \
33+
-C ./clang/cmake/caches/BOLT-PGO.cmake \
34+
-DBOOTSTRAP_LLVM_ENABLE_LLD=ON \
35+
-DBOOTSTRAP_BOOTSTRAP_LLVM_ENABLE_LLD=ON \
36+
-DPGO_INSTRUMENT_LTO=Thin \
37+
-DLLVM_ENABLE_RUNTIMES="compiler-rt" \
38+
-DCMAKE_INSTALL_PREFIX="$LLVM_SYSROOT" \
39+
-DLLVM_ENABLE_PROJECTS="bolt;clang;lld;clang-tools-extra" \
40+
-DLLVM_DISTRIBUTION_COMPONENTS="lld;compiler-rt;clang-format" \
41+
-DCLANG_DEFAULT_LINKER="lld" \
42+
-DBOOTSTRAP_CLANG_PGO_TRAINING_DATA_SOURCE_DIR=/llvm-project-llvmorg-$LLVM_VERSION/llvm
43+
44+
RUN ninja -C ./build stage2-instrumented-clang stage2-instrumented-lld
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
FROM docker.io/library/ubuntu:22.04 as base
2+
ENV LLVM_SYSROOT=/opt/llvm
3+
4+
FROM stage1-toolchain AS stage2-toolchain
5+
6+
RUN ninja -C ./build stage2-clang-bolt stage2-install-distribution && ninja -C ./build install-distribution && rm -rf ./build
7+
8+
FROM base
9+
10+
COPY --from=stage2-toolchain $LLVM_SYSROOT $LLVM_SYSROOT
11+
12+
# Need to install curl for hendrikmuhs/ccache-action
13+
# Need nodejs for some of the GitHub actions.
14+
# Need perl-modules for clang analyzer tests.
15+
RUN apt-get update && \
16+
apt-get install -y \
17+
binutils \
18+
cmake \
19+
curl \
20+
libstdc++-11-dev \
21+
ninja-build \
22+
nodejs \
23+
perl-modules \
24+
python3-psutil
25+
26+
ENV LLVM_SYSROOT=$LLVM_SYSROOT
27+
ENV PATH=${LLVM_SYSROOT}/bin:${PATH}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[storage]
2+
driver = "overlay"
3+
runroot = "/mnt/podman/container"
4+
graphroot = "/mnt/podman/image"

0 commit comments

Comments
 (0)