Skip to content

Commit cbb6f8e

Browse files
committed
Support for header file generation with dtype
1 parent 402f421 commit cbb6f8e

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

examples/selective_build/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ option(EXECUTORCH_SELECT_OPS_LIST "Register a list of ops, separated by comma"
6161
option(EXECUTORCH_SELECT_ALL_OPS
6262
"Whether to register all ops defined in portable kernel library." OFF
6363
)
64+
65+
# Option to enable dtype header selective build process
66+
option(EXECUTORCH_DTYPE_SELECTIVE_BUILD "Enable dtype selective build." OFF
67+
)
6468
# ------------------------------- OPTIONS END --------------------------------
6569

6670
#
@@ -108,6 +112,8 @@ gen_selected_ops(
108112
"${EXECUTORCH_SELECT_OPS_LIST}"
109113
INCLUDE_ALL_OPS
110114
"${EXECUTORCH_SELECT_ALL_OPS}"
115+
DTYPE_SELECTIVE_BUILD
116+
"${EXECUTORCH_DTYPE_SELECTIVE_BUILD}"
111117
)
112118

113119
generate_bindings_for_kernels(

tools/cmake/Codegen.cmake

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,23 @@
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)
15+
set(arg_names LIB_NAME OPS_SCHEMA_YAML ROOT_OPS INCLUDE_ALL_OPS 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}")
23+
message(STATUS " DTYPE_SELECTIVE_BUILD: ${GEN_DTYPE_SELECTIVE_BUILD}")
24+
if(GEN_DTYPE_SELECTIVE_BUILD)
25+
message(STATUS " DTYPE_SELECTIVE_BUILD is still WIP and may not be fully functional")
26+
endif()
2327

2428
set(_oplist_yaml
2529
${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME}/selected_operators.yaml
2630
)
31+
2732
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${GEN_LIB_NAME})
2833

2934
file(GLOB_RECURSE _codegen_tools_srcs "${EXECUTORCH_ROOT}/codegen/tools/*.py")
@@ -53,6 +58,23 @@ function(gen_selected_ops)
5358
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
5459
)
5560

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

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

0 commit comments

Comments
 (0)