diff --git a/backends/vulkan/README.md b/backends/vulkan/README.md index 3ae80950645..e0a953d05fe 100644 --- a/backends/vulkan/README.md +++ b/backends/vulkan/README.md @@ -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 diff --git a/docs/source/kernel-library-selective-build.md b/docs/source/kernel-library-selective-build.md index 3e9400f4d6a..7d6495656a2 100644 --- a/docs/source/kernel-library-selective-build.md +++ b/docs/source/kernel-library-selective-build.md @@ -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( @@ -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` diff --git a/docs/source/using-executorch-building-from-source.md b/docs/source/using-executorch-building-from-source.md index 8f9eb40ce5b..973e9c5f55b 100644 --- a/docs/source/using-executorch-building-from-source.md +++ b/docs/source/using-executorch-building-from-source.md @@ -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. diff --git a/docs/source/using-executorch-cpp.md b/docs/source/using-executorch-cpp.md index d64dad97da9..b1227aec7b3 100644 --- a/docs/source/using-executorch-cpp.md +++ b/docs/source/using-executorch-cpp.md @@ -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 @@ -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. diff --git a/tools/cmake/preset/default.cmake b/tools/cmake/preset/default.cmake index 09e9e2ffe6e..937ec690138 100644 --- a/tools/cmake/preset/default.cmake +++ b/tools/cmake/preset/default.cmake @@ -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 ) # ------------------------------------------------------------------------------ @@ -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 @@ -295,6 +296,11 @@ 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 @@ -302,19 +308,17 @@ check_required_options_on( 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})