Skip to content

Commit

Permalink
Make sccache work locally (#113)
Browse files Browse the repository at this point in the history
* Remove submodule stuff from workflow.

* Update sccache bucket to sccache-devs

* Update workflow to move source files to coder home.

* Fix path to composite action for sccache.

* Fix path.

* Use composite action before moving cloned repo.

* Reference composite action from moved dir.

* Copy instead of move.

* Reference cccl dir.

* Fix path for sccache hit rate script.

* Move sccache stats after cd to home dir.

* Don't write to step summary.

* cd to coder home dir for sccache script.

* Debug sccache hit rate step.

* Debug

* cat sccache files.

* Update sccache hitrate script to write output to stdout.

* Use notice workflow command for hit rate.

* Get rid of sccache debug stuff.

* Write the no new compile requests to stdout.

* Write hit rate to step summary.

* Wrap hitrate script stderr output in collapsed group.

* Don't write to step summary as we don't have permission as the coder user.

* Fix redirection.

* Fix end group.

* Make hit rate script more robust to allow spaces at start.

* Debug.

* Write awk output.

* Quotes around file paths.

* Use old style regex.

awk on Ubuntu 18.04 doesn't support [[:space:]] or [[:digit:]]
  • Loading branch information
jrhemstad committed Jun 23, 2023
1 parent 55fcdd8 commit 069e71e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/actions/configure_cccl_sccache/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ runs:
role-duration-seconds: 43200 # 12 hours)
- name: Set environment variables
run: |
echo "SCCACHE_BUCKET=rapids-sccache-east" >> $GITHUB_ENV
echo "SCCACHE_BUCKET=rapids-sccache-devs" >> $GITHUB_ENV
echo "SCCACHE_REGION=us-east-2" >> $GITHUB_ENV
echo "SCCACHE_IDLE_TIMEOUT=32768" >> $GITHUB_ENV
echo "SCCACHE_S3_USE_SSL=true" >> $GITHUB_ENV
Expand Down
37 changes: 31 additions & 6 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: build and test

defaults:
run:
shell: bash -eo pipefail {0}
shell: bash -exo pipefail {0}

on:
workflow_call:
Expand Down Expand Up @@ -33,10 +33,20 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: cccl
# In order for sccache to be shared between CI and lcaal devcontainers, code needs to be in the same absolute path
# This ensures the code is in the same path as it is within the devcontainer
- name: Move files to coder user home directory
run: |
cp -R cccl /home/coder/cccl
chown -R coder:coder /home/coder/
- name: Configure credentials and environment variables for sccache
uses: ./.github/actions/configure_cccl_sccache
uses: ./cccl/.github/actions/configure_cccl_sccache
- name: Run build script
shell: su coder {0}
run: |
cd ~/cccl
sccache -s > sccache_before.txt
cmd="${{ inputs.build_script }} \"${{inputs.compiler_exe}}\" \"${{inputs.std}}\" \"${{inputs.gpu_build_archs}}\""
eval $cmd || exit_code=$?
Expand All @@ -53,9 +63,14 @@ jobs:
fi
sccache -s > sccache_after.txt
- name: Calculate sccache hit rate
shell: su coder {0}
run: |
hit_rate=$(./ci/sccache_hit_rate.sh sccache_before.txt sccache_after.txt 2>&1 >/dev/null)
echo "sccache hit rate: $hit_rate" >> $GITHUB_STEP_SUMMARY
cd ~/cccl
hit_rate=$(./ci/sccache_hit_rate.sh sccache_before.txt sccache_after.txt 2> info.log)
echo "::group::Details"
cat info.log
echo "::endgroup::"
echo "::notice::sccache hit rate: $hit_rate"
test:
needs: build
if: ${{ !cancelled() && ( needs.build.result == 'success' || needs.build.result == 'skipped' ) && inputs.test_script != '' && inputs.test_image != '' }}
Expand All @@ -71,14 +86,24 @@ jobs:
steps:
- name: Checkout repo
uses: actions/checkout@v3
with:
path: cccl
- name: Move files to coder user home directory
run: |
cp -R cccl /home/coder/cccl
chown -R coder:coder /home/coder/
- name: Configure credentials and environment variables for sccache
uses: ./.github/actions/configure_cccl_sccache
uses: ./cccl/.github/actions/configure_cccl_sccache
- name: Run test script
shell: su coder {0}
run: |
cd ~/cccl
sccache -s > sccache_before.txt
time ./${{ inputs.test_script }} "${{inputs.compiler_exe}}" "${{inputs.std}}" "${{inputs.gpu_build_archs}}"
sccache -s > sccache_after.txt
- name: Calculate sccache hit rate
shell: su coder {0}
run: |
cd ~/cccl
hit_rate=$(./ci/sccache_hit_rate.sh sccache_before.txt sccache_after.txt 2>&1 >/dev/null)
echo "sccache hit rate: $hit_rate" >> $GITHUB_STEP_SUMMARY
echo "sccache hit rate: $hit_rate"
30 changes: 16 additions & 14 deletions ci/sccache_hit_rate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,38 @@ set -euo pipefail

# Ensure two arguments are provided
if [ $# -ne 2 ]; then
echo "Usage: $0 <before-file> <after-file>"
echo "Usage: $0 <before-file> <after-file>" >&2
exit 1
fi

# Print the contents of the before file
echo "=== Contents of $1 ==="
cat $1
echo "=== End of $1 ==="
echo "=== Contents of $1 ===" >&2
cat $1 >&2
echo "=== End of $1 ===" >&2

# Print the contents of the after file
echo "=== Contents of $2 ==="
cat $2
echo "=== End of $2 ==="
echo "=== Contents of $2 ===" >&2
cat $2 >&2
echo "=== End of $2 ===" >&2

# Extract compile requests and cache hits from the before and after files
requests_before=$(awk '/^Compile requests[[:space:]]+[[:digit:]]+/ {print $3}' $1)
hits_before=$(awk '/^Cache hits[[:space:]]+[[:digit:]]+/ {print $3}' $1)
requests_after=$(awk '/^Compile requests[[:space:]]+[[:digit:]]+/ {print $3}' $2)
hits_after=$(awk '/^Cache hits[[:space:]]+[[:digit:]]+/ {print $3}' $2)
requests_before=$(awk '/^[ \t]*Compile requests[ \t]+[0-9]+/ {print $3}' "$1")
hits_before=$(awk '/^[ \t]*Cache hits[ \t]+[0-9]+/ {print $3}' "$1")
requests_after=$(awk '/^[ \t]*Compile requests[ \t]+[0-9]+/ {print $3}' "$2")
hits_after=$(awk '/^[ \t]*Cache hits[ \t]+[0-9]+/ {print $3}' "$2")

# Calculate the differences to find out how many new requests and hits
requests_diff=$((requests_after - requests_before))
hits_diff=$((hits_after - hits_before))

echo "New Compile Requests: $requests_diff" >&2
echo "New Hits: $hits_diff" >&2

# Calculate and print the hit rate
if [ $requests_diff -eq 0 ]; then
echo "No new compile requests, hit rate is not applicable"
else
hit_rate=$(awk -v hits=$hits_diff -v requests=$requests_diff 'BEGIN {printf "%.2f", hits/requests * 100}')
echo "sccache hit rate: $hit_rate%"
# Write just the hit rate out to stderr to make it easier to get this value later
echo "$hit_rate" >&2
echo "sccache hit rate: $hit_rate%" >&2
echo "$hit_rate"
fi

0 comments on commit 069e71e

Please sign in to comment.