Skip to content

Commit dcc8748

Browse files
committed
GitHub cache and ccache
Use ccache in CIs. Set up GitHub Cache for storing the ccache data.
1 parent 923c655 commit dcc8748

File tree

12 files changed

+364
-7
lines changed

12 files changed

+364
-7
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,18 @@ jobs:
3333
name: 🔄 Update Stub Files
3434
needs: [ubuntu, intel, hip, macos, windows]
3535
uses: ./.github/workflows/stubs.yml
36+
37+
save_pr_number:
38+
if: github.event_name == 'pull_request'
39+
runs-on: ubuntu-latest
40+
steps:
41+
- name: Save PR number
42+
env:
43+
PR_NUMBER: ${{ github.event.number }}
44+
run: |
45+
echo $PR_NUMBER > pr_number.txt
46+
- uses: actions/upload-artifact@v3
47+
with:
48+
name: pr_number
49+
path: pr_number.txt
50+
retention-days: 1
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: CleanUpCachePostPR
2+
3+
on:
4+
workflow_run:
5+
workflows: [PostPR]
6+
types:
7+
- completed
8+
9+
jobs:
10+
CleanUpCcacheCachePostPR:
11+
name: Clean Up Ccahe Cache Post PR
12+
runs-on: ubuntu-latest
13+
permissions:
14+
actions: write
15+
contents: read
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Clean up ccahe
21+
run: |
22+
gh extension install actions/gh-actions-cache
23+
24+
REPO=${{ github.repository }}
25+
26+
gh run download ${{ github.event.workflow_run.id }} -n pr_number
27+
pr_number=`cat pr_number.txt`
28+
BRANCH=refs/pull/${pr_number}/merge
29+
30+
# Setting this to not fail the workflow while deleting cache keys.
31+
set +e
32+
33+
keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH | cut -f 1)
34+
for k in "$keys"
35+
do
36+
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm
37+
done
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
name: CleanUpCache
2+
3+
on:
4+
workflow_run:
5+
workflows: [👑 CI]
6+
types:
7+
- completed
8+
9+
jobs:
10+
CleanUpCcacheCache:
11+
name: Clean Up Ccahe Cache for ${{ github.event.workflow_run.name }}
12+
runs-on: ubuntu-latest
13+
permissions:
14+
actions: write
15+
contents: read
16+
env:
17+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
- name: Clean up ccahe
21+
run: |
22+
gh extension install actions/gh-actions-cache
23+
24+
REPO=${{ github.repository }}
25+
26+
# push or pull_request or schedule or ...
27+
EVENT=${{ github.event.workflow_run.event }}
28+
29+
# Triggering workflow run name (e.g., LinuxClang)
30+
WORKFLOW_NAME=${{ github.event.workflow_run.name }}
31+
32+
if [[ $EVENT == "pull_request" ]]; then
33+
gh run download ${{ github.event.workflow_run.id }} -n pr_number
34+
pr_number=`cat pr_number.txt`
35+
BRANCH=refs/pull/${pr_number}/merge
36+
else
37+
BRANCH=refs/heads/${{ github.event.workflow_run.head_branch }}
38+
fi
39+
40+
# Setting this to not fail the workflow while deleting cache keys.
41+
set +e
42+
43+
# In our cache keys, substring after `-git-` is git hash, substring
44+
# before that is a unique id for jobs (e.g., `ccache-LinuxClang-configure-2d`).
45+
# The goal is to keep the last used key of each job and delete all others.
46+
47+
# something like ccache-LinuxClang-
48+
keyprefix=ccache-${WORKFLOW_NAME}-
49+
50+
cached_jobs=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "$keyprefix" | awk -F '-git-' '{print $1}' | sort | uniq)
51+
52+
# cached_jobs is something like "ccache-LinuxClang-configure-1d ccache-LinuxClang-configure-2d".
53+
for j in "$cached_jobs"
54+
do
55+
old_keys=$(gh actions-cache list -L 100 -R $REPO -B $BRANCH --key "${j}-git-" --sort last-used | cut -f 1 | tail -n +2)
56+
for k in "$old_keys"
57+
do
58+
gh actions-cache delete "$k" -R $REPO -B $BRANCH --confirm
59+
done
60+
done
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ $# -eq 2 ]]; then
4+
CVER=$1
5+
else
6+
CVER=4.8
7+
fi
8+
9+
wget https://github.com/ccache/ccache/releases/download/v${CVER}/ccache-${CVER}-linux-x86_64.tar.xz
10+
tar xvf ccache-${CVER}-linux-x86_64.tar.xz
11+
sudo mv -f ccache-${CVER}-linux-x86_64/ccache /usr/local/bin/
12+
sudo rm -f ccache-${CVER}-linux-x86_64.tar.xz

