blob: 73df68fc4c670ce7557b72a23bcee5c071e39793 [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001#
Ryan OSheab5540542022-07-06 09:52:52 +01002# Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan3c24f432020-10-19 17:35:30 +01003# SPDX-License-Identifier: MIT
4#
5
Jan Eilersb968a4f2020-11-15 14:44:43 +00006cmake_minimum_required (VERSION 3.7.0)
Sadik Armagan3c24f432020-10-19 17:35:30 +01007project(armnnDelegate)
Ryan OShea238ecd92023-03-07 11:44:23 +00008set(CMAKE_CXX_STANDARD 17)
9set(CMAKE_CXX_STANDARD_REQUIRED ON)
Ryan OShea238ecd92023-03-07 11:44:23 +000010set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion -Wno-comment")
Finn Williamsbbbefec2020-11-25 14:32:42 +000011set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
Sadik Armagan3c24f432020-10-19 17:35:30 +010012
Teresa Charlinad1b3d72023-03-14 12:10:28 +000013option(BUILD_UNIT_TESTS "Build unit tests" ON)
14option(BUILD_CLASSIC_DELEGATE "Build classic delegate" ON)
15option(BUILD_OPAQUE_DELEGATE "Build opaque delegate" OFF)
16option(BUILD_SHARED_LIBS "Build share libs" ON)
17option(BUILD_DELEGATE_JNI_INTERFACE "Builds a library to allow accessing the Arm NN delegate from Java code.
18 This is an experimental feature." ON)
19
Sadik Armagan3c24f432020-10-19 17:35:30 +010020set(armnnDelegate_sources)
21list(APPEND armnnDelegate_sources
Teresa Charlinad1b3d72023-03-14 12:10:28 +000022 common/include/DelegateOptions.hpp
23 common/src/DelegateOptions.cpp
24 common/src/DelegateUtils.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010025
26## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000027if(NOT ARMNN_SUB_PROJECT)
28 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
29endif()
Teresa Charlinad1b3d72023-03-14 12:10:28 +000030
31if (BUILD_CLASSIC_DELEGATE)
32 add_subdirectory(classic)
33 add_library(armnnDelegate ${armnnDelegate_sources})
34
35 target_include_directories(armnnDelegate
36 PUBLIC
37 $<INSTALL_INTERFACE:include>
38 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common/include>
39 PRIVATE
40 ${CMAKE_CURRENT_SOURCE_DIR}/common/src)
41endif()
42if (BUILD_OPAQUE_DELEGATE)
43 add_subdirectory(opaque)
44 add_library(armnnOpaqueDelegate ${armnnDelegate_sources})
45
46 target_include_directories(armnnOpaqueDelegate
47 PUBLIC
48 $<INSTALL_INTERFACE:include>
49 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/common/include>
50 PRIVATE
51 ${CMAKE_CURRENT_SOURCE_DIR}/common/src)
52endif()
53
54include(GNUInstallDirs)
55
56if (BUILD_CLASSIC_DELEGATE)
57 target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
58
59 ## Add armnnClassicDelegateObject as a Dependency
60 target_link_libraries(armnnDelegate PUBLIC armnnClassicDelegateObject)
61endif()
62if (BUILD_OPAQUE_DELEGATE)
63 target_link_libraries(armnnOpaqueDelegate PUBLIC Armnn::Armnn)
64
65 ## Add armnnOpaqueDelegateObject as a Dependency
66 target_link_libraries(armnnOpaqueDelegate PUBLIC armnnOpaqueDelegateObject)
67endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +010068
Keith Davis9a701c82021-09-28 16:43:24 +010069## Add TfLite dependency
Jim Flynnfca233e2021-09-23 12:16:53 +010070find_package(TfLiteSrc REQUIRED MODULE)
Sadik Armagan3c24f432020-10-19 17:35:30 +010071find_package(TfLite REQUIRED MODULE)
Teresa Charlinad1b3d72023-03-14 12:10:28 +000072if (BUILD_CLASSIC_DELEGATE)
73 target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010074
Teresa Charlinad1b3d72023-03-14 12:10:28 +000075 # lpthread and ldl are not required for Android
76 if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL Android)
77 target_link_libraries(armnnDelegate PUBLIC -lpthread)
78 target_link_libraries(armnnDelegate PUBLIC -ldl)
79 endif()
Keith Davisd62eef92021-09-20 18:17:33 +010080endif()
Teresa Charlinad1b3d72023-03-14 12:10:28 +000081if (BUILD_OPAQUE_DELEGATE)
82 target_link_libraries(armnnOpaqueDelegate PUBLIC ${TfLite_LIB})
Keith Davisd62eef92021-09-20 18:17:33 +010083
Teresa Charlinad1b3d72023-03-14 12:10:28 +000084 # lpthread and ldl are not required for Android
85 if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL Android)
86 target_link_libraries(armnnOpaqueDelegate PUBLIC -lpthread)
87 target_link_libraries(armnnOpaqueDelegate PUBLIC -ldl)
88 endif()
89endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +010090
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +000091# Add libraries from armnn third-party libraries
92# Third-party header files are not warning clean
93# We can't change compilation flags on header files directly, so we need to add them to an interface library first
94add_library(thirdparty_headers INTERFACE)
95target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
96 $<INSTALL_INTERFACE:include/thirdparty_headers>)
97
98target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
Teresa Charlinad1b3d72023-03-14 12:10:28 +000099if (BUILD_CLASSIC_DELEGATE)
100 target_link_libraries(armnnDelegate PUBLIC thirdparty_headers)
101endif()
102if (BUILD_OPAQUE_DELEGATE)
103 target_link_libraries(armnnOpaqueDelegate PUBLIC thirdparty_headers)
104endif()
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000105
Jim Flynnfca233e2021-09-23 12:16:53 +0100106add_library(profiling_library_headers INTERFACE)
107target_include_directories(profiling_library_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/profiling>
108 $<INSTALL_INTERFACE:include/profiling_library_headers>)
Jim Flynnfca233e2021-09-23 12:16:53 +0100109
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000110if (BUILD_CLASSIC_DELEGATE)
111 target_link_libraries(armnnDelegate PUBLIC profiling_library_headers)
112 target_link_libraries(armnnDelegate PUBLIC Armnn::armnnUtils)
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000113
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000114 set_target_properties(armnnDelegate PROPERTIES VERSION ${DELEGATE_LIB_VERSION} SOVERSION ${DELEGATE_LIB_SOVERSION})
115endif()
116if (BUILD_OPAQUE_DELEGATE)
117 target_link_libraries(armnnOpaqueDelegate PUBLIC profiling_library_headers)
118 target_link_libraries(armnnOpaqueDelegate PUBLIC Armnn::armnnUtils)
119
120 set_target_properties(armnnOpaqueDelegate PROPERTIES VERSION ${OPAQUE_DELEGATE_LIB_VERSION} SOVERSION ${OPAQUE_DELEGATE_LIB_SOVERSION})
121endif()
122
Ryan OSheaac9607f2023-04-03 11:33:33 +0100123if(BUILD_UNIT_TESTS AND BUILD_CLASSIC_DELEGATE)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000124 set(armnnDelegate_unittest_sources)
125 list(APPEND armnnDelegate_unittest_sources
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000126 test/ActivationTest.cpp
127 test/ActivationTestHelper.hpp
128 test/ArgMinMaxTest.cpp
129 test/ArgMinMaxTestHelper.hpp
130 test/ArmnnDelegateTest.cpp
131 test/BatchMatMulTest.cpp
132 test/BatchMatMulTestHelper.hpp
133 test/BatchSpaceTest.cpp
134 test/BatchSpaceTestHelper.hpp
135 test/CastTest.cpp
136 test/CastTestHelper.hpp
137 test/ComparisonTest.cpp
138 test/ComparisonTestHelper.hpp
139 test/ControlTest.cpp
140 test/ControlTestHelper.hpp
141 test/Convolution2dTest.cpp
142 test/Convolution3dTest.cpp
143 test/ConvolutionTestHelper.hpp
144 test/DelegateOptionsTest.cpp
145 test/DelegateOptionsTestHelper.hpp
Matthew Sloyanebe392d2023-03-30 10:12:08 +0100146 classic/src/test/DelegateTestInterpreter.cpp
147 common/src/test/DelegateTestInterpreter.hpp
148 common/src/test/DelegateTestInterpreterUtils.hpp
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000149 test/DepthwiseConvolution2dTest.cpp
150 test/ElementwiseBinaryTest.cpp
151 test/ElementwiseBinaryTestHelper.hpp
152 test/ElementwiseUnaryTest.cpp
153 test/ElementwiseUnaryTestHelper.hpp
154 test/FillTest.cpp
155 test/FillTestHelper.hpp
156 test/FullyConnectedTest.cpp
157 test/FullyConnectedTestHelper.hpp
158 test/GatherTest.cpp
159 test/GatherTestHelper.hpp
160 test/GatherNdTest.cpp
161 test/GatherNdTestHelper.hpp
162 test/LogicalTest.cpp
163 test/LogicalTestHelper.hpp
164 test/LstmTest.cpp
165 test/LstmTestHelper.hpp
166 test/MirrorPadTest.cpp
167 test/NormalizationTest.cpp
168 test/NormalizationTestHelper.hpp
169 test/PackTest.cpp
170 test/PackTestHelper.hpp
171 test/PadTest.cpp
172 test/PadTestHelper.hpp
173 test/Pooling2dTest.cpp
174 test/Pooling2dTestHelper.hpp
175 test/Pooling3dTest.cpp
176 test/Pooling3dTestHelper.hpp
177 test/PreluTest.cpp
178 test/PreluTestHelper.hpp
179 test/QuantizationTest.cpp
180 test/QuantizationTestHelper.hpp
181 test/RedefineTestHelper.hpp
182 test/ReduceTest.cpp
183 test/ReduceTestHelper.hpp
184 test/ReshapeTest.cpp
185 test/ResizeTest.cpp
186 test/ResizeTestHelper.hpp
187 test/RoundTest.cpp
188 test/RoundTestHelper.hpp
189 test/SoftmaxTest.cpp
190 test/SoftmaxTestHelper.hpp
191 test/SpaceDepthTest.cpp
192 test/SpaceDepthTestHelper.hpp
193 test/ShapeTest.cpp
194 test/ShapeTestHelper.hpp
195 test/SliceTest.cpp
196 test/SliceTestHelper.hpp
197 test/StridedSliceTest.cpp
198 test/StridedSliceTestHelper.hpp
199 test/SplitTest.cpp
200 test/SplitTestHelper.hpp
201 test/TestUtils.hpp
202 test/TestUtils.cpp
203 test/TransposeTest.cpp
204 test/TransposeTestHelper.hpp
205 test/UnidirectionalSequenceLstmTest.cpp
206 test/UnidirectionalSequenceLstmTestHelper.hpp
207 test/UnpackTest.cpp
208 test/UnpackTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100209
Keith Davis7c67fab2021-04-08 11:47:23 +0100210 # There's a known Android NDK bug which causes a subset of NeonLayerTests to
211 # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
212 # a debug build and NDK is less than r21.
213 # https://github.com/android/ndk/issues/1135
214
215 # Default to always including these tests.
216 set(INCLUDE_NDK_BUG_TESTS "ON")
217 # Reconsider if we in a debug build.
218 string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
219 if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
220 message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
221 # And NDK_VERSION has been set.
222 if ( DEFINED NDK_VERSION )
223 message("CMAKE:: NDK DEFINED")
224 # And the version is less than r21.
225 if ( ${NDK_VERSION} STRLESS "r21" )
226 message("CMAKE:: BUG TESTS OFF")
227 set(INCLUDE_NDK_BUG_TESTS "OFF")
228 endif()
229 endif()
230 endif()
231
232 if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
233 list(APPEND armnnDelegate_unittest_sources
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000234 test/NeonDelegateTests_NDK_Issue.cpp
Keith Davis7c67fab2021-04-08 11:47:23 +0100235 )
236 else()
237
238 endif()
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000239 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
Keith Davis7c67fab2021-04-08 11:47:23 +0100240
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000241 target_include_directories(DelegateUnitTests SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}")
Matthew Sloyanebe392d2023-03-30 10:12:08 +0100242 target_include_directories(DelegateUnitTests SYSTEM PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/common/src/test")
Sadik Armagan3c24f432020-10-19 17:35:30 +0100243
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000244 # Add half library from armnn third-party libraries
245 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100246
Ryan OSheaac9607f2023-04-03 11:33:33 +0100247 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
248 target_include_directories(DelegateUnitTests PUBLIC ${PROJECT_SOURCE_DIR})
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000249 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000250
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000251 target_link_libraries(DelegateUnitTests PRIVATE profiling_library_headers)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000252endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100253
Jan Eilersa96489a2021-12-08 10:05:47 +0000254if(BUILD_DELEGATE_JNI_INTERFACE)
255 add_subdirectory(armnnDelegateJNI)
256endif()
257
Sadik Armagan3c24f432020-10-19 17:35:30 +0100258####################################################
259## Export targets
260set(armnn_delegate_export_targets)
261list(APPEND armnn_delegate_export_targets
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000262 armnnClassicDelegateObject
Finn Williams6f9f9902020-11-13 13:23:15 +0000263 armnnDelegate
264 tflite_headers
Jan Eilersc837f1e2021-11-08 10:19:31 +0000265 flatbuffer_headers
266 profiling_library_headers
267 thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100268
269install(
270 TARGETS ${armnn_delegate_export_targets}
271 EXPORT armnn-delegate-targets
272 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
273 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
274 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
275
276## Set export alias
277set_target_properties(armnnDelegate
278 PROPERTIES
279 EXPORT_NAME ArmnnDelegate)
280
281## Export target scrips
282install(
283 EXPORT armnn-delegate-targets
284 FILE ArmnnDelegateTargets.cmake
285 NAMESPACE ArmnnDelegate::
286 DESTINATION ${CMAKE_INSTALL_LIBDIR})
287
288## Create ArmnnDelegateConfig.cmake
289include(CMakePackageConfigHelpers)
290set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
291message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
292message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000293SET(Armnn_DIR "${Armnn_DIR}")
294
Sadik Armagan3c24f432020-10-19 17:35:30 +0100295configure_package_config_file(
296 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
297 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000298 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
299 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100300
301## Install ArmNN Delegate config file
302install(
303 FILES
304 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
305 DESTINATION ${INSTALL_CONFIGDIR})
306
307## Export from build tree
308export(
309 EXPORT armnn-delegate-targets
310 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
311 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000312add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
313
Sadik Armagan3c24f432020-10-19 17:35:30 +0100314
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000315####################################################