Skip to content

Commit 927fefa

Browse files
authored
Support for Header File Generation in DTYPE Selective Build in OSS (#11619)
### Summary Part of the process for enabling the dtype selective build flow requires a header file to be generated that includes information about kernel operators and their dtypes. This change adds support for generating this header file when operators are specified. This functionality is enabled via the command line flag: `-DEXECUTORCH_DTYPE_SELECTIVE_BUILD=ON`. When enabled, the resultant `selected_op_variants.h` file will be generated.
1 parent 7bde4c4 commit 927fefa

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ option(EXECUTORCH_SELECT_ALL_OPS
6565
# Option to enable parsing ops and dtypes directly from model pte file
6666
option(EXECUTORCH_SELECT_OPS_FROM_MODEL "Enable op selection from pte during build." OFF
6767
)
68+
69+
# Option to enable dtype selective build. Note: must be using selective build model API.
70+
option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF
71+
)
6872
# ------------------------------- OPTIONS END --------------------------------
6973

7074
#
@@ -114,6 +118,8 @@ gen_selected_ops(
114118
"${EXECUTORCH_SELECT_ALL_OPS}"
115119
OPS_FROM_MODEL
116120
"${EXECUTORCH_SELECT_OPS_FROM_MODEL}"
121+
DTYPE_SELECTIVE_BUILD
122+
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
117123
)
118124

119125
generate_bindings_for_kernels(

tools/cmake/Codegen.cmake

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
1313

1414
function(gen_selected_ops)
15-
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS OPS_FROM_MODEL)
15+
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS OPS_FROM_MODEL DTYPE_SELECTIVE_BUILD)
1616
cmake_parse_arguments(GEN "" "" "${arg_names}" ${ARGN})
1717

18-
message(STATUS "Generating operator lib:")
18+
message(STATUS "Generating selected operator lib:")
1919
message(STATUS " LIB_NAME: ${GEN_LIB_NAME}")
2020
message(STATUS " OPS_SCHEMA_YAML: ${GEN_OPS_SCHEMA_YAML}")
2121
message(STATUS " ROOT_OPS: ${GEN_ROOT_OPS}")
2222
message(STATUS " INCLUDE_ALL_OPS: ${GEN_INCLUDE_ALL_OPS}")
2323
message(STATUS " OPS_FROM_MODEL: ${GEN_OPS_FROM_MODEL}")
24+
message(STATUS " DTYPE_SELECTIVE_BUILD: ${GEN_DTYPE_SELECTIVE_BUILD}")
25+
if(GEN_DTYPE_SELECTIVE_BUILD)
26+
message(STATUS " DTYPE_SELECTIVE_BUILD is still WIP and may not be fully functional")
27+
endif()
2428

2529
set(_oplist_yaml
2630
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_operators.yaml
@@ -58,6 +62,23 @@ function(gen_selected_ops)
5862
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
5963
)
6064

65+
if(GEN_DTYPE_SELECTIVE_BUILD)
66+
set(_opvariant_h
67+
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_op_variants.h
68+
)
69+
set(_gen_opvariant_command "${PYTHON_EXECUTABLE}" -m codegen.tools.gen_selected_op_variants
70+
--yaml-file=${_oplist_yaml}
71+
--output-dir=${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/
72+
)
73+
message("Command - ${_gen_opvariant_command}")
74+
add_custom_command(
75+
COMMENT "Generating selected_op_variants.h for ${GEN_LIB_NAME}"
76+
OUTPUT ${_opvariant_h}
77+
COMMAND ${_gen_opvariant_command}
78+
DEPENDS ${_oplist_yaml} ${_codegen_tools_srcs}
79+
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
80+
)
81+
endif()
6182
endfunction()
6283

6384
# Codegen for registering kernels. Kernels are defined in functions_yaml and

0 commit comments

Comments
 (0)