.github/workflows/dependencies/dependencies_mac.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ brew update
1111
brew install gfortran || true
1212
brew install libomp || true
1313
brew install open-mpi || true
14+
brew install ccache || true

.github/workflows/hip.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,24 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- name: install dependencies
2020
shell: bash
21-
run: .github/workflows/dependencies/hip.sh
21+
run: |
22+
.github/workflows/dependencies/hip.sh
23+
.github/workflows/dependencies/dependencies_ccache.sh
24+
- name: Set Up Cache
25+
uses: actions/cache@v3
26+
with:
27+
path: ~/.cache/ccache
28+
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
29+
restore-keys: |
30+
ccache-${{ github.workflow }}-${{ github.job }}-git-
2231
- name: build ImpactX
2332
shell: bash
2433
run: |
34+
export CCACHE_COMPRESS=1
35+
export CCACHE_COMPRESSLEVEL=10
36+
export CCACHE_MAXSIZE=300M
37+
ccache -z
38+
2539
source /etc/profile.d/rocm.sh
2640
hipcc --version
2741
which clang
@@ -43,3 +57,6 @@ jobs:
4357
-DAMReX_AMD_ARCH=gfx900 \
4458
-DAMReX_SPACEDIM="1;2;3"
4559
cmake --build build --target pip_install -j 2
60+
61+
ccache -s
62+
du -hs ~/.cache/ccache

.github/workflows/intel.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ jobs:
1515
- name: Dependencies
1616
run: |
1717
.github/workflows/dependencies/dpcpp.sh
18+
.github/workflows/dependencies/dependencies_ccache.sh
19+
- name: Set Up Cache
20+
uses: actions/cache@v3
21+
with:
22+
path: ~/.cache/ccache
23+
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
24+
restore-keys: |
25+
ccache-${{ github.workflow }}-${{ github.job }}-git-
1826
- name: Build & Install
1927
# mkl/rng/device/detail/mrg32k3a_impl.hpp has a number of sign-compare error
2028
# mkl/rng/device/detail/mrg32k3a_impl.hpp has missing braces in array-array initalization
@@ -24,6 +32,12 @@ jobs:
2432
source /opt/intel/oneapi/setvars.sh
2533
set -e
2634
35+
export CCACHE_COMPRESS=1
36+
export CCACHE_COMPRESSLEVEL=10
37+
export CCACHE_MAXSIZE=200M
38+
export CCACHE_DEPEND=1
39+
ccache -z
40+
2741
export CC=$(which icx)
2842
export CXX=$(which icpx)
2943
python3 -m pip install -U pip setuptools wheel
@@ -39,6 +53,9 @@ jobs:
3953
-DAMReX_SPACEDIM="3"
4054
cmake --build build --target pip_install -j 2
4155
56+
ccache -s
57+
du -hs ~/.cache/ccache
58+
4259
tests-icpx:
4360
name: ICPX
4461
runs-on: ubuntu-20.04
@@ -47,6 +64,14 @@ jobs:
4764
- name: Dependencies
4865
run: |
4966
.github/workflows/dependencies/dpcpp.sh
67+
.github/workflows/dependencies/dependencies_ccache.sh
68+
- name: Set Up Cache
69+
uses: actions/cache@v3
70+
with:
71+
path: ~/.cache/ccache
72+
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
73+
restore-keys: |
74+
ccache-${{ github.workflow }}-${{ github.job }}-git-
5075
- name: Build & Install
5176
# mkl/rng/device/detail/mrg32k3a_impl.hpp has a number of sign-compare error
5277
# mkl/rng/device/detail/mrg32k3a_impl.hpp has missing braces in array-array initalization
@@ -56,6 +81,11 @@ jobs:
5681
source /opt/intel/oneapi/setvars.sh
5782
set -e
5883
84+
export CCACHE_COMPRESS=1
85+
export CCACHE_COMPRESSLEVEL=10
86+
export CCACHE_MAXSIZE=200M
87+
ccache -z
88+
5989
export CC=$(which icx)
6090
export CXX=$(which icpx)
6191
python3 -m pip install -U pip setuptools wheel
@@ -69,6 +99,9 @@ jobs:
6999
-DAMReX_SPACEDIM="1;2;3"
70100
cmake --build build --target pip_install -j 2
71101
102+
ccache -s
103+
du -hs ~/.cache/ccache
104+
72105
- name: Run tests
73106
run: |
74107
set +e
@@ -95,13 +128,26 @@ jobs:
95128
echo "deb https://apt.repos.intel.com/oneapi all main" | sudo tee /etc/apt/sources.list.d/oneAPI.list
96129
sudo apt-get update
97130
sudo apt-get install -y intel-oneapi-compiler-dpcpp-cpp-and-cpp-classic intel-oneapi-compiler-fortran intel-oneapi-mpi-devel
131+
.github/workflows/dependencies/dependencies_ccache.sh
132+
- name: Set Up Cache
133+
uses: actions/cache@v3
134+
with:
135+
path: ~/.cache/ccache
136+
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
137+
restore-keys: |
138+
ccache-${{ github.workflow }}-${{ github.job }}-git-
98139
- name: build
99140
env: {CXXFLAGS: "-Werror"}
100141
run: |
101142
set +e
102143
source /opt/intel/oneapi/setvars.sh
103144
set -e
104145
146+
export CCACHE_COMPRESS=1
147+
export CCACHE_COMPRESSLEVEL=10
148+
export CCACHE_MAXSIZE=600M
149+
ccache -z
150+
105151
export CXX=$(which icpc)
106152
export CC=$(which icc)
107153
python3 -m pip install -U pip setuptools wheel
@@ -116,6 +162,9 @@ jobs:
116162
-DAMReX_SPACEDIM="1;2;3"
117163
cmake --build build --target pip_install -j 2
118164
165+
ccache -s
166+
du -hs ~/.cache/ccache
167+
119168
- name: Run tests
120169
run: |
121170
set +e

