Android: export curated EXECUTORCH_1_0 ABI from libexecutorch.so (hot-pluggable backends, milestone 1) - #21945
Open
RanjithRagavan wants to merge 2 commits into
Open
Conversation
…-pluggable backends, milestone 1) First step of the hot-pluggable backends plan (pytorch#10457) to let Android apps opt out of unused backends (pytorch#19329). Today libexecutorch.so exports only JNI_OnLoad and Java_*. A backend built as a standalone .so cannot reach the process-wide backend/kernel registries, so its static registration writes into a private copy and delegation fails with 'backend not found' / duplicate-kernel errors. This change adds a versioned EXECUTORCH_1_0 node to extension/android/jni/version_script.txt exporting the curated surface an external .so needs to self-register at load time via ELF symbol interposition: - registration entry points: register_backend, get_backend_class, register_kernels - RTTI/vtables for polymorphic public types such as BackendInterface (its key function is emitted in the core .so) - the public executorch::runtime / executorch::aten API namespaces that backend implementations are written against (Tensor, EValue, MemoryManager, FreeableBuffer, logging) - the et_pal_* C API so backend .so files share process-wide logging/allocation hooks The boundary is namespace-scoped instead of symbol-by-symbol so it stays maintainable as public headers evolve; everything else stays hidden for LTO/gc-sections. Future additive symbols go into a new version node so external .so files can depend on a stable ABI tag. The monolithic .so topology is unchanged: no target, link, or loading behavior changes for existing consumers. Verification: build_android_library.sh now asserts the built libexecutorch.so actually exports the required symbols (via NDK llvm-nm), failing the build if the ABI surface regresses. Existing Android CI exercises the monolithic path end to end.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21945
Note: Links to docs will display an error until the docs builds have been completed.
|
Contributor
Author
|
@pytorchbot label "module: android" |
Contributor
Author
|
@pytorchbot label "release notes: none" |
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
First step of the hot-pluggable backends plan (#10457), which lets Android apps opt out of unused backends to shrink binary size (#19329).
Today the Android AAR ships a single
libexecutorch.sothat links every backend via--whole-archive, and its linker version script exports onlyJNI_OnLoadandJava_*. A backend built as a standalone.sotherefore can't reach the process-wide backend/kernel registries — its self-registration silently writes into a private copy, and delegation fails. This is why external attempts at per-backend.sofiles hit "duplicate kernel" errors.The fix: add a versioned
EXECUTORCH_1_0node toextension/android/jni/version_script.txtthat exports the curated surface an external.soneeds to self-register at load time through normal ELF symbol interposition — the same mechanism the QNN backend already relies on:register_backend,get_backend_class,register_kernelsBackendInterface(its key function is emitted in the core.so, so subclasses in external.sofiles need these symbols)executorch::runtime/executorch::atenAPI namespaces backend implementations are written against (Tensor, EValue, MemoryManager, FreeableBuffer, logging)et_pal_*C API so backend.sofiles share the process-wide logging/allocation hooksThe boundary is deliberately namespace-scoped rather than symbol-by-symbol so it stays maintainable as the public headers evolve; everything else stays hidden for LTO/
--gc-sections. Additive symbols go into a new version node so external.sofiles get a stable ABI tag — answering the issue's open question in favor of a curated, versioned list.What this does NOT change: the monolithic
.sotopology is untouched — no target, link, or loading-behavior change for existing consumers. Split build mode (milestone 2) and the first carved-out backend (milestone 3) build on top of this.Test plan
scripts/build_android_library.shnow asserts — via the NDK'sllvm-nm— that the builtlibexecutorch.soactually exports the required symbols (registration functions,BackendInterfaceRTTI/vtable,etensor::Tensor,EValue,et_pal_emit_log_message,JNI_OnLoad). If the ABI surface ever regresses, the Android AAR build fails loudly instead of shipping a silently broken artifact..socan now resolve the core registry symbols atdlopentime; milestone 3's Vulkan pilot will demonstrate the end-to-end flow.Refs #10457 (milestone 1 of 7), #19329
cc @kirklandsign @cbilgin