blob: 9f81eb1168e46c1cf11a600dd0b3ce3b4646d018 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Colm Donelan18e6f042023-01-24 22:10:12 +00002// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
telsoa01c577f2c2018-08-31 09:22:23 +01005
Teresa Charlin83b42912022-07-07 14:24:59 +01006#include "ArmNNExecutor.hpp"
Colm Donelan0dfb2652023-06-22 10:19:17 +01007#include "ExecuteNetworkProgramOptions.hpp"
Narumol Prangnawarat46e574e2023-05-05 16:39:05 +01008#if defined(ARMNN_TFLITE_DELEGATE) || defined(ARMNN_TFLITE_OPAQUE_DELEGATE)
Teresa Charlin83b42912022-07-07 14:24:59 +01009#include "TfliteExecutor.hpp"
10#endif
Colm Donelan0dfb2652023-06-22 10:19:17 +010011#include "FileComparisonExecutor.hpp"
Jan Eilers45274902020-10-15 18:34:43 +010012#include <armnn/Logging.hpp>
Jan Eilers45274902020-10-15 18:34:43 +010013
Teresa Charlin83b42912022-07-07 14:24:59 +010014std::unique_ptr<IExecutor> BuildExecutor(ProgramOptions& programOptions)
Nikhil Raj Armf4ccb1f2022-07-05 09:29:18 +000015{
Narumol Prangnawarat46e574e2023-05-05 16:39:05 +010016 if (programOptions.m_ExNetParams.m_TfLiteExecutor ==
17 ExecuteNetworkParams::TfLiteExecutor::ArmNNTfLiteOpaqueDelegate ||
18 programOptions.m_ExNetParams.m_TfLiteExecutor == ExecuteNetworkParams::TfLiteExecutor::ArmNNTfLiteDelegate ||
Teresa Charlin83b42912022-07-07 14:24:59 +010019 programOptions.m_ExNetParams.m_TfLiteExecutor == ExecuteNetworkParams::TfLiteExecutor::TfliteInterpreter)
Nikhil Raj Armf4ccb1f2022-07-05 09:29:18 +000020 {
Narumol Prangnawarat46e574e2023-05-05 16:39:05 +010021#if defined(ARMNN_TFLITE_DELEGATE) || defined(ARMNN_TFLITE_OPAQUE_DELEGATE)
Colm Donelan35a06892023-02-06 15:01:57 +000022 return std::make_unique<TfLiteExecutor>(programOptions.m_ExNetParams, programOptions.m_RuntimeOptions);
Teresa Charlin83b42912022-07-07 14:24:59 +010023#else
24 ARMNN_LOG(fatal) << "Not built with Arm NN Tensorflow-Lite delegate support.";
Colm Donelan18e6f042023-01-24 22:10:12 +000025 return nullptr;
Teresa Charlin83b42912022-07-07 14:24:59 +010026#endif
Sadik Armagan19a1c032021-01-20 12:17:00 +000027 }
Finn Williamsf806c4d2021-02-22 15:13:12 +000028 else
29 {
Teresa Charlin83b42912022-07-07 14:24:59 +010030 return std::make_unique<ArmNNExecutor>(programOptions.m_ExNetParams, programOptions.m_RuntimeOptions);
Finn Williamsf806c4d2021-02-22 15:13:12 +000031 }
Jan Eilers45274902020-10-15 18:34:43 +010032}
33
James Conroy7b4886f2019-04-11 10:23:58 +010034// MAIN
telsoa01c577f2c2018-08-31 09:22:23 +010035int main(int argc, const char* argv[])
36{
37 // Configures logging for both the ARMNN library and this test program.
Teresa Charlin83b42912022-07-07 14:24:59 +010038#ifdef NDEBUG
telsoa01c577f2c2018-08-31 09:22:23 +010039 armnn::LogSeverity level = armnn::LogSeverity::Info;
Teresa Charlin83b42912022-07-07 14:24:59 +010040#else
telsoa01c577f2c2018-08-31 09:22:23 +010041 armnn::LogSeverity level = armnn::LogSeverity::Debug;
Teresa Charlin83b42912022-07-07 14:24:59 +010042#endif
telsoa01c577f2c2018-08-31 09:22:23 +010043 armnn::ConfigureLogging(true, true, level);
telsoa01c577f2c2018-08-31 09:22:23 +010044
Jan Eilers45274902020-10-15 18:34:43 +010045 // Get ExecuteNetwork parameters and runtime options from command line
Jan Eilersf17fcd52021-07-26 22:20:00 +010046 // This might throw an InvalidArgumentException if the user provided invalid inputs
Teresa Charlin83b42912022-07-07 14:24:59 +010047 ProgramOptions programOptions;
48 try
49 {
50 programOptions.ParseOptions(argc, argv);
51 }
52 catch (const std::exception& e)
53 {
Jan Eilersf17fcd52021-07-26 22:20:00 +010054 ARMNN_LOG(fatal) << e.what();
55 return EXIT_FAILURE;
56 }
Narumol Prangnawaratd8cc8112020-03-24 13:54:05 +000057
Teresa Charlin83b42912022-07-07 14:24:59 +010058 std::vector<const void*> outputResults;
Colm Donelan78044812022-09-27 16:46:09 +010059 std::unique_ptr<IExecutor> executor;
60 try
Keith Davisf4874862021-08-09 16:49:18 +010061 {
Colm Donelan78044812022-09-27 16:46:09 +010062 executor = BuildExecutor(programOptions);
Colm Donelan18e6f042023-01-24 22:10:12 +000063 if ((!executor) || (executor->m_constructionFailed))
Colm Donelan78044812022-09-27 16:46:09 +010064 {
65 return EXIT_FAILURE;
66 }
67 }
68 catch (const std::exception& e)
69 {
70 ARMNN_LOG(fatal) << e.what();
Keith Davisf4874862021-08-09 16:49:18 +010071 return EXIT_FAILURE;
72 }
73
Teresa Charlin83b42912022-07-07 14:24:59 +010074 executor->PrintNetworkInfo();
75 outputResults = executor->Execute();
Jan Eilers45274902020-10-15 18:34:43 +010076
Teresa Charlin83b42912022-07-07 14:24:59 +010077 if (!programOptions.m_ExNetParams.m_ComparisonComputeDevices.empty() ||
Colm Donelan0dfb2652023-06-22 10:19:17 +010078 programOptions.m_ExNetParams.m_CompareWithTflite)
Finn Williamsd7fcafa2020-04-23 17:55:18 +010079 {
Teresa Charlin83b42912022-07-07 14:24:59 +010080 ExecuteNetworkParams comparisonParams = programOptions.m_ExNetParams;
Colm Donelan0dfb2652023-06-22 10:19:17 +010081 comparisonParams.m_ComputeDevices = programOptions.m_ExNetParams.m_ComparisonComputeDevices;
Teresa Charlin83b42912022-07-07 14:24:59 +010082
83 if (programOptions.m_ExNetParams.m_CompareWithTflite)
Finn Williamsf806c4d2021-02-22 15:13:12 +000084 {
Teresa Charlin83b42912022-07-07 14:24:59 +010085 comparisonParams.m_TfLiteExecutor = ExecuteNetworkParams::TfLiteExecutor::TfliteInterpreter;
Finn Williamsf806c4d2021-02-22 15:13:12 +000086 }
Teresa Charlin83b42912022-07-07 14:24:59 +010087
88 auto comparisonExecutor = BuildExecutor(programOptions);
89
90 if (!comparisonExecutor)
Sadik Armagan5d03e312020-11-17 16:43:56 +000091 {
Sadik Armagan5d03e312020-11-17 16:43:56 +000092 return EXIT_FAILURE;
Sadik Armagan5d03e312020-11-17 16:43:56 +000093 }
Teresa Charlin83b42912022-07-07 14:24:59 +010094
95 comparisonExecutor->PrintNetworkInfo();
96 comparisonExecutor->Execute();
97
98 comparisonExecutor->CompareAndPrintResult(outputResults);
telsoa014fcda012018-03-09 14:13:49 +000099 }
Colm Donelan0dfb2652023-06-22 10:19:17 +0100100
101 // If there's a file comparison specified create a FileComparisonExecutor.
102 if (!programOptions.m_ExNetParams.m_ComparisonFile.empty())
103 {
104 FileComparisonExecutor comparisonExecutor(programOptions.m_ExNetParams);
105 comparisonExecutor.Execute();
106 comparisonExecutor.CompareAndPrintResult(outputResults);
107 }
telsoa014fcda012018-03-09 14:13:49 +0000108}