Skip to content

Commit

Permalink
Use shared volume to cache packages (#217)
Browse files Browse the repository at this point in the history
GitHub has a limit of 10GB of cache per repository. Plus caches are
scoped to a key and a branch, so a cache created on branch-A won’t be
accessible by branch-B unless branch-A is the default branch. Since
llvm-target is not the default branch, we cannot use GitHub cache
directly.
  • Loading branch information
pbchekin authored Jan 10, 2024
1 parent c2b64f7 commit 1b22313
Showing 1 changed file with 72 additions and 15 deletions.
87 changes: 72 additions & 15 deletions .github/workflows/build_and_test_2.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,27 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check if pip cache exists
env:
# Increase this value to reset cache
CACHE_NUMBER: 1
run: |
PIP_CACHE_KEY="pip-3.9-${{ hashFiles('.pre-commit-config.yaml') }}-${{ env.CACHE_NUMBER }}"
PIP_CACHE="/cache/$PIP_CACHE_KEY"
echo "PIP_CACHE=$PIP_CACHE" >> "${GITHUB_ENV}"
if [[ -d $PIP_CACHE ]]; then
echo "Python cache found for key $PIP_CACHE_KEY"
echo $PIP_CACHE > .pip-cache
mkdir -p $HOME/.cache
ln -s $PIP_CACHE $HOME/.cache/pip
else
echo "Python cache not found for key $PIP_CACHE_KEY"
fi
- name: Install Python 3.9
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: |
.pre-commit-config.yaml

- name: Run pre-commit checks
run: |
Expand All @@ -38,6 +52,14 @@ jobs:
python3 -m pre_commit run --all-files --verbose yapf &> /dev/null || true
python3 -m pre_commit run --all-files --verbose
- name: Save pip cache
if: ${{ hashFiles('.pip-cache') == '' }}
run: |
TMPDIR=/cache/${{ github.run_id }}-$RANDOM
mkdir $TMPDIR
cp -r $HOME/.cache/pip/* $TMPDIR/
mv $TMPDIR $PIP_CACHE
integration-tests:
name: Integration tests
runs-on:
Expand All @@ -51,30 +73,57 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Check if pip cache exists
env:
# Increase this value to reset cache
CACHE_NUMBER: 1
run: |
PIP_CACHE_KEY="pip-3.9-${{ hashFiles('python/pyproject.toml', 'python/setup.py') }}-${{ env.CACHE_NUMBER }}"
PIP_CACHE="/cache/$PIP_CACHE_KEY"
echo "PIP_CACHE=$PIP_CACHE" >> "${GITHUB_ENV}"
if [[ -d $PIP_CACHE ]]; then
echo "Python cache found for key $PIP_CACHE_KEY"
echo $PIP_CACHE > .pip-cache
mkdir -p $HOME/.cache
ln -s $PIP_CACHE $HOME/.cache/pip
else
echo "Python cache not found for key $PIP_CACHE_KEY"
fi
- name: Install Python 3.9
uses: actions/setup-python@v4
with:
python-version: '3.9'
cache: 'pip'
cache-dependency-path: |
python/pyproject.toml
python/setup.py
- name: Read packages from cache
id: packages-cache
uses: actions/cache@v3

- name: Check if packages cache exists
env:
# Increase this value to reset cache
CACHE_NUMBER: 1
with:
path: /home/runner/packages
key: packages-${{ hashFiles('scripts/compile-triton.sh', 'cmake/llvm-hash.txt') }}-${{ env.CACHE_NUMBER }}
run: |
PACKAGES_CACHE_KEY="packages-${{ hashFiles('scripts/compile-triton.sh', 'cmake/llvm-hash.txt') }}-${{ env.CACHE_NUMBER }}"
PACKAGES_CACHE="/cache/$PACKAGES_CACHE_KEY"
echo "PACKAGES_CACHE=$PACKAGES_CACHE" >> "${GITHUB_ENV}"
if [[ -d $PACKAGES_CACHE ]]; then
echo "Packages cache found for key $PACKAGES_CACHE_KEY"
echo $PACKAGES_CACHE > .packages-cache
ln -s $PACKAGES_CACHE $HOME/packages
else
echo "Packages cache not found for key $PACKAGES_CACHE_KEY"
fi
- name: Build packages
if: steps.packages-cache.outputs.cache-hit != 'true'
if: ${{ hashFiles('.packages-cache') == '' }}
run: |
./scripts/compile-triton.sh
- name: Save packages cache
if: ${{ hashFiles('.packages-cache') == '' }}
run: |
TMPDIR=/cache/${{ github.run_id }}-$RANDOM
mkdir $TMPDIR
cp -r $HOME/packages/* $TMPDIR/
mv $TMPDIR $PACKAGES_CACHE
- name: Build Triton
run: |
cd python
Expand Down Expand Up @@ -111,3 +160,11 @@ jobs:
run: |
cd python/build/*cmake*
ctest
- name: Save pip cache
if: ${{ hashFiles('.pip-cache') == '' }}
run: |
TMPDIR=/cache/${{ github.run_id }}-$RANDOM
mkdir $TMPDIR
cp -r $HOME/.cache/pip/* $TMPDIR/
mv $TMPDIR $PIP_CACHE

0 comments on commit 1b22313

Please sign in to comment.