1# 2# Copyright © 2018-2023 Arm Ltd and Contributors. All rights reserved. 3# SPDX-License-Identifier: MIT 4# 5 6# UnitTests 7include(CheckIncludeFiles) 8 9# Setup the inference test framework 10set(inference_test_sources 11 ClassifierTestCaseData.hpp 12 InferenceModel.hpp 13 InferenceTest.hpp 14 InferenceTest.inl 15 InferenceTest.cpp 16 InferenceTestImage.hpp 17 InferenceTestImage.cpp) 18 19add_library_ex(inferenceTest STATIC ${inference_test_sources}) 20target_include_directories(inferenceTest PRIVATE ../src/armnnUtils) 21target_include_directories(inferenceTest PRIVATE ../src/backends) 22target_include_directories(inferenceTest PRIVATE ../third-party/stb) 23 24if (BUILD_TF_LITE_PARSER AND NOT EXECUTE_NETWORK_STATIC) 25 macro(TfLiteParserTest testName sources) 26 add_executable_ex(${testName} ${sources}) 27 target_include_directories(${testName} PRIVATE ../src/armnnUtils) 28 target_include_directories(${testName} PRIVATE ../src/backends) 29 30 target_link_libraries(${testName} inferenceTest) 31 target_link_libraries(${testName} armnnTfLiteParser) 32 target_link_libraries(${testName} armnn) 33 target_link_libraries(${testName} ${CMAKE_THREAD_LIBS_INIT}) 34 addDllCopyCommands(${testName}) 35 endmacro() 36 37 set(TfLiteBenchmark-Armnn_sources 38 TfLiteBenchmark-Armnn/TfLiteBenchmark-Armnn.cpp) 39 TfLiteParserTest(TfLiteBenchmark-Armnn "${TfLiteBenchmark-Armnn_sources}") 40 41 set(TfLiteMobilenetQuantized-Armnn_sources 42 TfLiteMobilenetQuantized-Armnn/TfLiteMobilenetQuantized-Armnn.cpp 43 ImagePreprocessor.hpp 44 ImagePreprocessor.cpp) 45 TfLiteParserTest(TfLiteMobilenetQuantized-Armnn "${TfLiteMobilenetQuantized-Armnn_sources}") 46 47 set(TfLiteMobileNetSsd-Armnn_sources 48 TfLiteMobileNetSsd-Armnn/TfLiteMobileNetSsd-Armnn.cpp 49 MobileNetSsdDatabase.hpp 50 MobileNetSsdInferenceTest.hpp 51 ObjectDetectionCommon.hpp) 52 TfLiteParserTest(TfLiteMobileNetSsd-Armnn "${TfLiteMobileNetSsd-Armnn_sources}") 53 54 set(TfLiteMobilenetV2Quantized-Armnn_sources 55 TfLiteMobilenetV2Quantized-Armnn/TfLiteMobilenetV2Quantized-Armnn.cpp 56 ImagePreprocessor.hpp 57 ImagePreprocessor.cpp) 58 TfLiteParserTest(TfLiteMobilenetV2Quantized-Armnn "${TfLiteMobilenetV2Quantized-Armnn_sources}") 59 60 set(TfLiteVGG16Quantized-Armnn_sources 61 TfLiteVGG16Quantized-Armnn/TfLiteVGG16Quantized-Armnn.cpp 62 ImagePreprocessor.hpp 63 ImagePreprocessor.cpp) 64 TfLiteParserTest(TfLiteVGG16Quantized-Armnn "${TfLiteVGG16Quantized-Armnn_sources}") 65 66 set(TfLiteMobileNetQuantizedSoftmax-Armnn_sources 67 TfLiteMobileNetQuantizedSoftmax-Armnn/TfLiteMobileNetQuantizedSoftmax-Armnn.cpp 68 ImagePreprocessor.hpp 69 ImagePreprocessor.cpp) 70 TfLiteParserTest(TfLiteMobileNetQuantizedSoftmax-Armnn "${TfLiteMobileNetQuantizedSoftmax-Armnn_sources}") 71 72 set(TfLiteInceptionV3Quantized-Armnn_sources 73 TfLiteInceptionV3Quantized-Armnn/TfLiteInceptionV3Quantized-Armnn.cpp 74 ImagePreprocessor.hpp 75 ImagePreprocessor.cpp) 76 TfLiteParserTest(TfLiteInceptionV3Quantized-Armnn "${TfLiteInceptionV3Quantized-Armnn_sources}") 77 78 set(TfLiteInceptionV4Quantized-Armnn_sources 79 TfLiteInceptionV4Quantized-Armnn/TfLiteInceptionV4Quantized-Armnn.cpp 80 ImagePreprocessor.hpp 81 ImagePreprocessor.cpp) 82 TfLiteParserTest(TfLiteInceptionV4Quantized-Armnn "${TfLiteInceptionV4Quantized-Armnn_sources}") 83 84 set(TfLiteResNetV2-Armnn_sources 85 TfLiteResNetV2-Armnn/TfLiteResNetV2-Armnn.cpp 86 ImagePreprocessor.hpp 87 ImagePreprocessor.cpp) 88 TfLiteParserTest(TfLiteResNetV2-Armnn "${TfLiteResNetV2-Armnn_sources}") 89 90 set(TfLiteResNetV2-50-Quantized-Armnn_sources 91 TfLiteResNetV2-50-Quantized-Armnn/TfLiteResNetV2-50-Quantized-Armnn.cpp 92 ImagePreprocessor.hpp 93 ImagePreprocessor.cpp) 94 TfLiteParserTest(TfLiteResNetV2-50-Quantized-Armnn "${TfLiteResNetV2-50-Quantized-Armnn_sources}") 95 96 set(TfLiteMnasNet-Armnn_sources 97 TfLiteMnasNet-Armnn/TfLiteMnasNet-Armnn.cpp 98 ImagePreprocessor.hpp 99 ImagePreprocessor.cpp) 100 TfLiteParserTest(TfLiteMnasNet-Armnn "${TfLiteMnasNet-Armnn_sources}") 101 102 103 set(TfLiteYoloV3Big-Armnn_sources 104 TfLiteYoloV3Big-Armnn/NMS.cpp 105 TfLiteYoloV3Big-Armnn/NMS.hpp 106 TfLiteYoloV3Big-Armnn/TfLiteYoloV3Big-Armnn.cpp 107 ImagePreprocessor.hpp 108 ImagePreprocessor.cpp) 109 TfLiteParserTest(TfLiteYoloV3Big-Armnn "${TfLiteYoloV3Big-Armnn_sources}") 110 111 112 113endif() 114 115if (BUILD_ONNX_PARSER AND NOT EXECUTE_NETWORK_STATIC) 116 macro(OnnxParserTest testName sources) 117 add_executable_ex(${testName} ${sources}) 118 target_include_directories(${testName} PRIVATE ../src/armnnUtils) 119 target_include_directories(${testName} PRIVATE ../src/backends) 120 121 target_link_libraries(${testName} inferenceTest) 122 target_link_libraries(${testName} armnnOnnxParser) 123 target_link_libraries(${testName} armnn) 124 target_link_libraries(${testName} ${CMAKE_THREAD_LIBS_INIT}) 125 addDllCopyCommands(${testName}) 126 endmacro() 127 128 set(OnnxMnist-Armnn_sources 129 OnnxMnist-Armnn/OnnxMnist-Armnn.cpp 130 MnistDatabase.hpp 131 MnistDatabase.cpp) 132 OnnxParserTest(OnnxMnist-Armnn "${OnnxMnist-Armnn_sources}") 133 134 set(OnnxMobileNet-Armnn_sources 135 OnnxMobileNet-Armnn/OnnxMobileNet-Armnn.cpp 136 ImagePreprocessor.hpp 137 ImagePreprocessor.cpp) 138 OnnxParserTest(OnnxMobileNet-Armnn "${OnnxMobileNet-Armnn_sources}") 139endif() 140 141if (BUILD_ARMNN_SERIALIZER 142 OR BUILD_TF_LITE_PARSER 143 OR BUILD_ONNX_PARSER 144 OR BUILD_CLASSIC_DELEGATE) 145 set(ExecuteNetwork_sources 146 ExecuteNetwork/IExecutor.hpp 147 ExecuteNetwork/ArmNNExecutor.cpp 148 ExecuteNetwork/ArmNNExecutor.hpp 149 ExecuteNetwork/ExecuteNetwork.cpp 150 ExecuteNetwork/ExecuteNetworkProgramOptions.cpp 151 ExecuteNetwork/ExecuteNetworkProgramOptions.hpp 152 ExecuteNetwork/ExecuteNetworkParams.cpp 153 ExecuteNetwork/ExecuteNetworkParams.hpp 154 NetworkExecutionUtils/NetworkExecutionUtils.cpp 155 NetworkExecutionUtils/NetworkExecutionUtils.hpp) 156 157 if(BUILD_CLASSIC_DELEGATE) 158 set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment") 159 set(ExecuteNetwork_sources 160 ${ExecuteNetwork_sources} 161 ExecuteNetwork/TfliteExecutor.cpp 162 ExecuteNetwork/TfliteExecutor.hpp) 163 endif() 164 165 add_executable_ex(ExecuteNetwork ${ExecuteNetwork_sources}) 166 target_include_directories(ExecuteNetwork PRIVATE ../src/armnn) 167 target_include_directories(ExecuteNetwork PRIVATE ../src/armnnUtils) 168 target_include_directories(ExecuteNetwork PRIVATE ../src/backends) 169 target_include_directories(ExecuteNetwork PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) 170 if(EXECUTE_NETWORK_STATIC) 171 target_link_libraries(ExecuteNetwork 172 -Wl,--whole-archive 173 armnnSerializer 174 armnnTfLiteParser 175 armnn 176 pthread 177 -Wl,--no-whole-archive 178 ) 179 else() 180 if (BUILD_ARMNN_SERIALIZER) 181 target_link_libraries(ExecuteNetwork armnnSerializer) 182 endif() 183 if (BUILD_TF_LITE_PARSER) 184 target_link_libraries(ExecuteNetwork armnnTfLiteParser) 185 endif() 186 if (BUILD_ONNX_PARSER) 187 target_link_libraries(ExecuteNetwork armnnOnnxParser) 188 endif() 189 if (BUILD_CLASSIC_DELEGATE) 190 target_link_libraries(ExecuteNetwork ArmnnDelegate::ArmnnDelegate) 191 endif() 192 target_link_libraries(ExecuteNetwork armnn) 193 endif() 194 195 target_link_libraries(ExecuteNetwork ${CMAKE_THREAD_LIBS_INIT}) 196 addDllCopyCommands(ExecuteNetwork) 197endif() 198 199if(BUILD_ACCURACY_TOOL) 200 macro(AccuracyTool executorName) 201 target_link_libraries(${executorName} ${CMAKE_THREAD_LIBS_INIT}) 202 if (BUILD_ARMNN_SERIALIZER) 203 target_link_libraries(${executorName} armnnSerializer) 204 endif() 205 if (BUILD_TF_LITE_PARSER) 206 target_link_libraries(${executorName} armnnTfLiteParser) 207 endif() 208 if (BUILD_ONNX_PARSER) 209 target_link_libraries(${executorName} armnnOnnxParser) 210 endif() 211 addDllCopyCommands(${executorName}) 212 endmacro() 213 214 set(ModelAccuracyTool-Armnn_sources 215 ModelAccuracyTool-Armnn/ModelAccuracyTool-Armnn.cpp) 216 217 add_executable_ex(ModelAccuracyTool ${ModelAccuracyTool-Armnn_sources}) 218 target_include_directories(ModelAccuracyTool PRIVATE ../src/armnn) 219 target_include_directories(ModelAccuracyTool PRIVATE ../src/armnnUtils) 220 target_include_directories(ModelAccuracyTool PRIVATE ../src/backends) 221 target_link_libraries(ModelAccuracyTool inferenceTest) 222 target_link_libraries(ModelAccuracyTool armnn) 223 target_link_libraries(ModelAccuracyTool armnnSerializer) 224 AccuracyTool(ModelAccuracyTool) 225endif() 226 227if(BUILD_ACCURACY_TOOL) 228 macro(ImageTensorExecutor executorName) 229 target_link_libraries(${executorName} ${CMAKE_THREAD_LIBS_INIT}) 230 addDllCopyCommands(${executorName}) 231 endmacro() 232 233 set(ImageTensorGenerator_sources 234 InferenceTestImage.hpp 235 InferenceTestImage.cpp 236 ImageTensorGenerator/ImageTensorGenerator.cpp) 237 238 add_executable_ex(ImageTensorGenerator ${ImageTensorGenerator_sources}) 239 target_include_directories(ImageTensorGenerator PRIVATE ../src/armnn) 240 target_include_directories(ImageTensorGenerator PRIVATE ../src/armnnUtils) 241 242 target_link_libraries(ImageTensorGenerator armnn) 243 ImageTensorExecutor(ImageTensorGenerator) 244 245 set(ImageCSVFileGenerator_sources 246 ImageCSVFileGenerator/ImageCSVFileGenerator.cpp) 247 248 add_executable_ex(ImageCSVFileGenerator ${ImageCSVFileGenerator_sources}) 249 target_include_directories(ImageCSVFileGenerator PRIVATE ../src/armnnUtils) 250 ImageTensorExecutor(ImageCSVFileGenerator) 251endif() 252 253if(BUILD_MEMORY_STRATEGY_BENCHMARK) 254 add_subdirectory(MemoryStrategyBenchmark) 255endif() 256