ArmNN
 22.08
NetworkExecutionUtils.cpp File Reference
#include "NetworkExecutionUtils.hpp"
#include <armnnUtils/Filesystem.hpp>
#include <iterator>

Go to the source code of this file.

Functions

std::vector< std::string > ParseStringList (const std::string &inputString, const char *delimiter)
 Splits a given string at every accurance of delimiter into a vector of string. More...
 
bool CheckInferenceTimeThreshold (const std::chrono::duration< double, std::milli > &duration, const double &thresholdTime)
 Given a measured duration and a threshold time tell the user whether we succeeded or not. More...
 
bool ValidatePath (const std::string &file, const bool expectFile)
 Verifies if the given string is a valid path. More...
 
std::vector< unsigned int > ParseArray (std::istream &stream)
 
bool ValidatePaths (const std::vector< std::string > &fileVec, const bool expectFile)
 Verifies if a given vector of strings are valid paths. More...
 
void LogAndThrow (std::string eMsg)
 

Function Documentation

◆ CheckInferenceTimeThreshold()

bool CheckInferenceTimeThreshold ( const std::chrono::duration< double, std::milli > &  duration,
const double &  thresholdTime 
)

Given a measured duration and a threshold time tell the user whether we succeeded or not.

Parameters
durationthe measured inference duration.
thresholdTimethe threshold time in milliseconds.
Returns
false if the measured time exceeded the threshold.

Definition at line 17 of file NetworkExecutionUtils.cpp.

References ARMNN_LOG.

Referenced by ArmNNExecutor::ArmNNExecutor(), and TfLiteExecutor::Execute().

19 {
20  ARMNN_LOG(info) << "Inference time: " << std::setprecision(2)
21  << std::fixed << duration.count() << " ms\n";
22  // If thresholdTime == 0.0 (default), then it hasn't been supplied at command line
23  if (thresholdTime != 0.0)
24  {
25  ARMNN_LOG(info) << "Threshold time: " << std::setprecision(2)
26  << std::fixed << thresholdTime << " ms";
27  auto thresholdMinusInference = thresholdTime - duration.count();
28  ARMNN_LOG(info) << "Threshold time - Inference time: " << std::setprecision(2)
29  << std::fixed << thresholdMinusInference << " ms" << "\n";
30  if (thresholdMinusInference < 0)
31  {
32  std::string errorMessage = "Elapsed inference time is greater than provided threshold time.";
33  ARMNN_LOG(fatal) << errorMessage;
34  return false;
35  }
36  }
37  return true;
38 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205

◆ LogAndThrow()

void LogAndThrow ( std::string  eMsg)

Definition at line 75 of file NetworkExecutionUtils.cpp.

References ARMNN_LOG.

Referenced by ArmNNExecutor::CompareAndPrintResult(), DequantizeArray(), TfLiteExecutor::Execute(), ArmNNExecutor::PrintNetworkInfo(), and TfLiteExecutor::TfLiteExecutor().

76 {
77  ARMNN_LOG(error) << eMsg;
78  throw armnn::Exception(eMsg);
79 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ ParseArray()

std::vector<unsigned int> ParseArray ( std::istream &  stream)

Definition at line 55 of file NetworkExecutionUtils.cpp.

References armnn::numeric_cast().

Referenced by CheckRequestedBackendsAreValid(), and ProgramOptions::ParseOptions().

56 {
57  return ParseArrayImpl<unsigned int>(
58  stream,
59  [](const std::string& s) { return armnn::numeric_cast<unsigned int>(std::stoi(s)); });
60 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35

◆ ParseStringList()

std::vector<std::string> ParseStringList ( const std::string &  inputString,
const char *  delimiter 
)

Splits a given string at every accurance of delimiter into a vector of string.

Definition at line 10 of file NetworkExecutionUtils.cpp.

References armnn::stringUtils::StringTrimCopy().

Referenced by CheckRequestedBackendsAreValid(), GetBackendIDs(), and ProgramOptions::ParseOptions().

11 {
12  std::stringstream stream(inputString);
13  return ParseArrayImpl<std::string>(stream, [](const std::string& s) {
14  return armnn::stringUtils::StringTrimCopy(s); }, delimiter);
15 }
std::string StringTrimCopy(const std::string &str, const std::string &chars="\\\")
Trim from both the start and the end of a string, returns a trimmed copy of the string.
Definition: StringUtils.hpp:88

◆ ValidatePath()

bool ValidatePath ( const std::string &  file,
const bool  expectFile 
)

Verifies if the given string is a valid path.

Reports invalid paths to std::err.

Parameters
filestring - A string containing the path to check
expectFilebool - If true, checks for a regular file.
Returns
bool - True if given string is a valid path., false otherwise.

Definition at line 40 of file NetworkExecutionUtils.cpp.

Referenced by CheckClTuningParameter(), DequantizeArray(), and ValidatePaths().

41 {
42  if (!fs::exists(file))
43  {
44  std::cerr << "Given file path '" << file << "' does not exist" << std::endl;
45  return false;
46  }
47  if (!fs::is_regular_file(file) && expectFile)
48  {
49  std::cerr << "Given file path '" << file << "' is not a regular file" << std::endl;
50  return false;
51  }
52  return true;
53 }

◆ ValidatePaths()

bool ValidatePaths ( const std::vector< std::string > &  fileVec,
const bool  expectFile 
)

Verifies if a given vector of strings are valid paths.

Reports invalid paths to std::err.

Parameters
fileVecvector of string - A vector of string containing the paths to check
expectFilebool - If true, checks for a regular file.
Returns
bool - True if all given strings are valid paths., false otherwise.

Definition at line 62 of file NetworkExecutionUtils.cpp.

References ValidatePath().

Referenced by DequantizeArray(), and ExecuteNetworkParams::ValidateParams().

63 {
64  bool allPathsValid = true;
65  for (auto const& file : fileVec)
66  {
67  if(!ValidatePath(file, expectFile))
68  {
69  allPathsValid = false;
70  }
71  }
72  return allPathsValid;
73 }
bool ValidatePath(const std::string &file, const bool expectFile)
Verifies if the given string is a valid path.