blob: bae1d31e71636504eca6d6209dfe5e56b28c4a55 [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001#
2# Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3# 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
Finn Williams6f9f9902020-11-13 13:23:15 +00009set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion")
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
23 src/BatchSpace.hpp
24 src/Comparison.hpp
25 src/Convolution.hpp
26 src/Control.hpp
27 src/DelegateUtils.hpp
28 src/ElementwiseBinary.hpp
29 src/ElementwiseUnary.hpp
30 src/Fill.hpp
31 src/FullyConnected.hpp
32 src/Gather.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000033 src/LogicalBinary.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010034 src/Lstm.hpp
Jim Flynn4b2f3472021-10-13 21:20:07 +010035 src/MultiLayerFacade.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010036 src/Normalization.hpp
Matthew Sloyana7a12f52021-05-06 10:05:28 +010037 src/Pack.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010038 src/Pad.hpp
39 src/Pooling.hpp
James Conroy39825482021-05-27 17:44:50 +010040 src/Prelu.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010041 src/Quantization.hpp
42 src/Redefine.hpp
Sadik Armagana2747482021-02-09 10:28:54 +000043 src/Reduce.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010044 src/Resize.hpp
45 src/Round.hpp
Keith Davis0176fd82021-06-01 17:36:32 +010046 src/Shape.hpp
Jim Flynn4b2f3472021-10-13 21:20:07 +010047 src/SharedFunctions.hpp
48 src/SharedFunctions.cpp
Sadik Armagan62483be2020-10-23 17:14:43 +010049 src/Slice.hpp
50 src/Softmax.hpp
51 src/SpaceDepth.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000052 src/Split.hpp
Kevin May8ab2d7a2021-05-07 09:32:51 +010053 src/Unpack.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +010054 src/Transpose.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +010055
56add_library(armnnDelegate SHARED ${armnnDelegate_sources})
57
58target_include_directories(armnnDelegate
59 PUBLIC
60 $<INSTALL_INTERFACE:include>
61 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
62 PRIVATE
63 ${CMAKE_CURRENT_SOURCE_DIR}/src)
64
65include(GNUInstallDirs)
66
67## Add Armnn as a Dependency
Finn Williamsbbbefec2020-11-25 14:32:42 +000068if(NOT ARMNN_SUB_PROJECT)
69 find_package(Armnn REQUIRED CONFIG HINTS ${Armnn_DIR})
70endif()
71target_link_libraries(armnnDelegate PUBLIC Armnn::Armnn)
Sadik Armagan3c24f432020-10-19 17:35:30 +010072
Keith Davis9a701c82021-09-28 16:43:24 +010073## Add TfLite dependency
Jim Flynnfca233e2021-09-23 12:16:53 +010074find_package(TfLiteSrc REQUIRED MODULE)
Sadik Armagan3c24f432020-10-19 17:35:30 +010075find_package(TfLite REQUIRED MODULE)
76
Finn Williamsbbbefec2020-11-25 14:32:42 +000077target_link_libraries(armnnDelegate PUBLIC ${TfLite_LIB})
Sadik Armagan3c24f432020-10-19 17:35:30 +010078
Keith Davisd62eef92021-09-20 18:17:33 +010079# lpthread and ldl are not required for Android
80if(NOT "${CMAKE_SYSTEM_NAME}" STREQUAL Android)
81 target_link_libraries(armnnDelegate PUBLIC -lpthread)
82 target_link_libraries(armnnDelegate PUBLIC -ldl)
83endif()
84
Finn Williams6f9f9902020-11-13 13:23:15 +000085# Various tflite header files are not warning clean
86# We can't change compilation flags on header files directly, so we need to add them to an interface library first
87add_library(tflite_headers INTERFACE)
88target_include_directories(tflite_headers INTERFACE $<BUILD_INTERFACE:${TfLite_INCLUDE_DIR}>
89 $<INSTALL_INTERFACE:include/tflite_headers>)
90
Finn Williams019840d2020-11-30 17:43:28 +000091target_compile_options(tflite_headers INTERFACE -Wno-conversion
92 -Wno-sign-conversion
93 -Wno-unused-parameter
94 -Wno-unused-function)
Finn Williams6f9f9902020-11-13 13:23:15 +000095
Finn Williamsbbbefec2020-11-25 14:32:42 +000096target_link_libraries(armnnDelegate PUBLIC tflite_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +010097
Sadik Armagan3c24f432020-10-19 17:35:30 +010098## Add Flatbuffers dependency
99find_package(Flatbuffers REQUIRED MODULE)
100
Finn Williamsbbbefec2020-11-25 14:32:42 +0000101target_link_libraries(armnnDelegate PRIVATE
Sadik Armagan3c24f432020-10-19 17:35:30 +0100102 ${Flatbuffers_LIB})
103
Finn Williams6f9f9902020-11-13 13:23:15 +0000104# include/flatbuffers/flatbuffers.h is not warning clean
105# We can't change compilation flags on header files directly, so we need to add them to an interface library first
106add_library(flatbuffer_headers INTERFACE)
107target_include_directories(flatbuffer_headers INTERFACE $<BUILD_INTERFACE:${Flatbuffers_INCLUDE_DIR}>
108 $<INSTALL_INTERFACE:include/flatbuffer_headers>)
Finn Williams019840d2020-11-30 17:43:28 +0000109target_compile_options(flatbuffer_headers INTERFACE -Wno-sign-conversion)
Finn Williams6f9f9902020-11-13 13:23:15 +0000110
Finn Williamsbbbefec2020-11-25 14:32:42 +0000111target_link_libraries(armnnDelegate PUBLIC flatbuffer_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100112
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000113# Add libraries from armnn third-party libraries
114# Third-party header files are not warning clean
115# We can't change compilation flags on header files directly, so we need to add them to an interface library first
116add_library(thirdparty_headers INTERFACE)
117target_include_directories(thirdparty_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/third-party>
118 $<INSTALL_INTERFACE:include/thirdparty_headers>)
119
120target_compile_options(thirdparty_headers INTERFACE -Wno-old-style-cast)
Jan Eilersc837f1e2021-11-08 10:19:31 +0000121target_link_libraries(armnnDelegate PUBLIC thirdparty_headers)
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000122
Jim Flynnfca233e2021-09-23 12:16:53 +0100123add_library(profiling_library_headers INTERFACE)
124target_include_directories(profiling_library_headers INTERFACE $<BUILD_INTERFACE:${ARMNN_SOURCE_DIR}/profiling>
125 $<INSTALL_INTERFACE:include/profiling_library_headers>)
Jan Eilersc837f1e2021-11-08 10:19:31 +0000126target_link_libraries(armnnDelegate PUBLIC profiling_library_headers)
127target_link_libraries(armnnDelegate PUBLIC Armnn::armnnUtils)
Jim Flynnfca233e2021-09-23 12:16:53 +0100128
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000129set_target_properties(armnnDelegate PROPERTIES VERSION ${DELEGATE_LIB_VERSION} SOVERSION ${DELEGATE_LIB_SOVERSION})
130
Sadik Armagan4189cc52020-11-11 18:01:48 +0000131option(BUILD_UNIT_TESTS "Build unit tests" ON)
132if(BUILD_UNIT_TESTS)
133 set(armnnDelegate_unittest_sources)
134 list(APPEND armnnDelegate_unittest_sources
David Monahan0cf84422020-11-16 15:53:03 +0000135 src/test/ActivationTest.cpp
136 src/test/ActivationTestHelper.hpp
Sadik Armagandc032fc2021-01-19 17:24:21 +0000137 src/test/ArgMinMaxTest.cpp
138 src/test/ArgMinMaxTestHelper.hpp
Sadik Armagan62483be2020-10-23 17:14:43 +0100139 src/test/ArmnnDelegateTest.cpp
Matthew Sloyana35b40b2021-02-05 17:22:28 +0000140 src/test/BatchSpaceTest.cpp
141 src/test/BatchSpaceTestHelper.hpp
Sadik Armagan937565b2021-04-21 14:03:28 +0100142 src/test/CastTest.cpp
143 src/test/CastTestHelper.hpp
Sadik Armagan8b9858d2020-11-09 08:26:22 +0000144 src/test/ComparisonTest.cpp
145 src/test/ComparisonTestHelper.hpp
Matthew Sloyan91c41712020-11-13 09:47:35 +0000146 src/test/ControlTest.cpp
147 src/test/ControlTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000148 src/test/Convolution2dTest.cpp
Matthew Sloyan81ec9942021-10-12 10:26:30 +0100149 src/test/Convolution3dTest.cpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000150 src/test/ConvolutionTestHelper.hpp
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000151 src/test/DelegateOptionsTest.cpp
152 src/test/DelegateOptionsTestHelper.hpp
Sadik Armagan32ca1442020-11-13 17:51:56 +0000153 src/test/DepthwiseConvolution2dTest.cpp
Sadik Armagan67e95f22020-10-29 16:14:54 +0000154 src/test/ElementwiseBinaryTest.cpp
155 src/test/ElementwiseBinaryTestHelper.hpp
Sadik Armagan0534e032020-10-27 17:30:18 +0000156 src/test/ElementwiseUnaryTest.cpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000157 src/test/ElementwiseUnaryTestHelper.hpp
Sadik Armagan29b49cf2021-02-22 18:09:07 +0000158 src/test/FillTest.cpp
159 src/test/FillTestHelper.hpp
Sadik Armagan6e36a642020-11-10 21:18:41 +0000160 src/test/FullyConnectedTest.cpp
161 src/test/FullyConnectedTestHelper.hpp
Teresa Charlin98427a12020-11-25 18:22:57 +0000162 src/test/GatherTest.cpp
163 src/test/GatherTestHelper.hpp
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000164 src/test/LogicalTest.cpp
165 src/test/LogicalTestHelper.hpp
Mike Kelly8ae17b32021-02-17 13:45:50 +0000166 src/test/LstmTest.cpp
167 src/test/LstmTestHelper.hpp
Matthew Sloyanaf3a4ef2021-10-22 15:48:12 +0100168 src/test/MirrorPadTest.cpp
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000169 src/test/NormalizationTest.cpp
170 src/test/NormalizationTestHelper.hpp
Matthew Sloyana7a12f52021-05-06 10:05:28 +0100171 src/test/PackTest.cpp
172 src/test/PackTestHelper.hpp
Narumol Prangnawarat958024b2020-12-17 12:17:58 +0000173 src/test/PadTest.cpp
174 src/test/PadTestHelper.hpp
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000175 src/test/Pooling2dTest.cpp
176 src/test/Pooling2dTestHelper.hpp
James Conroy39825482021-05-27 17:44:50 +0100177 src/test/PreluTest.cpp
178 src/test/PreluTestHelper.hpp
Matthew Sloyan0d35a932020-11-09 12:25:05 +0000179 src/test/QuantizationTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000180 src/test/QuantizationTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000181 src/test/RedefineTestHelper.hpp
Sadik Armagana2747482021-02-09 10:28:54 +0000182 src/test/ReduceTest.cpp
183 src/test/ReduceTestHelper.hpp
David Monahan1670b0c2020-11-18 14:40:27 +0000184 src/test/ReshapeTest.cpp
Jan Eilerse339bf62020-11-10 18:43:23 +0000185 src/test/ResizeTest.cpp
186 src/test/ResizeTestHelper.hpp
Sadik Armagan788e2c62021-02-10 16:26:44 +0000187 src/test/RoundTest.cpp
188 src/test/RoundTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000189 src/test/SoftmaxTest.cpp
190 src/test/SoftmaxTestHelper.hpp
Sadik Armagan89c5a9e2021-01-20 17:48:07 +0000191 src/test/SpaceDepthTest.cpp
192 src/test/SpaceDepthTestHelper.hpp
Keith Davis0176fd82021-06-01 17:36:32 +0100193 src/test/ShapeTest.cpp
194 src/test/ShapeTestHelper.hpp
Jan Eilers2ffddda2021-02-03 09:14:30 +0000195 src/test/SliceTest.cpp
196 src/test/SliceTestHelper.hpp
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000197 src/test/SplitTest.cpp
198 src/test/SplitTestHelper.hpp
James Warda8578102020-11-13 18:05:04 +0000199 src/test/TestUtils.hpp
Jan Eilers3812fbc2020-11-17 19:06:35 +0000200 src/test/TestUtils.cpp
James Wardf89964e2020-11-09 11:57:47 +0000201 src/test/TransposeTest.cpp
Kevin May8ab2d7a2021-05-07 09:32:51 +0100202 src/test/TransposeTestHelper.hpp
Narumol Prangnawarat7684b182021-08-12 14:48:15 +0100203 src/test/UnidirectionalSequenceLstmTest.cpp
204 src/test/UnidirectionalSequenceLstmTestHelper.hpp
Kevin May8ab2d7a2021-05-07 09:32:51 +0100205 src/test/UnpackTest.cpp
206 src/test/UnpackTestHelper.hpp)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100207
Keith Davis7c67fab2021-04-08 11:47:23 +0100208 # There's a known Android NDK bug which causes a subset of NeonLayerTests to
209 # fail. We'll exclude these tests in NeonLayerTests_NDK_Bug.cpp if we're doing
210 # a debug build and NDK is less than r21.
211 # https://github.com/android/ndk/issues/1135
212
213 # Default to always including these tests.
214 set(INCLUDE_NDK_BUG_TESTS "ON")
215 # Reconsider if we in a debug build.
216 string( TOLOWER ${CMAKE_BUILD_TYPE} BUILD_TYPE_LOWERCASE )
217 if ( NOT BUILD_TYPE_LOWERCASE STREQUAL "release" )
218 message("CMAKE:: BUILD TYPE IS ${CMAKE_BUILD_TYPE}")
219 # And NDK_VERSION has been set.
220 if ( DEFINED NDK_VERSION )
221 message("CMAKE:: NDK DEFINED")
222 # And the version is less than r21.
223 if ( ${NDK_VERSION} STRLESS "r21" )
224 message("CMAKE:: BUG TESTS OFF")
225 set(INCLUDE_NDK_BUG_TESTS "OFF")
226 endif()
227 endif()
228 endif()
229
230 if ( INCLUDE_NDK_BUG_TESTS STREQUAL "ON" )
231 list(APPEND armnnDelegate_unittest_sources
232 src/test/NeonDelegateTests_NDK_Issue.cpp
233 )
234 else()
235
236 endif()
237
Sadik Armagan4189cc52020-11-11 18:01:48 +0000238 add_executable(DelegateUnitTests ${armnnDelegate_unittest_sources})
Sadik Armagan3c24f432020-10-19 17:35:30 +0100239
Sadik Armagan4189cc52020-11-11 18:01:48 +0000240 # Add half library from armnn third-party libraries
Narumol Prangnawarat4cf0fe32020-12-18 16:13:06 +0000241 target_link_libraries(DelegateUnitTests PRIVATE thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100242
Finn Williamsbbbefec2020-11-25 14:32:42 +0000243 target_link_libraries(DelegateUnitTests PRIVATE armnnDelegate)
244 target_link_libraries(DelegateUnitTests PRIVATE Armnn::armnnUtils)
Sadik Armagan4189cc52020-11-11 18:01:48 +0000245
Finn Williamsbbbefec2020-11-25 14:32:42 +0000246 target_link_libraries(DelegateUnitTests PRIVATE tflite_headers)
247 target_link_libraries(DelegateUnitTests PRIVATE flatbuffer_headers)
Jim Flynnfca233e2021-09-23 12:16:53 +0100248 target_link_libraries(DelegateUnitTests PRIVATE profiling_library_headers)
Finn Williams6f9f9902020-11-13 13:23:15 +0000249
Sadik Armagan4189cc52020-11-11 18:01:48 +0000250endif()
Sadik Armagan3c24f432020-10-19 17:35:30 +0100251
252####################################################
253## Export targets
254set(armnn_delegate_export_targets)
255list(APPEND armnn_delegate_export_targets
Finn Williams6f9f9902020-11-13 13:23:15 +0000256 armnnDelegate
257 tflite_headers
Jan Eilersc837f1e2021-11-08 10:19:31 +0000258 flatbuffer_headers
259 profiling_library_headers
260 thirdparty_headers)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100261
262install(
263 TARGETS ${armnn_delegate_export_targets}
264 EXPORT armnn-delegate-targets
265 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
266 ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
267 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
268
269## Set export alias
270set_target_properties(armnnDelegate
271 PROPERTIES
272 EXPORT_NAME ArmnnDelegate)
273
274## Export target scrips
275install(
276 EXPORT armnn-delegate-targets
277 FILE ArmnnDelegateTargets.cmake
278 NAMESPACE ArmnnDelegate::
279 DESTINATION ${CMAKE_INSTALL_LIBDIR})
280
281## Create ArmnnDelegateConfig.cmake
282include(CMakePackageConfigHelpers)
283set(INSTALL_CONFIGDIR ${CMAKE_INSTALL_LIBDIR})
284message(STATUS "CMAKE_CURRENT_LIST_DIR ${CMAKE_CURRENT_LIST_DIR}" )
285message(STATUS "CMAKE_CURRENT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}" )
Finn Williamsbbbefec2020-11-25 14:32:42 +0000286SET(Armnn_DIR "${Armnn_DIR}")
287
Sadik Armagan3c24f432020-10-19 17:35:30 +0100288configure_package_config_file(
289 ${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/ArmnnDelegateConfig.cmake.in
290 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
Finn Williamsbbbefec2020-11-25 14:32:42 +0000291 INSTALL_DESTINATION ${INSTALL_CONFIGDIR}
292 PATH_VARS Armnn_DIR)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100293
294## Install ArmNN Delegate config file
295install(
296 FILES
297 ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateConfig.cmake
298 DESTINATION ${INSTALL_CONFIGDIR})
299
300## Export from build tree
301export(
302 EXPORT armnn-delegate-targets
303 FILE ${CMAKE_CURRENT_BINARY_DIR}/ArmnnDelegateTargets.cmake
304 NAMESPACE ArmnnDelegate::)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000305add_library(ArmnnDelegate::ArmnnDelegate ALIAS armnnDelegate)
306
Sadik Armagan3c24f432020-10-19 17:35:30 +0100307
Narumol Prangnawarat50c87d32020-11-09 18:42:11 +0000308####################################################