@@ -36,9 +36,27 @@ function(gen_selected_ops ops_schema_yaml root_ops include_all_ops)
3636
3737endfunction ()
3838
39+ # Return generated source files
40+ function (get_generated_sources list_name manual_registration)
41+ set (_temp_list
42+ ${CMAKE_CURRENT_BINARY_DIR} /Functions.h
43+ ${CMAKE_CURRENT_BINARY_DIR} /NativeFunctions.h)
44+ # If manually register ops, change source files
45+ if (manual_registration)
46+ list (APPEND _temp_list
47+ ${CMAKE_CURRENT_BINARY_DIR} /RegisterKernelsEverything.cpp)
48+ list (APPEND _temp_list ${CMAKE_CURRENT_BINARY_DIR} /RegisterKernels.h)
49+ else ()
50+ list (APPEND _temp_list
51+ ${CMAKE_CURRENT_BINARY_DIR} /RegisterCodegenUnboxedKernelsEverything.cpp)
52+ endif ()
53+
54+ set (${list_name} ${_temp_list} PARENT_SCOPE)
55+ endfunction ()
56+
3957# Codegen for registering kernels. Kernels are defined in functions_yaml and
4058# custom_ops_yaml
41- function (generate_bindings_for_kernels functions_yaml custom_ops_yaml)
59+ function (generate_bindings_for_kernels functions_yaml custom_ops_yaml manual )
4260 # Command to generate selected_operators.yaml from custom_ops.yaml.
4361 file (GLOB_RECURSE _codegen_templates "${EXECUTORCH_ROOT} /codegen/templates/*" )
4462 file (GLOB_RECURSE _torchgen_srcs "${TORCH_ROOT} /torchgen/*.py" )
@@ -55,10 +73,12 @@ function(generate_bindings_for_kernels functions_yaml custom_ops_yaml)
5573 --aten-yaml-path =${TORCH_ROOT} /aten/src/ATen/native/native_functions.yaml
5674 --op-selection-yaml-path =${_oplist_yaml} )
5775
58- set (_gen_command_sources
59- ${CMAKE_CURRENT_BINARY_DIR} /RegisterCodegenUnboxedKernelsEverything.cpp
60- ${CMAKE_CURRENT_BINARY_DIR} /Functions.h
61- ${CMAKE_CURRENT_BINARY_DIR} /NativeFunctions.h)
76+ get_generated_sources("_gen_command_sources" "${manual} " )
77+
78+ # If manually register ops, append --manual_registration and change out files
79+ if (manual)
80+ list (APPEND _gen_command --manual_registration)
81+ endif ()
6282
6383 if (functions_yaml)
6484 list (APPEND _gen_command --functions-yaml-path =${functions_yaml} )
@@ -105,14 +125,10 @@ function(gen_custom_ops_aot_lib lib_name kernel_sources)
105125endfunction ()
106126
107127# Generate a runtime lib for registering operators in Executorch
108- function (gen_operators_lib lib_name kernel_lib deps)
128+ function (gen_operators_lib lib_name kernel_lib deps manual_registration )
109129 add_library (${lib_name} )
110- target_sources (
111- ${lib_name}
112- PRIVATE
113- ${CMAKE_CURRENT_BINARY_DIR} /RegisterCodegenUnboxedKernelsEverything.cpp
114- ${CMAKE_CURRENT_BINARY_DIR} /Functions.h
115- ${CMAKE_CURRENT_BINARY_DIR} /NativeFunctions.h)
130+ get_generated_sources("_sources" "${manual_registration} " )
131+ target_sources (${lib_name} PRIVATE ${_sources} )
116132 target_link_libraries (${lib_name} PRIVATE ${deps} )
117133 if (kernel_lib)
118134 target_link_libraries (${lib_name} INTERFACE ${kernel_lib} )
0 commit comments