blob: 2d97899ce85f4c51d4fb0b6b6a372d160d3e74d3 [file] [log] [blame]
Pavel Macenauer59e057f2020-04-15 14:17:26 +00001#
Ryan OSheab5540542022-07-06 09:52:52 +01002# Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
Pavel Macenauer59e057f2020-04-15 14:17:26 +00003# Copyright 2020 NXP
4# SPDX-License-Identifier: MIT
5#
Jim Flynn870b96c2022-03-25 21:24:56 +00006
telsoa01c577f2c2018-08-31 09:22:23 +01007option(BUILD_ONNX_PARSER "Build Onnx parser" OFF)
telsoa014fcda012018-03-09 14:13:49 +00008option(BUILD_UNIT_TESTS "Build unit tests" ON)
9option(BUILD_TESTS "Build test applications" OFF)
Ryan OSheaa3dc95e2023-03-20 11:10:40 +000010option(ARMNN_SAMPLE_APPS_ENABLED "Build Sample ArmNN Applications" ON)
telsoa014fcda012018-03-09 14:13:49 +000011option(BUILD_FOR_COVERAGE "Use no optimization and output .gcno and .gcda files" OFF)
12option(ARMCOMPUTENEON "Build with ARM Compute NEON support" OFF)
13option(ARMCOMPUTECL "Build with ARM Compute OpenCL support" OFF)
Matteo Martincighf88663c2019-08-28 16:38:53 +010014option(ARMNNREF "Build with ArmNN reference support" ON)
Matthew Sloyand646b552022-10-10 12:42:16 +010015option(ARMNNTOSAREF "Build with TOSA reference support" OFF)
telsoa014fcda012018-03-09 14:13:49 +000016option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010017# options used for heap profiling and leak checking
surmeh013537c2c2018-05-18 16:31:43 +010018option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010019option(LEAK_CHECKING "Build with leak checking enabled" OFF)
surmeh013537c2c2018-05-18 16:31:43 +010020option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off)
telsoa01c577f2c2018-08-31 09:22:23 +010021# options used for tensorflow lite support
22option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000023option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF)
Éanna Ó Catháina563b922019-05-09 11:34:06 +010024option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000025option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010026option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF)
27option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
Matthew Sloyand646b552022-10-10 12:42:16 +010028option(TOSA_SERIALIZATION_LIB_ROOT "Location where the TOSA Serialization Library 'include' and 'lib' folders can be found" OFF)
29option(TOSA_REFERENCE_MODEL_ROOT "Location where the TOSA Reference Model 'include' and 'lib' folders can be found" OFF)
Matthew Sloyan67fd5262022-12-07 19:28:18 +000030option(TOSA_REFERENCE_MODEL_OUTPUT "TOSA Reference Model output is printed during layer support checks" ON)
Matteo Martincighe7d44982019-08-05 12:16:47 +010031option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010032option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010033option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000034option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Finn Williams2ed809c2020-04-20 21:21:07 +010035option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000036option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
37option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010038option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
39option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Teresa Charlinad1b3d72023-03-14 12:10:28 +000040option(BUILD_CLASSIC_DELEGATE "Build the Arm NN TfLite delegate" OFF)
41option(BUILD_OPAQUE_DELEGATE "Build the Arm NN TfLite Opaque delegate" OFF)
Jim Flynne1fdd282021-10-26 21:26:10 +010042option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
Jim Flynn870b96c2022-03-25 21:24:56 +000043option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF)
Jan Eilersa96489a2021-12-08 10:05:47 +000044option(BUILD_SHARED_LIBS "Determines if Armnn will be built statically or dynamically.
45 This is an experimental feature and not fully supported.
46 Only the ArmNN core and the Delegate can be built statically." ON)
Ryan OSheab5540542022-07-06 09:52:52 +010047option(EXECUTE_NETWORK_STATIC " This is a limited experimental build that is entirely static.
48 It currently only supports being set by changing the current CMake default options like so:
49 BUILD_TF_LITE_PARSER=1/0
50 BUILD_ARMNN_SERIALIZER=1/0
51 ARMCOMPUTENEON=1/0
52 ARMNNREF=1/0
53 ARMCOMPUTECL=0
54 BUILD_ONNX_PARSER=0
Teresa Charlinad1b3d72023-03-14 12:10:28 +000055 BUILD_CLASSIC_DELEGATE=0
56 BUILD_OPAQUE_DELEGATE=0
Ryan OSheab5540542022-07-06 09:52:52 +010057 BUILD_TIMELINE_DECODER=0
58 BUILD_BASE_PIPE_SERVER=0
59 BUILD_UNIT_TESTS=0
Ryan OSheaa3dc95e2023-03-20 11:10:40 +000060 ARMNN_SAMPLE_APPS_ENABLED=0
61 BUILD_SHARED_LIBS=0
62 BUILD_GATORD_MOCK=0
63 HEAP_PROFILING=0
64 LEAK_CHECKING=0" OFF)
telsoa014fcda012018-03-09 14:13:49 +000065
Teresa Charlinad1b3d72023-03-14 12:10:28 +000066if(BUILD_ARMNN_TFLITE_DELEGATE)
67 message(BUILD_ARMNN_TFLITE_DELEGATE option is deprecated, it will be removed in 24.02, please use BUILD_CLASSIC_DELEGATE instead)
68 set(BUILD_CLASSIC_DELEGATE 1)
69endif()
70
telsoa014fcda012018-03-09 14:13:49 +000071include(SelectLibraryConfigurations)
72
73set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010074if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
75 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
76 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000077 set(COMPILER_IS_GNU_LIKE 1)
78endif()
79
80# Enable CCache if available and not disabled
81option(USE_CCACHE "USE_CCACHE" ON)
82find_program(CCACHE_FOUND ccache)
83if(CCACHE_FOUND AND USE_CCACHE)
84 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
85 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
86endif()
87
88# Enable distcc if available and not disabled
89option(USE_DISTCC "USE_DISTCC" OFF)
90find_program(DISTCC_FOUND distcc)
91if(DISTCC_FOUND AND USE_DISTCC)
92 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
93 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
94endif()
95
96# Set to release configuration by default
97if(NOT CMAKE_BUILD_TYPE)
98 set(CMAKE_BUILD_TYPE "Release")
99endif()
100
101# Compiler flags that are always set
102set(CMAKE_POSITION_INDEPENDENT_CODE ON)
103if(COMPILER_IS_GNU_LIKE)
Ryan OShea238ecd92023-03-07 11:44:23 +0000104 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -Wall -Wextra -Werror -Wold-style-cast -Wno-missing-braces -Wconversion -Wsign-conversion")
Finn Williams3d626142021-08-11 13:04:32 +0100105 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
106 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
107 endif()
telsoa014fcda012018-03-09 14:13:49 +0000108elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Jim Flynn870b96c2022-03-25 21:24:56 +0000109 # Disable C4996 (use of deprecated identifier) due to
110 # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
Rob Hughesfc6bf052019-12-16 17:10:51 +0000111 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +0100112 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +0000113endif()
114if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
Keith Davisb8942bf2021-05-31 11:22:35 +0100115 # -lz is necessary for when building with ACL set with compressed kernels
116 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
117 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
telsoa014fcda012018-03-09 14:13:49 +0000118endif()
119
120# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +0100121set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +0000122if(COMPILER_IS_GNU_LIKE)
123 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
124elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
125 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
126endif()
127
128# Compiler flags for Debug builds
129if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +0100130 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +0000131elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +0100132 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +0000133 # Disable SAFESEH which is necessary for Edit and Continue to work
134 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
135 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
136endif()
137
138# Modify RelWithDebInfo so that NDEBUG isn't defined.
139# This enables asserts.
140if (COMPILER_IS_GNU_LIKE)
141 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
142elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
143 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
144endif()
145
146# Compiler flags for code coverage measurements
147if(BUILD_FOR_COVERAGE)
148 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
149 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
150 set(CMAKE_BUILD_TYPE "Debug")
151 endif()
152
153 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
154 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
155endif()
156
157if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
158 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
159endif()
160
161set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
162
Derek Lambertieac4adb2020-08-25 13:05:59 +0100163include(CMakeFindDependencyMacro)
164
Ryan OSheab5540542022-07-06 09:52:52 +0100165
166if(EXECUTE_NETWORK_STATIC)
167 add_definitions(-DARMNN_DISABLE_SOCKETS
Ryan OSheaa3dc95e2023-03-20 11:10:40 +0000168 -DARMNN_STUB_PROFILING
169 -DARMNN_DISABLE_DYNAMIC_BACKENDS)
170 set(ARMNN_SAMPLE_APPS_ENABLED 0)
171 set(DISABLE_DYNAMIC_BACKENDS 1)
172 set(BUILD_SHARED_LIBS 0)
Ryan OSheab5540542022-07-06 09:52:52 +0100173endif()
174
175if(BUILD_BARE_METAL)
176 add_definitions(-DARMNN_BUILD_BARE_METAL
Ryan OSheaa3dc95e2023-03-20 11:10:40 +0000177 -DARMNN_DISABLE_FILESYSTEM
178 -DARMNN_DISABLE_PROCESSES
179 -DARMNN_DISABLE_THREADS
180 -DARMNN_DISABLE_SOCKETS
181 -DARMNN_STUB_PROFILING
182 -DARMNN_DISABLE_DYNAMIC_BACKENDS)
183 set(DISABLE_DYNAMIC_BACKENDS 1)
184 set(BUILD_SHARED_LIBS 0)
Ryan OSheab5540542022-07-06 09:52:52 +0100185endif()
186
Jim Flynnbbfe6032020-07-20 16:57:44 +0100187if (NOT BUILD_PIPE_ONLY)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100188 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200189 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100190 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
191endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100192
Jim Flynnbbfe6032020-07-20 16:57:44 +0100193if (NOT BUILD_PIPE_ONLY)
194 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200195 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100196 include_directories(SYSTEM "${GHC_INCLUDE}")
197endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100198
Nikhil Raj23a6d002023-01-17 11:24:01 +0000199# JNI_BUILD has DBUILD_SHARED_LIBS set to 0 and not finding libs while building
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000200# hence added NOT BUILD_CLASSIC_DELEGATE/BUILD_OPAQUE_DELEGATE condition
201if(NOT BUILD_SHARED_LIBS AND NOT BUILD_CLASSIC_DELEGATE AND NOT BUILD_OPAQUE_DELEGATE)
Ryan OSheab5540542022-07-06 09:52:52 +0100202 set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
203endif()
204
telsoa014fcda012018-03-09 14:13:49 +0000205# pthread
Jim Flynn870b96c2022-03-25 21:24:56 +0000206if (NOT BUILD_BARE_METAL)
207find_package(Threads)
208endif()
telsoa014fcda012018-03-09 14:13:49 +0000209
Ryan OSheab5540542022-07-06 09:52:52 +0100210if (EXECUTE_NETWORK_STATIC)
211 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -pthread")
212endif()
213
telsoa014fcda012018-03-09 14:13:49 +0000214# Favour the protobuf passed on command line
Nikhil Raj5d955cf2021-04-19 16:59:48 +0100215if(BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000216 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
217 PATHS ${PROTOBUF_ROOT}/lib
218 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
219 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
220
221 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
222 PATHS ${PROTOBUF_ROOT}/lib
223 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
224 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
225
226 select_library_configurations(PROTOBUF)
227
228 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
229 PATHS ${PROTOBUF_ROOT}/include
230 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
231 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
232
233 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
234 add_definitions(-DPROTOBUF_USE_DLLS)
telsoa014fcda012018-03-09 14:13:49 +0000235
telsoa01c577f2c2018-08-31 09:22:23 +0100236 add_definitions(-DARMNN_ONNX_PARSER)
237
238 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
239
240 # C++ headers generated for onnx protobufs
241 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
242endif()
243
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000244if(BUILD_CLASSIC_DELEGATE)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000245 add_definitions(-DARMNN_TFLITE_DELEGATE)
246endif()
Matthew Sloyan9cb5bb62023-03-06 17:09:22 +0000247
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000248if(BUILD_OPAQUE_DELEGATE)
Matthew Sloyan9cb5bb62023-03-06 17:09:22 +0000249 add_definitions(-DARMNN_TFLITE_OPAQUE_DELEGATE)
250endif()
251
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100252# Flatbuffers support for TF Lite, Armnn Serializer or the TOSA backend.
253if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER OR ARMNNTOSAREF)
telsoa01c577f2c2018-08-31 09:22:23 +0100254 # verify we have a valid flatbuffers include path
255 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
256 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
257
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000258 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100259
260 find_library(FLATBUFFERS_LIBRARY
261 NAMES libflatbuffers.a flatbuffers
262 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
263
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000264 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000265endif()
266
267# Flatbuffers schema support for TF Lite
268if(BUILD_TF_LITE_PARSER)
269 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
270 schema_generated.h
271 HINTS ${TF_LITE_GENERATED_PATH})
272
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000273 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000274
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000275 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100276endif()
277
Kevin May43a799c2019-02-08 16:31:42 +0000278if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000279 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000280 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000281endif()
282
telsoa014fcda012018-03-09 14:13:49 +0000283include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000284include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000285
286# ARM Compute
287# Note that ARM Compute has a different folder layout depending on the branch but also on
288# whether it comes from a prepackaged archive (this is why we add several hints below)
289if(ARMCOMPUTENEON OR ARMCOMPUTECL)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000290 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000291 PATHS ${ARMCOMPUTE_ROOT}/include
292 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
293 PATHS ${ARMCOMPUTE_ROOT}
294 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000295 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
telsoa014fcda012018-03-09 14:13:49 +0000296 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
297
298 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
299 # e.g. if building clframework as a dependent cmake project)
300 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
301 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
302 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
303 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100304 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
305 # Default build directory for ComputeLibrary is under the root
306 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
307 endif()
308
telsoa014fcda012018-03-09 14:13:49 +0000309 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
310 PATHS ${ARMCOMPUTE_BUILD_DIR}
311 PATH_SUFFIXES "Debug"
312 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
313 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
314 PATHS ${ARMCOMPUTE_BUILD_DIR}
315 PATH_SUFFIXES "Release"
316 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
317 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static
318 PATHS ${ARMCOMPUTE_BUILD_DIR}
319 PATH_SUFFIXES "Debug"
320 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
321 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static
322 PATHS ${ARMCOMPUTE_BUILD_DIR}
323 PATH_SUFFIXES "Release"
324 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
325
326 # In case it wasn't there, try a default search (will work in cases where
327 # the library has been installed into a standard location)
328 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
329 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
330 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core-static)
331 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core-static)
332
Matthew Bentham6445cff2020-03-10 11:13:17 +0000333 # In case it wasn't there, try the dynamic libraries
334 # This case will get used in a linux setup where the Compute Library
335 # has been installed in a standard system library path as a dynamic library
336 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
337 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
338 find_library(ARMCOMPUTE_CORE_LIBRARY_DEBUG NAMES arm_compute_core)
339 find_library(ARMCOMPUTE_CORE_LIBRARY_RELEASE NAMES arm_compute_core)
340
telsoa014fcda012018-03-09 14:13:49 +0000341 set(ARMCOMPUTE_LIBRARIES
342 debug ${ARMCOMPUTE_LIBRARY_DEBUG} ${ARMCOMPUTE_CORE_LIBRARY_DEBUG}
343 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} ${ARMCOMPUTE_CORE_LIBRARY_RELEASE} )
344 endif()
345endif()
346
347# ARM Compute NEON backend
348if(ARMCOMPUTENEON)
349 # Add preprocessor definition for ARM Compute NEON
350 add_definitions(-DARMCOMPUTENEON_ENABLED)
351 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
352 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
353 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
354 endif()
355endif()
356
357# ARM Compute OpenCL backend
358if(ARMCOMPUTECL)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000359 # verify we have a valid flatbuffers include path
360 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
361 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
362
363 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
364
365 find_library(FLATBUFFERS_LIBRARY
366 NAMES libflatbuffers.a flatbuffers
367 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
368
369 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
370
telsoa014fcda012018-03-09 14:13:49 +0000371 # Always use Arm compute library OpenCL headers
Nikhil Raj407cddf2021-11-30 09:57:08 +0000372 find_path(OPENCL_INCLUDE CL/opencl.hpp
telsoa014fcda012018-03-09 14:13:49 +0000373 PATHS ${ARMCOMPUTE_ROOT}/include
374 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
375
Matthew Bentham3b72db02018-10-11 09:47:01 +0100376 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
377 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
378 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000379
Matthew Bentham416b41d2020-02-05 22:15:26 +0000380 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000381
382 # Add preprocessor definition for ARM Compute OpenCL
383 add_definitions(-DARMCOMPUTECL_ENABLED)
384
385 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
386endif()
387
388# Used by both Arm Compute backends, but should be added
389# to the search path after the system directories if necessary
390if(ARMCOMPUTENEON OR ARMCOMPUTECL)
391 find_path(HALF_INCLUDE half/half.hpp)
392 find_path(HALF_INCLUDE half/half.hpp
393 PATHS ${ARMCOMPUTE_ROOT}/include
394 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100395 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000396endif()
397
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100398# ArmNN reference backend
399if(ARMNNREF)
400 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100401endif()
402
Matthew Sloyanc01da452023-01-23 10:20:04 +0000403# If a backend requires TOSA common, add it here.
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100404if(ARMNNTOSAREF)
Matthew Sloyanc01da452023-01-23 10:20:04 +0000405 set(ARMNNTOSACOMMON ON)
406endif()
407
408if(ARMNNTOSACOMMON)
409 # Locate the includes for the TOSA serialization library as it is needed for TOSA common and TOSA backends.
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100410 message(STATUS "TOSA serialization library root set to ${TOSA_SERIALIZATION_LIB_ROOT}")
411
Matthew Sloyand646b552022-10-10 12:42:16 +0100412 find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h
413 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/include)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100414 message(STATUS "TOSA serialization library include directory located at: ${TOSA_SERIALIZATION_LIB_INCLUDE}")
415
416 find_library(TOSA_SERIALIZATION_LIB
Matthew Sloyand646b552022-10-10 12:42:16 +0100417 NAMES tosa_serialization_lib.a tosa_serialization_lib
418 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100419 message(STATUS "TOSA serialization library set to ${TOSA_SERIALIZATION_LIB}")
Matthew Sloyand646b552022-10-10 12:42:16 +0100420
Matthew Sloyanc01da452023-01-23 10:20:04 +0000421 # Include required headers for TOSA Serialization Library
422 include_directories(SYSTEM ${FLATBUFFERS_INCLUDE_PATH})
423 include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/half)
424 include_directories(SYSTEM ${TOSA_SERIALIZATION_LIB_INCLUDE})
425endif()
426
427# ArmNN TOSA reference backend
428if(ARMNNTOSAREF)
429 # Locate the includes for the TOSA Reference Model, which is specific to the TOSA Reference Backend.
Matthew Sloyand646b552022-10-10 12:42:16 +0100430 message(STATUS "TOSA Reference Model root set to ${TOSA_REFERENCE_MODEL_ROOT}")
431
432 find_path(TOSA_REFERENCE_MODEL_INCLUDE model_runner.h
433 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/include)
434 message(STATUS "TOSA Reference Model include directory located at: ${TOSA_REFERENCE_MODEL_INCLUDE}")
435
Matthew Sloyanc01da452023-01-23 10:20:04 +0000436 include_directories(SYSTEM ${TOSA_REFERENCE_MODEL_INCLUDE})
437
Matthew Sloyand646b552022-10-10 12:42:16 +0100438 find_library(TOSA_REFERENCE_MODEL_LIB
439 NAMES tosa_reference_model_lib.a tosa_reference_model_lib
440 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/lib /usr/local/lib /usr/lib)
441 message(STATUS "TOSA Reference Model set to ${TOSA_REFERENCE_MODEL_LIB}")
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000442
443 if(TOSA_REFERENCE_MODEL_OUTPUT)
444 add_definitions("-DTOSA_REFERENCE_MODEL_OUTPUT=1")
445 endif()
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100446endif()
447
Colm Donelanaa93d982020-06-28 08:16:46 +0100448# This is the root for the dynamic backend tests to search for dynamic
449# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100450add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100451
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000452# ArmNN dynamic backend
453if(DYNAMIC_BACKEND_PATHS)
454 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
455endif()
456
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000457if(SAMPLE_DYNAMIC_BACKEND)
458 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
459endif()
460
telsoa014fcda012018-03-09 14:13:49 +0000461# Streamline annotate
462if(PROFILING_BACKEND_STREAMLINE)
463 include_directories("${GATOR_ROOT}/annotate")
464 add_definitions(-DARMNN_STREAMLINE_ENABLED)
465endif()
466
telsoa01c577f2c2018-08-31 09:22:23 +0100467if(HEAP_PROFILING OR LEAK_CHECKING)
Kevin May1bbfaca2022-11-22 11:58:05 +0000468 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
469 PATHS ${GPERFTOOLS_ROOT}/include
470 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
471 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
472 find_library(GPERF_TOOLS_LIBRARY
473 NAMES tcmalloc_debug
474 HINTS ${GPERFTOOLS_ROOT}/lib)
475 link_directories(${GPERFTOOLS_ROOT}/lib)
surmeh013537c2c2018-05-18 16:31:43 +0100476
Kevin May1bbfaca2022-11-22 11:58:05 +0000477 link_libraries(${GPERF_TOOLS_LIBRARY})
478 if (HEAP_PROFILING)
479 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
480 endif()
481 if (LEAK_CHECKING)
482 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
surmeh013537c2c2018-05-18 16:31:43 +0100483 endif()
484else()
485 # Valgrind only works with gperftools version number <= 2.4
Ryan OSheaa3dc95e2023-03-20 11:10:40 +0000486 include(CheckIncludeFiles)
487 CHECK_INCLUDE_FILES("valgrind/memcheck.h" VALGRIND_FOUND)
Jim Flynn870b96c2022-03-25 21:24:56 +0000488endif()
surmeh013537c2c2018-05-18 16:31:43 +0100489
telsoa01c577f2c2018-08-31 09:22:23 +0100490if(NOT BUILD_TF_LITE_PARSER)
491 message(STATUS "Tensorflow Lite parser support is disabled")
492endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100493
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000494if(NOT BUILD_ARMNN_SERIALIZER)
495 message(STATUS "Armnn Serializer support is disabled")
496endif()
497
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000498if(NOT BUILD_PYTHON_WHL)
499 message(STATUS "PyArmNN wheel package is disabled")
500endif()
501
502if(NOT BUILD_PYTHON_SRC)
503 message(STATUS "PyArmNN source package is disabled")
504endif()
505
506if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
507 find_package(PythonInterp 3 REQUIRED)
508 if(NOT ${PYTHONINTERP_FOUND})
509 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
510 endif()
511
512 find_package(PythonLibs 3 REQUIRED)
513 if(NOT ${PYTHONLIBS_FOUND})
514 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
515 endif()
516
517 find_package(SWIG 4 REQUIRED)
518 if(NOT ${SWIG_FOUND})
519 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
520 endif()
521endif()
522
David Beck10b4dfd2018-09-19 12:03:20 +0100523# ArmNN source files required for all build options
524include_directories(SYSTEM third-party)