2 # Copyright © 2017 Arm Ltd. All rights reserved.
3 # SPDX-License-Identifier: MIT
5 cmake_minimum_required (VERSION 3.0.2) # 3.0.2 required for return() statement used in AddDllCopyCommands.cmake.
8 set(additional_cmake_files)
9 list(APPEND additional_cmake_files
11 cmake/GlobalConfig.cmake
12 cmake/AddDllCopyCommands.cmake)
14 foreach(cmake_file ${additional_cmake_files})
15 include(${cmake_file})
19 add_subdirectory(tests)
22 add_subdirectory(samples)
24 # Include the additional cmake files in their own target so that they will appear nicely in IDEs
25 add_custom_target(AdditionalCMakeFiles SOURCES ${additional_cmake_files})
27 set(armnnUtils_sources)
28 list(APPEND armnnUtils_sources
29 src/armnnUtils/GraphTopologicalSort.hpp
30 src/armnnUtils/Half.hpp
31 src/armnnUtils/Logging.hpp
32 src/armnnUtils/Permute.hpp
33 src/armnnUtils/Logging.cpp
34 src/armnnUtils/Permute.cpp
35 src/armnnUtils/DotSerializer.cpp
36 src/armnnUtils/DotSerializer.hpp
37 src/armnnUtils/HeapProfiling.cpp
38 src/armnnUtils/HeapProfiling.hpp
39 src/armnnUtils/LeakChecking.cpp
40 src/armnnUtils/LeakChecking.hpp
41 src/armnnUtils/CsvReader.cpp
42 src/armnnUtils/CsvReader.hpp
43 src/armnnUtils/FloatingPointConverter.cpp
44 src/armnnUtils/FloatingPointConverter.hpp
45 src/armnnUtils/VerificationHelpers.hpp
46 src/armnnUtils/VerificationHelpers.cpp
47 src/armnnUtils/ParserHelper.hpp
48 src/armnnUtils/ParserHelper.cpp
50 if(BUILD_TF_PARSER OR BUILD_CAFFE_PARSER)
51 list(APPEND armnnUtils_sources
52 src/armnnUtils/ParserPrototxtFixture.hpp
56 add_library_ex(armnnUtils STATIC ${armnnUtils_sources})
58 if(BUILD_CAFFE_PARSER)
59 # ArmNN Parser source files required for all build options
60 set(armnn_caffe_parser_sources)
61 list(APPEND armnn_caffe_parser_sources
62 include/armnnCaffeParser/ICaffeParser.hpp
63 src/armnnCaffeParser/RecordByRecordCaffeParser.hpp
64 src/armnnCaffeParser/RecordByRecordCaffeParser.cpp
65 src/armnnCaffeParser/CaffeParser.hpp
66 src/armnnCaffeParser/CaffeParser.cpp
67 ${CAFFE_GENERATED_SOURCES}/caffe/proto/caffe.pb.cc
69 # The generated Caffe protobuf .cc file is not warning clean and we can't fix them.
70 if(COMPILER_IS_GNU_LIKE)
71 set_source_files_properties(${CAFFE_GENERATED_SOURCES}/caffe/proto/caffe.pb.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion -Wno-sign-conversion")
74 add_library_ex(armnnCaffeParser SHARED ${armnn_caffe_parser_sources})
75 set_target_properties(armnnCaffeParser PROPERTIES COMPILE_FLAGS "${CAFFE_PARSER_ADDITIONAL_COMPILE_FLAGS}")
77 target_include_directories(armnnCaffeParser PRIVATE src/armnnUtils)
79 target_link_libraries(armnnCaffeParser ${Boost_LOG_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY})
81 target_link_libraries(armnnCaffeParser armnn)
82 target_link_libraries(armnnCaffeParser ${PROTOBUF_LIBRARIES})
87 set(armnn_onnx_parser_sources)
88 list(APPEND armnn_onnx_parser_sources
89 include/armnnOnnxParser/IOnnxParser.hpp
90 src/armnnOnnxParser/OnnxParser.hpp
91 src/armnnOnnxParser/OnnxParser.cpp
92 ${ONNX_GENERATED_SOURCES}/onnx/onnx.pb.cc
94 # The generated onnx protobuf .cc files are not warning clean and we can't fix them.
95 if(COMPILER_IS_GNU_LIKE)
96 set_source_files_properties(${ONNX_GENERATED_SOURCES}/onnx/onnx.pb.cc PROPERTIES COMPILE_FLAGS "-Wno-conversion -Wno-sign-conversion")
99 add_library_ex(armnnOnnxParser SHARED ${armnn_onnx_parser_sources})
101 target_include_directories(armnnOnnxParser PRIVATE src/armnnUtils)
103 target_link_libraries(armnnOnnxParser armnn)
106 target_link_libraries(armnnOnnxParser ${PROTOBUF_LIBRARIES})
110 set(armnn_tf_parser_sources)
111 list(APPEND armnn_tf_parser_sources
112 include/armnnTfParser/ITfParser.hpp
113 src/armnnTfParser/TfParser.hpp
114 src/armnnTfParser/TfParser.cpp
117 # The generated tensorflow protobuf .cc files are not warning clean and we can't fix them.
118 if(COMPILER_IS_GNU_LIKE)
119 set_source_files_properties(${TF_PROTOBUFS} PROPERTIES COMPILE_FLAGS "-Wno-conversion -Wno-sign-conversion")
122 add_library_ex(armnnTfParser SHARED ${armnn_tf_parser_sources})
124 target_include_directories(armnnTfParser PRIVATE src/armnnUtils)
126 target_link_libraries(armnnTfParser armnn)
128 # Protobuf (use the specific version tensorflow wants)
129 target_link_libraries(armnnTfParser ${PROTOBUF_LIBRARIES})
132 if(BUILD_TF_LITE_PARSER)
133 set(armnn_tf_lite_parser_sources)
134 list(APPEND armnn_tf_lite_parser_sources
135 include/armnnTfLiteParser/ITfLiteParser.hpp
136 src/armnnTfLiteParser/TfLiteParser.hpp
137 src/armnnTfLiteParser/TfLiteParser.cpp
140 add_library_ex(armnnTfLiteParser SHARED ${armnn_tf_lite_parser_sources})
142 target_include_directories(armnnTfLiteParser PRIVATE src/armnnUtils)
144 target_link_libraries(armnnTfLiteParser ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
145 target_link_libraries(armnnTfLiteParser armnn ${FLATBUFFERS_LIBRARY})
148 list(APPEND armnn_sources
149 include/armnn/ArmNN.hpp
150 include/armnn/BackendId.hpp
151 include/armnn/Descriptors.hpp
152 include/armnn/DescriptorsFwd.hpp
153 include/armnn/Exceptions.hpp
154 include/armnn/ILayerSupport.hpp
155 include/armnn/INetwork.hpp
156 include/armnn/IProfiler.hpp
157 include/armnn/IBackend.hpp
158 include/armnn/IRuntime.hpp
159 include/armnn/LayerSupport.hpp
160 include/armnn/LstmParams.hpp
161 include/armnn/NetworkFwd.hpp
162 include/armnn/Optional.hpp
163 include/armnn/Tensor.hpp
164 include/armnn/TensorFwd.hpp
165 include/armnn/Types.hpp
166 include/armnn/TypesUtils.hpp
167 include/armnn/Utils.hpp
168 include/armnn/Version.hpp
169 src/armnn/layers/LayerCloneBase.hpp
170 src/armnn/layers/LayerWithParameters.hpp
171 src/armnn/layers/ActivationLayer.hpp
172 src/armnn/layers/ActivationLayer.cpp
173 src/armnn/layers/AdditionLayer.hpp
174 src/armnn/layers/AdditionLayer.cpp
175 src/armnn/layers/ArithmeticBaseLayer.hpp
176 src/armnn/layers/ArithmeticBaseLayer.cpp
177 src/armnn/layers/BatchNormalizationLayer.hpp
178 src/armnn/layers/BatchNormalizationLayer.cpp
179 src/armnn/layers/ConstantLayer.hpp
180 src/armnn/layers/ConstantLayer.cpp
181 src/armnn/layers/Convolution2dLayer.hpp
182 src/armnn/layers/Convolution2dLayer.cpp
183 src/armnn/layers/ConvertFp16ToFp32Layer.hpp
184 src/armnn/layers/ConvertFp16ToFp32Layer.cpp
185 src/armnn/layers/ConvertFp32ToFp16Layer.hpp
186 src/armnn/layers/ConvertFp32ToFp16Layer.cpp
187 src/armnn/layers/DepthwiseConvolution2dLayer.hpp
188 src/armnn/layers/DepthwiseConvolution2dLayer.cpp
189 src/armnn/layers/FakeQuantizationLayer.hpp
190 src/armnn/layers/FakeQuantizationLayer.cpp
191 src/armnn/layers/FloorLayer.hpp
192 src/armnn/layers/FloorLayer.cpp
193 src/armnn/layers/FullyConnectedLayer.hpp
194 src/armnn/layers/FullyConnectedLayer.cpp
195 src/armnn/layers/InputLayer.hpp
196 src/armnn/layers/InputLayer.cpp
197 src/armnn/layers/L2NormalizationLayer.hpp
198 src/armnn/layers/L2NormalizationLayer.cpp
199 src/armnn/layers/LstmLayer.cpp
200 src/armnn/layers/LstmLayer.hpp
201 src/armnn/layers/MeanLayer.hpp
202 src/armnn/layers/MeanLayer.cpp
203 src/armnn/layers/MemCopyLayer.hpp
204 src/armnn/layers/MemCopyLayer.cpp
205 src/armnn/layers/MergerLayer.hpp
206 src/armnn/layers/MergerLayer.cpp
207 src/armnn/layers/MultiplicationLayer.hpp
208 src/armnn/layers/MultiplicationLayer.cpp
209 src/armnn/layers/NormalizationLayer.hpp
210 src/armnn/layers/NormalizationLayer.cpp
211 src/armnn/layers/OutputLayer.hpp
212 src/armnn/layers/OutputLayer.cpp
213 src/armnn/layers/PadLayer.hpp
214 src/armnn/layers/PadLayer.cpp
215 src/armnn/layers/PermuteLayer.hpp
216 src/armnn/layers/PermuteLayer.cpp
217 src/armnn/layers/Pooling2dLayer.hpp
218 src/armnn/layers/Pooling2dLayer.cpp
219 src/armnn/layers/DivisionLayer.cpp
220 src/armnn/layers/DivisionLayer.hpp
221 src/armnn/layers/ReshapeLayer.hpp
222 src/armnn/layers/ReshapeLayer.cpp
223 src/armnn/layers/SpaceToBatchNdLayer.hpp
224 src/armnn/layers/SpaceToBatchNdLayer.cpp
225 src/armnn/layers/ResizeBilinearLayer.hpp
226 src/armnn/layers/ResizeBilinearLayer.cpp
227 src/armnn/layers/SoftmaxLayer.hpp
228 src/armnn/layers/SoftmaxLayer.cpp
229 src/armnn/layers/SplitterLayer.hpp
230 src/armnn/layers/SplitterLayer.cpp
231 src/armnn/layers/SubtractionLayer.cpp
232 src/armnn/layers/SubtractionLayer.hpp
233 src/armnn/Descriptors.cpp
234 src/armnn/DeviceSpec.hpp
235 src/armnn/Exceptions.cpp
238 src/armnn/IGraphObservable.hpp
239 src/armnn/Instrument.hpp
240 src/armnn/InternalTypes.cpp
241 src/armnn/InternalTypes.hpp
242 src/armnn/JsonPrinter.cpp
243 src/armnn/JsonPrinter.hpp
245 src/armnn/LayerFwd.hpp
247 src/armnn/LayersFwd.hpp
248 src/armnn/LayerSupportCommon.hpp
249 src/armnn/LayerSupport.cpp
250 src/armnn/LoadedNetwork.cpp
251 src/armnn/LoadedNetwork.hpp
252 src/armnn/Network.cpp
253 src/armnn/Network.hpp
254 src/armnn/NetworkUtils.hpp
255 src/armnn/Observable.cpp
256 src/armnn/Observable.hpp
257 src/armnn/Optimizer.cpp
258 src/armnn/Optimizer.hpp
259 src/armnn/Profiling.cpp
260 src/armnn/ProfilingEvent.cpp
261 src/armnn/ProfilingEvent.hpp
262 src/armnn/Profiling.hpp
263 src/armnn/Runtime.cpp
264 src/armnn/Runtime.hpp
265 src/armnn/SerializeLayerParameters.cpp
266 src/armnn/SerializeLayerParameters.hpp
267 src/armnn/SubGraph.cpp
268 src/armnn/SubGraph.hpp
269 src/armnn/SubGraphSelector.cpp
270 src/armnn/SubGraphSelector.hpp
272 src/armnn/TypeUtils.hpp
274 src/armnn/WallClockTimer.cpp
275 src/armnn/WallClockTimer.hpp
276 src/armnn/optimizations/All.hpp
277 src/armnn/optimizations/ConvertConstants.hpp
278 src/armnn/optimizations/MovePermuteUp.hpp
279 src/armnn/optimizations/Optimization.hpp
280 src/armnn/optimizations/OptimizeConsecutiveReshapes.hpp
281 src/armnn/optimizations/OptimizeInversePermutes.hpp
282 src/armnn/optimizations/PermuteAsReshape.hpp
283 src/armnn/optimizations/SquashEqualSiblings.hpp
284 src/armnn/optimizations/OptimizeInverseConversions.hpp
285 src/armnn/optimizations/ConvertFp32NetworkToFp16.hpp
286 third-party/half/half.hpp
289 # Files used for Streamline-based profiling backend
290 if(PROFILING_BACKEND_STREAMLINE)
291 list(APPEND armnn_sources
292 ${GATOR_ROOT}/annotate/streamline_annotate.h
293 ${GATOR_ROOT}/annotate/streamline_annotate.c)
296 # the backends under src/backends extend the list of
297 # object libs armnn to include in the build
298 include(src/backends/backends.cmake)
299 foreach(lib ${armnnLibraries})
300 message("Adding object library dependency to armnn: ${lib}")
301 list(APPEND armnn_sources $<TARGET_OBJECTS:${lib}>)
304 add_library_ex(armnn SHARED ${armnn_sources})
306 target_include_directories(armnn PRIVATE src/armnn)
307 target_include_directories(armnn PRIVATE src/armnnUtils)
308 target_include_directories(armnn PRIVATE src/backends)
310 target_link_libraries(armnn armnnUtils)
312 target_link_libraries(armnn ${CMAKE_DL_LIBS})
314 install(TARGETS armnn DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
315 if(BUILD_CAFFE_PARSER)
316 install(TARGETS armnnCaffeParser DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
318 if(BUILD_ONNX_PARSER)
319 install(TARGETS armnnOnnxParser DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
322 install(TARGETS armnnTfParser DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
324 if(BUILD_TF_LITE_PARSER)
325 install(TARGETS armnnTfLiteParser DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
327 install(DIRECTORY include/ DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
329 target_link_libraries(armnn ${Boost_LOG_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_SYSTEM_LIBRARY})
331 if(ARMCOMPUTENEON OR ARMCOMPUTECL)
332 target_link_libraries(armnn ${ARMCOMPUTE_LIBRARIES})
335 target_link_libraries(armnn ${OPENCL_LIBRARIES})
338 if(PROFILING_BACKEND_STREAMLINE)
339 target_link_libraries(armnn pthread)
343 set(unittest_sources)
344 list(APPEND unittest_sources
345 src/armnn/test/CreateWorkload.hpp
346 src/armnn/test/CsvReaderTest.cpp
347 src/armnn/test/EndToEndTest.cpp
348 src/armnn/test/FloatingPointConverterTest.cpp
349 src/armnn/test/GraphTests.cpp
350 src/armnn/test/GraphUtils.hpp
351 src/armnn/test/InstrumentTests.cpp
352 src/armnn/test/NetworkTests.cpp
353 src/armnn/test/ObservableTest.cpp
354 src/armnn/test/OptimizerTests.cpp
355 src/armnn/test/OptionalTest.cpp
356 src/armnn/test/ProfilerTests.cpp
357 src/armnn/test/ProfilingEventTest.cpp
358 src/armnn/test/RuntimeTests.cpp
359 src/armnn/test/RuntimeTests.hpp
360 src/armnn/test/SubGraphTests.cpp
361 src/armnn/test/TensorHelpers.hpp
362 src/armnn/test/TensorTest.cpp
363 src/armnn/test/UnitTests.cpp
364 src/armnn/test/UnitTests.hpp
365 src/armnn/test/UtilsTests.cpp)
368 list(APPEND unittest_sources
369 src/armnnTfParser/test/Activations.cpp
370 src/armnnTfParser/test/Addition.cpp
371 src/armnnTfParser/test/BiasAdd.cpp
372 src/armnnTfParser/test/BroadcastForAdd.cpp
373 src/armnnTfParser/test/Convolution2d.cpp
374 src/armnnTfParser/test/Concat.cpp
375 src/armnnTfParser/test/ConcatOfConcats.cpp
376 src/armnnTfParser/test/DepthwiseConvolution2d.cpp
377 src/armnnTfParser/test/FusedBatchNorm.cpp
378 src/armnnTfParser/test/Identity.cpp
379 src/armnnTfParser/test/LocalResponseNormalization.cpp
380 src/armnnTfParser/test/MaximumForLeakyRelu.cpp
381 src/armnnTfParser/test/Multiplication.cpp
382 src/armnnTfParser/test/MultiOutput.cpp
383 src/armnnTfParser/test/PassThru.cpp
384 src/armnnTfParser/test/Pooling.cpp
385 src/armnnTfParser/test/RealDiv.cpp
386 src/armnnTfParser/test/Reshape.cpp
387 src/armnnTfParser/test/ResizeBilinear.cpp
388 src/armnnTfParser/test/Shape.cpp
389 src/armnnTfParser/test/Softmax.cpp
390 src/armnnTfParser/test/TestDependencies.cpp
391 src/armnnTfParser/test/FullyConnected.cpp
392 src/armnnTfParser/test/Constant.cpp
393 src/armnnTfParser/test/TestMultiInputsOutputs.cpp
394 src/armnnTfParser/test/Squeeze.cpp)
397 if(BUILD_TF_LITE_PARSER)
398 list(APPEND unittest_sources
399 src/armnnTfLiteParser/test/ParserFlatbuffersFixture.hpp
400 src/armnnTfLiteParser/test/Activations.cpp
401 src/armnnTfLiteParser/test/AvgPool2D.cpp
402 src/armnnTfLiteParser/test/Concatenation.cpp
403 src/armnnTfLiteParser/test/Conv2D.cpp
404 src/armnnTfLiteParser/test/DepthwiseConvolution2D.cpp
405 src/armnnTfLiteParser/test/FullyConnected.cpp
406 src/armnnTfLiteParser/test/MaxPool2D.cpp
407 src/armnnTfLiteParser/test/Reshape.cpp
408 src/armnnTfLiteParser/test/Softmax.cpp
409 src/armnnTfLiteParser/test/Squeeze.cpp
410 src/armnnTfLiteParser/test/LoadModel.cpp
411 src/armnnTfLiteParser/test/GetBuffer.cpp
412 src/armnnTfLiteParser/test/OutputShapeOfSqueeze.cpp
413 src/armnnTfLiteParser/test/InputOutputTensorNames.cpp
414 src/armnnTfLiteParser/test/GetTensorIds.cpp
415 src/armnnTfLiteParser/test/GetSubgraphInputsOutputs.cpp
416 src/armnnTfLiteParser/test/GetInputsOutputs.cpp
420 if(BUILD_CAFFE_PARSER)
421 list(APPEND unittest_sources
422 src/armnnCaffeParser/test/TestAdd.cpp
423 src/armnnCaffeParser/test/TestConcat.cpp
424 src/armnnCaffeParser/test/TestConvolution.cpp
425 src/armnnCaffeParser/test/TestDropout.cpp
426 src/armnnCaffeParser/test/TestInputs.cpp
427 src/armnnCaffeParser/test/TestMul.cpp
428 src/armnnCaffeParser/test/TestPooling2d.cpp
429 src/armnnCaffeParser/test/TestInPlace.cpp
430 src/armnnCaffeParser/test/TestMultiInputsOutputs.cpp
431 src/armnnCaffeParser/test/TestSplit.cpp
435 if(BUILD_ONNX_PARSER)
436 list(APPEND unittest_sources
437 src/armnnOnnxParser/test/Constructor.cpp
438 src/armnnOnnxParser/test/CreateNetwork.cpp
439 src/armnnOnnxParser/test/ProtoxtFixture.cpp
440 src/armnnOnnxParser/test/Const.cpp
441 src/armnnOnnxParser/test/Pooling.cpp
442 src/armnnOnnxParser/test/Reshape.cpp
443 src/armnnOnnxParser/test/Relu.cpp
444 src/armnnOnnxParser/test/Conv2D.cpp
445 src/armnnOnnxParser/test/Addition.cpp
446 src/armnnOnnxParser/test/FullyConnected.cpp
447 src/armnnOnnxParser/test/GetInputsOutputs.cpp
448 src/armnnOnnxParser/test/BatchNorm.cpp
449 src/armnnOnnxParser/test/DepthConv.cpp
453 foreach(lib ${armnnUnitTestLibraries})
454 message("Adding object library dependency to UnitTests: ${lib}")
455 list(APPEND unittest_sources $<TARGET_OBJECTS:${lib}>)
458 add_executable(UnitTests ${unittest_sources})
459 target_include_directories(UnitTests PRIVATE src/armnn)
460 target_include_directories(UnitTests PRIVATE src/armnnUtils)
461 target_include_directories(UnitTests PRIVATE src/backends)
464 if(HEAP_PROFILING OR LEAK_CHECKING)
465 message("Valgrind is disabled for heap profiling and leak checking builds.")
467 # Valgrind works with gperftools version number <= 2.4
468 target_compile_definitions(UnitTests PRIVATE "WITH_VALGRIND=1")
472 target_link_libraries(UnitTests ${CMAKE_THREAD_LIBS_INIT})
473 target_link_libraries(UnitTests ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} ${Boost_SYSTEM_LIBRARY} ${Boost_FILESYSTEM_LIBRARY})
475 target_link_libraries(UnitTests armnn)
476 target_link_libraries(UnitTests armnnUtils)
479 target_link_libraries(UnitTests armnnTfParser)
482 if(BUILD_CAFFE_PARSER)
483 target_link_libraries(UnitTests armnnCaffeParser)
486 if(BUILD_TF_LITE_PARSER)
487 target_link_libraries(UnitTests armnnTfLiteParser)
490 if(BUILD_ONNX_PARSER)
491 target_link_libraries(UnitTests armnnOnnxParser)
494 addDllCopyCommands(UnitTests)