Skip to content

Plumbing for dtype selection in cmake flow - header generation #11432

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BujSet
Copy link
Contributor

@BujSet BujSet commented Jun 5, 2025

Summary

This change introduces a new cmake command line option that can be enable via -DEXECUTORCH_SELECT_DTYPE=ON. For now , enabling this flag does not change the generated binary size. This change simply add the header file generation to the cmake build flow. Next steps will include automatically have the cmake build flow transplant the contents of the generated header file directly into the kernels/portable/cpu/selective_build.h file. This step must manually be done by a user to enable directed dtype pruning.

Test plan

Changes were test via bash examples/selective_build/test_selective_build.sh. The resultant header file generated by the flow is now created and retained at cmake-out/examples/selective_build/select_build_lib/selected_op_variants.h.

Copy link

pytorch-bot bot commented Jun 5, 2025

🔗 Helpful Links

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

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

❗ 1 Merge Blocking SEVs

There is 1 active merge blocking SEVs. Please view them below:

If you must merge, use @pytorchbot merge -f.

❌ 2 New Failures, 2 Unrelated Failures

As of commit 76cc4d4 with merge base 439aab7 (image):

NEW FAILURES - The following jobs have failed:

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.

@facebook-github-bot facebook-github-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 Jun 5, 2025
@BujSet
Copy link
Contributor Author

BujSet commented Jun 5, 2025

@pytorchbot label "release notes: none"

@pytorch-bot pytorch-bot bot added the release notes: none Do not include this in the release notes label Jun 5, 2025
@BujSet BujSet marked this pull request as ready for review June 5, 2025 22:29
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})

message(STATUS "Generating operator lib:")
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
message(STATUS " OPS_SCHEMA_YAML: ${GEN_OPS_SCHEMA_YAML}")
message(STATUS " ROOT_OPS: ${GEN_ROOT_OPS}")
message(STATUS " INCLUDE_ALL_OPS: ${GEN_INCLUDE_ALL_OPS}")
message(STATUS " DTYPE_SELECT: ${GEN_DTYPE_SELECT}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is GEN_DTYPE_SELECT being defined?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GEN_DTYPE_SELECT is toggled ON or OFF via the command line switch -DEXECUTORCH_SELECT_DTYPE=ON. The option is defined in examples/selective_build/CMakeLists.txt.

@@ -108,16 +112,30 @@ gen_selected_ops(
"${EXECUTORCH_SELECT_OPS_LIST}"
INCLUDE_ALL_OPS
"${EXECUTORCH_SELECT_ALL_OPS}"
DTYPE_SELECT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could we use DTYPE_SELECTIVE_BUILD to mirror the buck API here?

"${_custom_ops_yaml}"
DTYPE_SELECT
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only need this option in gen_selected_ops at the moment, so let's leave it out of the other APIs for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was running into an issue where if the selected_op_variants.h file wasn't include in the sources list in the gen_operators_lib function, cmake was smart enough to delete it. The casing in that function conditionally adds it to the source list if the flag is set.

@@ -94,6 +94,7 @@ test_cmake_select_all_ops() {
rm -rf ${build_dir}
retry cmake -DCMAKE_BUILD_TYPE=Release \
-DEXECUTORCH_SELECT_ALL_OPS=ON \
-DEXECUTORCH_SELECT_DTYPE=ON \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add these in once the E2E is working - currently, it won't enable dtype selective build so may be misleading

@@ -78,6 +98,13 @@ function(generate_bindings_for_kernels)
# By default selective build output is selected_operators.yaml
set(_oplist_yaml ${_out_dir}/selected_operators.yaml)

# If dtype selective build is enable, force header file to be preserved
if(GEN_DTYPE_SELECT)
Copy link
Contributor

@lucylq lucylq Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can leave this out for now, as it'll be preserved once we link the header into the portable library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/binaries ciflow/trunk CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: none Do not include this in the release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants