Skip to content

Update docs to use top-level CMake targets #12807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 47 commits into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions backends/vulkan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ GPU!

```shell
# Build a model runner binary linked with the Vulkan delegate libs
cmake --build cmake-android-out --target vulkan_executor_runner -j32
cmake --build cmake-android-out --target executor_runner -j32

# Push model to device
adb push vk_add.pte /data/local/tmp/vk_add.pte
# Push binary to device
adb push cmake-android-out/backends/vulkan/vulkan_executor_runner /data/local/tmp/runner_bin
adb push cmake-android-out/executor_runner /data/local/tmp/runner_bin

# Run the model
adb shell /data/local/tmp/runner_bin --model_path /data/local/tmp/vk_add.pte
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
24 changes: 14 additions & 10 deletions tools/cmake/preset/default.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -228,12 +228,14 @@ define_overridable_option(
define_overridable_option(
EXECUTORCH_SELECT_OPS_MODEL
"Build the executorch_kernels target with only operators from the given model .pte file."
STRING ""
STRING
""
)
define_overridable_option(
EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD
"Build the executorch_kernels target with only operator implementations for selected data types."
BOOL FALSE
BOOL
FALSE
)

# ------------------------------------------------------------------------------
Expand All @@ -248,8 +250,7 @@ check_required_options_on(

check_required_options_on(
IF_ON EXECUTORCH_BUILD_EXECUTOR_RUNNER REQUIRES
EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL
EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL
EXECUTORCH_BUILD_EXTENSION_EVALUE_UTIL EXECUTORCH_BUILD_EXTENSION_RUNNER_UTIL
)
check_required_options_on(
IF_ON EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR REQUIRES
Expand Down Expand Up @@ -295,26 +296,29 @@ check_required_options_on(
IF_ON EXECUTORCH_BUILD_TESTS REQUIRES EXECUTORCH_BUILD_EXTENSION_FLAT_TENSOR
)

check_required_options_on(
IF_ON EXECUTORCH_ENABLE_DTYPE_SELECTIVE_BUILD REQUIRES
EXECUTORCH_SELECT_OPS_MODEL
)

check_required_options_on(
IF_ON EXECUTORCH_BUILD_XNNPACK REQUIRES EXECUTORCH_BUILD_CPUINFO
EXECUTORCH_BUILD_PTHREADPOOL
)

check_conflicting_options_on(
IF_ON EXECUTORCH_BUILD_ARM_BAREMETAL CONFLICTS_WITH
EXECUTORCH_BUILD_PTHREADPOOL
EXECUTORCH_BUILD_CPUINFO
EXECUTORCH_BUILD_PTHREADPOOL 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
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_ON EXECUTORCH_SELECT_OPS_LIST CONFLICTS_WITH EXECUTORCH_SELECT_OPS_MODEL
)

if(NOT EXISTS ${EXECUTORCH_PAL_DEFAULT_FILE_PATH})
Expand Down
Loading