Ship the merged CPU kernels as their own library - #21524
Open
shoumikhin wants to merge 3 commits into
Open
Conversation
Contributor
Author
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21524
Note: Links to docs will display an error until the docs builds have been completed. ⏳ No Failures, 263 PendingAs of commit e06b763 with merge base d632341 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This was referenced Jul 31, 2026
This was referenced Jul 31, 2026
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.
The CPU operator kernels are compiled into whichever component links them, so
the Python bindings extension carries its own full copy. That makes the
extension large, and it means a C++ application cannot get the same operators
without building them from source. It also means two components that both want
CPU operators end up with two independent registrations of the same operator
set in one process.
Build the merged CPU kernels as a shared library and ship it in the wheel, so
the operators live in one place and both the Python bindings and a C++
application can link the same copy.
The library type is opt-in rather than a global change:
gen_operators_libhasmany callers that want an ordinary static library, and only the one shipped in
the wheel needs to be shared. Callers that do not pass
SHAREDare unaffected,and the whole change is gated on the existing
EXECUTORCH_BUILD_SHAREDoption,so iOS, Android, and embedded builds keep linking static libraries exactly as
before.
Test plan:
The wheel smoke test now asserts that exactly one shipped library defines the
CPU kernels, alongside the existing backend-registry and thread-pool
assertions, so a change that reintroduces a second copy fails in CI rather than
aborting at startup with a duplicate operator registration. The symbol used by
the assertion was confirmed to exist in the shipped libraries first, so the
check cannot pass by matching nothing.
Built the wheel from a clean checkout and verified against a fresh virtual
environment with a normal dependency-resolving install:
runtime and the thread pool.
nm -DCacross every shipped shared object shows exactly one definition of arepresentative CPU operator, in the new library rather than in the bindings
extension.
library loaded.
import executorch, the registered backend list, and.pteexecutionthrough the Python bindings are unchanged, with outputs matching eager
PyTorch.
EXECUTORCH_BUILD_SHAREDoff, the kernels remain a static library andno new shared object is produced, so every build that does not opt in is
unaffected.