blob: b37417c7cf6b27c986508a43205ceff3d2e47e12 [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)
David Monahan8a570462023-11-22 13:24:25 +000014option(ARMCOMPUTEGPUFSA "Build with GPU Dynamic Fusion Backend" OFF)
Matteo Martincighf88663c2019-08-28 16:38:53 +010015option(ARMNNREF "Build with ArmNN reference support" ON)
Matthew Sloyand646b552022-10-10 12:42:16 +010016option(ARMNNTOSAREF "Build with TOSA reference support" OFF)
telsoa014fcda012018-03-09 14:13:49 +000017option(PROFILING_BACKEND_STREAMLINE "Forward the armNN profiling events to DS-5/Streamline as annotations" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010018# options used for heap profiling and leak checking
surmeh013537c2c2018-05-18 16:31:43 +010019option(HEAP_PROFILING "Build with heap profiling enabled" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010020option(LEAK_CHECKING "Build with leak checking enabled" OFF)
surmeh013537c2c2018-05-18 16:31:43 +010021option(GPERFTOOLS_ROOT "Location where the gperftools 'include' and 'lib' folders to be found" Off)
telsoa01c577f2c2018-08-31 09:22:23 +010022# options used for tensorflow lite support
23option(BUILD_TF_LITE_PARSER "Build Tensorflow Lite parser" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000024option(BUILD_ARMNN_SERIALIZER "Build Armnn Serializer" OFF)
Éanna Ó Catháina563b922019-05-09 11:34:06 +010025option(BUILD_ACCURACY_TOOL "Build Accuracy Tool" OFF)
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +000026option(FLATC_DIR "Path to Flatbuffers compiler" OFF)
telsoa01c577f2c2018-08-31 09:22:23 +010027option(TF_LITE_GENERATED_PATH "Tensorflow lite generated C++ schema location" OFF)
28option(FLATBUFFERS_ROOT "Location where the flatbuffers 'include' and 'lib' folders to be found" Off)
Matthew Sloyand646b552022-10-10 12:42:16 +010029option(TOSA_SERIALIZATION_LIB_ROOT "Location where the TOSA Serialization Library 'include' and 'lib' folders can be found" OFF)
30option(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 +000031option(TOSA_REFERENCE_MODEL_OUTPUT "TOSA Reference Model output is printed during layer support checks" ON)
Matteo Martincighe7d44982019-08-05 12:16:47 +010032option(DYNAMIC_BACKEND_PATHS "Colon seperated list of paths where to load the dynamic backends from" "")
Colm Donelan0dbe00a2020-06-03 08:00:28 +010033option(SAMPLE_DYNAMIC_BACKEND "Include the sample dynamic backend and its tests in the build" OFF)
Colm Donelana21620d2019-10-11 13:09:49 +010034option(BUILD_GATORD_MOCK "Build the Gatord simulator for external profiling testing." ON)
Sadik Armagan6f86b692020-03-09 11:04:32 +000035option(BUILD_TIMELINE_DECODER "Build the Timeline Decoder for external profiling." ON)
Finn Williams2ed809c2020-04-20 21:21:07 +010036option(BUILD_BASE_PIPE_SERVER "Build the server to handle external profiling pipe traffic" ON)
Pavel Macenauer59e057f2020-04-15 14:17:26 +000037option(BUILD_PYTHON_WHL "Build Python wheel package" OFF)
38option(BUILD_PYTHON_SRC "Build Python source package" OFF)
Jim Flynnbbfe6032020-07-20 16:57:44 +010039option(BUILD_STATIC_PIPE_LIBS "Build Static PIPE libraries" OFF)
40option(BUILD_PIPE_ONLY "Build the PIPE libraries only" OFF)
Teresa Charlinad1b3d72023-03-14 12:10:28 +000041option(BUILD_CLASSIC_DELEGATE "Build the Arm NN TfLite delegate" OFF)
42option(BUILD_OPAQUE_DELEGATE "Build the Arm NN TfLite Opaque delegate" OFF)
Jim Flynne1fdd282021-10-26 21:26:10 +010043option(BUILD_MEMORY_STRATEGY_BENCHMARK "Build the MemoryBenchmark" OFF)
Jim Flynn870b96c2022-03-25 21:24:56 +000044option(BUILD_BARE_METAL "Disable features requiring operating system support" OFF)
Jan Eilersa96489a2021-12-08 10:05:47 +000045option(BUILD_SHARED_LIBS "Determines if Armnn will be built statically or dynamically.
46 This is an experimental feature and not fully supported.
47 Only the ArmNN core and the Delegate can be built statically." ON)
Ryan OSheab5540542022-07-06 09:52:52 +010048option(EXECUTE_NETWORK_STATIC " This is a limited experimental build that is entirely static.
49 It currently only supports being set by changing the current CMake default options like so:
50 BUILD_TF_LITE_PARSER=1/0
51 BUILD_ARMNN_SERIALIZER=1/0
52 ARMCOMPUTENEON=1/0
53 ARMNNREF=1/0
54 ARMCOMPUTECL=0
55 BUILD_ONNX_PARSER=0
Teresa Charlinad1b3d72023-03-14 12:10:28 +000056 BUILD_CLASSIC_DELEGATE=0
57 BUILD_OPAQUE_DELEGATE=0
Ryan OSheab5540542022-07-06 09:52:52 +010058 BUILD_TIMELINE_DECODER=0
59 BUILD_BASE_PIPE_SERVER=0
60 BUILD_UNIT_TESTS=0
Ryan OSheaa3dc95e2023-03-20 11:10:40 +000061 ARMNN_SAMPLE_APPS_ENABLED=0
62 BUILD_SHARED_LIBS=0
63 BUILD_GATORD_MOCK=0
64 HEAP_PROFILING=0
65 LEAK_CHECKING=0" OFF)
telsoa014fcda012018-03-09 14:13:49 +000066
Teresa Charlinad1b3d72023-03-14 12:10:28 +000067if(BUILD_ARMNN_TFLITE_DELEGATE)
68 message(BUILD_ARMNN_TFLITE_DELEGATE option is deprecated, it will be removed in 24.02, please use BUILD_CLASSIC_DELEGATE instead)
69 set(BUILD_CLASSIC_DELEGATE 1)
70endif()
71
telsoa014fcda012018-03-09 14:13:49 +000072include(SelectLibraryConfigurations)
73
74set(COMPILER_IS_GNU_LIKE 0)
Jim Flynn82262f52020-07-16 11:23:45 +010075if(${CMAKE_CXX_COMPILER_ID} STREQUAL GNU OR
76 ${CMAKE_CXX_COMPILER_ID} STREQUAL Clang OR
77 ${CMAKE_CXX_COMPILER_ID} STREQUAL AppleClang)
telsoa014fcda012018-03-09 14:13:49 +000078 set(COMPILER_IS_GNU_LIKE 1)
79endif()
80
81# Enable CCache if available and not disabled
82option(USE_CCACHE "USE_CCACHE" ON)
83find_program(CCACHE_FOUND ccache)
84if(CCACHE_FOUND AND USE_CCACHE)
85 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
86 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "CCACHE_CPP2=yes ${rule_launch_compile} ccache")
87endif()
88
89# Enable distcc if available and not disabled
90option(USE_DISTCC "USE_DISTCC" OFF)
91find_program(DISTCC_FOUND distcc)
92if(DISTCC_FOUND AND USE_DISTCC)
93 get_property(rule_launch_compile DIRECTORY PROPERTY RULE_LAUNCH_COMPILE)
94 set_property(DIRECTORY PROPERTY RULE_LAUNCH_COMPILE "${rule_launch_compile} distcc")
95endif()
96
97# Set to release configuration by default
98if(NOT CMAKE_BUILD_TYPE)
99 set(CMAKE_BUILD_TYPE "Release")
100endif()
101
102# Compiler flags that are always set
103set(CMAKE_POSITION_INDEPENDENT_CODE ON)
104if(COMPILER_IS_GNU_LIKE)
Ryan OShea238ecd92023-03-07 11:44:23 +0000105 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 +0100106 if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
107 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-psabi")
108 endif()
telsoa014fcda012018-03-09 14:13:49 +0000109elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Jim Flynn870b96c2022-03-25 21:24:56 +0000110 # Disable C4996 (use of deprecated identifier) due to
111 # https://developercommunity.visualstudio.com/content/problem/252574/deprecated-compilation-warning-for-virtual-overrid.html
Rob Hughesfc6bf052019-12-16 17:10:51 +0000112 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc /MP /wd4996")
Rob Hughesbc873d22020-05-20 13:11:37 +0100113 add_definitions(-DNO_STRICT=1)
telsoa014fcda012018-03-09 14:13:49 +0000114endif()
115if("${CMAKE_SYSTEM_NAME}" STREQUAL Android)
Keith Davisb8942bf2021-05-31 11:22:35 +0100116 # -lz is necessary for when building with ACL set with compressed kernels
117 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -llog -lz")
118 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -llog -lz")
telsoa014fcda012018-03-09 14:13:49 +0000119endif()
120
121# Compiler flags for Release builds
Matthew Benthame30054f2019-06-24 13:10:54 +0100122set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -DNDEBUG")
telsoa014fcda012018-03-09 14:13:49 +0000123if(COMPILER_IS_GNU_LIKE)
124 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
125elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
126 set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD /O2")
127endif()
128
129# Compiler flags for Debug builds
130if(COMPILER_IS_GNU_LIKE)
Matthew Benthame30054f2019-06-24 13:10:54 +0100131 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -O0")
telsoa014fcda012018-03-09 14:13:49 +0000132elseif(${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
Matthew Benthame30054f2019-06-24 13:10:54 +0100133 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd /ZI /Od")
telsoa014fcda012018-03-09 14:13:49 +0000134 # Disable SAFESEH which is necessary for Edit and Continue to work
135 set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
136 set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} /SAFESEH:NO")
137endif()
138
139# Modify RelWithDebInfo so that NDEBUG isn't defined.
140# This enables asserts.
141if (COMPILER_IS_GNU_LIKE)
142 string(REPLACE "-DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
143elseif (${CMAKE_CXX_COMPILER_ID} STREQUAL MSVC)
144 string(REPLACE "/DNDEBUG" "" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
145endif()
146
147# Compiler flags for code coverage measurements
148if(BUILD_FOR_COVERAGE)
149 if(NOT CMAKE_BUILD_TYPE EQUAL "Debug")
150 message(WARNING "BUILD_FOR_COVERAGE set so forcing to Debug build")
151 set(CMAKE_BUILD_TYPE "Debug")
152 endif()
153
154 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --coverage")
155 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
156endif()
157
158if(BUILD_FOR_COVERAGE AND NOT BUILD_UNIT_TESTS)
159 message(WARNING "BUILD_FOR_COVERAGE set but not BUILD_UNIT_TESTS, so code coverage will not be able to run")
160endif()
161
162set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules ${CMAKE_MODULE_PATH})
163
Derek Lambertieac4adb2020-08-25 13:05:59 +0100164include(CMakeFindDependencyMacro)
165
Ryan OSheab5540542022-07-06 09:52:52 +0100166
167if(EXECUTE_NETWORK_STATIC)
168 add_definitions(-DARMNN_DISABLE_SOCKETS
Ryan OSheaa3dc95e2023-03-20 11:10:40 +0000169 -DARMNN_STUB_PROFILING
170 -DARMNN_DISABLE_DYNAMIC_BACKENDS)
171 set(ARMNN_SAMPLE_APPS_ENABLED 0)
172 set(DISABLE_DYNAMIC_BACKENDS 1)
173 set(BUILD_SHARED_LIBS 0)
Ryan OSheab5540542022-07-06 09:52:52 +0100174endif()
175
176if(BUILD_BARE_METAL)
177 add_definitions(-DARMNN_BUILD_BARE_METAL
Ryan OSheaa3dc95e2023-03-20 11:10:40 +0000178 -DARMNN_DISABLE_FILESYSTEM
179 -DARMNN_DISABLE_PROCESSES
180 -DARMNN_DISABLE_THREADS
181 -DARMNN_DISABLE_SOCKETS
182 -DARMNN_STUB_PROFILING
183 -DARMNN_DISABLE_DYNAMIC_BACKENDS)
184 set(DISABLE_DYNAMIC_BACKENDS 1)
185 set(BUILD_SHARED_LIBS 0)
Ryan OSheab5540542022-07-06 09:52:52 +0100186endif()
187
Jim Flynnbbfe6032020-07-20 16:57:44 +0100188if (NOT BUILD_PIPE_ONLY)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100189 # cxxopts (Alternative to boost::program_options)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200190 find_path(CXXOPTS_INCLUDE cxxopts/cxxopts.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100191 include_directories(SYSTEM "${CXXOPTS_INCLUDE}")
192endif()
Jan Eilers7e989832020-06-19 11:47:21 +0100193
Jim Flynnbbfe6032020-07-20 16:57:44 +0100194if (NOT BUILD_PIPE_ONLY)
195 # ghc (Alternative to boost::filesystem)
Vincent ABRIOU54940192020-09-03 13:02:43 +0200196 find_path(GHC_INCLUDE ghc/filesystem.hpp PATHS third-party NO_CMAKE_FIND_ROOT_PATH)
Jim Flynnbbfe6032020-07-20 16:57:44 +0100197 include_directories(SYSTEM "${GHC_INCLUDE}")
198endif()
Jan Eilers307fd342020-06-23 14:16:04 +0100199
Nikhil Raj23a6d002023-01-17 11:24:01 +0000200# JNI_BUILD has DBUILD_SHARED_LIBS set to 0 and not finding libs while building
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000201# hence added NOT BUILD_CLASSIC_DELEGATE/BUILD_OPAQUE_DELEGATE condition
202if(NOT BUILD_SHARED_LIBS AND NOT BUILD_CLASSIC_DELEGATE AND NOT BUILD_OPAQUE_DELEGATE)
Ryan OSheab5540542022-07-06 09:52:52 +0100203 set(CMAKE_FIND_LIBRARY_SUFFIXES .a .lib)
204endif()
205
telsoa014fcda012018-03-09 14:13:49 +0000206# pthread
Jim Flynn870b96c2022-03-25 21:24:56 +0000207if (NOT BUILD_BARE_METAL)
208find_package(Threads)
209endif()
telsoa014fcda012018-03-09 14:13:49 +0000210
Ryan OSheab5540542022-07-06 09:52:52 +0100211if (EXECUTE_NETWORK_STATIC)
212 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc -static -pthread")
213endif()
214
telsoa014fcda012018-03-09 14:13:49 +0000215# Favour the protobuf passed on command line
Nikhil Raj5d955cf2021-04-19 16:59:48 +0100216if(BUILD_ONNX_PARSER)
telsoa014fcda012018-03-09 14:13:49 +0000217 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd"
218 PATHS ${PROTOBUF_ROOT}/lib
219 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
220 find_library(PROTOBUF_LIBRARY_DEBUG NAMES "protobufd")
221
222 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf"
223 PATHS ${PROTOBUF_ROOT}/lib
224 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
225 find_library(PROTOBUF_LIBRARY_RELEASE NAMES "protobuf")
226
227 select_library_configurations(PROTOBUF)
228
229 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h"
230 PATHS ${PROTOBUF_ROOT}/include
231 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
232 find_path(PROTOBUF_INCLUDE_DIRS "google/protobuf/message.h")
233
234 include_directories(SYSTEM "${PROTOBUF_INCLUDE_DIRS}")
235 add_definitions(-DPROTOBUF_USE_DLLS)
telsoa014fcda012018-03-09 14:13:49 +0000236
telsoa01c577f2c2018-08-31 09:22:23 +0100237 add_definitions(-DARMNN_ONNX_PARSER)
238
239 find_path(ONNX_GENERATED_SOURCES "onnx/onnx.pb.cc")
240
241 # C++ headers generated for onnx protobufs
242 include_directories(SYSTEM "${ONNX_GENERATED_SOURCES}")
243endif()
244
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000245if(BUILD_CLASSIC_DELEGATE)
Sadik Armagan5d03e312020-11-17 16:43:56 +0000246 add_definitions(-DARMNN_TFLITE_DELEGATE)
247endif()
Matthew Sloyan9cb5bb62023-03-06 17:09:22 +0000248
Teresa Charlinad1b3d72023-03-14 12:10:28 +0000249if(BUILD_OPAQUE_DELEGATE)
Matthew Sloyan9cb5bb62023-03-06 17:09:22 +0000250 add_definitions(-DARMNN_TFLITE_OPAQUE_DELEGATE)
251endif()
252
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100253# Flatbuffers support for TF Lite, Armnn Serializer or the TOSA backend.
254if(BUILD_TF_LITE_PARSER OR BUILD_ARMNN_SERIALIZER OR ARMNNTOSAREF)
telsoa01c577f2c2018-08-31 09:22:23 +0100255 # verify we have a valid flatbuffers include path
256 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
257 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
258
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000259 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
telsoa01c577f2c2018-08-31 09:22:23 +0100260
261 find_library(FLATBUFFERS_LIBRARY
262 NAMES libflatbuffers.a flatbuffers
263 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
264
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000265 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000266endif()
267
268# Flatbuffers schema support for TF Lite
269if(BUILD_TF_LITE_PARSER)
270 find_path(TF_LITE_SCHEMA_INCLUDE_PATH
271 schema_generated.h
272 HINTS ${TF_LITE_GENERATED_PATH})
273
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000274 message(STATUS "Tf Lite generated header found at: ${TF_LITE_SCHEMA_INCLUDE_PATH}")
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000275
Matthew Benthamd1ae3a62019-02-22 17:30:32 +0000276 add_definitions(-DARMNN_TF_LITE_PARSER)
telsoa01c577f2c2018-08-31 09:22:23 +0100277endif()
278
Kevin May43a799c2019-02-08 16:31:42 +0000279if(BUILD_ARMNN_SERIALIZER)
Kevin May43a799c2019-02-08 16:31:42 +0000280 add_definitions(-DARMNN_SERIALIZER)
Matthew Bentham268509a2019-02-25 13:58:24 +0000281 add_definitions(-DARMNN_SERIALIZER_SCHEMA_PATH="${CMAKE_CURRENT_SOURCE_DIR}/src/armnnSerializer/ArmnnSchema.fbs")
Kevin May43a799c2019-02-08 16:31:42 +0000282endif()
283
telsoa014fcda012018-03-09 14:13:49 +0000284include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
Sadik Armagana97a0be2020-03-03 10:44:56 +0000285include_directories(${CMAKE_CURRENT_SOURCE_DIR}/profiling)
telsoa014fcda012018-03-09 14:13:49 +0000286
287# ARM Compute
288# Note that ARM Compute has a different folder layout depending on the branch but also on
289# whether it comes from a prepackaged archive (this is why we add several hints below)
David Monahan8a570462023-11-22 13:24:25 +0000290if(ARMCOMPUTENEON OR ARMCOMPUTECL OR ARMCOMPUTEGPUFSA)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000291 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h
telsoa014fcda012018-03-09 14:13:49 +0000292 PATHS ${ARMCOMPUTE_ROOT}/include
293 PATHS ${ARMCOMPUTE_ROOT}/applications/arm_compute
294 PATHS ${ARMCOMPUTE_ROOT}
295 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
Francis Murtagh82490ee2020-11-04 13:33:41 +0000296 find_path(ARMCOMPUTE_INCLUDE arm_compute/core/CL/OpenCL.h)
telsoa014fcda012018-03-09 14:13:49 +0000297 include_directories(SYSTEM "${ARMCOMPUTE_INCLUDE}")
298
299 # Find the Arm Compute libraries if not already specified (the user may have already defined this in advance,
300 # e.g. if building clframework as a dependent cmake project)
301 if (NOT DEFINED ARMCOMPUTE_LIBRARIES)
302 # We link to the static variant so that customers don't need to find and build a compatible version of clframework.
303 # First try the folders specified ARMCOMPUTE_BUILD_DIR (with PATH_SUFFIXES for
304 # Windows builds)
Matthew Bentham2624dd72020-05-20 10:44:18 +0100305 if ((NOT DEFINED ARMCOMPUTE_BUILD_DIR) AND (DEFINED ARMCOMPUTE_ROOT))
306 # Default build directory for ComputeLibrary is under the root
307 set(ARMCOMPUTE_BUILD_DIR ${ARMCOMPUTE_ROOT}/build)
308 endif()
309
telsoa014fcda012018-03-09 14:13:49 +0000310 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static
311 PATHS ${ARMCOMPUTE_BUILD_DIR}
312 PATH_SUFFIXES "Debug"
313 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
314 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static
315 PATHS ${ARMCOMPUTE_BUILD_DIR}
316 PATH_SUFFIXES "Release"
317 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa014fcda012018-03-09 14:13:49 +0000318
319 # In case it wasn't there, try a default search (will work in cases where
320 # the library has been installed into a standard location)
321 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute-static)
322 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute-static)
telsoa014fcda012018-03-09 14:13:49 +0000323
Matthew Bentham6445cff2020-03-10 11:13:17 +0000324 # In case it wasn't there, try the dynamic libraries
325 # This case will get used in a linux setup where the Compute Library
326 # has been installed in a standard system library path as a dynamic library
327 find_library(ARMCOMPUTE_LIBRARY_DEBUG NAMES arm_compute)
328 find_library(ARMCOMPUTE_LIBRARY_RELEASE NAMES arm_compute)
Matthew Bentham6445cff2020-03-10 11:13:17 +0000329
telsoa014fcda012018-03-09 14:13:49 +0000330 set(ARMCOMPUTE_LIBRARIES
Nikhil Raj4179c6a2023-11-24 10:19:40 +0000331 debug ${ARMCOMPUTE_LIBRARY_DEBUG}
332 optimized ${ARMCOMPUTE_LIBRARY_RELEASE} )
telsoa014fcda012018-03-09 14:13:49 +0000333 endif()
334endif()
335
336# ARM Compute NEON backend
337if(ARMCOMPUTENEON)
338 # Add preprocessor definition for ARM Compute NEON
339 add_definitions(-DARMCOMPUTENEON_ENABLED)
340 # The ARM Compute headers contain some NEON intrinsics, so we need to build armnn with NEON support on armv7
341 if(${CMAKE_SYSTEM_PROCESSOR} MATCHES armv7 AND COMPILER_IS_GNU_LIKE)
342 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfpu=neon")
343 endif()
344endif()
345
346# ARM Compute OpenCL backend
David Monahan8a570462023-11-22 13:24:25 +0000347if(ARMCOMPUTECL OR ARMCOMPUTEGPUFSA)
Nikhil Rajb55d3662021-02-11 14:49:19 +0000348 # verify we have a valid flatbuffers include path
349 find_path(FLATBUFFERS_INCLUDE_PATH flatbuffers/flatbuffers.h
350 HINTS ${FLATBUFFERS_ROOT}/include /usr/local/include /usr/include)
351
352 message(STATUS "Flatbuffers headers are located at: ${FLATBUFFERS_INCLUDE_PATH}")
353
354 find_library(FLATBUFFERS_LIBRARY
355 NAMES libflatbuffers.a flatbuffers
356 HINTS ${FLATBUFFERS_ROOT}/lib /usr/local/lib /usr/lib)
357
358 message(STATUS "Flatbuffers library located at: ${FLATBUFFERS_LIBRARY}")
359
telsoa014fcda012018-03-09 14:13:49 +0000360 # Always use Arm compute library OpenCL headers
Nikhil Raj407cddf2021-11-30 09:57:08 +0000361 find_path(OPENCL_INCLUDE CL/opencl.hpp
telsoa014fcda012018-03-09 14:13:49 +0000362 PATHS ${ARMCOMPUTE_ROOT}/include
363 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
364
Matthew Bentham3b72db02018-10-11 09:47:01 +0100365 # Link against libOpenCL in opencl-1.2-stubs, but don't search there at runtime
366 link_libraries(-L${ARMCOMPUTE_BUILD_DIR}/opencl-1.2-stubs)
367 set(OPENCL_LIBRARIES OpenCL)
telsoa014fcda012018-03-09 14:13:49 +0000368
Matthew Bentham416b41d2020-02-05 22:15:26 +0000369 include_directories(SYSTEM ${OPENCL_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000370
David Monahan8a570462023-11-22 13:24:25 +0000371 if(ARMCOMPUTECL)
372 # Add preprocessor definition for ARM Compute OpenCL
373 add_definitions(-DARMCOMPUTECL_ENABLED)
374 endif()
375
376 if(ARMCOMPUTEGPUFSA)
377 # Add preprocessor definition for ARM Compute OpenCL with Fusion
378 add_definitions(-DARMCOMPUTEGPUFSA_ENABLED)
379 endif()
telsoa014fcda012018-03-09 14:13:49 +0000380
381 set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DARM_COMPUTE_DEBUG_ENABLED")
382endif()
383
384# Used by both Arm Compute backends, but should be added
385# to the search path after the system directories if necessary
David Monahan8a570462023-11-22 13:24:25 +0000386if(ARMCOMPUTENEON OR ARMCOMPUTECL OR ARMCOMPUTEGPUFSA)
telsoa014fcda012018-03-09 14:13:49 +0000387 find_path(HALF_INCLUDE half/half.hpp)
388 find_path(HALF_INCLUDE half/half.hpp
389 PATHS ${ARMCOMPUTE_ROOT}/include
390 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
telsoa01c577f2c2018-08-31 09:22:23 +0100391 include_directories(SYSTEM ${HALF_INCLUDE})
telsoa014fcda012018-03-09 14:13:49 +0000392endif()
393
Matteo Martincighdb16dd32019-08-27 16:41:11 +0100394# ArmNN reference backend
395if(ARMNNREF)
396 add_definitions(-DARMNNREF_ENABLED)
Matteo Martincighe67edb22019-08-14 14:05:46 +0100397endif()
398
Matthew Sloyanc01da452023-01-23 10:20:04 +0000399# If a backend requires TOSA common, add it here.
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100400if(ARMNNTOSAREF)
Matthew Sloyanc01da452023-01-23 10:20:04 +0000401 set(ARMNNTOSACOMMON ON)
402endif()
403
404if(ARMNNTOSACOMMON)
405 # 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 +0100406 message(STATUS "TOSA serialization library root set to ${TOSA_SERIALIZATION_LIB_ROOT}")
407
Matthew Sloyand646b552022-10-10 12:42:16 +0100408 find_path(TOSA_SERIALIZATION_LIB_INCLUDE tosa_serialization_handler.h
409 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/include)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100410 message(STATUS "TOSA serialization library include directory located at: ${TOSA_SERIALIZATION_LIB_INCLUDE}")
411
412 find_library(TOSA_SERIALIZATION_LIB
Matthew Sloyand646b552022-10-10 12:42:16 +0100413 NAMES tosa_serialization_lib.a tosa_serialization_lib
414 HINTS ${TOSA_SERIALIZATION_LIB_ROOT}/lib /usr/local/lib /usr/lib)
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100415 message(STATUS "TOSA serialization library set to ${TOSA_SERIALIZATION_LIB}")
Matthew Sloyand646b552022-10-10 12:42:16 +0100416
Matthew Sloyanc01da452023-01-23 10:20:04 +0000417 # Include required headers for TOSA Serialization Library
418 include_directories(SYSTEM ${FLATBUFFERS_INCLUDE_PATH})
419 include_directories(SYSTEM ${PROJECT_SOURCE_DIR}/third-party/half)
420 include_directories(SYSTEM ${TOSA_SERIALIZATION_LIB_INCLUDE})
421endif()
422
423# ArmNN TOSA reference backend
424if(ARMNNTOSAREF)
425 # Locate the includes for the TOSA Reference Model, which is specific to the TOSA Reference Backend.
Matthew Sloyand646b552022-10-10 12:42:16 +0100426 message(STATUS "TOSA Reference Model root set to ${TOSA_REFERENCE_MODEL_ROOT}")
427
428 find_path(TOSA_REFERENCE_MODEL_INCLUDE model_runner.h
429 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/include)
430 message(STATUS "TOSA Reference Model include directory located at: ${TOSA_REFERENCE_MODEL_INCLUDE}")
431
Matthew Sloyanc01da452023-01-23 10:20:04 +0000432 include_directories(SYSTEM ${TOSA_REFERENCE_MODEL_INCLUDE})
433
Matthew Sloyand646b552022-10-10 12:42:16 +0100434 find_library(TOSA_REFERENCE_MODEL_LIB
435 NAMES tosa_reference_model_lib.a tosa_reference_model_lib
436 HINTS ${TOSA_REFERENCE_MODEL_ROOT}/lib /usr/local/lib /usr/lib)
437 message(STATUS "TOSA Reference Model set to ${TOSA_REFERENCE_MODEL_LIB}")
Matthew Sloyan67fd5262022-12-07 19:28:18 +0000438
439 if(TOSA_REFERENCE_MODEL_OUTPUT)
440 add_definitions("-DTOSA_REFERENCE_MODEL_OUTPUT=1")
441 endif()
Cathal Corbett9c9d5b92022-08-17 17:30:16 +0100442endif()
443
Colm Donelanaa93d982020-06-28 08:16:46 +0100444# This is the root for the dynamic backend tests to search for dynamic
445# backends. By default it will be the project build directory.
Rob Hughes35c31c02020-08-17 15:47:20 +0100446add_definitions(-DDYNAMIC_BACKEND_BUILD_DIR="${PROJECT_BINARY_DIR}")
Colm Donelanaa93d982020-06-28 08:16:46 +0100447
Narumol Prangnawarat60a20fb2019-12-09 17:24:41 +0000448# ArmNN dynamic backend
449if(DYNAMIC_BACKEND_PATHS)
450 add_definitions(-DARMNN_DYNAMIC_BACKEND_ENABLED)
451endif()
452
Narumol Prangnawarat867eba52020-02-03 12:29:56 +0000453if(SAMPLE_DYNAMIC_BACKEND)
454 add_definitions(-DSAMPLE_DYNAMIC_BACKEND_ENABLED)
455endif()
456
telsoa014fcda012018-03-09 14:13:49 +0000457# Streamline annotate
458if(PROFILING_BACKEND_STREAMLINE)
459 include_directories("${GATOR_ROOT}/annotate")
460 add_definitions(-DARMNN_STREAMLINE_ENABLED)
461endif()
462
telsoa01c577f2c2018-08-31 09:22:23 +0100463if(HEAP_PROFILING OR LEAK_CHECKING)
Kevin May1bbfaca2022-11-22 11:58:05 +0000464 find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
465 PATHS ${GPERFTOOLS_ROOT}/include
466 NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH)
467 include_directories(SYSTEM "${HEAP_PROFILER_INCLUDE}")
468 find_library(GPERF_TOOLS_LIBRARY
469 NAMES tcmalloc_debug
470 HINTS ${GPERFTOOLS_ROOT}/lib)
471 link_directories(${GPERFTOOLS_ROOT}/lib)
surmeh013537c2c2018-05-18 16:31:43 +0100472
Kevin May1bbfaca2022-11-22 11:58:05 +0000473 link_libraries(${GPERF_TOOLS_LIBRARY})
474 if (HEAP_PROFILING)
475 add_definitions("-DARMNN_HEAP_PROFILING_ENABLED=1")
476 endif()
477 if (LEAK_CHECKING)
478 add_definitions("-DARMNN_LEAK_CHECKING_ENABLED=1")
surmeh013537c2c2018-05-18 16:31:43 +0100479 endif()
480else()
481 # Valgrind only works with gperftools version number <= 2.4
Ryan OSheaa3dc95e2023-03-20 11:10:40 +0000482 include(CheckIncludeFiles)
483 CHECK_INCLUDE_FILES("valgrind/memcheck.h" VALGRIND_FOUND)
Jim Flynn870b96c2022-03-25 21:24:56 +0000484endif()
surmeh013537c2c2018-05-18 16:31:43 +0100485
telsoa01c577f2c2018-08-31 09:22:23 +0100486if(NOT BUILD_TF_LITE_PARSER)
487 message(STATUS "Tensorflow Lite parser support is disabled")
488endif()
David Beck10b4dfd2018-09-19 12:03:20 +0100489
Nattapat Chaimanowong949f1252019-01-31 15:36:39 +0000490if(NOT BUILD_ARMNN_SERIALIZER)
491 message(STATUS "Armnn Serializer support is disabled")
492endif()
493
Pavel Macenauer59e057f2020-04-15 14:17:26 +0000494if(NOT BUILD_PYTHON_WHL)
495 message(STATUS "PyArmNN wheel package is disabled")
496endif()
497
498if(NOT BUILD_PYTHON_SRC)
499 message(STATUS "PyArmNN source package is disabled")
500endif()
501
502if(BUILD_PYTHON_WHL OR BUILD_PYTHON_SRC)
503 find_package(PythonInterp 3 REQUIRED)
504 if(NOT ${PYTHONINTERP_FOUND})
505 message(FATAL_ERROR "Python 3.x required to build PyArmNN, but not found")
506 endif()
507
508 find_package(PythonLibs 3 REQUIRED)
509 if(NOT ${PYTHONLIBS_FOUND})
510 message(FATAL_ERROR "Python 3.x development package required to build PyArmNN, but not found")
511 endif()
512
513 find_package(SWIG 4 REQUIRED)
514 if(NOT ${SWIG_FOUND})
515 message(FATAL_ERROR "SWIG 4.x requried to build PyArmNN, but not found")
516 endif()
517endif()
518
David Beck10b4dfd2018-09-19 12:03:20 +0100519# ArmNN source files required for all build options
520include_directories(SYSTEM third-party)