Ship the CUDA delegate as its own library - #21530
Closed
shoumikhin wants to merge 1 commit into
Closed
Conversation
Contributor
Author
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21530
Note: Links to docs will display an error until the docs builds have been completed. ❌ 18 New Failures, 2 Unclassified FailuresAs of commit f93438c with merge base d632341 ( NEW FAILURES - The following jobs have failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
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 CUDA delegate is compiled into whichever component links it, so a C++
application cannot use it without building from source, and the shim layer it
depends on ends up duplicated across several shipped libraries.
Build the delegate as a shared library and ship it in the wheel, so a process
has one copy and both the Python bindings and a C++ application can link the
same one. The CUDA runtime itself is not bundled; it continues to come from the
environment.
Two things were needed to make that actually reduce duplication:
The platform helper resolved the ExecuTorch core statically, which would give
the delegate its own copy of the backend registry. It now resolves the runtime
from the shared runtime library instead.
The shim library force-links its shim objects so their symbols survive, which is
correct, but it did so as a public link option. That propagated to every
consumer, so each one embedded another copy of the same shim code. Making it
private keeps the symbols in the library that owns them while consumers resolve
against it, which takes a representative shim symbol from three definitions down
to one.
Registration still happens through a static initializer, and the delegate is
retained on the link line so that initializer runs even though no symbol from it
is referenced directly.
This is gated on the existing
EXECUTORCH_BUILD_SHAREDoption, so only theLinux wheel changes; every other build keeps linking static libraries exactly as
before.
Test plan:
The wheel smoke test now asserts that exactly one shipped library defines the
CUDA delegate, alongside the existing backend-registry, thread-pool, CPU kernel,
and XNNPACK assertions. Because the delegate is only present in wheels built
with CUDA, that assertion skips cleanly when it is absent rather than failing.
All three behaviors were confirmed: it passes on a wheel built with this change,
it fails on a wheel built before it (correctly reporting three definers by
name), and it skips on a wheel built without CUDA.
The delegate's own methods are weak symbols, so the assertion checks a strong
symbol from the shim layer instead.
Built the wheel with CUDA enabled from a clean checkout and verified against a
fresh virtual environment with a normal dependency-resolving install:
the thread pool, the CPU kernels, and the XNNPACK delegate.
nm -DCacross every shipped shared object shows exactly one definition of arepresentative delegate symbol, down from three.
not introduce a second one.
CUDA delegate loaded.
EXECUTORCH_BUILD_SHAREDoff, the delegate remains a static library andno new shared object is produced, so every build that does not opt in is
unaffected.
Note for anyone building with CUDA: the build needs an explicit
CMAKE_CUDA_ARCHITECTURESfor compute capability 6.1 or newer, otherwise aninteger dot-product intrinsic used by one of the kernels does not compile. That
is independent of this change.