Skip to content

Commit e186bc9

Browse files
perfacebook-github-bot
authored andcommitted
Corstone-320 support (pytorch#5628)
Summary: Adds support for compiling for Corstone-320 FVP containing Ethos-U85. Follow up PR will add downloading and running of the FVP once it's available. Pull Request resolved: pytorch#5628 Reviewed By: digantdesai Differential Revision: D63637308 Pulled By: mergennachin fbshipit-source-id: 2d87575a46e0f6be0ccdafe4969215dab566b5ff
1 parent 418c4c3 commit e186bc9

File tree

6 files changed

+69
-17
lines changed

6 files changed

+69
-17
lines changed

backends/arm/test/runner_utils.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import json
77
import logging
88
import os
9+
import re
910
import shutil
1011
import subprocess
1112
import tempfile
@@ -229,7 +230,9 @@ def run_corstone300(
229230
os.path.join(self.intermediate_path, f"{name}.bin"),
230231
)
231232
elf_path = os.path.join(
232-
"cmake-out", "arm_semihosting_executor_runner", "arm_executor_runner"
233+
"cmake-out",
234+
"arm_semihosting_executor_runner_corstone-300",
235+
"arm_executor_runner",
233236
)
234237
assert os.path.exists(
235238
elf_path
@@ -266,7 +269,12 @@ def run_corstone300(
266269
]
267270
result = _run_cmd(command_args, check=False)
268271
result_stdout = result.stdout.decode()
269-
if "Hard fault" in result_stdout or len(result.stderr) > 0:
272+
273+
error_regex = r"(^[EF][: ].*$)|(^.*Hard fault.*$)|(^.*Assertion.*$)"
274+
275+
# Check for errors in the output
276+
# regex to check for error or fault messages in stdout from FVP
277+
if re.compile(error_regex, re.MULTILINE).search(result_stdout):
270278
raise RuntimeError(
271279
f"Corstone simulation failed, log: \n {result_stdout}\n{result.stderr.decode()}"
272280
)

backends/arm/test/setup_testing.sh

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,30 @@ ethos_u_root_dir=${et_root_dir}/examples/arm/ethos-u-scratch/ethos-u
1313

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
16-
build_test_dir=${et_build_dir}/arm_semihosting_executor_runner
16+
build_root_test_dir=${et_build_dir}/arm_semihosting_executor_runner
1717
fvp_model=FVP_Corstone_SSE-300_Ethos-U55
1818

1919
# Build Arm Baremetal executor_runner in semihosting mode.
2020
# Put in backends/arm/test/res to be used by unit tests.
2121
function build_semihosting_executorch_runner() {
22+
target_board=$1
23+
build_test_dir=${build_root_test_dir}_${target_board}
24+
echo "[${FUNCNAME[0]}] Configuring ${target_board}"
25+
if [[ ${target_board} == "corstone-300" ]]; then
26+
local target_cpu=cortex-m55
27+
elif [[ ${target_board} == "corstone-320" ]]; then
28+
local target_cpu=cortex-m85
29+
else
30+
echo "[${FUNCNAME[0]}] ERROR: Invalid target_board specified!"
31+
exit 1
32+
fi
2233
cd ${et_root_dir}/examples/arm/executor_runner
2334
pwd
2435
mkdir -p ${build_test_dir}
2536
cmake -DCMAKE_TOOLCHAIN_FILE=${toolchain_cmake} \
26-
-DTARGET_CPU=cortex-m55 \
37+
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
38+
-DTARGET_CPU=${target_cpu} \
39+
-DTARGET_BOARD=${target_board} \
2740
-DSEMIHOSTING=ON \
2841
-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${build_test_dir} \
2942
-B ${build_test_dir} \
@@ -40,4 +53,6 @@ function build_semihosting_executorch_runner() {
4053
find ${build_test_dir} -name "arm_executor_runner"
4154
}
4255

43-
build_semihosting_executorch_runner
56+
build_semihosting_executorch_runner corstone-300
57+
58+
build_semihosting_executorch_runner corstone-320
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
From 162ea6b51bd94fabf623cc6b63cf271497eaff8d Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Per=20=C3=85strand?= <[email protected]>
3+
Date: Fri, 13 Sep 2024 11:47:03 +0200
4+
Subject: [PATCH] Add .data fixup from Corestone-300
5+
6+
---
7+
targets/corstone-320/platform.ld | 1 +
8+
1 file changed, 1 insertion(+)
9+
10+
diff --git a/targets/corstone-320/platform.ld b/targets/corstone-320/platform.ld
11+
index 2010d14..fb4e7b7 100644
12+
--- a/targets/corstone-320/platform.ld
13+
+++ b/targets/corstone-320/platform.ld
14+
@@ -77,6 +77,7 @@ PHDRS
15+
rom_boot PT_LOAD;
16+
rom_exec PT_LOAD;
17+
rom_dram PT_LOAD;
18+
+ data PT_LOAD; /* HACK: New prog header for .data (and friends) going in DTCM */
19+
null PT_NULL;
20+
}
21+
22+
--
23+
2.39.3 (Apple Git-146)
24+

examples/arm/executor_runner/CMakeLists.txt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ if(NOT DEFINED ET_PTE_FILE_PATH AND NOT ${SEMIHOSTING})
1616
)
1717
endif()
1818

19+
set(TARGET_BOARD "corstone-300" CACHE STRING "Target board")
20+
1921
# Example ExecuTorch demo for bare metal Cortex-M based systems
2022
set(ET_DIR_PATH
2123
"../../.."
@@ -55,10 +57,13 @@ endif()
5557
# libraries. We link against ethosu_target_init which includes all of these
5658
# dependencies.
5759

58-
# For Corstone-300 FVP builds we put models into the larger DRAM area
59-
set(MEMORY_MODEL "dram")
60-
set(MEMORY_ARENA "dram")
61-
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-300 target)
60+
if(TARGET_BOARD STREQUAL "corstone-300")
61+
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-300 target)
62+
elseif(TARGET_BOARD STREQUAL "corstone-320")
63+
add_subdirectory(${ETHOS_SDK_PATH}/core_platform/targets/corstone-320 target)
64+
else()
65+
message(FATAL_ERROR "Unsupported TARGET_BOARD: ${TARGET_BOARD}")
66+
endif()
6267

