xref: /aosp_15_r20/external/executorch/examples/apple/mps/scripts/build_mps_executor_runner.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/usr/bin/env bash
2#  Copyright (c) 2024 Apple Inc. All rights reserved.
3#  Provided subject to the LICENSE file in the top level directory.
4
5set -e
6
7MODE="Release"
8OUTPUT="cmake-out"
9
10usage() {
11  echo "Usage: $0 [OPTIONS]"
12  echo "Build frameworks for Apple platforms."
13  echo "SOURCE_ROOT_DIR defaults to the current directory if not provided."
14  echo
15  echo "Options:"
16  echo "  --output=DIR         Output directory. Default: 'cmake-out'"
17  echo "  --Debug              Use Debug build mode. Default: 'Release'"
18  echo "Example:"
19  echo "  $0 --output=cmake-out --Debug"
20  exit 0
21}
22
23for arg in "$@"; do
24  case $arg in
25      -h|--help) usage ;;
26      --output=*) OUTPUT="${arg#*=}" ;;
27      --Debug) MODE="Debug" ;;
28      *)
29      if [[ -z "$SOURCE_ROOT_DIR" ]]; then
30          SOURCE_ROOT_DIR="$arg"
31      else
32          echo "Invalid argument: $arg"
33          exit 1
34      fi
35      ;;
36  esac
37done
38
39rm -rf "$OUTPUT"
40
41cmake -DBUCK2="$BUCK" \
42          -DCMAKE_INSTALL_PREFIX=cmake-out \
43          -DCMAKE_BUILD_TYPE="$MODE" \
44          -DEXECUTORCH_BUILD_DEVTOOLS=ON \
45          -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
46          -DEXECUTORCH_BUILD_MPS=ON \
47          -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
48          -Bcmake-out .
49cmake --build cmake-out -j9 --target install --config "$MODE"
50CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
51# build mps_executor_runner
52rm -rf cmake-out/examples/apple/mps
53cmake \
54    -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
55    -DCMAKE_BUILD_TYPE="$MODE" \
56    -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
57    -Bcmake-out/examples/apple/mps \
58    examples/apple/mps
59
60cmake --build cmake-out/examples/apple/mps -j9 --config "$MODE"
61
62echo "Build succeeded!"
63
64./cmake-out/examples/apple/mps/mps_executor_runner --model_path mps_logical_not.pte --bundled_program
65