Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 113 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -351,6 +353,15 @@ 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 "")

# 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)
Expand Down Expand Up @@ -494,6 +505,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)
Expand All @@ -502,30 +514,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)
Expand All @@ -538,14 +557,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)
Expand All @@ -556,26 +578,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)
Expand Down Expand Up @@ -677,21 +705,101 @@ 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)
# 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)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
list(APPEND _executorch_backends vulkan_backend)
endif()

# Top-level interface targets.

# A target containing all configured backends.
add_library(executorch_backends INTERFACE)
add_library(executorch::backends ALIAS executorch_backends)
target_link_libraries(executorch_backends INTERFACE ${_executorch_backends})

# A target containing all configured extensions.
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 ""
)
Comment on lines +816 to +819
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for adding this!

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"
Copy link
Contributor

@lucylq lucylq Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this to top-level cmake!

So, executorch_selected_kernels is a selective build library for portable_kernels only it seems? If a user wants to selectively build on optimized or custom kernel libs, they should either:

  1. Update here (for test purposes, I guess).
  2. Follow the current flow and create their own selective build lib.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, as a follow-up, I intend to enable optimized (and portable_optimized) kernels. To enable selective build for other libraries (quantized ops, llm ops, etc.), I should just be able to use the merge_yaml functionality to generate a combined op yaml, right?

For user's custom op libs, I think they'll probably need to define their own targets, as we can't access their targets from here (unless we re-wrote as a macro/function, but we can look at that separately).

Backend op libs are another case that needs more thinking through, as well. But hopefully this should be a good starting point.

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 executorch_kernels
INCLUDES
DESTINATION ${_common_include_directories}
)

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)
Expand All @@ -710,18 +818,10 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
list(APPEND _executor_runner_libs $<LINK_LIBRARY:WHOLE_ARCHIVE,custom_ops>)
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)
Expand All @@ -737,14 +837,13 @@ 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()

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()
Expand Down
14 changes: 0 additions & 14 deletions backends/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +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 ${_executor_runner_libs} vulkan_schema
vulkan_backend
)
target_compile_options(vulkan_executor_runner PUBLIC ${VULKAN_CXX_FLAGS})
endif()

# Test targets

install(
Expand Down
33 changes: 33 additions & 0 deletions tools/cmake/preset/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
#
Expand Down Expand Up @@ -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
)
Comment on lines +310 to +313
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean in the future it should be composable. I'm OK with having this for now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GregoryComer Should this also check for a conflict with the OPS_FROM_MODEL API?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see it there, later down.


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
Expand Down
Loading