6368
# Dependencies from the ExecuTorch build
6469
add_library(executorch STATIC IMPORTED)
@@ -171,7 +176,7 @@ endif()
171176
if(SEMIHOSTING)
172177
# Remove this when MLBEDSW-8910 is closed.
173178
set_source_files_properties(
174-
${ETHOS_SDK_PATH}/core_platform/targets/corstone-300/retarget.c
179+
${ETHOS_SDK_PATH}/core_platform/targets/${TARGET_BOARD}/retarget.c
175180
PROPERTIES HEADER_FILE_ONLY TRUE
176181
)
177182
endif()

examples/arm/executor_runner/arm_executor_runner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@
3131
* In our unit test flow, we have the capability to provide an enitre model to
3232
* the Corstone-3xx FVP using semi hosting. Hence, the input file allocation
3333
* pool needs to be large enough to take an entire model and input. On the FVP,
34-
* network_model_sec is linked to the DDR, which is large (256MB on
34+
* input_data_sec is linked to the DDR, which is large (256MB on
3535
* Corstone-300).
3636
* If you use semihosting on your HW this can be lowered to fit your
3737
* files/memory
3838
*/
3939

4040
const size_t input_file_allocation_pool_size = 60 * 1024 * 1024;
4141
unsigned char __attribute__((
42-
section("network_model_sec"),
42+
section("input_data_sec"),
4343
aligned(16))) input_file_allocation_pool[input_file_allocation_pool_size];
4444
char* model_pte = nullptr;
4545

@@ -90,7 +90,7 @@ using executorch::runtime::TensorInfo;
9090
const size_t method_allocation_pool_size =
9191
ET_ARM_BAREMETAL_METHOD_ALLOCATOR_POOL_SIZE;
9292
unsigned char __attribute__((
93-
section("network_model_sec"),
93+
section("input_data_sec"),
9494
aligned(16))) method_allocation_pool[method_allocation_pool_size];
9595

9696
/**
@@ -105,7 +105,7 @@ unsigned char __attribute__((
105105
const size_t temp_allocation_pool_size =
106106
ET_ARM_BAREMETAL_TEMP_ALLOCATOR_POOL_SIZE;
107107
unsigned char __attribute__((
108-
section("network_model_sec"),
108+
section("input_data_sec"),
109109
aligned(16))) temp_allocation_pool[temp_allocation_pool_size];
110110

111111
void et_pal_init(void) {}

examples/arm/setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ fi
7676

7777
# ethos-u
7878
ethos_u_repo_url="https://review.mlplatform.org/ml/ethos-u/ethos-u"
79-
ethos_u_base_rev="24.05"
79+
ethos_u_base_rev="24.08"
8080

8181
########
8282
### Mandatory user args
@@ -163,7 +163,7 @@ function patch_repo() {
163163
name="$(basename $repo_dir)"
164164
echo -e "[${FUNCNAME[0]}] Preparing ${name}..."
165165
cd $repo_dir
166-
166+
git fetch
167167
git reset --hard ${base_rev}
168168

169169
patch_dir=${script_dir}/ethos-u-setup/${name}/patches/
@@ -261,7 +261,7 @@ setup_ethos_u
261261

262262
# Patch the ethos-u dev environment to include executorch application
263263
repo_dir="${root_dir}/ethos-u/core_platform"
264-
base_rev=204210b1074071532627da9dc69950d058a809f4
264+
base_rev=b728c774158248ba2cad8e78a515809e1eb9b77f
265265
patch_repo
266266

267267
# Setup the tosa_reference_model

0 commit comments

Comments
 (0)