diff --git a/CMakeLists.txt b/CMakeLists.txt index 5c3787b3863..f254987e3ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,6 +123,8 @@ set(CMAKE_INSTALL_RPATH_USE_LINK_PATH ON) # Instead please use `find_package(executorch REQUIRED)` in the example # directory and add a new executable in the example `CMakeLists.txt`. +set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}) + if(NOT EXECUTORCH_ENABLE_LOGGING) # Avoid pulling in the logging strings, which can be large. Note that this # will set the compiler flag for all targets in this directory, and for all @@ -386,6 +388,9 @@ set(_executorch_backends "") # A list of all configured extensions. set(_executorch_extensions "") +# A list of all configured kernel libraries. +set(_executorch_kernels "") + target_link_libraries(executorch_core PRIVATE program_schema) if(ANDROID) target_link_libraries(executorch_core PUBLIC log) @@ -774,11 +779,13 @@ endif() if(EXECUTORCH_BUILD_KERNELS_LLM) # TODO: move all custom kernels to ${CMAKE_CURRENT_SOURCE_DIR}/kernels/custom add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/custom_ops) + list(APPEND _executorch_kernels custom_ops_aot_lib) endif() if(EXECUTORCH_BUILD_KERNELS_QUANTIZED) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/kernels/quantized) executorch_target_link_options_shared_lib(quantized_ops_lib) + list(APPEND _executorch_kernels quantized_ops_lib) endif() if(EXECUTORCH_BUILD_VULKAN) @@ -803,6 +810,60 @@ add_library(executorch_extensions INTERFACE) add_library(executorch::extensions ALIAS executorch_extensions) target_link_libraries(executorch_extensions INTERFACE ${_executorch_extensions}) +# A target containing all configured kernels, with selective build, if enabled. +add_library(executorch_kernels INTERFACE) +add_library(executorch::kernels ALIAS executorch_kernels) +if(NOT EXECUTORCH_SELECT_OPS_YAML STREQUAL "" + OR NOT EXECUTORCH_SELECT_OPS_LIST STREQUAL "" + OR NOT EXECUTORCH_SELECT_OPS_MODEL STREQUAL "" +) + gen_selected_ops( + LIB_NAME + "executorch_selected_kernels" + OPS_SCHEMA_YAML + "${EXECUTORCH_SELECT_OPS_LIB}" + ROOT_OPS + "${EXECUTORCH_SELECT_OPS_LIST}" + INCLUDE_ALL_OPS + FALSE + OPS_FROM_MODEL + "${EXECUTORCH_SELECT_OPS_MODEL}" + DTYPE_SELECTIVE_BUILD + "${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}" + ) + + generate_bindings_for_kernels( + LIB_NAME + "executorch_selected_kernels" + FUNCTIONS_YAML + ${EXECUTORCH_ROOT}/kernels/portable/functions.yaml + CUSTOM_OPS_YAML + "" + DTYPE_SELECTIVE_BUILD + "${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}" + ) + + gen_operators_lib( + LIB_NAME + "executorch_selected_kernels" + KERNEL_LIBS + "portable_kernels" + DEPS + executorch_core + DTYPE_SELECTIVE_BUILD + "${EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD}" + ) + list(APPEND _executorch_kernels executorch_selected_kernels) +else() + # No selective build - link the full library. + if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) + list(APPEND _executorch_kernels optimized_native_cpu_ops_lib) + else() + list(APPEND _executorch_kernels portable_ops_lib) + endif() +endif() +target_link_libraries(executorch_kernels INTERFACE ${_executorch_kernels}) + if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. set(_executor_runner_libs executorch extension_evalue_util diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index 06558b85460..09e9e2ffe6e 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -214,6 +214,28 @@ define_overridable_option( EXECUTORCH_USE_CPP_CODE_COVERAGE "Build with code coverage enabled" BOOL OFF ) +# Selective build options. These affect the executorch_kernels target. +define_overridable_option( + EXECUTORCH_SELECT_OPS_YAML + "Build the executorch_kernels target with YAML selective build config." + STRING "" +) +define_overridable_option( + EXECUTORCH_SELECT_OPS_LIST + "Build the executorch_kernels target with a list of selected operators." + STRING "" +) +define_overridable_option( + EXECUTORCH_SELECT_OPS_MODEL + "Build the executorch_kernels target with only operators from the given model .pte file." + STRING "" +) +define_overridable_option( + EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD + "Build the executorch_kernels target with only operator implementations for selected data types." + BOOL FALSE +) + # ------------------------------------------------------------------------------ # Validations # @@ -284,6 +306,17 @@ check_conflicting_options_on( EXECUTORCH_BUILD_CPUINFO ) +# Selective build specifiers are mutually exclusive. +check_conflicting_options_on( + IF_ON EXECUTORCH_SELECT_OPS_YAML CONFLICTS_WITH + EXECUTORCH_SELECT_OPS_LIST EXECUTORCH_SELECT_OPS_MODEL +) + +check_conflicting_options_on( + IF_ON EXECUTORCH_SELECT_OPS_LIST CONFLICTS_WITH + EXECUTORCH_SELECT_OPS_MODEL +) + if(NOT EXISTS ${EXECUTORCH_PAL_DEFAULT_FILE_PATH}) message( FATAL_ERROR