Skip to content

Commit 9a23cff

Browse files
authored
Arm backend: Test TOSA, Ethos-U55 and Ethos-U85 on github (#6888)
This will run some more models in the github test flow and also enable some unit tests to use Corston3x0 FVP. Signed-off-by: Zingo Andersen <[email protected]>
1 parent 2e24b4e commit 9a23cff

File tree

9 files changed

+181
-25
lines changed

9 files changed

+181
-25
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Copyright 2024 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
# NB: This function could be used to install Arm dependencies
8+
# Setup arm example environment (including TOSA tools)
9+
git config --global user.email "[email protected]"
10+
git config --global user.name "Github Executorch"
11+
bash examples/arm/setup.sh --i-agree-to-the-contained-eula

.ci/scripts/utils.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,6 @@ install_flatc_from_source() {
5959
popd || return
6060
}
6161

62-
install_arm() {
63-
# NB: This function could be used to install Arm dependencies
64-
# Setup arm example environment (including TOSA tools)
65-
git config --global user.email "[email protected]"
66-
git config --global user.name "Github Executorch"
67-
bash examples/arm/setup.sh --i-agree-to-the-contained-eula
68-
69-
# Test tosa_reference flow
70-
source examples/arm/ethos-u-scratch/setup_path.sh
71-
}
72-
7362
build_executorch_runner_buck2() {
7463
# Build executorch runtime with retry as this step is flaky on macos CI
7564
retry buck2 build //examples/portable/executor_runner:executor_runner

.github/workflows/pull.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,11 @@ jobs:
354354
EXECUTORCH_BUILD_ARM_BAREMETAL=ON \
355355
.ci/scripts/setup-linux.sh "${BUILD_TOOL}"
356356
357-
source .ci/scripts/utils.sh
358357
# Install Arm dependencies
359-
install_arm
360-
361-
# Run pytest with coverage
362-
pytest -c /dev/null -v -n auto --cov=./ --cov-report=xml backends/arm/test
358+
.ci/scripts/setup-arm-baremetal-tools.sh
363359
360+
# Run pytest without simulator
361+
backends/arm/test/test_arm_baremetal.sh test_pytest
364362
365363
test-llama-runner-qnn-linux:
366364
name: test-llama-runner-qnn-linux

.github/workflows/trunk.yml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,15 @@ jobs:
146146
source .ci/scripts/utils.sh
147147
install_executorch
148148
149-
install_arm
149+
.ci/scripts/setup-arm-baremetal-tools.sh
150150
151151
# Increase number of files user can monitor to bypass buck failures.
152152
# Hopefully this is high enough for this setup.
153153
sudo sysctl fs.inotify.max_user_watches=1048576 # 1024 * 1024
154154
155155
# Test ethos-u delegate examples with run.sh
156-
PYTHON_EXECUTABLE=python bash examples/arm/run.sh examples/arm/ethos-u-scratch/
156+
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
157+
157158
158159
test-arm-reference-delegation:
159160
name: test-arm-reference-delegation
@@ -172,10 +173,10 @@ jobs:
172173
source .ci/scripts/utils.sh
173174
install_executorch
174175
175-
install_arm
176+
.ci/scripts/setup-arm-baremetal-tools.sh
176177
177-
# Run arm unit tests
178-
pytest -c /dev/null -v -n auto --cov=./ --cov-report=xml backends/arm/test
178+
# Run arm unit tests using the simulator
179+
backends/arm/test/test_arm_baremetal.sh test_pytest_ethosu_fvp
179180
180181
test-coreml-delegate:
181182
name: test-coreml-delegate

backends/arm/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@ Other:
3939
- `third-party/` - Dependencies on other code - in particular the TOSA serialization_lib for compiling to TOSA and the ethos-u-core-driver for the bare-metal backend supporting Ethos-U
4040
- `test/` - Unit test and test support functions
4141

42+
## Testing
43+
44+
After a setup you can run unit tests with the test_arm_baremetal.sh script.
45+
46+
To run the pytests suite run
47+
48+
```
49+
backends/arm/test/test_arm_baremetal.sh test_pytest
50+
```
51+
52+
To run the unit test suite with Corstone3x0 FVP simulator support use
53+
54+
```
55+
backends/arm/test/test_arm_baremetal.sh test_pytest_ethosu_fvp
56+
```
57+
58+
You can test to run some models with the run.sh flow
59+
60+
```
61+
backends/arm/test/test_arm_baremetal.sh test_run_ethosu_fvp
62+
```
63+
4264
## Unit tests
4365
This is the structure of the test directory
4466

@@ -51,6 +73,8 @@ test # Root test folder
5173
├── tester # Arm Tester class
5274
├── tosautil # Utility functions for TOSA artifacts
5375
├ common.py # Common functions and definitions used by many tests
76+
├ setup_testing.sh # Script to prepare testing for using the Corstone 3x0 FVP
77+
├ test_arm_baremetal.sh # Help script to trigger testing
5478
```
5579

5680
Some example commands to run these tests follow. Run a single test:
@@ -59,6 +83,12 @@ Some example commands to run these tests follow. Run a single test:
5983
python -m unittest backends.arm.test.ops.test_add.TestSimpleAdd -k test_add2_tosa_BI
6084
```
6185

86+
or with pytest
87+
88+
```
89+
pytest -c /dev/null -v -n auto backends/arm/test/ops/test_add.py -k test_add2_tosa_BI
90+
```
91+
6292
Or all tests in "TestSimpleAdd":
6393

6494
```
@@ -71,6 +101,28 @@ Or discover and run many tests:
71101
python -m unittest discover -s backends/arm/test/ops/
72102
```
73103

104+
or with pytest
105+
106+
```
107+
pytest -c /dev/null -v -n auto backends/arm/test/ops/
108+
```
109+
110+
111+
You can run tests using Corstone3x0 simulators to see how it would work on something more target like
112+
first you need to build and prepare some used target libs
113+
114+
```
115+
examples/arm/run.sh --model_name=add --build_only
116+
backends/arm/test/setup_testing.sh
117+
```
118+
119+
The you can run the tests with
120+
121+
```
122+
pytest -c /dev/null -v -n auto backends/arm/test --arm_quantize_io --arm_run_corstoneFVP
123+
```
124+
125+
74126
### A note on unit tests
75127

76128
There are currently 3 ways we unit test our code.

backends/arm/test/runner_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def __init__(
178178
self.output_name: str = None
179179
self.qp_input: list[QuantizationParams] = None
180180
self.qp_output: QuantizationParams = None
181-
self.timeout = 120
181+
self.timeout = 480
182182
self.target_board: str = None
183183

184184
self._has_init_run = False
@@ -316,7 +316,7 @@ def run_corstone(
316316
result = _run_cmd(command_args[self.target_board], check=False)
317317
if result.returncode != 0:
318318
raise RuntimeError(
319-
f"Failed to run {command_args[self.target_board]}\nError: {result.stderr.decode()}"
319+
f"Failed to run {command_args[self.target_board]}\nOutput:\n{result.stdout.decode()}\nError: {result.stderr.decode()}"
320320
)
321321
result_stdout = result.stdout.decode()
322322

backends/arm/test/setup_testing.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ ethos_u_root_dir=${et_root_dir}/examples/arm/ethos-u-scratch/ethos-u
1414
toolchain_cmake=${et_root_dir}/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
1515
et_build_dir=${et_root_dir}/cmake-out
1616
build_root_test_dir=${et_build_dir}/arm_semihosting_executor_runner
17-
fvp_model=FVP_Corstone_SSE-300_Ethos-U55
1817

1918
# Build Arm Baremetal executor_runner in semihosting mode.
2019
# Put in backends/arm/test/res to be used by unit tests.
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/bash
2+
# Copyright 2024 Arm Limited and/or its affiliates.
3+
#
4+
# This source code is licensed under the BSD-style license found in the
5+
# LICENSE file in the root directory of this source tree.
6+
7+
set -e
8+
9+
script_dir=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
10+
11+
# Executorch root
12+
et_root_dir=$(cd ${script_dir}/../../.. && pwd)
13+
cd "${et_root_dir}"
14+
pwd
15+
16+
17+
TEST_SUITE=$1
18+
19+
help() {
20+
echo "Usage:"
21+
echo " $0 <TESTNAME>"
22+
echo " where <TESTNAME> can be any of:"
23+
# This will list all lines in this file that is starting with test_ remove () { and print it as a list.
24+
# e,g, "test_pytest() { # Test ops and other things" -> test_pytest # Test ops and other things
25+
echo "all # run all tests"
26+
grep "^test_" $0 | sed 's/([^)]*)[[:space:]]*{*//g'
27+
exit
28+
}
29+
30+
if [[ -z "${TEST_SUITE:-}" ]]; then
31+
echo "Missing test suite name, exiting..."
32+
help
33+
else
34+
echo "Run Arm baremetal test suite ${TEST_SUITE}"
35+
fi
36+
37+
TEST_SUITE_NAME="$(basename "$0") ${TEST_SUITE}"
38+
39+
all() { # Run all tests
40+
# This will list all lines in this file that is starting with test_ remove () { and add this script name in
41+
# front of it and execute it in a sub shell
42+
# e.g. from this file:
43+
#
44+
# test_pytest() { # Test ops and other things
45+
# bla bla bla
46+
# }
47+
# test_pytest_ethosu_fvp() { # Same as test_pytest but ...
48+
# bla bla bla
49+
# }
50+
#...
51+
# become a small script:
52+
# ----
53+
# backends/arm/test/test_arm_baremetal.sh test_pytest # Test ops and other things
54+
# backends/arm/test/test_arm_baremetal.sh test_pytest_ethosu_fvp # Same as test_pytest but ...
55+
# ...
56+
# ----
57+
# That is executed
58+
echo "${TEST_SUITE_NAME}: Run all tests"
59+
grep "^test_" backends/arm/test/test_arm_baremetal.sh | sed 's/([^)]*)[[:space:]]*{*//g' | sed "s|^|$0 |" | sh
60+
}
61+
62+
test_pytest() { # Test ops and other things
63+
echo "${TEST_SUITE_NAME}: Run pytest"
64+
cd "${et_root_dir}"
65+
source examples/arm/ethos-u-scratch/setup_path.sh
66+
67+
# Run arm baremetal pytest tests without FVP
68+
pytest --verbose --color=yes --numprocesses=auto backends/arm/test/
69+
}
70+
71+
test_pytest_ethosu_fvp() { # Same as test_pytest but also sometime verify using Corstone FVP
72+
echo "${TEST_SUITE_NAME}: Run pytest with fvp"
73+
74+
source examples/arm/ethos-u-scratch/setup_path.sh
75+
76+
# Prepare Corstone-3x0 FVP for pytest
77+
examples/arm/run.sh --model_name=add --build_only
78+
backends/arm/test/setup_testing.sh
79+
80+
# Run arm baremetal pytest tests with FVP
81+
pytest --verbose --color=yes --numprocesses=auto backends/arm/test/ --arm_quantize_io --arm_run_corstoneFVP
82+
}
83+
84+
test_run_ethosu_fvp() { # End to End model tests
85+
echo "${TEST_SUITE_NAME}: Test ethos-u delegate examples with run.sh"
86+
87+
source examples/arm/ethos-u-scratch/setup_path.sh
88+
89+
# TOSA quantized
90+
echo "${TEST_SUITE_NAME}: Test ethos-u target TOSA"
91+
examples/arm/run.sh --target=TOSA --model_name=mv2
92+
examples/arm/run.sh --target=TOSA --model_name=lstm
93+
examples/arm/run.sh --target=TOSA --model_name=edsr
94+
95+
# Ethos-U55
96+
echo "${TEST_SUITE_NAME}: Test ethos-u target Ethos-U55"
97+
examples/arm/run.sh --target=ethos-u55-128 --model_name=mv2
98+
examples/arm/run.sh --target=ethos-u55-128 --model_name=lstm --reorder_inputs=1,0,2
99+
100+
# Ethos-U85
101+
echo "${TEST_SUITE_NAME}: Test ethos-u target Ethos-U85"
102+
examples/arm/run.sh --target=ethos-u85-128 --model_name=mv2
103+
examples/arm/run.sh --target=ethos-u85-128 --model_name=lstm --reorder_inputs=1,0,2
104+
}
105+
106+
${TEST_SUITE}

backends/arm/test/tester/arm_tester.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def to_executorch(self, to_executorch_stage: Optional[ToExecutorch] | None = Non
251251
return super().to_executorch(to_executorch_stage)
252252

253253
def serialize(
254-
self, serialize_stage: Optional[Serialize] = None, timeout: int = 120
254+
self, serialize_stage: Optional[Serialize] = None, timeout: int = 480
255255
):
256256
if serialize_stage is None:
257257
serialize_stage = Serialize(self.runner_util, timeout=timeout)

0 commit comments

Comments
 (0)