Skip to content

Commit

Permalink
Simplify SDK tutorial by moving cmake commands to a script (#3438)
Browse files Browse the repository at this point in the history
Summary:
As titled. Tested the commands on mac locally and they worked.

Pull Request resolved: #3438

Reviewed By: Jack-Khuu

Differential Revision: D56792240

Pulled By: Olivia-liu

fbshipit-source-id: dd62ea2fc788c5e1867d1e50037d7b4fd7e3a3f9
(cherry picked from commit a4ffd96)
  • Loading branch information
Olivia-liu authored and pytorchbot committed May 2, 2024
1 parent 6a1703e commit 6cd7122
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
6 changes: 2 additions & 4 deletions docs/source/tutorials_source/sdk-integration-tutorial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <bundled_program>
# ./examples/sdk/build_sdk_example_runner.sh
# cmake-out/examples/sdk/sdk_example_runner --bundled_program_path="bundled_program.bp"

######################################################################
# Creating an Inspector
Expand Down
50 changes: 50 additions & 0 deletions examples/sdk/build_sdk_example_runner.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit 6cd7122

Please sign in to comment.