xref: /aosp_15_r20/external/executorch/examples/devtools/test_example_runner.sh (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1#!/bin/bash
2# Copyright (c) Meta Platforms, Inc. and affiliates.
3# All rights reserved.
4#
5# This source code is licensed under the BSD-style license found in the
6# LICENSE file in the root directory of this source tree.
7
8# Test the end-to-end flow of building devtools/example_runner and use it to run
9# an actual model.
10
11
12set -e
13
14# shellcheck source=/dev/null
15source "$(dirname "${BASH_SOURCE[0]}")/../../.ci/scripts/utils.sh"
16
17cmake_install_executorch_devtools_lib() {
18  echo "Installing libexecutorch.a, libportable_kernels.a, libetdump.a, libbundled_program.a"
19  rm -rf cmake-out
20
21  retry cmake -DCMAKE_INSTALL_PREFIX=cmake-out \
22          -DCMAKE_BUILD_TYPE=Release \
23          -DEXECUTORCH_BUILD_DEVTOOLS=ON \
24          -DEXECUTORCH_ENABLE_EVENT_TRACER=ON \
25          -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
26          -Bcmake-out .
27  cmake --build cmake-out -j9 --target install --config Release
28}
29
30test_cmake_devtools_example_runner() {
31  echo "Exporting MobilenetV2"
32  ${PYTHON_EXECUTABLE} -m examples.devtools.scripts.export_bundled_program --model_name="mv2"
33  local example_dir=examples/devtools
34  local build_dir=cmake-out/${example_dir}
35  CMAKE_PREFIX_PATH="${PWD}/cmake-out/lib/cmake/ExecuTorch;${PWD}/cmake-out/third-party/gflags"
36  rm -rf ${build_dir}
37  retry cmake \
38        -DCMAKE_PREFIX_PATH="$CMAKE_PREFIX_PATH" \
39        -DCMAKE_BUILD_TYPE=Release \
40        -DPYTHON_EXECUTABLE="$PYTHON_EXECUTABLE" \
41        -B${build_dir} \
42        ${example_dir}
43
44  echo "Building ${example_dir}"
45  cmake --build ${build_dir} -j9 --config Release
46
47  echo 'Running example_runner'
48  ${build_dir}/example_runner --bundled_program_path="./mv2_bundled.bpte"
49}
50
51if [[ -z $PYTHON_EXECUTABLE ]];
52then
53  PYTHON_EXECUTABLE=python3
54fi
55
56if [[ -z $BUCK ]];
57then
58  BUCK=buck2
59fi
60
61cmake_install_executorch_devtools_lib
62test_cmake_devtools_example_runner
63