Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions .ci/docker/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,13 @@ case "${IMAGE_NAME}" in
exit 1
esac

# NB: All files needed to build the Docker image needs to be in .ci/docker
# folder so that the image hash is updated correctly when they change. The
# good news is that links can be setup to refer to them from other locations

TORCH_VERSION=$(cat ci_commit_pins/pytorch.txt)
BUILD_DOCS=1

# Copy requirements-lintrunner.txt from root to here
cp ../../requirements-lintrunner.txt ./

# Copy arm setup script from root to here
# TODO(huydhn): Figure out a way to rebuild the Docker image automatically
# with a new image hash when the content here is updated
cp -r ../../examples/arm/ ./arm

docker build \
--no-cache \
--progress=plain \
Expand Down
105 changes: 105 additions & 0 deletions .ci/docker/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#
# Copyright (c) 2020-2022 Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed under the Apache License, Version 2.0 (the License); you may
# not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Copied this file from core_platform/cmake/toolchain/arm-non-eabi-gcc.cmake
# And modified to align better with cs300 platform

set(TARGET_CPU "cortex-m55" CACHE STRING "Target CPU")
string(TOLOWER ${TARGET_CPU} CMAKE_SYSTEM_PROCESSOR)

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_C_COMPILER "arm-none-eabi-gcc")
set(CMAKE_CXX_COMPILER "arm-none-eabi-g++")
set(CMAKE_ASM_COMPILER "arm-none-eabi-gcc")
set(CMAKE_LINKER "arm-none-eabi-ld")

set(CMAKE_EXECUTABLE_SUFFIX ".elf")
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Select C/C++ version
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

set(GCC_CPU ${CMAKE_SYSTEM_PROCESSOR})
string(REPLACE "cortex-m85" "cortex-m55" GCC_CPU ${GCC_CPU})

# Compile options
add_compile_options(
-mcpu=${GCC_CPU}
-mthumb
"$<$<CONFIG:DEBUG>:-gdwarf-3>"
"$<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables;-fno-rtti;-fno-exceptions>"
-fdata-sections
-ffunction-sections)

# Compile defines
add_compile_definitions(
"$<$<NOT:$<CONFIG:DEBUG>>:NDEBUG>")

# Link options
add_link_options(
-mcpu=${GCC_CPU}
-mthumb
--specs=nosys.specs)

# Set floating point unit
if(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+fp")
set(FLOAT hard)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "\\+nofp")
set(FLOAT soft)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m33(\\+|$)" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m55(\\+|$)" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m85(\\+|$)")
set(FLOAT hard)
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m4(\\+|$)" OR
CMAKE_SYSTEM_PROCESSOR MATCHES "cortex-m7(\\+|$)")
set(FLOAT hard)
set(FPU_CONFIG "fpv4-sp-d16")
add_compile_options(-mfpu=${FPU_CONFIG})
add_link_options(-mfpu=${FPU_CONFIG})
else()
set(FLOAT soft)
endif()

if(FLOAT)
add_compile_options(-mfloat-abi=${FLOAT})
add_link_options(-mfloat-abi=${FLOAT})
endif()

add_link_options(LINKER:--nmagic,--gc-sections)

