tilelang icon indicating copy to clipboard operation
tilelang copied to clipboard

[CI] Enable `ccache` for cibw on linux

Open oraluben opened this issue 1 month ago • 4 comments

Closes #1155

Reduce build time of linux wheels from ~30m to ~3m (all cache hit, env setup included)

Mostly copied from https://github.com/pypa/cibuildwheel/issues/1030#issuecomment-2443820382

cc @XuehaiPan

Summary by CodeRabbit

  • Chores

    • Unified compiler-cache setup across platforms, simplified cache keys with restore-keys, and added Linux host-cache propagation to improve cross-runner cache reuse.
    • Removed the in-tree SDist build validation and adjusted build pipelines to rely on the unified caching strategy.
  • Tests

    • Updated build/test flows to use the new cache-aware pipeline for faster, more reproducible artifact builds.

oraluben avatar Nov 04 '25 04:11 oraluben

Walkthrough

Cross-platform ccache keys and layered restore-keys were added to CI and dist workflows; SDist and wheel test steps now pip-install built artifacts; Linux host-cache mounting via CIBW_BEFORE_BUILD_LINUX was introduced; CMake appends base_dir=${CMAKE_SOURCE_DIR} to CCACHE_PROGRAM on Apple; .gitignore filename normalized.

Changes

Cohort / File(s) Summary
Dist workflow
./.github/workflows/dist.yml
Generalized ccache for sdist and wheels (keys include runner OS/arch/toolkit and hashFiles('**/*.cc')), added append-timestamp: false, layered restore-keys, added Linux host-cache export and CIBW_BEFORE_BUILD_LINUX before-build steps, replaced SDist/wheel test steps to pip install built artifacts, removed macOS-only ccache framing.
CI workflow
./.github/workflows/ci.yml
Simplified/generalized ccache key to ${{ runner.os }}-${{ runner.arch }}-${{ matrix.runner.toolkit }}-${{ hashFiles('**/*.cc') }}, added append-timestamp: false and layered restore-keys; removed matrix-specific parts from cache key.
Build config
CMakeLists.txt
When CCACHE_PROGRAM is detected, append base_dir=${CMAKE_SOURCE_DIR} to the status message and, on Apple, append ;base_dir=${CMAKE_SOURCE_DIR} to CCACHE_PROGRAM before setting compiler launchers.
Ignore file
./.gitignore
Replaced _git_commit.txt with dot-prefixed .git_commit.txt in gitignore entries (two occurrences).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Runner as CI runner
    participant Cache as GitHub Cache
    participant Host as Runner host
    participant CIBW as cibuildwheel
    participant Container as Linux container

    Note over Runner,Cache: Restore layered ccache keys (sdist/wheel-<os>-<arch>-<toolkit>-hash)
    Runner->>Cache: Restore ccache (primary and fallback keys)
    Runner->>Host: Export host cache dir & set CIBW_BEFORE_BUILD_LINUX
    alt Linux wheel build in container
        Host->>CIBW: supply CIBW_BEFORE_BUILD_LINUX (host mount)
        CIBW->>Container: start container with mounted host cache
        Container->>Container: build wheels using mounted ccache
    else Non-container build
        Runner->>Runner: use local ccache during build
    end
    Runner->>Cache: Save updated cache (append-timestamp: false)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Files needing careful review:
    • ./.github/workflows/dist.yml — cache key composition, restore-keys, before-build injection and pip-install steps.
    • ./.github/workflows/ci.yml — cache key/restore-keys correctness and cross-platform implications.
    • CMakeLists.txt — Apple-specific CCACHE_PROGRAM suffix formatting.
    • ./.gitignore — filename change occurrences.

Possibly related PRs

  • tile-ai/tilelang#1098 — Overlaps dist workflow changes (SDist/wheel CI, artifact flow, ccache keys).
  • tile-ai/tilelang#1171 — Related edits to dist/CI workflow behavior and sdist git-commit handling.

Poem

🐇 I hopped through workflows, caching in tow,

