Skip to content

Add Buck support for right-sizing operator registry#19513

Draft
rascani wants to merge 1 commit into
pytorch:mainfrom
rascani:export-D104440331
Draft

Add Buck support for right-sizing operator registry#19513
rascani wants to merge 1 commit into
pytorch:mainfrom
rascani:export-D104440331

Conversation

@rascani
Copy link
Copy Markdown
Contributor

@rascani rascani commented May 12, 2026

Summary:
Adds Buck support for auto-right-sizing the ExecuTorch operator registry, matching the CMake feature landed in #19118.

A new operator_registry_selective() macro mirrors prim_ops_registry_selective(): a genrule stages operator_registry.cpp, operator_registry.h, and a generated selected_max_kernel_num.h in one artifact tree, and a per-binary cxx_library compiles them together. operator_registry.cpp's existing __has_include ladder picks up EXECUTORCH_SELECTED_MAX_KERNEL_NUM from the generated header.

executorch_generated_lib gains an opt-in auto_size_kernel_registry parameter (default False). The operator registry is intentionally global, so the per-binary variant defines the same external-linkage symbols as the shared //executorch/runtime/kernel:operator_registry. Turning the flag on requires the consumer to ensure no transitive dep on the shared target. User
-c executorch.max_kernel_num=N still wins via the existing preprocessor flags.

When include_all_prim_ops=False, the binary already builds its own selective prim ops variant; the counter receives the aggregated selected_prim_ops.h(via the new --selected-prim-ops-header flag on gen_max_kernel_num.py) so prim ops compiled out under ET_PRIM_OPS_SELECTIVE_BUILD aren't counted.

Fixes #19512

Differential Revision: D104440331

Summary:
Adds Buck support for auto-right-sizing the ExecuTorch operator registry, matching the CMake feature landed in pytorch#19118.

A new `operator_registry_selective()` macro mirrors `prim_ops_registry_selective()`: a genrule stages `operator_registry.cpp`, `operator_registry.h`, and a generated `selected_max_kernel_num.h` in one artifact tree, and a per-binary cxx_library compiles them together. `operator_registry.cpp`'s existing `__has_include` ladder picks up `EXECUTORCH_SELECTED_MAX_KERNEL_NUM` from the generated header.

`executorch_generated_lib` gains an opt-in `auto_size_kernel_registry` parameter (default False). The operator registry is intentionally global, so the per-binary variant defines the same external-linkage symbols as the shared `//executorch/runtime/kernel:operator_registry`. Turning the flag on requires the consumer to ensure no transitive dep on the shared target. User
`-c executorch.max_kernel_num=N` still wins via the existing preprocessor flags.

When `include_all_prim_ops=False`, the binary already builds its own selective prim ops variant; the counter receives the aggregated `selected_prim_ops.h`(via the new `--selected-prim-ops-header` flag on `gen_max_kernel_num.py`) so prim ops compiled out under `ET_PRIM_OPS_SELECTIVE_BUILD` aren't counted.

Differential Revision: D104440331
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 12, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/19513

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 10 New Failures, 6 Unrelated Failures

As of commit 5505272 with merge base 8020fe0 (image):

NEW FAILURES - The following jobs have failed:

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

BROKEN TRUNK - The following jobs failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 12, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented May 12, 2026

@rascani has exported this pull request. If you are a Meta employee, you can view the originating Diff in D104440331.

@github-actions
Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

@rascani rascani marked this pull request as draft May 12, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. fb-exported meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Buck support for right-sizing operator registry

1 participant