Skip to content
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
7c0481e
Update
GregoryComer Jul 21, 2025
d562557
Update
GregoryComer Jul 21, 2025
295206e
Update
GregoryComer Jul 21, 2025
1a6d403
Update
GregoryComer Jul 22, 2025
9a9d56c
Update
GregoryComer Jul 22, 2025
9b1cd87
Update
GregoryComer Jul 22, 2025
91792fd
Update
GregoryComer Jul 22, 2025
c6d1ff2
Update
GregoryComer Jul 24, 2025
1f9ab62
Update
GregoryComer Jul 24, 2025
533901d
Update
GregoryComer Jul 24, 2025
ba46772
Update
GregoryComer Jul 24, 2025
c3a6a73
Update
GregoryComer Jul 24, 2025
1816540
Update
GregoryComer Jul 24, 2025
046b989
Update
GregoryComer Jul 24, 2025
70ba5b7
Update
GregoryComer Jul 24, 2025
25e18d7
Update
GregoryComer Jul 24, 2025
8ae3a4e
Update
GregoryComer Jul 24, 2025
09fd5fc
Update
GregoryComer Jul 24, 2025
5244f91
Update
GregoryComer Jul 24, 2025
4e244ab
Update
GregoryComer Jul 24, 2025
e270da8
Update
GregoryComer Jul 24, 2025
d0e4350
Update
GregoryComer Jul 24, 2025
08760b1
Update
GregoryComer Jul 24, 2025
b20aa65
Update
GregoryComer Jul 24, 2025
4d94a3b
Update
GregoryComer Jul 24, 2025
d999dc0
Update
GregoryComer Jul 24, 2025
317799f
Update
GregoryComer Jul 24, 2025
c8783b9
Update
GregoryComer Jul 24, 2025
ba6efc4
Update
GregoryComer Jul 24, 2025
64f4668
Update
GregoryComer Jul 24, 2025
1aac01f
Update
GregoryComer Jul 24, 2025
fb8c715
Update
GregoryComer Jul 24, 2025
dacb25b
Update
GregoryComer Jul 24, 2025
d2bdf8b
Update
GregoryComer Jul 28, 2025
fab6b9d
Update
GregoryComer Jul 28, 2025
73c2cb0
Update
GregoryComer Jul 28, 2025
7507aa2
Update
GregoryComer Jul 28, 2025
f7d413f
Update
GregoryComer Jul 28, 2025
65087f5
Update
GregoryComer Jul 28, 2025
9d1824d
Update
GregoryComer Jul 28, 2025
c7786c1
Update
GregoryComer Jul 28, 2025
b3944b3
Update
GregoryComer Jul 28, 2025
56f84cc
Update
GregoryComer Jul 28, 2025
1d1391d
Update
GregoryComer Jul 28, 2025
42c53a6
Update
GregoryComer Jul 29, 2025
2a5ab06
Update
GregoryComer Jul 29, 2025
e9af248
Update
GregoryComer Jul 29, 2025
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
135 changes: 119 additions & 16 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -380,6 +382,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 @@ -524,6 +535,7 @@ install(FILES 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 @@ -532,30 +544,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 @@ -568,6 +587,7 @@ 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)
Expand All @@ -578,6 +598,7 @@ if(EXECUTORCH_BUILD_EXTENSION_DATA_LOADER)
FILES_MATCHING
PATTERN "*.h"
)
list(APPEND _executorch_extensions extension_data_loader)
endif()

if(EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL)
Expand All @@ -592,6 +613,7 @@ 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 @@ -602,6 +624,7 @@ if(EXECUTORCH_BUILD_EXTENSION_MODULE)
FILES_MATCHING
PATTERN "*.h"
)
list(APPEND _executorch_extensions extension_module_static)
endif()

if(EXECUTORCH_BUILD_EXTENSION_LLM)
Expand All @@ -621,10 +644,17 @@ if(EXECUTORCH_BUILD_EXTENSION_LLM)
${ORIGINAL_CMAKE_POSITION_INDEPENDENT_CODE_FLAG}
)
endif()
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_LLM_APPLE)
Expand All @@ -639,10 +669,12 @@ if(EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL)
FILES_MATCHING
PATTERN "*.h"
)
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 @@ -745,22 +777,109 @@ 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)
executorch_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 vulkan_schema)
endif()

if(EXECUTORCH_BUILD_VGF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
list(APPEND _executorch_backends vgf_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 ""
)
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 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 extension_evalue_util
extension_runner_util gflags
executorch_backends
)

if(EXECUTORCH_BUILD_KERNELS_OPTIMIZED)
Expand All @@ -780,18 +899,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 @@ -814,14 +925,6 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
endif()
endif()

if(EXECUTORCH_BUILD_VULKAN)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/vulkan)
endif()
if(EXECUTORCH_BUILD_VGF)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
endif()


if(EXECUTORCH_BUILD_ANDROID_JNI)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extension/android)
endif()
Expand Down
21 changes: 0 additions & 21 deletions backends/vulkan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -122,27 +122,6 @@ executorch_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}/")

set(VGF_BACKEND )
if(EXECUTORCH_BUILD_VGF)
set(VGF_BACKEND vgf_backend)
endif()

