Android: allow building Vulkan/XNNPACK backends as separate shared libraries - #21849
Open
msluszniak wants to merge 1 commit into
Open
Android: allow building Vulkan/XNNPACK backends as separate shared libraries#21849msluszniak wants to merge 1 commit into
msluszniak wants to merge 1 commit into
Conversation
…braries
The Android AAR links every enabled backend into libexecutorch_jni.so, so an
app pays for all of them even when it uses one. Vulkan and XNNPACK are the
largest contributors, and an app that ships only the CPU path still carries the
GPU backend.
Add EXECUTORCH_BUILD_VULKAN_BACKEND_SHARED and
EXECUTORCH_BUILD_XNNPACK_BACKEND_SHARED, both defaulting to OFF so existing
builds are unchanged. When set, the backend is emitted as its own .so that
whole-archives the corresponding static archive, and the JNI library no longer
links it. Consumers then load only the backends they need.
Notes:
* jni_noop.cpp is an empty translation unit. A SHARED target whose only
content is a whole-archived static library still needs one source file for
CMake to invoke the linker.
* custom_ops links xnnpack_backend directly, which would pull the backend
back into the JNI library and defeat the split, so that link is dropped
when the shared XNNPACK build is selected.
* build_android_library.sh forwards both variables so they can be driven
from the environment.
msluszniak
requested review from
kirklandsign,
larryliu0820 and
psiddh
as code owners
August 14, 2026 17:40
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21849
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Android AAR links every enabled backend into
libexecutorch_jni.so, so anapp pays for all of them even when it uses one. Vulkan and XNNPACK are the
largest contributors, and an app shipping only the CPU path still carries the
GPU backend.
This PR adds
EXECUTORCH_BUILD_VULKAN_BACKEND_SHAREDandEXECUTORCH_BUILD_XNNPACK_BACKEND_SHARED, both defaulting to OFF, soexisting builds are byte-for-byte unchanged. When set, the backend is emitted as
its own
.sothat whole-archives the corresponding static archive, and the JNIlibrary no longer links it — consumers load only what they need.
Two details worth calling out for review:
extension/android/jni/jni_noop.cppis an empty translation unit. ASHAREDtarget whose only content is a whole-archived static library still needs one
source file for CMake to invoke the linker on.
custom_opslinksxnnpack_backenddirectly, which would pull the backendback into the JNI library and defeat the split, so that link is dropped when
the shared XNNPACK build is selected.
build_android_library.shforwards both variables so they can be driven fromthe environment.
Test plan
libexecutorch.soasbefore.
EXECUTORCH_BUILD_VULKAN=ON EXECUTORCH_BUILD_VULKAN_BACKEND_SHARED=ON,the Vulkan backend builds as a separate
.soand an app loading it runsVulkan-delegated models on device (Galaxy S26 Ultra, Adreno).
had real-world exercise across both backends.
cc @SS-JIA @manuelcandales @digantdesai @cbilgin