blob: d044ed991decfd390834ac0f51a30e8a1670fbf2 [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)
8
Colm Donelan718966f2022-10-10 10:06:12 +01009set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion -Wno-comment")
Sadik Armagan3c24f432020-10-19 17:35:30 +010010
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
13set(armnnDelegate_sources)
14list(APPEND armnnDelegate_sources
15 include/armnn_delegate.hpp
16 include/DelegateOptions.hpp
Matthew Sloyanac001ee2021-02-03 10:43:04 +000017 include/Version.hpp
Sadik Armagan3c24f432020-10-19 17:35:30 +010018 src/armnn_delegate.cpp
Jan Eilers2cd18472020-12-15 10:42:38 +000019 src/armnn_external_delegate.cpp
Sadik Armagan62483be2020-10-23 17:14:43 +010020 src/DelegateOptions.cpp
21 src/Activation.hpp
22 src/ArgMinMax.hpp
Ryan OShea49ed0df2022-09-21 16:09:41 +010023 src/BatchMatMul.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010024 src/BatchSpace.hpp
25 src/Comparison.hpp
26 src/Convolution.hpp
27 src/Control.hpp
28 src/DelegateUtils.hpp
29 src/ElementwiseBinary.hpp
30 src/ElementwiseUnary.hpp
31 src/Fill.hpp
32 src/FullyConnected.hpp
33 src/Gather.hpp
Teresa Charlind5c0ed22022-04-25 18:23:41 +010034 src/GatherNd.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000035 src/LogicalBinary.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010036 src/Lstm.hpp
Jim Flynn4b2f3472021-10-13 21:20:07 +010037 src/MultiLayerFacade.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010038 src/Normalization.hpp
Matthew Sloyana7a12f52021-05-06 10:05:28 +010039 src/Pack.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010040 src/Pad.hpp
41 src/Pooling.hpp
James Conroy39825482021-05-27 17:44:50 +010042 src/Prelu.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010043 src/Quantization.hpp
44 src/Redefine.hpp
Sadik Armagana2747482021-02-09 10:28:54 +000045 src/Reduce.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010046 src/Resize.hpp
47 src/Round.hpp
Keith Davis0176fd82021-06-01 17:36:32 +010048 src/Shape.hpp
Jim Flynn4b2f3472021-10-13 21:20:07 +010049 src/SharedFunctions.hpp
50 src/SharedFunctions.cpp
Sadik Armagan62483be2020-10-23 17:14:43 +010051 src/Slice.hpp
52 src/Softmax.hpp
53 src/SpaceDepth.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000054 src/Split.hpp
Kevin May8ab2d7a2021-05-07 09:32:51 +010055 src/Unpack.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010056 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010057
Jan Eilersa96489a2021-12-08 10:05:47 +000058add_library(armnnDelegate ${armnnDelegate_sources})
Sadik Armagan3c24f432020-10-19 17:35:30 +010059
60target_include_directories(armnnDelegate
61 PUBLIC
62 $<INSTALL_INTERFACE:include>
63 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
64 PRIVATE
65 ${CMAKE_CURRENT_SOURCE_DIR}/src)
66
67include(GNUInstallDirs)
68
69## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000070if(NOT ARMNN_SUB_PROJECT)
71 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
72endif()
73target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
Sadik Armagan3c24f432020-10-19 17:35:30 +010074
Keith Davis9a701c82021-09-28 16:43:24 +010075## Add TfLite dependency
Jim Flynnfca233e2021-09-23 12:16:53 +010076find_package(TfLiteSrc REQUIRED MODULE)
Sadik Armagan3c24f432020-10-19 17:35:30 +010077find_package(TfLite REQUIRED MODULE)
78
Finn Williamsbbbefec2020-11-25 14:32:42 +000079target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010080
Keith Davisd62eef92021-09-20 18:17:33 +010081# lpthread and ldl are not required for Android
82if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL Android)
83 target_link_libraries(armnnDelegate PUBLIC -lpthread)
84 target_link_libraries(armnnDelegate PUBLIC -ldl)
85endif()
86
Finn Williams6f9f9902020-11-13 13:23:15 +000087# Various tflite header files are not warning clean
88# We can't change compilation flags on header files directly, so we need to add them to an interface library first
89add_library(tflite_headers INTERFACE)
90target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
91 $<INSTALL_INTERFACE:include/tflite_headers>)
92
Finn Williams019840d2020-11-30 17:43:28 +000093target_compile_options(tflite_headers INTERFACE -Wno-conversion
94 -Wno-sign-conversion
95 -Wno-unused-parameter
96 -Wno-unused-function)
Finn Williams6f9f9902020-11-13 13:23:15 +000097
Finn Williamsbbbefec2020-11-25 14:32:42 +000098target_link_libraries(armnnDelegate PUBLIC tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010099
Sadik Armagan3c24f432020-10-19 17:35:30 +0100100## Add Flatbuffers dependency
101find_package(Flatbuffers REQUIRED MODULE)
102
Finn Williamsbbbefec2020-11-25 14:32:42 +0000103target_link_libraries(armnnDelegate PRIVATE
Sadik Armagan3c24f432020-10-19 17:35:30 +0100104 ${Flatbuffers_LIB})
105
Finn Williams6f9f9902020-11-13 13:23:15 +0000106# include/flatbuffers/flatbuffers.h is not warning clean
107# We can't change compilation flags on header files directly, so we need to add them to an interface library first
108add_library(flatbuffer_headers INTERFACE)
109target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
110 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
Finn Williams019840d2020-11-30 17:43:28 +0000111target_compile_options(flatbuffer_headers INTERFACE -Wno-sign-conversion)
Finn Williams6f9f9902020-11-13 13:23:15 +0000112
Finn Williamsbbbefec2020-11-25 14:32:42 +0000113target_link_libraries(armnnDelegate PUBLIC flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100114
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000115# Add libraries from armnn third-party libraries
116# Third-party header files are not warning clean
117# We can't change compilation flags on header files directly, so we need to add them to an interface library first
118add_library(thirdparty_headers INTERFACE)
119target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
120 $<INSTALL_INTERFACE:include/thirdparty_headers>)
121
122target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
Jan Eilersc837f1e2021-11-08 10:19:31 +0000123target_link_libraries(armnnDelegate PUBLIC thirdparty_headers)
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000124
Jim Flynnfca233e2021-09-23 12:16:53 +0100125add_library(profiling_library_headers INTERFACE)
126target_include_directories(profiling_library_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/profiling>
127 $<INSTALL_INTERFACE:include/profiling_library_headers>)
Jan Eilersc837f1e2021-11-08 10:19:31 +0000128target_link_libraries(armnnDelegate PUBLIC profiling_library_headers)
129target_link_libraries(armnnDelegate PUBLIC Armnn::armnnUtils)
Jim Flynnfca233e2021-09-23 12:16:53 +0100130
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000131set_target_properties(armnnDelegate PROPERTIES VERSION ${DELEGATE_LIB_VERSION} SOVERSION ${DELEGATE_LIB_SOVERSION})
132
Sadik Armagan4189cc52020-11-11 18:01:48 +0000133option(BUILD_UNIT_TESTS "Build unit tests" ON)
134if(BUILD_UNIT_TESTS)
135 set(armnnDelegate_unittest_sources)
136 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000137 src/test/ActivationTest.cpp
138 src/test/ActivationTestHelper.hpp
Sadik Armagandc032fc2021-01-19 17:24:21 +0000139 src/test/ArgMinMaxTest.cpp
140 src/test/ArgMinMaxTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100141 src/test/ArmnnDelegateTest.cpp
Ryan OShea49ed0df2022-09-21 16:09:41 +0100142 src/test/BatchMatMulTest.cpp
143 src/test/BatchMatMulTestHelper.hpp
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000144 src/test/BatchSpaceTest.cpp
145 src/test/BatchSpaceTestHelper.hpp
Sadik Armagan937565b2021-04-21 14:03:28 +0100146 src/test/CastTest.cpp
147 src/test/CastTestHelper.hpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000148 src/test/ComparisonTest.cpp
149 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000150 src/test/ControlTest.cpp
151 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000152 src/test/Convolution2dTest.cpp
Matthew Sloyan81ec9942021-10-12 10:26:30 +0100153 src/test/Convolution3dTest.cpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000154 src/test/ConvolutionTestHelper.hpp
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000155 src/test/DelegateOptionsTest.cpp
156 src/test/DelegateOptionsTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000157 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000158 src/test/ElementwiseBinaryTest.cpp
159 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000160 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000161 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan29b49cf2021-02-22 18:09:07 +0000162 src/test/FillTest.cpp
163 src/test/FillTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000164 src/test/FullyConnectedTest.cpp
165 src/test/FullyConnectedTestHelper.hpp
Teresa Charlin98427a12020-11-25 18:22:57 +0000166 src/test/GatherTest.cpp
167 src/test/GatherTestHelper.hpp
Teresa Charlind5c0ed22022-04-25 18:23:41 +0100168 src/test/GatherNdTest.cpp
169 src/test/GatherNdTestHelper.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000170 src/test/LogicalTest.cpp
171 src/test/LogicalTestHelper.hpp
Mike Kelly8ae17b32021-02-17 13:45:50 +0000172 src/test/LstmTest.cpp
173 src/test/LstmTestHelper.hpp
Matthew Sloyanaf3a4ef2021-10-22 15:48:12 +0100174 src/test/MirrorPadTest.cpp
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000175 src/test/NormalizationTest.cpp
176 src/test/NormalizationTestHelper.hpp
Matthew Sloyana7a12f52021-05-06 10:05:28 +0100177 src/test/PackTest.cpp
178 src/test/PackTestHelper.hpp
Narumol Prangnawarat958024b2020-12-17 12:17:58 +0000179 src/test/PadTest.cpp
180 src/test/PadTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000181 src/test/Pooling2dTest.cpp
182 src/test/Pooling2dTestHelper.hpp
Ryan OShead21abaf2022-06-10 14:49:11 +0100183 src/test/Pooling3dTest.cpp
184 src/test/Pooling3dTestHelper.hpp
James Conroy39825482021-05-27 17:44:50 +0100185 src/test/PreluTest.cpp
186 src/test/PreluTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000187 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000188 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000189 src/test/RedefineTestHelper.hpp
Sadik Armagana2747482021-02-09 10:28:54 +0000190 src/test/ReduceTest.cpp
191 src/test/ReduceTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000192 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000193 src/test/ResizeTest.cpp
194 src/test/ResizeTestHelper.hpp
Sadik Armagan788e2c62021-02-10 16:26:44 +0000195 src/test/RoundTest.cpp
196 src/test/RoundTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000197 src/test/SoftmaxTest.cpp
198 src/test/SoftmaxTestHelper.hpp
Sadik Armagan89c5a9e2021-01-20 17:48:07 +0000199 src/test/SpaceDepthTest.cpp
200 src/test/SpaceDepthTestHelper.hpp
Keith Davis0176fd82021-06-01 17:36:32 +0100201 src/test/ShapeTest.cpp
202 src/test/ShapeTestHelper.hpp
Jan Eilers2ffddda2021-02-03 09:14:30 +0000203 src/test/SliceTest.cpp
204 src/test/SliceTestHelper.hpp
Cathal Corbett839b9322022-11-18 08:52:18 +0000205 src/test/StridedSliceTest.cpp
206 src/test/StridedSliceTestHelper.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000207 src/test/SplitTest.cpp
208 src/test/SplitTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000209 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000210 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000211 src/test/TransposeTest.cpp
Kevin May8ab2d7a2021-05-07 09:32:51 +0100212 src/test/TransposeTestHelper.hpp
Narumol Prangnawarat7684b182021-08-12 14:48:15 +0100213 src/test/UnidirectionalSequenceLstmTest.cpp
214 src/test/UnidirectionalSequenceLstmTestHelper.hpp
Kevin May8ab2d7a2021-05-07 09:32:51 +0100215 src/test/UnpackTest.cpp
216 src/test/UnpackTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100217
Keith Davis7c67fab2021-04-08 11:47:23 +0100218 # There's a known Android NDK bug which causes a subset of NeonLayerTests to
219 # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
220 # a debug build and NDK is less than r21.
221 # https://github.com/android/ndk/issues/1135
222
223 # Default to always including these tests.
224 set(INCLUDE_NDK_BUG_TESTS "ON")
225 # Reconsider if we in a debug build.
226 string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
227 if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
228 message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
229 # And NDK_VERSION has been set.
230 if ( DEFINED NDK_VERSION )
231 message("CMAKE:: NDK DEFINED")
232 # And the version is less than r21.
233 if ( ${NDK_VERSION} STRLESS "r21" )
234 message("CMAKE:: BUG TESTS OFF")
235 set(INCLUDE_NDK_BUG_TESTS "OFF")
236 endif()
237 endif()
238 endif()
239
240 if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
241 list(APPEND armnnDelegate_unittest_sources
242 src/test/NeonDelegateTests_NDK_Issue.cpp
243 )
244 else()
245
246 endif()
247
Sadik Armagan4189cc52020-11-11 18:01:48 +0000248 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
Sadik Armagan3c24f432020-10-19 17:35:30 +0100249
Sadik Armagan4189cc52020-11-11 18:01:48 +0000250 # Add half library from armnn third-party libraries
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000251 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100252
Finn Williamsbbbefec2020-11-25 14:32:42 +0000253 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
254 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000255
Finn Williamsbbbefec2020-11-25 14:32:42 +0000256 target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
257 target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
Jim Flynnfca233e2021-09-23 12:16:53 +0100258 target_link_libraries(DelegateUnitTests PRIVATE profiling_library_headers)
Finn Williams6f9f9902020-11-13 13:23:15 +0000259
Sadik Armagan4189cc52020-11-11 18:01:48 +0000260endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100261
Jan Eilersa96489a2021-12-08 10:05:47 +0000262option(BUILD_DELEGATE_JNI_INTERFACE "Builds a library to allow accessing the Arm NN delegate from Java code.
263 This is an experimental feature." Off)
264if(BUILD_DELEGATE_JNI_INTERFACE)
265 add_subdirectory(armnnDelegateJNI)
266endif()
267
Sadik Armagan3c24f432020-10-19 17:35:30 +0100268####################################################
269## Export targets
270set(armnn_delegate_export_targets)
271list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000272 armnnDelegate
273 tflite_headers
Jan Eilersc837f1e2021-11-08 10:19:31 +0000274 flatbuffer_headers
275 profiling_library_headers
276 thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100277
278install(
279 TARGETS ${armnn_delegate_export_targets}
280 EXPORT armnn-delegate-targets
281 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
282 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
283 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
284
285## Set export alias
286set_target_properties(armnnDelegate
287 PROPERTIES
288 EXPORT_NAME ArmnnDelegate)
289
290## Export target scrips
291install(
292 EXPORT armnn-delegate-targets
293 FILE ArmnnDelegateTargets.cmake
294 NAMESPACE ArmnnDelegate::
295 DESTINATION ${CMAKE_INSTALL_LIBDIR})
296
297## Create ArmnnDelegateConfig.cmake
298include(CMakePackageConfigHelpers)
299set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
300message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
301message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000302SET(Armnn_DIR "${Armnn_DIR}")
303
Sadik Armagan3c24f432020-10-19 17:35:30 +0100304configure_package_config_file(
305 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
306 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000307 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
308 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100309
310## Install ArmNN Delegate config file
311install(
312 FILES
313 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
314 DESTINATION ${INSTALL_CONFIGDIR})
315
316## Export from build tree
317export(
318 EXPORT armnn-delegate-targets
319 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
320 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000321add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
322
Sadik Armagan3c24f432020-10-19 17:35:30 +0100323
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000324####################################################