From 7c0481efe7bb263a5069735ff7b16d5ab9ec4583 Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Mon, 21 Jul 2025 14:38:58 -0700 Subject: [PATCH 01/13] Update [ghstack-poisoned] --- CMakeLists.txt | 36 ++++++++++++++++--------- tools/cmake/executorch-config.cmake | 41 ++++++++++++++++++++--------- 2 files changed, 51 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c17ff893830..2778c104227 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -351,6 +351,9 @@ add_library(executorch_core ${_executorch_core__srcs}) # Legacy name alias. add_library(executorch_no_prim_ops ALIAS executorch_core) +# A list of all configured backends. +set(_executorch_backends "") + target_link_libraries(executorch_core PRIVATE program_schema) if(ANDROID) target_link_libraries(executorch_core PUBLIC log) @@ -494,6 +497,7 @@ install(FILES tools/cmake/Utils.cmake tools/cmake/executorch-config.cmake if(EXECUTORCH_BUILD_ARM_BAREMETAL) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm) + list(APPEND _executorch_backends executorch_delegate_ethos_u) endif() if(EXECUTORCH_BUILD_CADENCE) @@ -502,30 +506,37 @@ endif() if(EXECUTORCH_BUILD_NXP_NEUTRON) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/nxp) + list(APPEND _executorch_backends executorch_delegate_neutron) endif() if(EXECUTORCH_BUILD_COREML) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/coreml) + list(APPEND _executorch_backends coremldelegate) endif() if(EXECUTORCH_BUILD_MPS) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/apple/mps) + list(APPEND _executorch_backends mpsdelegate) endif() if(EXECUTORCH_BUILD_NEURON) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/mediatek) + list(APPEND _executorch_backends neuron_backend) endif() if(EXECUTORCH_BUILD_OPENVINO) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/openvino) + list(APPEND _executorch_backends openvino_backend) endif() if(EXECUTORCH_BUILD_QNN) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/qualcomm) + list(APPEND _executorch_backends qnn_executorch_backend) endif() if(EXECUTORCH_BUILD_XNNPACK) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/xnnpack) + list(APPEND _executorch_backends xnnpack_backend) endif() if(EXECUTORCH_BUILD_CORTEX_M) @@ -689,9 +700,20 @@ if(EXECUTORCH_BUILD_KERNELS_QUANTIZED) target_link_options_shared_lib(quantized_ops_lib) endif() +if(EXECUTORCH_BUILD_VULKAN) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan) + list(APPEND _executorch_backends vulkan_backend) +endif() + +# Top-level interface targets. +add_library(executorch_backends INTERFACE) + +# A target containing all configured backends. +target_link_libraries(executorch_backends INTERFACE ${_executorch_backends}) + if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. - set(_executor_runner_libs executorch gflags) + set(_executor_runner_libs executorch gflags executorch_backends) if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib) @@ -710,18 +732,10 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) list(APPEND _executor_runner_libs $) endif() - if(EXECUTORCH_BUILD_XNNPACK) - list(APPEND _executor_runner_libs xnnpack_backend) - endif() - if(EXECUTORCH_ENABLE_EVENT_TRACER) list(APPEND _executor_runner_libs etdump flatccrt) endif() - if(EXECUTORCH_BUILD_COREML AND APPLE) - list(APPEND _executor_runner_libs coremldelegate) - endif() - add_executable(executor_runner ${_executor_runner__srcs}) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options_gc_sections(executor_runner) @@ -741,10 +755,6 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) endif() endif() -if(EXECUTORCH_BUILD_VULKAN) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan) -endif() - if(EXECUTORCH_BUILD_ANDROID_JNI) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android) endif() diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index 6472648786c..fcc791f4a04 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -57,18 +57,28 @@ set(EXECUTORCH_FOUND ON) target_link_libraries(executorch INTERFACE executorch_core) -set(lib_list - flatccrt - etdump - bundled_program - extension_data_loader - extension_flat_tensor +set(backend_lib_list coreml_util coreml_inmemoryfs coremldelegate mpsdelegate neuron_backend qnn_executorch_backend + # Start XNNPACK Lib Deps + XNNPACK + xnnpack-microkernels-prod + kleidiai + # End XNNPACK Lib Deps + xnnpack_backend + vulkan_backend +) + +set(lib_list + flatccrt + etdump + bundled_program + extension_data_loader + extension_flat_tensor portable_ops_lib custom_ops extension_module @@ -77,15 +87,8 @@ set(lib_list extension_tensor extension_threadpool extension_training - xnnpack_backend - # Start XNNPACK Lib Deps - XNNPACK - xnnpack-microkernels-prod - kleidiai - # End XNNPACK Lib Deps cpuinfo pthreadpool - vulkan_backend optimized_kernels optimized_portable_kernels cpublas @@ -96,6 +99,9 @@ set(lib_list quantized_ops_lib quantized_ops_aot_lib ) + +list(APPEND lib_list ${backend_lib_list}) + foreach(lib ${lib_list}) # Name of the variable which stores result of the find_library search set(lib_var "LIB_${lib}") @@ -198,3 +204,12 @@ if(TARGET xnnpack_backend) ) target_link_options_shared_lib(xnnpack_backend) endif() + +# An interface target containing all available backends. +add_library(executorch_backends INTERFACE) + +foreach(lib ${backend_lib_list}) + if(TARGET ${lib}) + target_link_options(executorch_backends INTERFACE ${lib}) + endif() +endforeach() From d562557e18648ae1fa7e366f252efe66124310a6 Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Mon, 21 Jul 2025 16:23:28 -0700 Subject: [PATCH 02/13] Update [ghstack-poisoned] --- CMakeLists.txt | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2778c104227..c6a5b6adf1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -713,7 +713,7 @@ target_link_libraries(executorch_backends INTERFACE ${_executorch_backends}) if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. - set(_executor_runner_libs executorch gflags executorch_backends) + set(_executor_runner_libs executorch gflags) if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib) @@ -732,27 +732,30 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) list(APPEND _executor_runner_libs $) endif() + if(EXECUTORCH_BUILD_XNNPACK) + list(APPEND _executor_runner_libs xnnpack_backend) + endif() + if(EXECUTORCH_ENABLE_EVENT_TRACER) list(APPEND _executor_runner_libs etdump flatccrt) endif() + if(EXECUTORCH_BUILD_COREML AND APPLE) + list(APPEND _executor_runner_libs coremldelegate) + endif() + add_executable(executor_runner ${_executor_runner__srcs}) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options_gc_sections(executor_runner) endif() - target_link_libraries(executor_runner ${_executor_runner_libs}) - target_compile_options(executor_runner PUBLIC ${_common_compile_options}) - - # Automatically set when using `emcmake cmake` for Wasm build. - if(EMSCRIPTEN) - # Directory of model pte files to embed in the wasm binary. - if(NOT DEFINED WASM_MODEL_DIR) - set(WASM_MODEL_DIR "${CMAKE_SOURCE_DIR}/models/") - endif() - - set(CMAKE_EXECUTABLE_SUFFIX ".html") - target_link_options(executor_runner PUBLIC -sALLOW_MEMORY_GROWTH --embed-file "${WASM_MODEL_DIR}@/") - endif() +endif() + +if(EXECUTORCH_BUILD_VULKAN) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan) +endif() + +if(EXECUTORCH_BUILD_ANDROID_JNI) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android) endif() if(EXECUTORCH_BUILD_ANDROID_JNI) From 295206e43038702aff47c00a18185745b064019d Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Mon, 21 Jul 2025 16:54:29 -0700 Subject: [PATCH 03/13] Update [ghstack-poisoned] --- CMakeLists.txt | 19 ++++++++++++++++++- tools/cmake/executorch-config.cmake | 26 +++++++++++++++++++------- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a5b6adf1e..31f27bf69b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -354,6 +354,9 @@ add_library(executorch_no_prim_ops ALIAS executorch_core) # A list of all configured backends. set(_executorch_backends "") +# A list of all configured extensions. +set(_executorch_extensions "") + target_link_libraries(executorch_core PRIVATE program_schema) if(ANDROID) target_link_libraries(executorch_core PUBLIC log) @@ -549,14 +552,17 @@ endif() if(EXECUTORCH_BUILD_EXTENSION_APPLE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/apple) + list(APPEND _executorch_extensions apple_extension) endif() if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/data_loader) + list(APPEND _executorch_extensions extension_data_loader) endif() if(EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/flat_tensor) + list(APPEND _executorch_extensions extension_flat_tensor) endif() if(EXECUTORCH_BUILD_EXTENSION_MODULE) @@ -567,26 +573,32 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE) FILES_MATCHING PATTERN "*.h" ) +list(APPEND _executorch_extensions extension_module_static) endif() if(EXECUTORCH_BUILD_EXTENSION_LLM) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/tokenizers) + list(APPEND _executorch_extensions tokenizers) endif() if(EXECUTORCH_BUILD_EXTENSION_LLM_APPLE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/apple) + list(APPEND _executorch_extensions extension_llm_apple) endif() if(EXECUTORCH_BUILD_EXTENSION_LLM_RUNNER) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/llm/runner) + list(APPEND _executorch_extensions extension_llm_runner) endif() if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/runner_util) + list(APPEND _executorch_extensions extension_runner_util) endif() if(EXECUTORCH_BUILD_EXTENSION_TENSOR) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/tensor) + list(APPEND _executorch_extensions extension_tensor) endif() if(EXECUTORCH_BUILD_PTHREADPOOL AND EXECUTORCH_BUILD_CPUINFO) @@ -688,6 +700,7 @@ endif() if(EXECUTORCH_BUILD_EXTENSION_TRAINING) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/training) + list(APPEND _executorch_extensions extension_training) endif() if(EXECUTORCH_BUILD_KERNELS_LLM) @@ -706,11 +719,15 @@ if(EXECUTORCH_BUILD_VULKAN) endif() # Top-level interface targets. -add_library(executorch_backends INTERFACE) # A target containing all configured backends. +add_library(executorch_backends INTERFACE) target_link_libraries(executorch_backends INTERFACE ${_executorch_backends}) +# A target containing all configured extensions. +add_library(executorch_extensions INTERFACE) +target_link_libraries(executorch_extensions INTERFACE ${_executorch_extensions}) + if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. set(_executor_runner_libs executorch gflags) diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index fcc791f4a04..d1ee3fd02d8 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -73,20 +73,23 @@ set(backend_lib_list vulkan_backend ) -set(lib_list - flatccrt - etdump - bundled_program +set(extension_lib_list extension_data_loader extension_flat_tensor - portable_ops_lib - custom_ops extension_module extension_module_static extension_runner_util extension_tensor extension_threadpool extension_training +) + +set(lib_list + flatccrt + etdump + bundled_program + portable_ops_lib + custom_ops cpuinfo pthreadpool optimized_kernels @@ -100,7 +103,7 @@ set(lib_list quantized_ops_aot_lib ) -list(APPEND lib_list ${backend_lib_list}) +list(APPEND lib_list ${backend_lib_list} ${extension_lib_list}) foreach(lib ${lib_list}) # Name of the variable which stores result of the find_library search @@ -213,3 +216,12 @@ foreach(lib ${backend_lib_list}) target_link_options(executorch_backends INTERFACE ${lib}) endif() endforeach() + +# An interface target containing all available extensions. +add_library(executorch_extensions INTERFACE) + +foreach(lib ${extension_lib_list}) + if(TARGET ${lib}) + target_link_options(executorch_extensions INTERFACE ${lib}) + endif() +endforeach() From 1a6d403367c8bf0a08f3682afbec38742414175b Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Mon, 21 Jul 2025 17:57:36 -0700 Subject: [PATCH 04/13] Update [ghstack-poisoned] --- CMakeLists.txt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a5b6adf1e..bb16cb66b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -748,6 +748,19 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options_gc_sections(executor_runner) endif() + target_link_libraries(executor_runner ${_executor_runner_libs}) + target_compile_options(executor_runner PUBLIC ${_common_compile_options}) + + # Automatically set when using `emcmake cmake` for Wasm build. + if(EMSCRIPTEN) + # Directory of model pte files to embed in the wasm binary. + if(NOT DEFINED WASM_MODEL_DIR) + set(WASM_MODEL_DIR "${CMAKE_SOURCE_DIR}/models/") + endif() + + set(CMAKE_EXECUTABLE_SUFFIX ".html") + target_link_options(executor_runner PUBLIC -sALLOW_MEMORY_GROWTH --embed-file "${WASM_MODEL_DIR}@/") + endif() endif() if(EXECUTORCH_BUILD_VULKAN) @@ -758,10 +771,6 @@ if(EXECUTORCH_BUILD_ANDROID_JNI) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android) endif() -if(EXECUTORCH_BUILD_ANDROID_JNI) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android) -endif() - include(Test.cmake) # Print all the configs that were called with announce_configured_options. From 9b1cd879120849b1e130edbce146ca061717f0bc Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Mon, 21 Jul 2025 21:37:52 -0700 Subject: [PATCH 05/13] Update [ghstack-poisoned] --- CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb16cb66b9c..5096e3fe5c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -763,10 +763,6 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) endif() endif() -if(EXECUTORCH_BUILD_VULKAN) - add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan) -endif() - if(EXECUTORCH_BUILD_ANDROID_JNI) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android) endif() From c6d1ff27c1f593dd6f0e0bf3adc7f0467011db4a Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Wed, 23 Jul 2025 21:28:01 -0700 Subject: [PATCH 06/13] Update [ghstack-poisoned] --- CMakeLists.txt | 6 +++++ tools/cmake/executorch-config.cmake | 41 +++++++++-------------------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5096e3fe5c8..f1499116dea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -711,6 +711,12 @@ add_library(executorch_backends INTERFACE) # A target containing all configured backends. target_link_libraries(executorch_backends INTERFACE ${_executorch_backends}) +install( + TARGETS executorch_backends + INCLUDES + DESTINATION ${_common_include_directories} +) + if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. set(_executor_runner_libs executorch gflags) diff --git a/tools/cmake/executorch-config.cmake b/tools/cmake/executorch-config.cmake index fcc791f4a04..6472648786c 100644 --- a/tools/cmake/executorch-config.cmake +++ b/tools/cmake/executorch-config.cmake @@ -57,28 +57,18 @@ set(EXECUTORCH_FOUND ON) target_link_libraries(executorch INTERFACE executorch_core) -set(backend_lib_list - coreml_util - coreml_inmemoryfs - coremldelegate - mpsdelegate - neuron_backend - qnn_executorch_backend - # Start XNNPACK Lib Deps - XNNPACK - xnnpack-microkernels-prod - kleidiai - # End XNNPACK Lib Deps - xnnpack_backend - vulkan_backend -) - set(lib_list flatccrt etdump bundled_program extension_data_loader extension_flat_tensor + coreml_util + coreml_inmemoryfs + coremldelegate + mpsdelegate + neuron_backend + qnn_executorch_backend portable_ops_lib custom_ops extension_module @@ -87,8 +77,15 @@ set(lib_list extension_tensor extension_threadpool extension_training + xnnpack_backend + # Start XNNPACK Lib Deps + XNNPACK + xnnpack-microkernels-prod + kleidiai + # End XNNPACK Lib Deps cpuinfo pthreadpool + vulkan_backend optimized_kernels optimized_portable_kernels cpublas @@ -99,9 +96,6 @@ set(lib_list quantized_ops_lib quantized_ops_aot_lib ) - -list(APPEND lib_list ${backend_lib_list}) - foreach(lib ${lib_list}) # Name of the variable which stores result of the find_library search set(lib_var "LIB_${lib}") @@ -204,12 +198,3 @@ if(TARGET xnnpack_backend) ) target_link_options_shared_lib(xnnpack_backend) endif() - -# An interface target containing all available backends. -add_library(executorch_backends INTERFACE) - -foreach(lib ${backend_lib_list}) - if(TARGET ${lib}) - target_link_options(executorch_backends INTERFACE ${lib}) - endif() -endforeach() From 533901dc1d92aedde7bdb94023c8bf4bda70c7b5 Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Wed, 23 Jul 2025 21:28:01 -0700 Subject: [PATCH 07/13] Update [ghstack-poisoned] --- CMakeLists.txt | 57 +++++++++++++++++++++++++++++++- tools/cmake/preset/default.cmake | 33 ++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e984f337a74..f229c559fb0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -357,6 +357,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) @@ -706,11 +709,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) target_link_options_shared_lib(quantized_ops_lib) + list(APPEND _executorch_kernels quantized_ops_lib) endif() if(EXECUTORCH_BUILD_VULKAN) @@ -728,8 +733,58 @@ target_link_libraries(executorch_backends INTERFACE ${_executorch_backends}) add_library(executorch_extensions INTERFACE) target_link_libraries(executorch_extensions INTERFACE ${_executorch_extensions}) +# A target containing all configured kernels, with selective build, if enabled. +add_library(executorch_kernels INTERFACE) +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}) + install( - TARGETS executorch_backends executorch_extensions + TARGETS executorch_backends executorch_extensions executorch_kernels INCLUDES DESTINATION ${_common_include_directories} ) diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index 0500e730b1a..4e9c8d4188f 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -203,6 +203,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 # @@ -253,6 +275,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 From c3a6a73ca552766b4785e7dd37a5d74c3838b0ac Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Wed, 23 Jul 2025 22:03:50 -0700 Subject: [PATCH 08/13] Update [ghstack-poisoned] --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index f1499116dea..807f20be54a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -765,7 +765,10 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) endif() set(CMAKE_EXECUTABLE_SUFFIX ".html") - target_link_options(executor_runner PUBLIC -sALLOW_MEMORY_GROWTH --embed-file "${WASM_MODEL_DIR}@/") + target_link_options( + executor_runner PUBLIC -sALLOW_MEMORY_GROWTH --embed-file + "${WASM_MODEL_DIR}@/" + ) endif() endif() From 8ae3a4ef2b3340819c7a8dc12f05ede94eab1b2c Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Wed, 23 Jul 2025 22:22:35 -0700 Subject: [PATCH 09/13] Update [ghstack-poisoned] --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 807f20be54a..50a84bae55f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -707,6 +707,7 @@ endif() # Top-level interface targets. add_library(executorch_backends INTERFACE) +add_library(executorch::backends ALIAS executorch_backends) # A target containing all configured backends. target_link_libraries(executorch_backends INTERFACE ${_executorch_backends}) From 4e244abcd2b6a092798490cf21c4a575809c51b7 Mon Sep 17 00:00:00 2001 From: Gregory Comer Date: Wed, 23 Jul 2025 23:06:40 -0700 Subject: [PATCH 10/13] Update [ghstack-poisoned] --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 15dcd5eb0e5..e06a04eccdc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,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 From d0e4350dea42d7e593ffb6c8e005e40e26d20f92 Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Thu, 24 Jul 2025 14:29:22 -0700 Subject: [PATCH 11/13] Update [ghstack-poisoned] --- backends/vulkan/CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index e4fd991858e..28f135edb5b 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -125,7 +125,12 @@ if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") add_executable(vulkan_executor_runner ${VULKAN_RUNNER_SRCS}) target_link_libraries( - vulkan_executor_runner ${_executor_runner_libs} vulkan_schema + vulkan_executor_runner + gflags + executorch + executorch_extensions + executorch_kernels + vulkan_schema vulkan_backend ) target_compile_options(vulkan_executor_runner PUBLIC ${VULKAN_CXX_FLAGS}) From d999dc0e87af1868fd9b8b2934f21eb33c6fe2c7 Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Thu, 24 Jul 2025 16:01:33 -0700 Subject: [PATCH 12/13] Update [ghstack-poisoned] --- CMakeLists.txt | 10 +--------- backends/vulkan/CMakeLists.txt | 19 ------------------- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 50a84bae55f..2b6b0f2ddcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -720,7 +720,7 @@ install( if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) # Baseline libraries that executor_runner will link against. - set(_executor_runner_libs executorch gflags) + set(_executor_runner_libs executorch gflags executorch_backends) if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED) list(APPEND _executor_runner_libs optimized_native_cpu_ops_lib) @@ -739,18 +739,10 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER) list(APPEND _executor_runner_libs $) endif() - if(EXECUTORCH_BUILD_XNNPACK) - list(APPEND _executor_runner_libs xnnpack_backend) - endif() - if(EXECUTORCH_ENABLE_EVENT_TRACER) list(APPEND _executor_runner_libs etdump flatccrt) endif() - if(EXECUTORCH_BUILD_COREML AND APPLE) - list(APPEND _executor_runner_libs coremldelegate) - endif() - add_executable(executor_runner ${_executor_runner__srcs}) if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") target_link_options_gc_sections(executor_runner) diff --git a/backends/vulkan/CMakeLists.txt b/backends/vulkan/CMakeLists.txt index 28f135edb5b..16b22c1f348 100644 --- a/backends/vulkan/CMakeLists.txt +++ b/backends/vulkan/CMakeLists.txt @@ -117,25 +117,6 @@ target_link_options_shared_lib(vulkan_backend) set_property(TARGET vulkan_backend PROPERTY CXX_STANDARD 17) -# Executor Runner - -if(NOT CMAKE_TOOLCHAIN_FILE MATCHES ".*(iOS|ios\.toolchain)\.cmake$") - set(VULKAN_RUNNER_SRCS ${_executor_runner__srcs}) - list(TRANSFORM VULKAN_RUNNER_SRCS PREPEND "${EXECUTORCH_ROOT}/") - - add_executable(vulkan_executor_runner ${VULKAN_RUNNER_SRCS}) - target_link_libraries( - vulkan_executor_runner - gflags - executorch - executorch_extensions - executorch_kernels - vulkan_schema - vulkan_backend - ) - target_compile_options(vulkan_executor_runner PUBLIC ${VULKAN_CXX_FLAGS}) -endif() - # Test targets install( From f7d413f9d37a4ef16956694f5948b7afcd781a3b Mon Sep 17 00:00:00 2001 From: Gregory James Comer Date: Mon, 28 Jul 2025 13:39:28 -0700 Subject: [PATCH 13/13] Update [ghstack-poisoned] --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8dc69ebb134..d94e6e2fda6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -777,7 +777,6 @@ if(EXECUTORCH_BUILD_VGF) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm) list(APPEND _executorch_backends vgf_backend) endif() -endif() # Top-level interface targets.