From 6cd712243bcdeba7abadf31489c979f3ccb03b0b Mon Sep 17 00:00:00 2001 From: Olivia Liu Date: Wed, 1 May 2024 14:15:20 -0700 Subject: [PATCH] Simplify SDK tutorial by moving cmake commands to a script (#3438) Summary: As titled. Tested the commands on mac locally and they worked. Pull Request resolved: https://github.com/pytorch/executorch/pull/3438 Reviewed By: Jack-Khuu Differential Revision: D56792240 Pulled By: Olivia-liu fbshipit-source-id: dd62ea2fc788c5e1867d1e50037d7b4fd7e3a3f9 (cherry picked from commit a4ffd96a5093fb14c91a47d23703beb98d0fbfb9) --- .../sdk-integration-tutorial.py | 6 +-- examples/sdk/build_sdk_example_runner.sh | 50 +++++++++++++++++++ 2 files changed, 52 insertions(+), 4 deletions(-) create mode 100755 examples/sdk/build_sdk_example_runner.sh diff --git a/docs/source/tutorials_source/sdk-integration-tutorial.py b/docs/source/tutorials_source/sdk-integration-tutorial.py index 27474c2251e..ccc2e480ad0 100644 --- a/docs/source/tutorials_source/sdk-integration-tutorial.py +++ b/docs/source/tutorials_source/sdk-integration-tutorial.py @@ -172,10 +172,8 @@ def forward(self, x): # Use CMake (follow `these instructions <../runtime-build-and-cross-compilation.html#configure-the-cmake-build>`__ to set up cmake) to execute the Bundled Program to generate the ``ETDump``:: # # cd executorch -# rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake -DEXECUTORCH_BUILD_SDK=1 -DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=1 .. -# cd .. -# cmake --build cmake-out -j8 -t sdk_example_runner -# ./cmake-out/examples/sdk/sdk_example_runner --bundled_program_path +# ./examples/sdk/build_sdk_example_runner.sh +# cmake-out/examples/sdk/sdk_example_runner --bundled_program_path="bundled_program.bp" ###################################################################### # Creating an Inspector diff --git a/examples/sdk/build_sdk_example_runner.sh b/examples/sdk/build_sdk_example_runner.sh new file mode 100755 index 00000000000..291febb36db --- /dev/null +++ b/examples/sdk/build_sdk_example_runner.sh @@ -0,0 +1,50 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the BSD-style license found in the +# LICENSE file in the root directory of this source tree. + +# Builds sdk_example_runner and prints its path. + +set -euo pipefail + +SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +readonly SCRIPT_DIR + +readonly EXECUTORCH_ROOT="${SCRIPT_DIR}/../.." + +# Allow overriding the number of build jobs. Default to 9. +export CMAKE_BUILD_PARALLEL_LEVEL="${CMAKE_BUILD_PARALLEL_LEVEL:-9}" + +main() { + cd "${EXECUTORCH_ROOT}" + + rm -rf cmake-out + cmake -DCMAKE_INSTALL_PREFIX=cmake-out \ + -DCMAKE_BUILD_TYPE=Release \ + -DEXECUTORCH_BUILD_SDK=ON \ + -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \ + -Bcmake-out . + cmake --build cmake-out --target install --config Release + + local example_dir=examples/sdk + local build_dir="cmake-out/${example_dir}" + local cmake_prefix_path="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags" + rm -rf ${build_dir} + cmake -DCMAKE_PREFIX_PATH="${cmake_prefix_path}" \ + -DCMAKE_BUILD_TYPE=Release \ + -B"${build_dir}" \ + "${example_dir}" + cmake --build "${build_dir}" --config Release + + local runner="${PWD}/${build_dir}/sdk_example_runner" + if [[ ! -f "${runner}" ]]; then + echo "ERROR: Failed to build ${build_dir}/sdk_example_runner" >&2 + exit 1 + else + echo "Built ${build_dir}/sdk_example_runner" + fi +} + +main "$@"