From fd627ffaec8fd8801d980b4c91ee7c0607ab6aaf Mon Sep 17 00:00:00 2001 From: Jan Eilers Date: Thu, 25 Feb 2021 17:44:00 +0000 Subject: IVGCVSW-5687 Update Doxygen Docu * Update Doxygen Documentation for 21.02 release Signed-off-by: Jan Eilers Change-Id: I9ed2f9caab038836ea99d7b378d7899fe431a4e5 --- 21.02/_network_execution_utils_8cpp.xhtml | 580 ++++++++++++++++++++++++++++++ 1 file changed, 580 insertions(+) create mode 100644 21.02/_network_execution_utils_8cpp.xhtml (limited to '21.02/_network_execution_utils_8cpp.xhtml') diff --git a/21.02/_network_execution_utils_8cpp.xhtml b/21.02/_network_execution_utils_8cpp.xhtml new file mode 100644 index 0000000000..e3db6844fb --- /dev/null +++ b/21.02/_network_execution_utils_8cpp.xhtml @@ -0,0 +1,580 @@ + + + + + + + + + + + + + +ArmNN: tests/NetworkExecutionUtils/NetworkExecutionUtils.cpp File Reference + + + + + + + + + + + + + + + + +
+
+ + + + ArmNN + + + +
+
+  21.02 +
+
+
+ + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+ +
+ +
+ +
+
NetworkExecutionUtils.cpp File Reference
+
+
+
#include "NetworkExecutionUtils.hpp"
+#include <Filesystem.hpp>
+#include <InferenceTest.hpp>
+#include <ResolveType.hpp>
+
+

Go to the source code of this file.

+ + + + + + +

+Typedefs

using TContainer = mapbox::util::variant< std::vector< float >, std::vector< int >, std::vector< unsigned char > >
 
using QuantizationParams = std::pair< float, int32_t >
 
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

+Functions

template<armnn::DataType NonQuantizedType>
auto ParseDataArray (std::istream &stream)
 
template<armnn::DataType QuantizedType>
auto ParseDataArray (std::istream &stream, const float &quantizationScale, const int32_t &quantizationOffset)
 
template<>
auto ParseDataArray< armnn::DataType::Float32 > (std::istream &stream)
 
template<>
auto ParseDataArray< armnn::DataType::Signed32 > (std::istream &stream)
 
template<>
auto ParseDataArray< armnn::DataType::QAsymmU8 > (std::istream &stream)
 
template<>
auto ParseDataArray< armnn::DataType::QAsymmU8 > (std::istream &stream, const float &quantizationScale, const int32_t &quantizationOffset)
 
template<armnn::DataType ArmnnType, typename T = armnn::ResolveType<ArmnnType>>
std::vector< T > GenerateDummyTensorData (unsigned int numElements)
 
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. More...
 
void PopulateTensorWithData (TContainer &tensorData, unsigned int numElements, const std::string &dataTypeStr, const armnn::Optional< QuantizationParams > &qParams, const armnn::Optional< std::string > &dataFile)
 
bool ValidatePath (const std::string &file, const bool expectFile)
 Verifies if the given string is a valid path. More...
 
bool ValidatePaths (const std::vector< std::string > &fileVec, const bool expectFile)
 Verifies if a given vector of strings are valid paths. More...
 
+

Typedef Documentation

+ +

◆ QuantizationParams

+ +
+
+ + + + +
using QuantizationParams = std::pair<float, int32_t>
+
+ +

Definition at line 174 of file NetworkExecutionUtils.cpp.

+ +
+
+ +

◆ TContainer

+ +
+
+ + + + +
using TContainer = mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char> >
+
+ +

Definition at line 173 of file NetworkExecutionUtils.cpp.

+ +
+
+

Function Documentation

+ +

◆ GenerateDummyTensorData()

+ +
+
+ + + + + + + + +
std::vector<T> GenerateDummyTensorData (unsigned int numElements)
+
+ +

Definition at line 71 of file NetworkExecutionUtils.cpp.

+
72 {
73  return std::vector<T>(numElements, static_cast<T>(0));
74 }
+
+
+ +

◆ ParseArray()

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

Definition at line 77 of file NetworkExecutionUtils.cpp.

+ +

References armnn::numeric_cast().

+ +

Referenced by ProgramOptions::ParseOptions().

