Skip to content

Commit 7fbb88c

Browse files
authored
Use optimized kernels when available in top-level selective build (#14203)
### Summary Use optimized kernels for the top-level executorch_selected_kernels target when built. ### Test plan I've manually built with top-level selective build to verify that this works. CI coverage will be provided with #13741, which should land shortly.
1 parent d28f924 commit 7fbb88c

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CMakeLists.txt

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,19 @@ if(NOT EXECUTORCH_SELECT_OPS_YAML STREQUAL ""
926926
OR NOT EXECUTORCH_SELECT_OPS_LIST STREQUAL ""
927927
OR NOT EXECUTORCH_SELECT_OPS_MODEL STREQUAL ""
928928
)
929+
# Use optimized kernels when available.
930+
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
931+
set(_selected_kernel_functions_yaml
932+
${CMAKE_CURRENT_BINARY_DIR}/configurations/merged.yaml
933+
)
934+
set(_selected_kernel_libs "optimized_kernels" "optimized_portable_kernels")
935+
else()
936+
set(_selected_kernel_functions_yaml
937+
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
938+
)
939+
set(_selected_kernel_libs "portable_kernels")
940+
endif()
941+
929942
gen_selected_ops(
930943
LIB_NAME
931944
"executorch_selected_kernels"
@@ -945,7 +958,7 @@ if(NOT EXECUTORCH_SELECT_OPS_YAML STREQUAL ""
945958
LIB_NAME
946959
"executorch_selected_kernels"
947960
FUNCTIONS_YAML
948-
${EXECUTORCH_ROOT}/kernels/portable/functions.yaml
961+
${_selected_kernel_functions_yaml}
949962
CUSTOM_OPS_YAML
950963
""
951964
DTYPE_SELECTIVE_BUILD
@@ -956,13 +969,19 @@ if(NOT EXECUTORCH_SELECT_OPS_YAML STREQUAL ""
956969
LIB_NAME
957970
"executorch_selected_kernels"
958971
KERNEL_LIBS
959-
"portable_kernels"
972+
${_selected_kernel_libs}
960973
DEPS
961974
executorch_core
962975
DTYPE_SELECTIVE_BUILD
963976
"${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}"
964977
)
965978
list(APPEND _executorch_kernels executorch_selected_kernels)
979+
980+
install(
981+
TARGETS executorch_selected_kernels
982+
EXPORT ExecuTorchTargets
983+
DESTINATION lib
984+
)
966985
else()
967986
# No selective build - link the full library.
968987
if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)

tools/cmake/Codegen.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ function(merge_yaml)
342342
DEPENDS ${GEN_FUNCTIONS_YAML} ${GEN_FALLBACK_YAML}
343343
WORKING_DIRECTORY ${EXECUTORCH_ROOT}
344344
)
345+
346+
# Mark the file as generated to allow it to be referenced from other
347+
# CMakeLists in the project.
348+
set_source_files_properties(
349+
${GEN_OUTPUT_DIR}/merged.yaml PROPERTIES GENERATED TRUE
350+
)
345351
endfunction()
346352

347353
# Append the file list in the variable named `name` in build/build_variables.bzl

0 commit comments

Comments
 (0)