Skip to content

Commit 2b3cd50

Browse files
committed
Arm backend: Linux backend for U85 direct drive
Add support for a Linux version of the executor_runner targetting the corstone1000 fvp. This commit splits the backends/arm/runtime/EthosUBackend.cpp into multiple files for Cortex-M and Cortex-A. * Cortex-M is for baremetal and zephyr, this is mostly "old" code moved into its new home. * Cortex-A is for the Linux version of the executor_runner to communicate with the Linux kernel device driver. This is enabled in cmake with EXECUTORCH_BUILD_ARM_ETHOSU_LINUX=ON. The EthosUBackend.cpp is keept for shared code between the different targets. Change-Id: I0dfdf4bff793f7c7d83e20eb4d388f3c151fbfd3 Signed-off-by: Per Held <per.held@arm.com>
1 parent 15c3fcd commit 2b3cd50

10 files changed

Lines changed: 1018 additions & 291 deletions

File tree

CMakeLists.txt

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (c) Meta Platforms, Inc. and affiliates.
22
# All rights reserved.
3-
# Copyright 2024-2025 Arm Limited and/or its affiliates.
3+
# Copyright 2024-2026 Arm Limited and/or its affiliates.
44
#
55
# This source code is licensed under the BSD-style license found in the
66
# LICENSE file in the root directory of this source tree.
@@ -614,8 +614,14 @@ install(FILES tools/cmake/executorch-config.cmake
614614
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/ExecuTorch
615615
)
616616

617-
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
617+
if(EXECUTORCH_BUILD_ARM_BAREMETAL
618+
OR EXECUTORCH_BUILD_ARM_ETHOSU_LINUX
619+
OR EXECUTORCH_BUILD_VGF
620+
)
618621
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
622+
endif()
623+
624+
if(EXECUTORCH_BUILD_ARM_BAREMETAL OR EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
619625
list(APPEND _executorch_backends executorch_delegate_ethos_u)
620626
endif()
621627

@@ -1067,7 +1073,6 @@ if(EXECUTORCH_BUILD_VULKAN)
10671073
endif()
10681074

10691075
if(EXECUTORCH_BUILD_VGF)
1070-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/backends/arm)
10711076
list(APPEND _executorch_backends vgf_backend)
10721077
endif()
10731078