+
78 {
79  return ParseArrayImpl<unsigned int>(
80  stream,
81  [](const std::string& s) { return armnn::numeric_cast<unsigned int>(std::stoi(s)); });
82 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
+
+
+
+ +

◆ ParseDataArray() [1/2]

+ +
+
+ + + + + + + + +
auto ParseDataArray (std::istream & stream)
+
+ +
+
+ +

◆ ParseDataArray() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
auto ParseDataArray (std::istream & stream,
const float & quantizationScale,
const int32_t & quantizationOffset 
)
+
+ +
+
+ +

◆ ParseDataArray< armnn::DataType::Float32 >()

+ +
+
+ + + + + + + + +
auto ParseDataArray< armnn::DataType::Float32 > (std::istream & stream)
+
+ +

Definition at line 37 of file NetworkExecutionUtils.cpp.

+
38 {
39  return ParseArrayImpl<float>(stream, [](const std::string& s) { return std::stof(s); });
40 }
+
+
+ +

◆ ParseDataArray< armnn::DataType::QAsymmU8 >() [1/2]

+ +
+
+ + + + + + + + +
auto ParseDataArray< armnn::DataType::QAsymmU8 > (std::istream & stream)
+
+ +

Definition at line 49 of file NetworkExecutionUtils.cpp.

+ +

References armnn::numeric_cast().

+
50 {
51  return ParseArrayImpl<uint8_t>(stream,
52  [](const std::string& s) { return armnn::numeric_cast<uint8_t>(std::stoi(s)); });
53 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
+
+
+
+ +

◆ ParseDataArray< armnn::DataType::QAsymmU8 >() [2/2]

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
auto ParseDataArray< armnn::DataType::QAsymmU8 > (std::istream & stream,
const float & quantizationScale,
const int32_t & quantizationOffset 
)
+
+ +

Definition at line 56 of file NetworkExecutionUtils.cpp.

+ +

References armnn::numeric_cast().

+
59 {
60  return ParseArrayImpl<uint8_t>(stream,
61  [&quantizationScale, &quantizationOffset](const std::string& s)
62  {
63  return armnn::numeric_cast<uint8_t>(
64  armnn::Quantize<uint8_t>(std::stof(s),
65  quantizationScale,
66  quantizationOffset));
67  });
68 }
std::enable_if_t< std::is_unsigned< Source >::value &&std::is_unsigned< Dest >::value, Dest > numeric_cast(Source source)
Definition: NumericCast.hpp:35
+
+
+
+ +

◆ ParseDataArray< armnn::DataType::Signed32 >()

+ +
+
+ + + + + + + + +
auto ParseDataArray< armnn::DataType::Signed32 > (std::istream & stream)
+
+ +

Definition at line 43 of file NetworkExecutionUtils.cpp.

+
44 {
45  return ParseArrayImpl<int>(stream, [](const std::string& s) { return std::stoi(s); });
46 }
+
+
+ +

◆ 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 84 of file NetworkExecutionUtils.cpp.

+ +

References armnn::stringUtils::StringTrimCopy().

+ +

Referenced by ProgramOptions::ParseOptions().

+
85 {
86  std::stringstream stream(inputString);
87  return ParseArrayImpl<std::string>(stream, [](const std::string& s) {
88  return armnn::stringUtils::StringTrimCopy(s); }, delimiter);
89 }
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:85
+
+
+
+ +

◆ PopulateTensorWithData()

+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
void PopulateTensorWithData (TContainertensorData,
unsigned int numElements,
const std::string & dataTypeStr,
const armnn::Optional< QuantizationParams > & qParams,
const armnn::Optional< std::string > & dataFile 
)
+
+ +

Definition at line 176 of file NetworkExecutionUtils.cpp.

+ +

References ARMNN_LOG, OptionalBase::has_value(), OptionalReferenceSwitch< std::is_reference< T >::value, T >::value(), and OptionalReferenceSwitch< IsReference, T >::value().

+ +

Referenced by MainImpl().

+
181 {
182  const bool readFromFile = dataFile.has_value() && !dataFile.value().empty();
183  const bool quantizeData = qParams.has_value();
184 
185  std::ifstream inputTensorFile;
186  if (readFromFile)
187  {
188  inputTensorFile = std::ifstream(dataFile.value());
189  }
190 
191  if (dataTypeStr.compare("float") == 0)
192  {
193  if (quantizeData)
194  {
195  const float qScale = qParams.value().first;
196  const int qOffset = qParams.value().second;
197 
198  tensorData = readFromFile ?
199  ParseDataArray<armnn::DataType::QAsymmU8>(inputTensorFile, qScale, qOffset) :
200  GenerateDummyTensorData<armnn::DataType::QAsymmU8>(numElements);
201  }
202  else
203  {
204  tensorData = readFromFile ?
205  ParseDataArray<armnn::DataType::Float32>(inputTensorFile) :
206  GenerateDummyTensorData<armnn::DataType::Float32>(numElements);
207  }
208  }
209  else if (dataTypeStr.compare("int") == 0)
210  {
211  tensorData = readFromFile ?
212  ParseDataArray<armnn::DataType::Signed32>(inputTensorFile) :
213  GenerateDummyTensorData<armnn::DataType::Signed32>(numElements);
214  }
215  else if (dataTypeStr.compare("qasymm8") == 0)
216  {
217  tensorData = readFromFile ?
218  ParseDataArray<armnn::DataType::QAsymmU8>(inputTensorFile) :
219  GenerateDummyTensorData<armnn::DataType::QAsymmU8>(numElements);
220  }
221  else
222  {
223  std::string errorMessage = "Unsupported tensor data type " + dataTypeStr;
224  ARMNN_LOG(fatal) << errorMessage;
225 
226  inputTensorFile.close();
227  throw armnn::Exception(errorMessage);
228  }
229 
230  inputTensorFile.close();
231 }
#define ARMNN_LOG(severity)
Definition: Logging.hpp:202
+ +
bool has_value() const noexcept
Definition: Optional.hpp:53
+
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
+
+
+
+ +

◆ 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 233 of file NetworkExecutionUtils.cpp.

+ +

Referenced by CheckClTuningParameter(), and ValidatePaths().

+
234 {
235  if (!fs::exists(file))
236  {
237  std::cerr << "Given file path '" << file << "' does not exist" << std::endl;
238  return false;
239  }
240  if (!fs::is_regular_file(file) && expectFile)
241  {
242  std::cerr << "Given file path '" << file << "' is not a regular file" << std::endl;
243  return false;
244  }
245  return true;
246 }
+
+
+ +

◆ 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 248 of file NetworkExecutionUtils.cpp.

+ +

References ValidatePath().

+ +

Referenced by ExecuteNetworkParams::ValidateParams().

+
249 {
250  bool allPathsValid = true;
251  for (auto const& file : fileVec)
252  {
253  if(!ValidatePath(file, expectFile))
254  {
255  allPathsValid = false;
256  }
257  }
258  return allPathsValid;
259 }
bool ValidatePath(const std::string &file, const bool expectFile)
Verifies if the given string is a valid path.
+
+
+
+
+
+ + + + -- cgit v1.2.1