forked from pytorch/executorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
181 lines (152 loc) · 6.05 KB
/
CMakeLists.txt
File metadata and controls
181 lines (152 loc) · 6.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# Copyright 2023, 2025-2026 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
cmake_minimum_required(VERSION 3.19)
project(arm_backend)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Source root directory for executorch.
if(NOT EXECUTORCH_ROOT)
set(EXECUTORCH_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/../..)
endif()
include(${EXECUTORCH_ROOT}/tools/cmake/Utils.cmake)
if(POLICY CMP0169)
# Allow FetchContent_Populate to be used for source-only fetch
cmake_policy(SET CMP0169 OLD)
endif()
set(_common_include_directories
${EXECUTORCH_ROOT}/.. ${EXECUTORCH_ROOT}/runtime/core/portable_type/c10
)
add_compile_definitions(C10_USING_CUSTOM_GENERATED_MACROS)
set(ETHOSU_LINUX_DRIVER_GIT_REPO
"https://gitlab.arm.com/artificial-intelligence/ethos-u/ethos-u-linux-driver-stack.git"
CACHE STRING "Git repository that hosts the Ethos-U Linux driver stack"
)
set(ETHOSU_LINUX_DRIVER_GIT_TAG
"26.02"
CACHE STRING
"Git tag/branch/commit used to fetch the Ethos-U Linux driver stack"
)
set(ETHOSU_LINUX_DRIVER_SOURCE_DIR
""
CACHE
PATH
"Optional local path to an existing ethos-u-linux-driver stack checkout"
)
if(EXECUTORCH_BUILD_ARM_BAREMETAL AND EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
message(
FATAL_ERROR
"EXECUTORCH_BUILD_ARM_BAREMETAL and EXECUTORCH_BUILD_ARM_ETHOSU_LINUX cannot be enabled at the same time."
)
endif()
# Ethos-U backend builds (bare metal or Linux driver stack)
if(EXECUTORCH_BUILD_ARM_BAREMETAL OR EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
add_compile_options("-Wall" "-Werror")
set(THIRD_PARTY_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/third-party")
set(_arm_backend_sources backends/arm/runtime/EthosUBackend.cpp
backends/arm/runtime/VelaBinStream.cpp
)
list(TRANSFORM _arm_backend_sources PREPEND "${EXECUTORCH_ROOT}/")
add_library(executorch_delegate_ethos_u STATIC ${_arm_backend_sources})
target_link_libraries(executorch_delegate_ethos_u PUBLIC executorch_core)
if(EXECUTORCH_BUILD_ARM_BAREMETAL)
target_sources(
executorch_delegate_ethos_u
PRIVATE ${EXECUTORCH_ROOT}/backends/arm/runtime/EthosUBackend_Cortex_M.cpp
)
set(DRIVER_ETHOSU_INCLUDE_DIR
"${THIRD_PARTY_ROOT}/ethos-u-core-driver/include"
)
target_include_directories(
executorch_delegate_ethos_u PRIVATE ${DRIVER_ETHOSU_INCLUDE_DIR}
)
target_link_libraries(executorch_delegate_ethos_u PUBLIC ethosu_core_driver)
elseif(EXECUTORCH_BUILD_ARM_ETHOSU_LINUX)
target_sources(
executorch_delegate_ethos_u
PRIVATE ${EXECUTORCH_ROOT}/backends/arm/runtime/EthosUBackend_Cortex_A.cpp
)
if(NOT ETHOSU_LINUX_DRIVER_SOURCE_DIR
OR NOT EXISTS
"${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/driver_library/src/ethosu.cpp"
)
include(FetchContent)
FetchContent_Declare(
ethosu_linux_driver_src
GIT_REPOSITORY ${ETHOSU_LINUX_DRIVER_GIT_REPO}
GIT_TAG ${ETHOSU_LINUX_DRIVER_GIT_TAG}
GIT_SHALLOW TRUE
)
FetchContent_GetProperties(ethosu_linux_driver_src)
if(NOT ethosu_linux_driver_src_POPULATED)
FetchContent_Populate(ethosu_linux_driver_src)
endif()
set(ETHOSU_LINUX_DRIVER_SOURCE_DIR ${ethosu_linux_driver_src_SOURCE_DIR})
endif()
target_include_directories(
executorch_delegate_ethos_u
PRIVATE ${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/driver_library/include
${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/kernel/include
)
target_sources(
executorch_delegate_ethos_u
PRIVATE ${ETHOSU_LINUX_DRIVER_SOURCE_DIR}/driver_library/src/ethosu.cpp
)
endif()
install(TARGETS executorch_delegate_ethos_u EXPORT ExecuTorchTargets)
endif()
# VGF backend builds
if(EXECUTORCH_BUILD_VGF)
set(VULKAN_THIRD_PARTY_PATH ${EXECUTORCH_ROOT}/backends/vulkan/third-party)
set(VULKAN_HEADERS_PATH ${VULKAN_THIRD_PARTY_PATH}/Vulkan-Headers/include)
set(VOLK_HEADERS_PATH ${VULKAN_THIRD_PARTY_PATH}/volk)
if(EXISTS
"${EXECUTORCH_ROOT}/examples/arm/arm-scratch/ml-sdk-for-vulkan-manifest/"
)
message(STATUS "libvgf sourced from local scratch tree")
# Legacy layout: libvgf sourced from local scratch tree
set(LIBVGF_PATH
"${EXECUTORCH_ROOT}/examples/arm/arm-scratch/ml-sdk-for-vulkan-manifest/sw/vgf-lib/"
)
set(LIBVGF_STATIC "${LIBVGF_PATH}/build/src/libvgf.a")
else()
message(STATUS "libvgf installed from pip package")
set(Python3_FIND_VIRTUALENV FIRST)
if(EXECUTORCH_ROOT AND EXISTS "${EXECUTORCH_ROOT}/env")
set(Python3_EXECUTABLE "${EXECUTORCH_ROOT}/env/bin/python3")
endif()
find_package(Python3 REQUIRED COMPONENTS Interpreter)
# Prefer arch-specific site-packages if present, else pure
set(_vgf_site_arch "${Python3_SITEARCH}/vgf_lib/binaries")
set(_vgf_site_pure "${Python3_SITELIB}/vgf_lib/binaries")
if(EXISTS "${_vgf_site_arch}")
set(LIBVGF_PATH "${_vgf_site_arch}")
else()
set(LIBVGF_PATH "${_vgf_site_pure}")
endif()
set(LIBVGF_STATIC "${LIBVGF_PATH}/lib/libvgf.a")
endif()
set(LIBVGF_INCLUDE "${LIBVGF_PATH}/include/")
add_library(vgf STATIC IMPORTED)
set_property(TARGET vgf PROPERTY IMPORTED_LOCATION "${LIBVGF_STATIC}")
target_include_directories(vgf INTERFACE "${LIBVGF_INCLUDE}")
# Add backend delegate for VGF
set(_vgf_backend_sources backends/arm/runtime/VGFBackend.cpp
backends/arm/runtime/VGFSetup.cpp
)
# vgf backend
list(TRANSFORM _vgf_backend_sources PREPEND "${EXECUTORCH_ROOT}/")
add_library(vgf_backend ${_vgf_backend_sources})
install(TARGETS vgf_backend EXPORT ExecuTorchTargets)
target_include_directories(
vgf_backend PRIVATE ${_common_include_directories} ${VULKAN_HEADERS_PATH}
${VOLK_HEADERS_PATH}
)
target_compile_options(
vgf_backend PRIVATE -DUSE_VULKAN_WRAPPER -DUSE_VULKAN_VOLK
)
target_link_libraries(vgf_backend PRIVATE executorch_core)
target_link_libraries(vgf_backend PRIVATE vgf)
executorch_target_link_options_shared_lib(vgf_backend)
# end config for VGF builds
endif()