|
| 1 | +# Native runtime CMake targets |
| 2 | + |
| 3 | +Enable `EXECUTORCH_BUILD_NATIVE=ON` to build the shared native runtime, or |
| 4 | +`EXECUTORCH_BUILD_NATIVE_VULKAN=ON` to build it together with the Vulkan engine. |
| 5 | +Both options default to `OFF`. |
| 6 | + |
| 7 | +The native runtime requires C++20, a host `flatc`, the vendored FlatBuffers and |
| 8 | +nlohmann JSON headers, and an installed libzip package with the `libzip::zip` |
| 9 | +CMake target. Set `CMAKE_PREFIX_PATH` to the libzip installation if necessary. |
| 10 | +Native Vulkan also requires the Vulkan submodules and `glslc`, as described in |
| 11 | +the [Vulkan build instructions](../vulkan/README.md). |
| 12 | + |
| 13 | +From the ExecuTorch checkout: |
| 14 | + |
| 15 | +```sh |
| 16 | +cmake -S . -B cmake-out -DCMAKE_BUILD_TYPE=Release \ |
| 17 | + -DEXECUTORCH_BUILD_NATIVE_VULKAN=ON |
| 18 | +cmake --build cmake-out --target native_api native_vulkan_engine |
| 19 | +cmake --install cmake-out --prefix install |
| 20 | +``` |
| 21 | + |
| 22 | +## Shared targets |
| 23 | + |
| 24 | +| Target | Contents | |
| 25 | +| --- | --- | |
| 26 | +| `native_graph` | Graph IR, graph utilities, and memory planning | |
| 27 | +| `native_package` | PTN archive, safetensors, and owned byte readers | |
| 28 | +| `native_runtime` | Program deserialization, validation, and method metadata | |
| 29 | +| `native_engine` | Engine host, context, and executable interfaces | |
| 30 | +| `native_api` | Engine-independent `Model`, `Session`, and tensor API | |
| 31 | +| `native_vulkan_passes` | Native graph rewrites for Vulkan | |
| 32 | +| `native_vulkan_engine` | Vulkan host and executable implementation | |
| 33 | +| `vulkan_compute_api` | Vulkan device, allocator, and command API | |
| 34 | +| `vulkan_graph_runtime` | ComputeGraph, operator registrations, and shaders | |
| 35 | + |
| 36 | +The common native targets have no dependency on the ExecuTorch executor or a |
| 37 | +specific engine. New engines link `native_engine` and implement its interfaces. |
| 38 | +Applications link `native_api` and the engines they use. The Vulkan engine and |
| 39 | +the existing `vulkan_backend` delegate share `vulkan_graph_runtime`; its static |
| 40 | +operator and shader registrations are retained automatically when linking. |
| 41 | + |
| 42 | +All library targets are installed in `ExecuTorchTargets`. For example: |
| 43 | + |
| 44 | +```cmake |
| 45 | +find_package(executorch CONFIG REQUIRED) |
| 46 | +target_link_libraries(my_app PRIVATE native_api native_vulkan_engine) |
| 47 | +``` |
| 48 | + |
| 49 | +With `EXECUTORCH_BUILD_TESTS=ON`, `native_runtime_test` covers the shared runtime |
| 50 | +and API. `native_vulkan_passes_test` covers the Vulkan graph rewrites without |
| 51 | +requiring a GPU. When the vision runner below is enabled, |
| 52 | +`native_runner_utils_test` covers its shared runner utilities. Run these with |
| 53 | +`ctest --test-dir cmake-out -R native_`. |
| 54 | + |
| 55 | +## Vision classification runner |
| 56 | + |
| 57 | +Enable `EXECUTORCH_BUILD_NATIVE_VISION_RUNNER=ON` together with |
| 58 | +`EXECUTORCH_BUILD_NATIVE_VULKAN=ON` to build `run_classification` from |
| 59 | +`examples/vision`. The runner additionally requires gflags; an OSS build uses |
| 60 | +the vendored copy, and other builds resolve an installed gflags package. |
| 61 | +Running the runner requires a Vulkan device. |
| 62 | + |
| 63 | +```sh |
| 64 | +cmake -S . -B cmake-out -DCMAKE_BUILD_TYPE=Release \ |
| 65 | + -DEXECUTORCH_BUILD_NATIVE_VULKAN=ON \ |
| 66 | + -DEXECUTORCH_BUILD_NATIVE_VISION_RUNNER=ON |
| 67 | +cmake --build cmake-out --target run_classification |
| 68 | +cmake --install cmake-out --prefix install |
| 69 | +install/bin/run_classification \ |
| 70 | + --package mv2.ptn --input mv2_input.bin \ |
| 71 | + --expected mv2_expected.bin --categories categories.txt |
| 72 | +``` |
| 73 | + |
| 74 | +Export the `.ptn`, input, reference logits, and labels with |
| 75 | +[`export.py`](../../examples/native/vision/export.py). The runner prints the |
| 76 | +top-5 logits and, when `--expected` is given, exits nonzero if the logits |
| 77 | +differ from the reference beyond `--rtol`/`--atol` (both default to `1e-3`). |
0 commit comments