ArmNN
 22.08
NetworkExecutionUtils.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
7 
9 #include <iterator>
10 std::vector<std::string> ParseStringList(const std::string& inputString, const char* delimiter)
11 {
12  std::stringstream stream(inputString);
13  return ParseArrayImpl<std::string>(stream, [](const std::string& s) {
14  return armnn::stringUtils::StringTrimCopy(s); }, delimiter);
15 }
16 
17 bool CheckInferenceTimeThreshold(const std::chrono::duration<double, std::milli>& duration,
18  const double& thresholdTime)
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 }
39 
40 bool ValidatePath(const std::string& file, const bool expectFile)
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 }
54 
55 std::vector<unsigned int> ParseArray(std::istream& stream)
56 {
57  return ParseArrayImpl<unsigned int>(
58  stream,
59  [](const std::string& s) { return armnn::numeric_cast<unsigned int>(std::stoi(s)); });
60 }
61 
62 bool ValidatePaths(const std::vector<std::string>& fileVec, const bool expectFile)
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 }
74 
75 void LogAndThrow(std::string eMsg)
76 {
77  ARMNN_LOG(error) << eMsg;
78  throw armnn::Exception(eMsg);
79 }
80 
void LogAndThrow(std::string eMsg)
std::vector< unsigned int > ParseArray(std::istream &stream)
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.
#define ARMNN_LOG(severity)
Definition: Logging.hpp:205
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
bool ValidatePaths(const std::vector< std::string > &fileVec, const bool expectFile)
Verifies if a given vector of strings are valid paths.
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
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...
bool ValidatePath(const std::string &file, const bool expectFile)
Verifies if the given string is a valid path.