Skip to content

Commit 5984786

Browse files
leofangclaude
andcommitted
Add sccache-summary action and surface container stats in job summary
sccache stats were previously lost because cibuildwheel runs compilation inside a manylinux container with its own sccache server instance, while sccache-action on the host sees 0 hits. Fix by dumping sccache stats JSON from inside the container to the host filesystem (via /host/ mount), then reading it in a new composite action that writes a formatted table to GITHUB_STEP_SUMMARY. Inspired by NVIDIA/cccl PR #3621. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e5b7d53 commit 5984786

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
name: sccache summary
6+
description: Parse sccache stats JSON and write a summary table to GITHUB_STEP_SUMMARY
7+
8+
# Inspired by NVIDIA/cccl's prepare-execution-summary.py (PR #3621).
9+
# Only counts C/C++ and CUDA language hits (excludes PTX/CUBIN which are
10+
# not included in sccache's compile_requests counter).
11+
12+
inputs:
13+
json-file:
14+
description: "Path to the sccache stats JSON file (from sccache --show-stats --stats-format=json)"
15+
required: true
16+
label:
17+
description: "Label for the stats row (e.g. cuda.bindings, cuda.core)"
18+
required: false
19+
default: "sccache"
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Report sccache stats
25+
shell: bash --noprofile --norc -euo pipefail {0}
26+
run: |
27+
json_file="${{ inputs.json-file }}"
28+
label="${{ inputs.label }}"
29+
30+
if [ ! -f "$json_file" ]; then
31+
echo "::warning::sccache stats file not found: $json_file"
32+
exit 0
33+
fi
34+
35+
python3 - "$json_file" "$label" <<'PYEOF'
36+
import json, sys
37+
38+
json_file, label = sys.argv[1], sys.argv[2]
39+
with open(json_file) as f:
40+
stats = json.load(f)["stats"]
41+
42+
requests = stats.get("compile_requests", 0)
43+
# Only count C/C++ and CUDA hits (PTX/CUBIN are not in compile_requests)
44+
counted_languages = {"C/C++", "CUDA"}
45+
hits = sum(
46+
v for k, v in stats.get("cache_hits", {}).get("counts", {}).items()
47+
if k in counted_languages
48+
)
49+
misses = requests - hits
50+
pct = int(100 * hits / requests) if requests > 0 else 0
51+
52+
with open(sys.argv[1].replace(".json", "") + "_summary.md", "w") as out:
53+
out.write(f"### \U0001f4ca {label} — sccache stats\n")
54+
out.write("| Hit Rate | Hits | Misses | Requests |\n")
55+
out.write("|----------|------|--------|----------|\n")
56+
out.write(f"| {pct}% | {hits} | {misses} | {requests} |\n")
57+
58+
# Also write to GITHUB_STEP_SUMMARY
59+
import os
60+
summary_file = os.environ.get("GITHUB_STEP_SUMMARY", "")
61+
if summary_file:
62+
with open(summary_file, "a") as sf:
63+
sf.write(f"### \U0001f4ca {label} — sccache stats\n")
64+
sf.write("| Hit Rate | Hits | Misses | Requests |\n")
65+
sf.write("|----------|------|--------|----------|\n")
66+
sf.write(f"| {pct}% | {hits} | {misses} | {requests} |\n\n")
67+
68+
print(f"{label}: {pct}% hit rate ({hits}/{requests})")
69+
PYEOF

.github/workflows/build-wheel.yml

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,21 @@ jobs:
177177
CUDA_PYTHON_PARALLEL_LEVEL=${{ env.CUDA_PYTHON_PARALLEL_LEVEL }}
178178
# check cache stats before leaving cibuildwheel
179179
CIBW_BEFORE_TEST_LINUX: >
180-
"/host/${{ env.SCCACHE_PATH }}" --show-stats
180+
"/host/${{ env.SCCACHE_PATH }}" --show-stats &&
181+
"/host/${{ env.SCCACHE_PATH }}" --show-stats --stats-format=json > /host/${{ github.workspace }}/sccache_bindings.json
181182
# force the test stage to be run (so that before-test is not skipped)
182183
# TODO: we might want to think twice on adding this, it does a lot of
183184
# things before reaching this command.
184185
CIBW_TEST_COMMAND: >
185186
echo "ok!"
186187
188+
- name: Report sccache stats (cuda.bindings)
189+
if: ${{ inputs.host-platform != 'win-64' }}
190+
uses: ./.github/actions/sccache-summary
191+
with:
192+
json-file: sccache_bindings.json
193+
label: "cuda.bindings"
194+
187195
- name: List the cuda.bindings artifacts directory
188196
run: |
189197
if [[ "${{ inputs.host-platform }}" == win* ]]; then
@@ -235,13 +243,21 @@ jobs:
235243
PIP_FIND_LINKS="$(cygpath -w ${{ env.CUDA_BINDINGS_ARTIFACTS_DIR }})"
236244
# check cache stats before leaving cibuildwheel
237245
CIBW_BEFORE_TEST_LINUX: >
238-
"/host${{ env.SCCACHE_PATH }}" --show-stats
246+
"/host${{ env.SCCACHE_PATH }}" --show-stats &&
247+
"/host${{ env.SCCACHE_PATH }}" --show-stats --stats-format=json > /host/${{ github.workspace }}/sccache_core.json
239248
# force the test stage to be run (so that before-test is not skipped)
240249
# TODO: we might want to think twice on adding this, it does a lot of
241250
# things before reaching this command.
242251
CIBW_TEST_COMMAND: >
243252
echo "ok!"
244253
254+
- name: Report sccache stats (cuda.core)
255+
if: ${{ inputs.host-platform != 'win-64' }}
256+
uses: ./.github/actions/sccache-summary
257+
with:
258+
json-file: sccache_core.json
259+
label: "cuda.core"
260+
245261
- name: List the cuda.core artifacts directory and rename
246262
run: |
247263
if [[ "${{ inputs.host-platform }}" == win* ]]; then
@@ -414,13 +430,21 @@ jobs:
414430
PIP_FIND_LINKS="$(cygpath -w ${{ env.CUDA_BINDINGS_ARTIFACTS_DIR }})"
415431
# check cache stats before leaving cibuildwheel
416432
CIBW_BEFORE_TEST_LINUX: >
417-
"/host${{ env.SCCACHE_PATH }}" --show-stats
433+
"/host${{ env.SCCACHE_PATH }}" --show-stats &&
434+
"/host${{ env.SCCACHE_PATH }}" --show-stats --stats-format=json > /host/${{ github.workspace }}/sccache_core_prev.json
418435
# force the test stage to be run (so that before-test is not skipped)
419436
# TODO: we might want to think twice on adding this, it does a lot of
420437
# things before reaching this command.
421438
CIBW_TEST_COMMAND: >
422439
echo "ok!"
423440
441+
- name: Report sccache stats (cuda.core prev)
442+
if: ${{ inputs.host-platform != 'win-64' }}
443+
uses: ./.github/actions/sccache-summary
444+
with:
445+
json-file: sccache_core_prev.json
446+
label: "cuda.core (prev CTK)"
447+
424448
- name: List the cuda.core artifacts directory and rename
425449
run: |
426450
if [[ "${{ inputs.host-platform }}" == win* ]]; then

0 commit comments

Comments
 (0)