blob: f9f583a9c6d856418bcf64c0f620638bb37de686 [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
Jan Eilers45274902020-10-15 18:34:43 +01006#include "ExecuteNetworkProgramOptions.hpp"
Teresa Charlin83b42912022-07-07 14:24:59 +01007#include "ArmNNExecutor.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
Jan Eilers45274902020-10-15 18:34:43 +010011#include <armnn/Logging.hpp>
Jan Eilers45274902020-10-15 18:34:43 +010012
Nikhil Raj Armf4ccb1f2022-07-05 09:29:18 +000013
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
telsoa01c577f2c2018-08-31 09:22:23 +010045
Jan Eilers45274902020-10-15 18:34:43 +010046 // Get ExecuteNetwork parameters and runtime options from command line
Jan Eilersf17fcd52021-07-26 22:20:00 +010047 // This might throw an InvalidArgumentException if the user provided invalid inputs
Teresa Charlin83b42912022-07-07 14:24:59 +010048 ProgramOptions programOptions;
49 try
50 {
51 programOptions.ParseOptions(argc, argv);
52 }
53 catch (const std::exception& e)
54 {
Jan Eilersf17fcd52021-07-26 22:20:00 +010055 ARMNN_LOG(fatal) << e.what();
56 return EXIT_FAILURE;
57 }
Narumol Prangnawaratd8cc8112020-03-24 13:54:05 +000058
Teresa Charlin83b42912022-07-07 14:24:59 +010059 std::vector<const void*> outputResults;
Colm Donelan78044812022-09-27 16:46:09 +010060 std::unique_ptr<IExecutor> executor;
61 try
Keith Davisf4874862021-08-09 16:49:18 +010062 {
Colm Donelan78044812022-09-27 16:46:09 +010063 executor = BuildExecutor(programOptions);
Colm Donelan18e6f042023-01-24 22:10:12 +000064 if ((!executor) || (executor->m_constructionFailed))
Colm Donelan78044812022-09-27 16:46:09 +010065 {
66 return EXIT_FAILURE;
67 }
68 }
69 catch (const std::exception& e)
70 {
71 ARMNN_LOG(fatal) << e.what();
Keith Davisf4874862021-08-09 16:49:18 +010072 return EXIT_FAILURE;
73 }
74
Colm Donelan78044812022-09-27 16:46:09 +010075
Teresa Charlin83b42912022-07-07 14:24:59 +010076 executor->PrintNetworkInfo();
77 outputResults = executor->Execute();
Jan Eilers45274902020-10-15 18:34:43 +010078
Teresa Charlin83b42912022-07-07 14:24:59 +010079 if (!programOptions.m_ExNetParams.m_ComparisonComputeDevices.empty() ||
80 programOptions.m_ExNetParams.m_CompareWithTflite)
Finn Williamsd7fcafa2020-04-23 17:55:18 +010081 {
Teresa Charlin83b42912022-07-07 14:24:59 +010082 ExecuteNetworkParams comparisonParams = programOptions.m_ExNetParams;
83 comparisonParams.m_ComputeDevices = programOptions.m_ExNetParams.m_ComparisonComputeDevices;
84
85 if (programOptions.m_ExNetParams.m_CompareWithTflite)
Finn Williamsf806c4d2021-02-22 15:13:12 +000086 {
Teresa Charlin83b42912022-07-07 14:24:59 +010087 comparisonParams.m_TfLiteExecutor = ExecuteNetworkParams::TfLiteExecutor::TfliteInterpreter;
Finn Williamsf806c4d2021-02-22 15:13:12 +000088 }
Teresa Charlin83b42912022-07-07 14:24:59 +010089
90 auto comparisonExecutor = BuildExecutor(programOptions);
91
92 if (!comparisonExecutor)
Sadik Armagan5d03e312020-11-17 16:43:56 +000093 {
Sadik Armagan5d03e312020-11-17 16:43:56 +000094 return EXIT_FAILURE;
Sadik Armagan5d03e312020-11-17 16:43:56 +000095 }
Teresa Charlin83b42912022-07-07 14:24:59 +010096
97 comparisonExecutor->PrintNetworkInfo();
98 comparisonExecutor->Execute();
99
100 comparisonExecutor->CompareAndPrintResult(outputResults);
telsoa014fcda012018-03-09 14:13:49 +0000101 }
102}