10 #include "../src/armnn/Profiling.hpp" 11 #include <cxxopts/cxxopts.hpp> 31 cxxopts::Options options(
"InferenceTest",
"Inference iteration parameters");
37 .allow_unrecognised_options()
39 (
"h,help",
"Display help messages")
40 (
"i,iterations",
"Sets the number of inferences to perform. If unset, will only be run once.",
41 cxxopts::value<unsigned int>(outParams.
m_IterationCount)->default_value(
"0"))
42 (
"inference-times-file",
43 "If non-empty, each individual inference time will be recorded and output to this file",
45 (
"e,event-based-profiling",
"Enables built in profiler. If unset, defaults to off.",
48 std::vector<std::string> required;
53 auto result = options.parse(argc, argv);
55 if (result.count(
"help"))
57 std::cout << options.help() << std::endl;
64 catch (
const cxxopts::OptionException& e)
66 std::cerr << e.what() << std::endl << options.help() << std::endl;
69 catch (
const std::exception& e)
75 std::cerr <<
"Fatal internal error: " << e.what() << std::endl;
91 std::cerr <<
"No directory specified" << std::endl;
95 if (dir[dir.length() - 1] !=
'/')
100 if (!fs::exists(dir))
102 std::cerr <<
"Given directory " << dir <<
" does not exist" << std::endl;
106 if (!fs::is_directory(dir))
108 std::cerr <<
"Given directory [" << dir <<
"] is not a directory" << std::endl;
116 const std::vector<unsigned int>& defaultTestCaseIds,
119 #if !defined (NDEBUG) 122 ARMNN_LOG(
warning) <<
"Performance test running in DEBUG build - results may be inaccurate.";
126 double totalTime = 0;
127 unsigned int nbProcessed = 0;
131 ofstream inferenceTimesFile;
133 if (recordInferenceTimes)
136 if (!inferenceTimesFile.good())
138 ARMNN_LOG(
error) <<
"Failed to open inference times file for writing: " 145 std::unique_ptr<IProfiler> profiler = std::make_unique<IProfiler>();
146 ProfilerManager::GetInstance().RegisterProfiler(profiler.get());
152 std::unique_ptr<IInferenceTestCase> warmupTestCase = testCaseProvider.
GetTestCase(0);
153 if (warmupTestCase ==
nullptr)
161 warmupTestCase->Run();
170 :
static_cast<unsigned int>(defaultTestCaseIds.size());
172 for (; nbProcessed < nbTotalToProcess; nbProcessed++)
174 const unsigned int testCaseId = params.
m_IterationCount > 0 ? nbProcessed : defaultTestCaseIds[nbProcessed];
175 std::unique_ptr<IInferenceTestCase> testCase = testCaseProvider.
GetTestCase(testCaseId);
177 if (testCase ==
nullptr)
183 time_point<high_resolution_clock> predictStart;
184 time_point<high_resolution_clock> predictEnd;
190 predictStart = high_resolution_clock::now();
194 predictEnd = high_resolution_clock::now();
197 double timeTakenS = duration<double>(predictEnd - predictStart).count();
198 totalTime += timeTakenS;
201 if (recordInferenceTimes)
203 inferenceTimesFile << testCaseId <<
" " << (timeTakenS * 1000.0) << std::endl;
206 result = testCase->ProcessResult(params);
212 result = TestCaseResult::Abort;
217 case TestCaseResult::Ok:
219 case TestCaseResult::Abort:
221 case TestCaseResult::Failed:
231 const double averageTimePerTestCaseMs = totalTime / nbProcessed * 1000.0f;
234 "Total time for " << nbProcessed <<
" test cases: " << totalTime <<
" seconds";
236 "Average time per test case: " << averageTimePerTestCaseMs <<
" ms";
239 if (profiler && profiler->IsProfilingEnabled())
241 profiler->Print(std::cout);
bool ParseCommandLine(int argc, char **argv, IInferenceTestCaseProvider &testCaseProvider, InferenceTestOptions &outParams)
Parse the command line of an ArmNN (or referencetests) inference test program.
bool CheckRequiredOptions(const cxxopts::ParseResult &result, const std::vector< std::string > &required)
Ensure all mandatory command-line parameters have been passed to cxxopts.
std::string m_InferenceTimesFile
virtual bool OnInferenceTestFinished()
virtual const char * what() const noexcept override
#define ARMNN_LOG(severity)
Copyright (c) 2021 ARM Limited and Contributors.
virtual void AddCommandLineOptions(cxxopts::Options &options, std::vector< std::string > &required)
#define ARMNN_ASSERT_MSG(COND, MSG)
virtual bool ProcessCommandLineOptions(const InferenceTestOptions &commonOptions)
virtual std::unique_ptr< IInferenceTestCase > GetTestCase(unsigned int testCaseId)=0
bool InferenceTest(const InferenceTestOptions ¶ms, const std::vector< unsigned int > &defaultTestCaseIds, IInferenceTestCaseProvider &testCaseProvider)
unsigned int m_IterationCount
bool ValidateDirectory(std::string &dir)