Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sccache to accelerate android build #9587

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

kirklandsign
Copy link
Contributor

@kirklandsign kirklandsign commented Mar 25, 2025

Android didn't use sccache because it has its own NDK clang. Now use env var to trigger clang from sccache.

Copy link

pytorch-bot bot commented Mar 25, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/9587

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures, 3 Unrelated Failures

As of commit 0ce7cc2 with merge base 7248b19 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 25, 2025
@kirklandsign kirklandsign marked this pull request as ready for review March 26, 2025 18:29
@kirklandsign kirklandsign changed the title [TEST] Try to see if sccache is in use Use sccache to accelerate android build Mar 26, 2025
Comment on lines 25 to 27
# Use sccache for NDK compiler as well
export CMAKE_CXX_COMPILER_LAUNCHER=sccache
export CMAKE_C_COMPILER_LAUNCHER=sccache
Copy link
Contributor

Choose a reason for hiding this comment

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

What are your thoughts on exporting this in .ci/scripts/setup-linux.sh so we get it for all CI builds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would rely on https://github.com/pytorch/executorch/blob/main/.ci/docker/common/install_cache.sh#L47 to trigger sccache for general linux.

Seems that if I put these in https://github.com/pytorch/executorch/blob/main/.ci/scripts/setup-linux.sh, it will be used not only on android, but generic, and I would avoid doing that to mess up with the set up above.

Copy link
Contributor

Choose a reason for hiding this comment

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

Generally, I'm hoping we can find one place to change and export these variables instead of multiple places. If someone adds another android job, they do not get caching if they forget these lines

Copy link
Contributor

Choose a reason for hiding this comment

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

IMO, you could try the simpler fix to install NDK before sccache in https://github.com/pytorch/executorch/blob/main/.ci/docker/ubuntu/Dockerfile#L57-L83. We install sccache as part of building Docker image and /opt/cache/bin is added to PATH in https://github.com/pytorch/executorch/blob/main/.ci/docker/common/install_cache.sh#L43. Atm, installing NDK happens after installing sccache, so I guess NDK path takes the priority?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry not sure if that's the situation here. Currently for android build, clang path is /opt/ndk/toolchains/llvm/prebuilt/...bin and we should not use /opt/cache/bin/clang (stub which points to the system clang)?

Basically for android, we need /opt/ndk/.../clang to point to a stub as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Using a stub works transparently as part of the Docker image. Setting CMAKE_CXX_COMPILER_LAUNCHER needs to be done later, i.e. people need to remember to set that explicitly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I feel like it's hard to do stub... In NDK we have so many variants of clang

armv7a-linux-androideabi21-clang    i686-linux-android29-clang++  x86_64-linux-android21-clang
armv7a-linux-androideabi21-clang++  i686-linux-android30-clang    x86_64-linux-android21-clang++
armv7a-linux-androideabi22-clang    i686-linux-android30-clang++  x86_64-linux-android22-clang
armv7a-linux-androideabi22-clang++  i686-linux-android31-clang    x86_64-linux-android22-clang++
armv7a-linux-androideabi23-clang    i686-linux-android31-clang++  x86_64-linux-android23-clang
armv7a-linux-androideabi23-clang++  i686-linux-android32-clang    x86_64-linux-android23-clang++

Copy link
Contributor

Choose a reason for hiding this comment

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

@kirklandsign I think you can use $ANDROID_NDK/ndk-which clang to get the specific location

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jathu I can have a try - just use clang instead of these variants (which are basically for clang --target=x86_64-linux-android21 stuff)

I was just worried if somehow android NDK triggered clang via x86_64-linux-android21-clang not clang

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@kirklandsign kirklandsign temporarily deployed to upload-benchmark-results March 26, 2025 19:21 — with GitHub Actions Inactive
@@ -89,10 +89,26 @@ init_sccache() {
as_ci_user sccache --zero-stats || true
}

function write_android_sccache_stub() {
BINARY=$1
mv "/opt/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/$1" "/opt/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/.$1"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

/opt/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang
/opt/ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. topic: not user facing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants