Skip to content

Commit 7a931b2

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Setup CI to run tests on Simulator. (#839)
Summary: Pull Request resolved: #839 Preliminary CI rule, waiting for all the changes to get in before landing Reviewed By: huydhn Differential Revision: D50181786 fbshipit-source-id: 55785bb346dd71e08d6af27ac6e46b4a1794a213
1 parent d84b5fb commit 7a931b2

File tree

6 files changed

+201
-73
lines changed

6 files changed

+201
-73
lines changed

.github/workflows/pull.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,29 @@ jobs:
114114
# Test selective build
115115
PYTHON_EXECUTABLE=python bash examples/selective_build/test_selective_build.sh "${BUILD_TOOL}"
116116
117+
test-demo-ios:
118+
name: test-demo-ios
119+
uses: pytorch/test-infra/.github/workflows/macos_job.yml@main
120+
strategy:
121+
matrix:
122+
include:
123+
- build-tool: cmake
124+
fail-fast: false
125+
with:
126+
runner: macos-latest-xlarge
127+
submodules: 'true'
128+
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
129+
timeout: 60
130+
script: |
131+
WORKSPACE=$(pwd)
132+
pushd "${WORKSPACE}/pytorch/executorch"
133+
BUILD_TOOL=${{ matrix.build-tool }}
134+
# Setup MacOS dependencies as there is no Docker support on MacOS atm
135+
PYTHON_EXECUTABLE=python bash .ci/scripts/setup-macos.sh "${BUILD_TOOL}"
136+
# Build and test iOS Demo App
137+
PYTHON_EXECUTABLE=python sh build/test_ios_ci.sh
138+
popd
139+
117140
unittest:
118141
uses: ./.github/workflows/_unittest.yml
119142
with:

build/build_apple_frameworks.sh

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ MODE="Debug"
1515
TOOLCHAIN=""
1616
BUCK2="/tmp/buck2"
1717
PYTHON=$(which python3)
18+
FLATC=""
1819
IOS_DEPLOYMENT_TARGET="17.0"
1920
COREML=OFF
2021
MPS=OFF
@@ -37,6 +38,7 @@ usage() {
3738
echo " --toolchain=FILE Cmake toolchain file. Default: '\$SOURCE_ROOT_DIR/third-party/pytorch/cmake/iOS.cmake'"
3839
echo " --buck2=FILE Buck2 executable path. Default: '/tmp/buck2'"
3940
echo " --python=FILE Python executable path. Default: Path of python3 found in the current \$PATH"
41+
echo " --flatc=FILE FlatBuffers Compiler executable path. Default: '\$SOURCE_ROOT_DIR/third-party/flatbuffers/cmake-out/flatc'"
4042
echo " --coreml Include this flag to build Core ML backend."
4143
echo " --mps Include this flag to build Metal Performance Shaders backend."
4244
echo " --xnnpack Include this flag to build XNNPACK backend."
@@ -54,6 +56,7 @@ for arg in "$@"; do
5456
--toolchain=*) TOOLCHAIN="${arg#*=}" ;;
5557
--buck2=*) BUCK2="${arg#*=}" ;;
5658
--python=*) PYTHON="${arg#*=}" ;;
59+
--flatc=*) FLATC="${arg#*=}" ;;
5760
--ios-deployment-target=*) IOS_DEPLOYMENT_TARGET="${arg#*=}" ;;
5861
--coreml) COREML=ON ;;
5962
--mps) MPS=ON ;;
@@ -78,6 +81,10 @@ if [[ -z "$TOOLCHAIN" ]]; then
7881
fi
7982
[[ -f "$TOOLCHAIN" ]] || { echo >&2 "Toolchain file $TOOLCHAIN does not exist."; exit 1; }
8083

84+
if [[ -z "$FLATC" ]]; then
85+
FLATC="$SOURCE_ROOT_DIR/third-party/flatbuffers/cmake-out/flatc"
86+
fi
87+
8188
check_command() {
8289
command -v "$1" >/dev/null 2>&1 || { echo >&2 "$1 is not installed"; exit 1; }
8390
}
@@ -86,13 +93,10 @@ check_command cmake
8693
check_command rsync
8794
check_command "$BUCK2"
8895
check_command "$PYTHON"
96+
check_command "$FLATC"
8997

