-
Notifications
You must be signed in to change notification settings - Fork 685
Add selective build support for prim ops #14332
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
Add selective build support for prim ops #14332
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/14332
Note: Links to docs will display an error until the docs builds have been completed. ❌ 2 New FailuresAs of commit d6e35a3 with merge base 5fd66ee ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review automatically exported from Phabricator review in Meta.
This PR needs a
|
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
ffea630
to
e64e3f1
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
e64e3f1
to
7178438
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
7178438
to
b126bfd
Compare
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
b126bfd
to
fc6d311
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
fc6d311
to
70a41c8
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
70a41c8
to
83d39a9
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
83d39a9
to
df69d80
Compare
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
df69d80
to
b049c7b
Compare
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
b049c7b
to
cd2bd8b
Compare
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
cd2bd8b
to
a2bc614
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Summary: This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time. ## Key Changes: 1. **Conditional compilation in register_prim_ops.cpp**: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (`EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD`) and individual op selection (e.g., `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 2. **Code generation tool**: Added `gen_selected_prim_ops.py` that takes comma-separated prim op names and generates a header file (`selected_prim_ops.h`) containing appropriate `#define` statements for selected ops. The tool normalizes op names to macro-safe format (e.g., `executorch_prim::et_view.default` → `INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT`). 3. **Build system integration**: In order to make et_operator_library also handle prim of selective build we make a few changes. 1. Extract prim ops in et_operator_library 2. Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h file per et_operator_library target. Thus et_operator_library now generates selected_operators.yaml and selected_prim_ops.h. Note that in order to make these work we have to allow et_operator_libray to handle the following cases. 1. All ops are aten ops 2. All ops are prim ops 3. Mix To do this we must make sure that the genrule continues to produce the file it says it will produce. In the case of 1 we have to produce empty selected_prim_opsh. and in case 2 we have to produce emtpy selected_operators.yaml 3. In gen_all_oplist we allow for empty selected_operators.yaml and skip the file. 4. Similar to gen_all_oplist we introduce another binary that combines all selected_prim_ops.h. 5. Then in executorch_generated_lib we query targets from 4 that have selected_prim_ops and use those to compile register_prim_ops.cpp. In executorch_generate_lib we introduce include_all_prim_ops which by default is True. Hence if one wants to enable selective build for prim ops one must turn off that flag ## Usage: Users can now specify prim ops like: ``` et_operator_library(name="my_aten_prim_ops", ops=["aten::mul.out", "executorch_prim::et_view.default", "aten::sym_size.int"]) executorch_generated_lib(name="my_lib", deps=[":my_aten_prim_ops"] + other_deps, include_all_prim_ops=False) ``` Reviewed By: ivayloen, larryliu0820 Differential Revision: D81648030
a2bc614
to
d6e35a3
Compare
@kimishpatel has exported this pull request. If you are a Meta employee, you can view the originating diff in D81648030. |
Differential Revision: D81648030 Pull Request resolved: pytorch#14332
Summary:
This diff implements selective build functionality for primitive operations (prim ops) in ExecutorTorch, allowing users to include only specific prim ops in their builds to reduce binary size and compilation time.
Key Changes:
Conditional compilation in register_prim_ops.cpp: Wrapped each of the prim op registrations with conditional compilation macros that check both selective build enablement (
EXECUTORCH_ENABLE_PRIM_OPS_SELECTIVE_BUILD
) and individual op selection (e.g.,INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT
).Code generation tool: Added
gen_selected_prim_ops.py
that takes comma-separated prim op names and generates a header file (selected_prim_ops.h
) containing appropriate#define
statements for selected ops. The tool normalizes op names to macro-safe format (e.g.,executorch_prim::et_view.default
→INCLUDE_EXECUTORCH_PRIM_ET_VIEW_DEFAULT
).Build system integration:
In order to make et_operator_library also handle prim of selective build we
make a few changes.
Extract prim ops in et_operator_library
Similar to gen_op_list, we invoke script that geneates selected_prim_ops.h
file per et_operator_library target. Thus et_operator_library now generates
selected_operators.yaml and selected_prim_ops.h.
Note that in order to make these work we have to allow et_operator_libray to
handle the following cases.
To do this we must make sure that the genrule continues to produce the file
it says it will produce. In the case of 1 we have to produce empty
selected_prim_opsh. and in case 2 we have to produce emtpy
selected_operators.yaml
In gen_all_oplist we allow for empty selected_operators.yaml and skip the
file.
Similar to gen_all_oplist we introduce another binary that combines all
selected_prim_ops.h.
Then in executorch_generated_lib we query targets from 4 that have
selected_prim_ops and use those to compile register_prim_ops.cpp.
In executorch_generate_lib we introduce include_all_prim_ops which by default
is True. Hence if one wants to enable selective build for prim ops one must
turn off that flag
Usage:
Users can now specify prim ops like:
Reviewed By: ivayloen, larryliu0820
Differential Revision: D81648030