add_executable(vulkan_executor_runner ${VULKAN_RUNNER_SRCS})
target_link_libraries(
vulkan_executor_runner ${_executor_runner_libs} vulkan_schema
vulkan_backend
${VGF_BACKEND}
)

target_compile_options(vulkan_executor_runner PUBLIC ${VULKAN_CXX_FLAGS})
endif()

# Test targets

install(
Expand Down
20 changes: 18 additions & 2 deletions docs/source/kernel-library-selective-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,25 @@ The basic flow looks like this:
3. A _kernel resolver _takes in the linked kernel libraries as well as the merged op info yaml file, then makes a decision on which kernels to be registered into ExecuTorch runtime.


## Selective Build CMake Options

To enable selective build when building the executorch kernel libraries as part of a CMake build, the following CMake options are exposed. These options affect the `executorch_kernels` CMake target. Make sure to link this target when using selective build.

* `EXECUTORCH_SELECT_OPS_YAML`: A path to a YAML file specifying the operators to include.
* `EXECUTORCH_SELECT_OPS_LIST`: A string containing the operators to include.
* `EXECUTORCH_SELECT_OPS_MODEL`: A path to a PTE file. Only operators used in this model will be included.
* `EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD`: If enabled, operators will be further specialized to only operator on the data types specified in the operator selection.

Note that `EXECUTORCH_SELECT_OPS_YAML`, `EXECUTORCH_SELECT_OPS_LIST`, and `EXECUTORCH_SELECT_OPS_MODEL` are mutually exclusive. Only one operator specifier directive is allowed.

As an example, to build with only operators used in mv2_xnnpack_fp32.pte, the CMake build can be configured as follows.
```
cmake .. -DEXECUTORCH_SELECT_OPS_MODEL=mv2_xnnpack_fp32.pte
```

## APIs

We expose a CMake macro [gen_selected_ops](https://github.com/pytorch/executorch/blob/main/tools/cmake/Codegen.cmake#L12), to allow users specifying op info:
For fine-grained control, we expose a CMake macro [gen_selected_ops](https://github.com/pytorch/executorch/blob/main/tools/cmake/Codegen.cmake#L12) to allow users to specify op info:

```
gen_selected_ops(
Expand Down Expand Up @@ -75,7 +91,7 @@ Beyond pruning the binary to remove unused operators, the binary size can furthe

## Example Walkthrough

In [CMakeLists.txt](https://github.com/BujSet/executorch/blob/main/examples/selective_build/CMakeLists.txt#L48-L72), we have the following cmake config options:
In [examples/selective_build/CMakeLists.txt](https://github.com/BujSet/executorch/blob/main/examples/selective_build/CMakeLists.txt#L48-L72), we have the following cmake config options:

1. `EXECUTORCH_SELECT_OPS_YAML`
2. `EXECUTORCH_SELECT_OPS_LIST`
Expand Down
11 changes: 11 additions & 0 deletions docs/source/using-executorch-building-from-source.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ I 00:00:00.000764 executorch:executor_runner.cpp:180] Model executed successfull
I 00:00:00.000770 executorch:executor_runner.cpp:184] 1 outputs:
Output 0: tensor(sizes=[1], [2.])
```

### CMake Targets

To link against the ExecuTorch framework from CMake, the following top-level targets are exposed:

* `executorch::backends`: Contains all configured backends.
* `executorch::extensions`: Contains all configured extensions.
* `executorch::kernels`: Contains all configured kernel libraries.

The backends, extensions, and kernels included in these targets are controlled by the various `EXECUTORCH_` CMake options specified by the build.

## Build ExecuTorch for Windows

This document outlines the current known working build instructions for building and validating ExecuTorch on a Windows machine.
Expand Down
9 changes: 4 additions & 5 deletions docs/source/using-executorch-cpp.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Running a model using the low-level runtime APIs allows for a high-degree of con

## Building with CMake

ExecuTorch uses CMake as the primary build system. Inclusion of the module and tensor APIs are controlled by the `EXECUTORCH_BUILD_EXTENSION_MODULE` and `EXECUTORCH_BUILD_EXTENSION_TENSOR` CMake options. As these APIs may not be supported on embedded systems, they are disabled by default when building from source. The low-level API surface is always included. To link, add the `executorch` target as a CMake dependency, along with `extension_module_static` and `extension_tensor`, if desired.
ExecuTorch uses CMake as the primary build system. Inclusion of the module and tensor APIs are controlled by the `EXECUTORCH_BUILD_EXTENSION_MODULE` and `EXECUTORCH_BUILD_EXTENSION_TENSOR` CMake options. As these APIs may not be supported on embedded systems, they are disabled by default when building from source. The low-level API surface is always included. To link, add the `executorch` target as a CMake dependency, along with `executorch_backends`, `executorch_extensions`, and `extension_kernels`, to link all configured backends, extensions, and kernels.

```
# CMakeLists.txt
Expand All @@ -49,10 +49,9 @@ add_subdirectory("executorch")
target_link_libraries(
my_target
PRIVATE executorch
extension_module_static
extension_tensor
optimized_native_cpu_ops_lib
xnnpack_backend)
executorch::backends
executorch::extensions
executorch::kernels)
```

See [Building from Source](using-executorch-building-from-source.md) for more information on the CMake build process.
Expand Down
Loading
Loading