.github/workflows/macos.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,20 @@ jobs:
1818
- uses: actions/checkout@v3
1919
- name: Dependencies
2020
run: .github/workflows/dependencies/dependencies_mac.sh
21+
- name: Set Up Cache
22+
uses: actions/cache@v3
23+
with:
24+
path: /Users/runner/Library/Caches/ccache
25+
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
26+
restore-keys: |
27+
ccache-${{ github.workflow }}-${{ github.job }}-git-
2128
- name: Build & Install
2229
run: |
30+
export CCACHE_COMPRESS=1
31+
export CCACHE_COMPRESSLEVEL=10
32+
export CCACHE_MAXSIZE=600M
33+
ccache -z
34+
2335
export CMAKE_BUILD_PARALLEL_LEVEL=3
2436
2537
python3 -m pip install -U pip setuptools wheel pytest
@@ -28,6 +40,10 @@ jobs:
2840
python3 -c "import amrex.space1d as amr; print(amr.__version__)"
2941
python3 -c "import amrex.space2d as amr; print(amr.__version__)"
3042
python3 -c "import amrex.space3d as amr; print(amr.__version__)"
43+
44+
ccache -s
45+
du -hs /Users/runner/Library/Caches/ccache
46+
3147
- name: Unit tests
3248
run: |
3349
python3 -m pytest tests/

.github/workflows/post-pr.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: PostPR
2+
on:
3+
pull_request:
4+
types:
5+
- closed
6+
7+
jobs:
8+
cleanup:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Save PR number
12+
env:
13+
PR_NUMBER: ${{ github.event.number }}
14+
run: |
15+
echo $PR_NUMBER > pr_number.txt
16+
- uses: actions/upload-artifact@v3
17+
with:
18+
name: pr_number
19+
path: pr_number.txt
20+
retention-days: 1

.github/workflows/stubs.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,33 @@ jobs:
4040
python-version: '3.9'
4141

4242
- name: Dependencies
43-
run: .github/workflows/dependencies/dependencies_gcc10.sh
43+
run: |
44+
.github/workflows/dependencies/dependencies_gcc10.sh
45+
.github/workflows/dependencies/dependencies_ccache.sh
46+
47+
- name: Set Up Cache
48+
uses: actions/cache@v3
49+
with:
50+
path: ~/.cache/ccache
51+
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
52+
restore-keys: |
53+
ccache-${{ github.workflow }}-${{ github.job }}-git-
4454
4555
- name: Build & Install
4656
run: |
57+
export CCACHE_COMPRESS=1
58+
export CCACHE_COMPRESSLEVEL=10
59+
export CCACHE_MAXSIZE=200M
60+
ccache -z
61+
4762
python3 -m pip install -U pip setuptools wheel
4863
python3 -m pip install -U pip mpi4py pytest pybind11-stubgen pre-commit
4964
cmake -S . -B build -DAMReX_SPACEDIM="1;2;3" -DpyAMReX_IPO=OFF
5065
cmake --build build -j 2 --target pip_install
5166
67+
ccache -s
68+
du -hs ~/.cache/ccache
69+
5270
- name: Update Stubs
5371
run: |
5472
.github/update_stub.sh

0 commit comments

Comments
 (0)