@@ -1201,6 +1206,21 @@ if(EXECUTORCH_BUILD_EXECUTOR_RUNNER)
12011206
endif()
12021207
target_link_libraries(executor_runner ${_executor_runner_libs})
12031208
target_compile_options(executor_runner PUBLIC ${_common_compile_options})
1209+
if(EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
1210+
target_sources(
1211+
executor_runner
1212+
PRIVATE
1213+
${CMAKE_SOURCE_DIR}/examples/arm/executor_runner/ethosu_link_helper.cpp
1214+
)
1215+
target_compile_definitions(
1216+
executor_runner PRIVATE EXECUTORCH_BUILD_ARM_ETHOSU_LINUX=1
1217+
)
1218+
# Wrap static linking like the delegate_runner to keep images
1219+
# self-contained.
1220+
target_link_options(
1221+
executor_runner PRIVATE -static-libstdc++ -static-libgcc
1222+
)
1223+
endif()
12041224

12051225
# Automatically set when using `emcmake cmake` for Wasm build.
12061226
if(EMSCRIPTEN)

backends/arm/CMakeLists.txt

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,102 @@ endif()
1414

1515
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
1616

17+
if(POLICY CMP0169)
18+
# Allow FetchContent_Populate to be used for source-only fetch
19+
cmake_policy(SET CMP0169 OLD)
20+
endif()
21+
1722
set(_common_include_directories
1823
${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10
1924
)
2025
add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS)
2126

22-
# bare metal backend builds
23-
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
27+
set(ETHOSU_LINUX_DRIVER_GIT_REPO
28+
"https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-linux-driver-stack.git"
29+
CACHE STRING "Git repository that hosts the Ethos-U Linux driver stack"
30+
)
31+
set(ETHOSU_LINUX_DRIVER_GIT_TAG
32+
"25.11"
33+
CACHE STRING
34+
"Git tag/branch/commit used to fetch the Ethos-U Linux driver stack"
35+
)
36+
set(ETHOSU_LINUX_DRIVER_SOURCE_DIR
37+
""
38+
CACHE
39+
PATH
40+
"Optional local path to an existing ethos-u-linux-driver stack checkout"
41+
)
42+
43+
if(EXECUTORCH_BUILD_ARM_BAREMETAL AND EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
44+
message(
45+
FATAL_ERROR
46+
"EXECUTORCH_BUILD_ARM_BAREMETAL and EXECUTORCH_BUILD_ARM_ETHOSU_LINUX cannot be enabled at the same time."
47+
)
48+
endif()
49+
50+
# Ethos-U backend builds (bare metal or Linux driver stack)
51+
if(EXECUTORCH_BUILD_ARM_BAREMETAL OR EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
2452

2553
add_compile_options("-Wall" "-Werror")
2654

27-
# Third-party folder and Ethos-U driver inclued
2855
set(THIRD_PARTY_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
29-
set(DRIVER_ETHOSU_INCLUDE_DIR
30-
"${THIRD_PARTY_ROOT}/ethos-u-core-driver/include"
31-
)
32-
include_directories(${DRIVER_ETHOSU_INCLUDE_DIR})
3356

34-
set(_arm_baremetal_sources backends/arm/runtime/EthosUBackend.cpp
35-
backends/arm/runtime/VelaBinStream.cpp
57+
set(_arm_backend_sources backends/arm/runtime/EthosUBackend.cpp
58+
backends/arm/runtime/VelaBinStream.cpp
3659
)
37-
list(TRANSFORM _arm_baremetal_sources PREPEND "${EXECUTORCH_ROOT}/")
60+
list(TRANSFORM _arm_backend_sources PREPEND "${EXECUTORCH_ROOT}/")
3861

39-
add_library(executorch_delegate_ethos_u STATIC ${_arm_baremetal_sources})
40-
target_link_libraries(
41-
executorch_delegate_ethos_u PUBLIC executorch_core ethosu_core_driver
42-
)
62+
add_library(executorch_delegate_ethos_u STATIC ${_arm_backend_sources})
63+
target_link_libraries(executorch_delegate_ethos_u PUBLIC executorch_core)
64+
65+
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
66+
target_sources(
67+
executorch_delegate_ethos_u
68+
PRIVATE ${EXECUTORCH_ROOT}/backends/arm/runtime/EthosUBackend_Cortex_M.cpp
69+
)
70+
set(DRIVER_ETHOSU_INCLUDE_DIR
71+
"${THIRD_PARTY_ROOT}/ethos-u-core-driver/include"
72+
)
73+
target_include_directories(
74+
executorch_delegate_ethos_u PRIVATE ${DRIVER_ETHOSU_INCLUDE_DIR}
75+
)
76+
target_link_libraries(executorch_delegate_ethos_u PUBLIC ethosu_core_driver)
77+
elseif(EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
78+
target_sources(
79+
executorch_delegate_ethos_u
80+
PRIVATE ${EXECUTORCH_ROOT}/backends/arm/runtime/EthosUBackend_Cortex_A.cpp
81+
)
82+
if(NOT ETHOSU_LINUX_DRIVER_SOURCE_DIR
83+
OR NOT EXISTS
84+
"${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/driver_library/src/ethosu.cpp"
85+
)
86+
include(FetchContent)
87+
FetchContent_Declare(
88+
ethosu_linux_driver_src
89+
GIT_REPOSITORY ${ETHOSU_LINUX_DRIVER_GIT_REPO}
90+
GIT_TAG ${ETHOSU_LINUX_DRIVER_GIT_TAG}
91+
GIT_SHALLOW TRUE
92+
)
93+
FetchContent_GetProperties(ethosu_linux_driver_src)
94+
if(NOT ethosu_linux_driver_src_POPULATED)
95+
FetchContent_Populate(ethosu_linux_driver_src)
96+
endif()
97+
set(ETHOSU_LINUX_DRIVER_SOURCE_DIR ${ethosu_linux_driver_src_SOURCE_DIR})
98+
endif()
99+
100+
target_include_directories(
101+
executorch_delegate_ethos_u
102+
PRIVATE ${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/driver_library/include
103+
${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/kernel/include
104+
)
105+
target_sources(
106+
executorch_delegate_ethos_u
107+
PRIVATE ${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/driver_library/src/ethosu.cpp
108+
)
109+
endif()
43110

44111
install(TARGETS executorch_delegate_ethos_u EXPORT ExecuTorchTargets)
45112

46-
# end config for bare metal builds
47113
endif()
48114

49115
# VGF backend builds

0 commit comments

Comments
 (0)