7 #include "../src/armnn/Profiling.hpp" 8 #include <boost/algorithm/string.hpp> 9 #include <boost/numeric/conversion/cast.hpp> 10 #include <boost/filesystem/path.hpp> 11 #include <boost/assert.hpp> 12 #include <boost/format.hpp> 13 #include <boost/program_options.hpp> 14 #include <boost/filesystem/operations.hpp> 34 namespace po = boost::program_options;
36 po::options_description desc(
"Options");
42 (
"help",
"Display help messages")
43 (
"iterations,i", po::value<unsigned int>(&outParams.
m_IterationCount)->default_value(0),
44 "Sets the number number of inferences to perform. If unset, a default number will be ran.")
45 (
"inference-times-file", po::value<std::string>(&outParams.
m_InferenceTimesFile)->default_value(
""),
46 "If non-empty, each individual inference time will be recorded and output to this file")
47 (
"event-based-profiling,e", po::value<bool>(&outParams.
m_EnableProfiling)->default_value(0),
48 "Enables built in profiler. If unset, defaults to off.");
53 catch (
const std::exception& e)
58 BOOST_ASSERT_MSG(
false,
"Caught unexpected exception");
59 std::cerr <<
"Fatal internal error: " << e.what() << std::endl;
67 po::store(po::parse_command_line(argc, argv, desc), vm);
71 std::cout << desc << std::endl;
79 std::cerr << e.what() << std::endl << std::endl;
80 std::cerr << desc << std::endl;
96 std::cerr <<
"No directory specified" << std::endl;
100 if (dir[dir.length() - 1] !=
'/')
105 if (!boost::filesystem::exists(dir))
107 std::cerr <<
"Given directory " << dir <<
" does not exist" << std::endl;
111 if (!boost::filesystem::is_directory(dir))
113 std::cerr <<
"Given directory [" << dir <<
"] is not a directory" << std::endl;
121 const std::vector<unsigned int>& defaultTestCaseIds,
124 #if !defined (NDEBUG) 127 ARMNN_LOG(
warning) <<
"Performance test running in DEBUG build - results may be inaccurate.";
131 double totalTime = 0;
132 unsigned int nbProcessed = 0;
136 ofstream inferenceTimesFile;
138 if (recordInferenceTimes)
141 if (!inferenceTimesFile.good())
143 ARMNN_LOG(
error) <<
"Failed to open inference times file for writing: " 150 std::unique_ptr<Profiler> profiler = std::make_unique<Profiler>();
151 ProfilerManager::GetInstance().RegisterProfiler(profiler.get());
157 std::unique_ptr<IInferenceTestCase> warmupTestCase = testCaseProvider.
GetTestCase(0);
158 if (warmupTestCase ==
nullptr)
166 warmupTestCase->Run();
175 :
static_cast<unsigned int>(defaultTestCaseIds.size());
177 for (; nbProcessed < nbTotalToProcess; nbProcessed++)
179 const unsigned int testCaseId = params.
m_IterationCount > 0 ? nbProcessed : defaultTestCaseIds[nbProcessed];
180 std::unique_ptr<IInferenceTestCase> testCase = testCaseProvider.
GetTestCase(testCaseId);
182 if (testCase ==
nullptr)
188 time_point<high_resolution_clock> predictStart;
189 time_point<high_resolution_clock> predictEnd;
195 predictStart = high_resolution_clock::now();
199 predictEnd = high_resolution_clock::now();
202 double timeTakenS = duration<double>(predictEnd - predictStart).count();
203 totalTime += timeTakenS;
206 if (recordInferenceTimes)
208 inferenceTimesFile << testCaseId <<
" " << (timeTakenS * 1000.0) << std::endl;
211 result = testCase->ProcessResult(params);
217 result = TestCaseResult::Abort;
222 case TestCaseResult::Ok:
224 case TestCaseResult::Abort:
226 case TestCaseResult::Failed:
231 BOOST_ASSERT_MSG(
false,
"Unexpected TestCaseResult");
236 const double averageTimePerTestCaseMs = totalTime / nbProcessed * 1000.0f;
239 "Total time for " << nbProcessed <<
" test cases: " << totalTime <<
" seconds";
241 "Average time per test case: " << averageTimePerTestCaseMs <<
" ms";
244 if (profiler && profiler->IsProfilingEnabled())
246 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.
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)