Mounted a host-cache so builds faster go,
Wheels and sdists now pip-install with grace,
CMake tucked base_dir into its place,
A rabbit cheers — faster builds in the race.

Pre-merge checks and finishing touches

✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly reflects the main change: enabling ccache for CIBW (cibuildwheel) on Linux, which matches the primary objective of the pull request.
Linked Issues check ✅ Passed All code changes (workflow configs, CMakeLists.txt, .gitignore) implement the linked issue #1155 requirement to enable ccache for cibuildwheel on Linux and improve caching efficiency.
Out of Scope Changes check ✅ Passed All changes are scoped to CI infrastructure, ccache configuration, and build optimization—directly related to #1155. No extraneous modifications were introduced.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b6c6482812690defa56b5fa20eb4baf4bb8252aa and 81fe26ab9d19e4b27059c3c76b3f875a62128f4c.

📒 Files selected for processing (1)
  • .gitignore (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .gitignore
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: Test for Python 3.12 with ROCm-6.3 (on self-hosted-amd)
  • GitHub Check: Test for Python 3.12 with Metal (on macos-latest)
  • GitHub Check: Test for Python 3.12 with CUDA-12.8 (on self-hosted-nvidia)
  • GitHub Check: Build wheels for Python 3.9 on ubuntu-24.04-arm with CUDA-12.8
  • GitHub Check: Build SDist
  • GitHub Check: Build wheels for Python 3.9 on ubuntu-latest with CUDA-12.1
  • GitHub Check: Build wheels for Python 3.9 on macos-latest with Metal

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Nov 04 '25 04:11 coderabbitai[bot]

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

github-actions[bot] avatar Nov 04 '25 04:11 github-actions[bot]

Even if using a hard-coded path, ccache doesn't work when building from sdist.

Given that (and the complexity trying to make it work), I think we may just generate a sdist on GA runner, and maybe build from sdist on self-hosted runners? @XuehaiPan do you have any suggestion here?

oraluben avatar Nov 04 '25 14:11 oraluben

Even if using a hard-coded path, ccache doesn't work when building from sdist.

Given that (and the complexity trying to make it work)

The solution I posted in https://github.com/tile-ai/tilelang/pull/1184#discussion_r2489246467 works perfectly for me.

$ rm -rf "$(ccache --get-config cache_dir)"
$ ccache --show-stats
Local storage:
  Cache size (GiB): 0.0 / 5.0 ( 0.00%)
$ uv build --sdist
$ uv cache clean
$ uv pip uninstall tilelang
$ uv pip install -v dist/tilelang-*.tar.gz
$ ccache --show-stats
Cacheable calls:    631 / 631 (100.0%)
  Hits:               0 / 631 ( 0.00%)
    Direct:           0
    Preprocessed:     0
  Misses:           631 / 631 (100.0%)
Local storage:
  Cache size (GiB): 0.1 / 5.0 ( 1.61%)
  Hits:               0 / 631 ( 0.00%)
  Misses:           631 / 631 (100.0%)

$ uv cache clean
$ uv pip uninstall tilelang
$ uv pip install -v dist/tilelang-*.tar.gz
$ ccache --show-stats
Cacheable calls:    1262 / 1262 (100.0%)
  Hits:              631 / 1262 (50.00%)
    Direct:          631 /  631 (100.0%)
    Preprocessed:      0 /  631 ( 0.00%)
  Misses:            631 / 1262 (50.00%)
Local storage:
  Cache size (GiB):  0.1 /  5.0 ( 1.61%)
  Hits:              631 / 1262 (50.00%)
  Misses:            631 / 1262 (50.00%)

XuehaiPan avatar Nov 04 '25 15:11 XuehaiPan

I have cleared the GHA cache:

$ gh cache delete --all
✓ Deleted 102 caches from tile-ai/tilelang

I will trigger the Dist workflow twice; let's see if it works.

XuehaiPan avatar Nov 05 '25 08:11 XuehaiPan

run time after cache's been cleared just for record: https://github.com/tile-ai/tilelang/actions/runs/19094657395/usage

oraluben avatar Nov 05 '25 12:11 oraluben