Commit b81a779
committed
Split the runtime out of the Python bindings extension
## The problem
`pip install executorch` gives you the Python half of ExecuTorch and nothing a C++ program can
link. Everything is fused into one large Python extension file, so a C++ developer has to clone
the repository, sync submodules, and build from source.
There is a correctness problem underneath the packaging one. Because the runtime is fused into the
extension, anything else that needs it gets its own private copy, and two copies mean two
registries. A backend registered in one is invisible to the other.
## The change
Build the runtime and the pieces around it as separate shared libraries, and make the Python
extension link them instead of embedding them. A shared library is a file a program loads at run
time, so several programs can use one copy instead of each carrying its own.
```
executorch/
lib/libexecutorch.so the runtime
lib/libexecutorch_kernels_optimized.so CPU operator kernels
lib/libexecutorch_backend_xnnpack.so the XNNPACK delegate
lib/libexecutorch_threadpool.so one thread pool per process
lib/libexecutorch_etdump.so the profiler
extension/pybindings/_portable_lib.so now under a megabyte, links the above
```
The extension is much smaller than before, because it no longer contains what it now links.
Linux only, and only when the CUDA backend is off. macOS and Windows keep the fused extension
because the split relies on ELF sonames, the `$ORIGIN` search-path token and GNU linker options,
none of which apply there, and enabling it elsewhere now fails while configuring rather than much
later. A CUDA build also keeps the fused extension for now, because the CUDA libraries are not yet
shipped alongside the others.
## Test plan
Built the wheel from source, installed it into a clean environment, and checked:
- exactly one library defines each component, and it is the library that should own it. Counting
owners alone would also pass on the old fused layout, which has exactly one too.
- the Python extension defines none of them and resolves all of them from outside.
- every shipped library loads with no unresolved dependency, and none of them searches a directory
from the machine that built the wheel. The build-directory patterns are matched as whole path
components, because a bare substring also matched an unrelated directory a user could really
have, such as `/home/user/cmake-outputs/torchlibs`, and stripping that breaks a dependency the
library legitimately resolves there.
- a read-only build output is no longer archived world-writable. The previous code granted write
to the group and to everyone via an absolute chmod mode; the fix only grants owner-write, so a
`0555` file lands as `0755` instead of `0777`.
- a custom operator library compiles and links against the shipped Python extension, which is the
existing contract this must not break. Linking these libraries from a standalone C++ application
additionally needs an installed CMake package, which the wheel does not carry yet.
- the ahead-of-time quantized library records its route to the runtime through the same helper the
other targets use. It was written by hand in two blocks that between them covered only the wheel
layout and only when the wheel flag was set, so a plain `-DEXECUTORCH_BUILD_SHARED=ON` build left
it with no route at all. Checked all four combinations of the shared build and the presence of the
Python extension.
Ran on Linux x86_64 and aarch64, including a Jetson device.
Not fixed here: these libraries bundle third-party code that torch also links, and both keep it
visible, so a process holds two definitions of symbols like `pthreadpool_create`. A caller reaches
whichever the loader found first. Fixing it means hiding or dropping the bundled copies, which is a
larger change.
ghstack-source-id: b7977f7
ghstack-comment-id: 5200527760
Pull-Request: #216101 parent 43f89fb commit b81a779
31 files changed
Lines changed: 2719 additions & 147 deletions
File tree
- .ci/scripts
- tests
- wheel
- .github/workflows
- backends
- qualcomm
- xnnpack
- codegen/tools
- configurations
- devtools
- bundled_program
- etdump
- extension
- llm
- custom_ops
- runner
- threadpool
- training
- kernels
- portable
- quantized
- runtime/core/exec_aten/util
- tools/cmake
- preset
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
10 | 12 | | |
11 | 13 | | |
| 14 | + | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| |||
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
44 | 53 | | |
45 | 54 | | |
46 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
| 12 | + | |
9 | 13 | | |
10 | 14 | | |
11 | 15 | | |
| |||
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
29 | 39 | | |
30 | 40 | | |
31 | 41 | | |
| |||
0 commit comments