10 #include "../src/armnn/Profiling.hpp" 11 #include <boost/numeric/conversion/cast.hpp> 12 #include <boost/format.hpp> 13 #include <boost/program_options.hpp> 33 namespace po = boost::program_options;
35 po::options_description desc(
"Options");
41 (
"help",
"Display help messages")
42 (
"iterations,i", po::value<unsigned int>(&outParams.
m_IterationCount)->default_value(0),
43 "Sets the number number of inferences to perform. If unset, a default number will be ran.")
44 (
"inference-times-file", po::value<std::string>(&outParams.
m_InferenceTimesFile)->default_value(
""),
45 "If non-empty, each individual inference time will be recorded and output to this file")
46 (
"event-based-profiling,e", po::value<bool>(&outParams.
m_EnableProfiling)->default_value(0),
47 "Enables built in profiler. If unset, defaults to off.");
52 catch (
const std::exception& e)
58 std::cerr <<
"Fatal internal error: " << e.what() << std::endl;
66 po::store(po::parse_command_line(argc, argv, desc), vm);
70 std::cout << desc << std::endl;
78 std::cerr << e.what() << std::endl << std::endl;
79 std::cerr << desc << std::endl;
95 std::cerr <<
"No directory specified" << std::endl;
99 if (dir[dir.length() - 1] !=
'/')
104 if (!fs::exists(dir))
106 std::cerr <<
"Given directory " << dir <<
" does not exist" << std::endl;
110 if (!fs::is_directory(dir))
112 std::cerr <<
"Given directory [" << dir <<
"] is not a directory" << std::endl;
120 const std::vector<unsigned int>& defaultTestCaseIds,
123 #if !defined (NDEBUG) 126 ARMNN_LOG(
warning) <<
"Performance test running in DEBUG build - results may be inaccurate.";
130 double totalTime = 0;
131 unsigned int nbProcessed = 0;
135 ofstream inferenceTimesFile;
137 if (recordInferenceTimes)
140 if (!inferenceTimesFile.good())
142 ARMNN_LOG(
error) <<
"Failed to open inference times file for writing: " 149 std::unique_ptr<Profiler> profiler = std::make_unique<Profiler>();
150 ProfilerManager::GetInstance().RegisterProfiler(profiler.get());
156 std::unique_ptr<IInferenceTestCase> warmupTestCase = testCaseProvider.
GetTestCase(0);
157 if (warmupTestCase ==
nullptr)
165 warmupTestCase->Run();
174 :
static_cast<unsigned int>(defaultTestCaseIds.size());
176 for (; nbProcessed < nbTotalToProcess; nbProcessed++)
178 const unsigned int testCaseId = params.
m_IterationCount > 0 ? nbProcessed : defaultTestCaseIds[nbProcessed];
179 std::unique_ptr<IInferenceTestCase> testCase = testCaseProvider.
GetTestCase(testCaseId);
181 if (testCase ==
nullptr)
187 time_point<high_resolution_clock> predictStart;
188 time_point<high_resolution_clock> predictEnd;
194 predictStart = high_resolution_clock::now();
198 predictEnd = high_resolution_clock::now();
201 double timeTakenS = duration<double>(predictEnd - predictStart).count();
202 totalTime += timeTakenS;
205 if (recordInferenceTimes)
207 inferenceTimesFile << testCaseId <<
" " << (timeTakenS * 1000.0) << std::endl;
210 result = testCase->ProcessResult(params);
216 result = TestCaseResult::Abort;
221 case TestCaseResult::Ok:
223 case TestCaseResult::Abort:
225 case TestCaseResult::Failed:
235 const double averageTimePerTestCaseMs = totalTime / nbProcessed * 1000.0f;
238 "Total time for " << nbProcessed <<
" test cases: " << totalTime <<
" seconds";
240 "Average time per test case: " << averageTimePerTestCaseMs <<
" ms";
243 if (profiler && profiler->IsProfilingEnabled())
245 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.
std::string m_InferenceTimesFile
virtual bool OnInferenceTestFinished()
virtual const char * what() const noexcept override
#define ARMNN_LOG(severity)
virtual void AddCommandLineOptions(boost::program_options::options_description &options)
Copyright (c) 2020 ARM Limited.
#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)