Skip to content

[ci] Use GH cache for bitstream PRs - #31260

Open
mfnch wants to merge 3 commits into
lowRISC:masterfrom
mfnch:gh-cache
Open

[ci] Use GH cache for bitstream PRs#31260
mfnch wants to merge 3 commits into
lowRISC:masterfrom
mfnch:gh-cache

Conversation

@mfnch

@mfnch mfnch commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Use the GitHub action cache to save bitstreams during a PR's review lifetime. This is useful for PRs that change the bitstream. The GitHub cache saves the bitstream in early PR uploads so that it can be reused in later revisions where possible, thus alleviating CI wait times during reviews.

NOTES: The GitHub cache is indexed using the SHA built by the recently introduced //hw/bitstream/vivado:fpga_cw340_hash Bazel target (#31041). This minimizes bitstream rebuilds if compared to other caching
mechanisms we rely on (e.g. the GCS caching). However, it currently has a flaw: the bitstream is not rebuilt when the only thing to change is the FuseSoC command-line. Indeed, the cache indexing is based exclusively on the source files that are used by FuseSoC to build the bitstream.

Note also that the GitHub action cache is scoped to the repository branch and therefore is not reused across different PRs.

Cached items are shown here

Testing:
This was done by adding temporary testing commits to this PR (removed in the final revision):

Closes: #31059

@mfnch
mfnch requested a review from a team as a code owner September 8, 2026 09:31
@mfnch
mfnch marked this pull request as draft September 8, 2026 09:50
id: gh-cache-key
if: steps.strategy.outputs.bitstreamStrategy != 'cached'
run: |
hash_gen_command="//hw/bitstream/vivado:fpga_${{ inputs.design_suffix }}_hash"

@pamaury pamaury Sep 8, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a small note that this caching strategy has one (unavoidable) flaw: changes to the fusesoc command line or fusesoc rule will not change the hash and hence the bitstream might not get rebuild in those cases.

I don't know how likely it is to happen, we could potentially modify the rule to hash more stuff (like part of the command line if necessary) but there will always be a "gap" which can only be solved by using the bazel action cache (maybe a future work, I have some ideas for this).

Maybe github having a label to force a bitstream rebuild could solve this in cases where we know we want to rebuild

@mfnch mfnch Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. I incorporated this note in a follow up issue that I just created #31264.

I guess this may cause surprises in commits that touch the build system in this way. Do you think the other caching mechanisms we have are subject to the same (or similar) flaw? I guess the diff mechanism used for the GCS bitstream cache may miss updates to the tool itself, which is probably tolerable.

I would be happy if the GH cache mechanism was - at least - not worse than the one we already have (in terms of missing changes to the bitstream). I guess adding some BUILD files could be enough. Or - as you suggest - add parts of the command line. Not very sure how to do this, though.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We discussed in the office about this. @engdoreis thinks that in practice this shouldn't be an issue. Well, he said it never has been so far. I'll look into adding a label to force rebuilding the bitstream and update the documentation on bitstream caching.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bitstream strategy computed by the script rebuilds on any rule file change. This means that it will rebuild too often than necessary but it also means that it doesn't have this flaw. I can add the command line hash in another PR. I don't think it's a big problem though as long as the merge run does not use the GH cache.

Comment thread .github/workflows/bitstream.yml Outdated
Comment thread .github/workflows/bitstream.yml Outdated
@mfnch
mfnch force-pushed the gh-cache branch 2 times, most recently from 50b4933 to bc1af4e Compare September 9, 2026 15:45
Use the GitHub cache to reuse FPGA bitstreams built during the review
lifetime of a PR. This allows to skip rebuilding the bitstream when
pushing a PR update that doesn't touch any of the bitstream sources.

Note that this caching mechanism only helps PRs that require rebuilding
the bitstream and undergo several review cycles which don't need
the bitstream to be rebuilt. The GitHub cache is disabled on PR merges,
meaning that the bitstream is always recomputed at merge time.

NOTE: The GitHub cache is indexed using the SHA built by the recently
introduced `//hw/bitstream/vivado:fpga_cw340_hash` Bazel target.
This minimizes bitstream rebuilds if compared to other caching
mechanisms we rely on (e.g. the GCS caching). However, it currently
has a flaw: the bitstream is not rebuilt when the only thing to change
is the FuseSoC command-line. Indeed, the cache indexing is based
exclusively on the source files that are used by FuseSoC to build
the bitstream.

Signed-off-by: Matteo Franchin <matteo.franchin@lowrisc.org>
This name is not well suited now that we have multiple bitstream caches.
Rename this script to check-bitstream-gcs-cache.sh to indicate that what
it does is to just check whether we can reuse a bistream from the Google
Cloud Storage (GCS) cache.

Signed-off-by: Matteo Franchin <matteo.franchin@lowrisc.org>
In particular, add details on how the GitHub cache is used and what
it aims to achieve.

Signed-off-by: Matteo Franchin <matteo.franchin@lowrisc.org>
@mfnch
mfnch marked this pull request as ready for review September 10, 2026 10:20
@mfnch
mfnch requested a review from vogelpi as a code owner September 10, 2026 10:20
@mfnch mfnch changed the title [DO NOT MERGE][WIP][ci] Use GH cache for bitstream PRs [ci] Use GH cache for bitstream PRs Sep 10, 2026
@mfnch mfnch added the CI:Rerun Rerun failed CI jobs label Sep 10, 2026
@github-actions github-actions Bot removed the CI:Rerun Rerun failed CI jobs label Sep 10, 2026
@pamaury

pamaury commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Something is not clear to me but that might be due to my lack of knowledge about github caching: where is the bitstream upload to the cache? Is the caching mechanism looking for previously built artifacts of the same PR?

@mfnch

mfnch commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Something is not clear to me but that might be due to my lack of knowledge about github caching: where is the bitstream upload to the cache? Is the caching mechanism looking for previously built artifacts of the same PR?

It all happens here:

      - name: Extract cached bitstream from GitHub cache
        uses: actions/cache@v6
        with:
          path: build-bin.tar
          key: ABC

This action checks whether an entry exists in the GitHub cache with key ABC. If it exists, then it restores the file build-bin.tar, sets steps.gh-cache.outputs.cache-hit to true and ends there. If it doesn't, then it sets steps.gh-cache.outputs.cache-hit to false. However, it also schedules an extra step to run if the entire job completes successfully. This extra step uploads the created binary build-bin.tar into the GitHub cache with the same key that was before used to check the cache.

In the example run I posted this action can be seen running as one of the final steps named "Post Extract cached bitstream from GitHub cache".

So a single action implements the whole caching mechanism... relying on the job will actually producing itself the build-bin.tar binary, if case of a cache miss. This is how the primary action behaves, but the GitHub action cache also provides separate secondary actions for restoring and saving cache entries, in case the all-in-one approach is not suitable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] Cache bitstreams on PRs

3 participants