9098
echo "Building libraries"
9199

92-
if [[ -z "$SOURCE_ROOT_DIR" ]]; then
93-
SOURCE_ROOT_DIR=$(pwd)
94-
fi
95-
96100
rm -rf "$OUTPUT" && mkdir -p "$OUTPUT" && cd "$OUTPUT" || exit 1
97101

98102
cmake_build() {
@@ -102,9 +106,11 @@ cmake_build() {
102106
mkdir "$platform" && cd "$platform" || exit 1
103107
cmake "$SOURCE_ROOT_DIR" -G Xcode \
104108
-DCMAKE_TOOLCHAIN_FILE="$TOOLCHAIN" \
109+
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LANGUAGE_STANDARD="c++17" \
110+
-DCMAKE_XCODE_ATTRIBUTE_CLANG_CXX_LIBRARY="libc++" \
105111
-DBUCK2="$BUCK2" \
106112
-DPYTHON_EXECUTABLE="$PYTHON" \
107-
-DFLATC_EXECUTABLE="$SOURCE_ROOT_DIR/third-party/flatbuffers/cmake-out/flatc" \
113+
-DFLATC_EXECUTABLE="$FLATC" \
108114
-DEXECUTORCH_BUILD_EXTENSION_DATA_LOADER=ON \
109115
-DCMAKE_ARCHIVE_OUTPUT_DIRECTORY="$(pwd)" \
110116
-DIOS_DEPLOYMENT_TARGET="$IOS_DEPLOYMENT_TARGET" \

build/test_ios.sh

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,27 @@ set -e
1515

1616
OUTPUT="${1:-executorch}"
1717
EXIT_STATUS=0
18+
APP_PATH="examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo"
19+
MODEL_NAME="mv3"
20+
SIMULATOR_NAME="executorch"
1821

19-
report() {
20-
if [ $EXIT_STATUS -eq 0 ]; then
21-
say "SUCCEEDED"
22-
else
23-
say "FAILED"
24-
fi
25-
}
26-
27-
cleanup() {
28-
if xcrun simctl list | grep -q 'executorch'; then
22+
finish() {
23+
EXIT_STATUS=$?
24+
if xcrun simctl list | grep -q "$SIMULATOR_NAME"; then
2925
say "Deleting Simulator"
30-
xcrun simctl delete executorch
26+
xcrun simctl delete "$SIMULATOR_NAME"
3127
fi
32-
3328
if [ -d "$OUTPUT" ]; then
3429
popd > /dev/null
3530
say "Deleting Output Directory"
3631
rm -rf "$OUTPUT"
3732
fi
38-
}
39-
40-
finish() {
41-
EXIT_STATUS=$?
42-
cleanup
43-
report
33+
if [ $EXIT_STATUS -eq 0 ]; then
34+
say "SUCCEEDED"
35+
else
36+
say "FAILED"
37+
fi
38+
exit $EXIT_STATUS
4439
}
4540

4641
trap finish EXIT
@@ -86,31 +81,31 @@ say "Installing MPS Backend Requirements"
8681

8782
say "Exporting Models"
8883

89-
python3 -m examples.portable.scripts.export --model_name="mv3"
90-
python3 -m examples.apple.coreml.scripts.export_and_delegate --model_name="mv3"
91-
python3 -m examples.apple.mps.scripts.mps_example --model_name="mv3"
92-
python3 -m examples.xnnpack.aot_compiler --model_name="mv3" --delegate
84+
python3 -m examples.portable.scripts.export --model_name="$$MODEL_NAME"
85+
python3 -m examples.apple.coreml.scripts.export_and_delegate --model_name="$$MODEL_NAME"
86+
python3 -m examples.apple.mps.scripts.mps_example --model_name="$$MODEL_NAME"
87+
python3 -m examples.xnnpack.aot_compiler --model_name="$$MODEL_NAME" --delegate
9388

94-
mkdir -p examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
95-
mv mv3*.pte examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/
89+
mkdir -p "$APP_PATH/Resources/Models/MobileNet/"
90+
mv $MODEL_NAME*.pte "$APP_PATH/Resources/Models/MobileNet/"
9691

9792
say "Downloading Labels"
9893

9994
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \
100-
-o examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Resources/Models/MobileNet/imagenet_classes.txt
95+
-o "$APP_PATH/Resources/Models/MobileNet/imagenet_classes.txt"
10196

10297
say "Building Frameworks"
10398

10499
./build/build_apple_frameworks.sh --buck2="$(realpath .venv/bin/buck2)" --Release --coreml --mps --xnnpack
105-
mv cmake-out examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo/Frameworks
100+
mv cmake-out "$APP_PATH/Frameworks"
106101

107102
say "Creating Simulator"
108103

109-
xcrun simctl create executorch "iPhone 15"
104+
xcrun simctl create "$SIMULATOR_NAME" "iPhone 15"
110105

111106
say "Running Tests"
112107

113-
xcodebuild clean test \
114-
-project examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo.xcodeproj \
115-
-scheme App \
116-
-destination name=executorch
108+
xcodebuild test \
109+
-project "$APP_PATH.xcodeproj" \
110+
-scheme MobileNetClassifierTest \
111+
-destination name="$SIMULATOR_NAME"

build/test_ios_ci.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
set -e
9+
10+
APP_PATH="examples/demo-apps/apple_ios/ExecuTorchDemo/ExecuTorchDemo"
11+
MODEL_NAME="mv3"
12+
SIMULATOR_NAME="executorch"
13+
14+
finish() {
15+
EXIT_STATUS=$?
16+
if xcrun simctl list | grep -q "$SIMULATOR_NAME"; then
17+
say "Deleting Simulator"
18+
xcrun simctl delete "$SIMULATOR_NAME"
19+
fi
20+
if [ $EXIT_STATUS -eq 0 ]; then
21+
say "SUCCEEDED"
22+
else
23+
say "FAILED"
24+
fi
25+
exit $EXIT_STATUS
26+
}
27+
28+
trap finish EXIT
29+
30+
say() {
31+
echo -e "\033[1m\n\t** $1 **\n\033[0m"
32+
}
33+
34+
say "Installing Requirements"
35+
36+
./install_requirements.sh
37+
38+
say "Exporting Models"
39+
40+
python3 -m examples.portable.scripts.export --model_name="$MODEL_NAME"
41+
python3 -m examples.xnnpack.aot_compiler --model_name="$MODEL_NAME" --delegate
42+
43+
mkdir -p "$APP_PATH/Resources/Models/MobileNet/"
44+
mv $MODEL_NAME*.pte "$APP_PATH/Resources/Models/MobileNet/"
45+
46+
say "Downloading Labels"
47+
48+
curl https://raw.githubusercontent.com/pytorch/hub/master/imagenet_classes.txt \
49+
-o "$APP_PATH/Resources/Models/MobileNet/imagenet_classes.txt"
50+
51+
say "Building Frameworks"
52+
53+
./build/build_apple_frameworks.sh --buck2="$(which buck2)" --flatc="$(which flatc)" --xnnpack
54+
mv cmake-out "$APP_PATH/Frameworks"
55+
56+
say "Creating Simulator"
57+
58+
xcrun simctl create "$SIMULATOR_NAME" "iPhone 14"
59+
60+
say "Running Tests"
61+
62+
xcodebuild test \
63+
-project "$APP_PATH.xcodeproj" \
64+
-scheme MobileNetClassifierTest \
65+
-destination name="$SIMULATOR_NAME" \
66+
-skip-testing:MobileNetClassifierTest/MobileNetClassifierTest/testV3WithCoreMLBackend \
67+
-skip-testing:MobileNetClassifierTest/MobileNetClassifierTest/testV3WithMPSBackend

0 commit comments

Comments
 (0)