# Compilation warnings
add_compile_options(
# -Wall
# -Wextra
# -Wcast-align
# -Wdouble-promotion
# -Wformat
# -Wmissing-field-initializers
# -Wnull-dereference
# -Wredundant-decls
# -Wshadow
# -Wswitch
# -Wswitch-default
# -Wunused
# -Wno-redundant-decls
-Wno-psabi
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
From 949334fe4cfd84c4d4682a92d055be26670670be Mon Sep 17 00:00:00 2001
From: Digant Desai <digantdesai@meta.com>
Date: Tue, 3 Oct 2023 21:20:21 -0700
Subject: [Executorch 1/7] Add README

---
applications/executorch_tests/README.md | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 applications/executorch_tests/README.md

diff --git a/applications/executorch_tests/README.md b/applications/executorch_tests/README.md
new file mode 100644
index 0000000..f2dfb05
--- /dev/null
+++ b/applications/executorch_tests/README.md
@@ -0,0 +1,16 @@
+## ExecuTorch
+A unified ML software stack within the PyTorch platform for edge devices. It
+defines new compiler entry points as well as a state-of-art runtime.
+
+Home: https://github.com/pytorch/executorch/
+
+### executor_runner
+
+This test is a simple wrapper around ExecuTorch runtime, capable of running
+`.pte` model files compatible with ExecuTorch.
+
+If configured correctly with `ET_*` CMake variables pointing to the ExecuTorch
+project build, then this test bin executes `model.pte.h` file converted from
+`model.pte` using `pte_to_header.py`, from the ExecuTorch project root dir,
+containing an ExecuTorch compatible PyTorch model on the Costrone 300 FVP using
+ExecuTorch runtime.
--
2.42.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
From ef976aa04e7d6b7571e9791900f9d80aeb0338da Mon Sep 17 00:00:00 2001
From: Digant Desai <digantdesai@meta.com>
Date: Thu, 28 Sep 2023 18:05:03 -0700
Subject: [Executorch 2/7] regress cmake version from 3.21 --> 3.20

---
targets/corstone-300/CMakeLists.txt | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/targets/corstone-300/CMakeLists.txt b/targets/corstone-300/CMakeLists.txt
index 62205bb..7dda8a1 100644
--- a/targets/corstone-300/CMakeLists.txt
+++ b/targets/corstone-300/CMakeLists.txt
@@ -42,7 +42,7 @@ set(MEMORY_ARENA "dram" CACHE STRING "Memory config for arena")
# Project
#############################################################################

-cmake_minimum_required(VERSION 3.21)
+cmake_minimum_required(VERSION 3.20)

project(ethos-u-corstone-300 VERSION 0.0.1)

--
2.42.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
From cbda805f968a45205c9d3d4a2f4cb534e207d504 Mon Sep 17 00:00:00 2001
From: Digant Desai <digantdesai@meta.com>
Date: Thu, 28 Sep 2023 18:05:30 -0700
Subject: [Executorch 3/7] Disable warnings to reduce verbosity

---
cmake/toolchain/arm-none-eabi-gcc.cmake | 28 ++++++++++++-------------
1 file changed, 14 insertions(+), 14 deletions(-)

diff --git a/cmake/toolchain/arm-none-eabi-gcc.cmake b/cmake/toolchain/arm-none-eabi-gcc.cmake
index 093005e..0e6a2ed 100644
--- a/cmake/toolchain/arm-none-eabi-gcc.cmake
+++ b/cmake/toolchain/arm-none-eabi-gcc.cmake
@@ -85,21 +85,21 @@ add_link_options(LINKER:--nmagic,--gc-sections)

# Compilation warnings
add_compile_options(
- -Wall
- -Wextra
+ # -Wall
+ # -Wextra

- -Wcast-align
- -Wdouble-promotion
- -Wformat
- -Wmissing-field-initializers
- -Wnull-dereference
- -Wredundant-decls
- -Wshadow
- -Wswitch
- -Wswitch-default
- -Wunused
+ # -Wcast-align
+ # -Wdouble-promotion
+ # -Wformat
+ # -Wmissing-field-initializers
+ # -Wnull-dereference
+ # -Wredundant-decls
+ # -Wshadow
+ # -Wswitch
+ # -Wswitch-default
+ # -Wunused

- -Wno-redundant-decls
+ # -Wno-redundant-decls

- -Wno-psabi
+ # -Wno-psabi
)
--
2.42.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
From 02eb3615cdb2cc963f20e103893f76499c98ad50 Mon Sep 17 00:00:00 2001
From: Digant Desai <digantdesai@meta.com>
Date: Mon, 2 Oct 2023 20:39:39 -0700
Subject: [Executorch 4/7] New phdr for .data section

---
targets/corstone-300/platform.ld | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/targets/corstone-300/platform.ld b/targets/corstone-300/platform.ld
index 8d77329..8de77c4 100644
--- a/targets/corstone-300/platform.ld
+++ b/targets/corstone-300/platform.ld
@@ -94,6 +94,7 @@ PHDRS
{
rom_exec PT_LOAD;
rom_dram PT_LOAD;
+ data PT_LOAD; /* HACK: New prog header for .data (and friends) going in DTCM */
null PT_NULL;
}

@@ -247,7 +248,7 @@ SECTIONS
/* All data end */
__data_end__ = .;

- } > DTCM :rom_exec
+ } > DTCM :data

.sram.bss :
{
--
2.42.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
From 55019e4eb8d39f3fb1fb303380e903294604837c Mon Sep 17 00:00:00 2001
From: Digant Desai <digantdesai@meta.com>
Date: Tue, 3 Oct 2023 21:20:07 -0700
Subject: [Executorch 5/7] Add pte to header script

---
.../executorch_tests/pte_to_header.py | 65 +++++++++++++++++++
1 file changed, 65 insertions(+)
create mode 100644 applications/executorch_tests/pte_to_header.py

diff --git a/applications/executorch_tests/pte_to_header.py b/applications/executorch_tests/pte_to_header.py
new file mode 100644
index 0000000..37d88aa
--- /dev/null
+++ b/applications/executorch_tests/pte_to_header.py
@@ -0,0 +1,65 @@
+# Copyright (c) Meta Platforms, Inc. and affiliates.
+# All rights reserved.
+#
+# This source code is licensed under the BSD-style license found in the
+# LICENSE file in the root directory of this source tree.
+
+import binascii
+import os
+from argparse import ArgumentParser, ArgumentTypeError
+
+# Also see: https://git.mlplatform.org/ml/ethos-u/ml-embedded-evaluation-kit.git/tree/scripts/py/gen_model_cpp.py
+
+bytes_per_line = 32
+hex_digits_per_line = bytes_per_line * 2
+
+
+def input_file_path(path):
+ if os.path.exists(path):
+ return path
+ else:
+ raise ArgumentTypeError(f"input filepath:{path} does not exist")
+
+
+parser = ArgumentParser()
+parser.add_argument(
+ "--pte",
+ help="ExecuTorch .pte model file",
+ type=input_file_path,
+ required=True,
+)
+parser.add_argument(
+ "--outdir",
+ help="Output dir for model_pte.h",
+ type=str,
+ required=False,
+ default=".",
+)
+parser.add_argument(
+ "--section",
+ help="Section attribute for the data array",
+ type=str,
+ required=False,
+ default=".sram.data",
+)
+args = parser.parse_args()
+outfile = os.path.join(args.outdir, "model_pte.h")
+attr = f'__attribute__((section("{args.section}"), aligned(16))) char '
+
+with open(args.pte, "rb") as fr, open(
+ outfile, "w"
+) as fw:
+ data = fr.read()
+ hexstream = binascii.hexlify(data).decode("utf-8")
+ hexstring = attr + "model_pte[] = {"
+
+ for i in range(0, len(hexstream), 2):
+ if 0 == (i % hex_digits_per_line):
+ hexstring += "\n"
+ hexstring += "0x" + hexstream[i : i + 2] + ", "
+
+ hexstring += "};\n"
+ fw.write(hexstring)
+ print(
+ f"Input: {args.pte} with {len(data)} bytes. Output: {outfile} with {len(hexstring)} bytes. Section: {args.section}."
+ )
--
2.42.0

Loading