ArmNN
 22.05.01
ProfilingDetails.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <iomanip>
9 
10 #include "armnn/Types.hpp"
11 #include "armnn/TypesUtils.hpp"
13 
15 #include "JsonUtils.hpp"
16 
17 namespace armnn
18 {
19 
20 /// ProfilingDetails class records any details associated with the operator and passes on for outputting to the user
22 {
23 public:
24  /// Constructor
25  ProfilingDetails() : JsonUtils(m_ProfilingDetails), m_DetailsExist(false), m_PrintSeparator(false)
26  {}
27 
28  /// Destructor
29  ~ProfilingDetails() noexcept
30  {}
31 
32  /// Add to the ProfilingDetails
33  template<typename DescriptorType>
34  void AddDetailsToString(const std::string& workloadName,
35  const DescriptorType& desc,
36  const WorkloadInfo& infos,
37  const arm::pipe::ProfilingGuid guid)
38  {
39  // Once details exist, we can assume we're on the second iteration of details
40  if (m_DetailsExist)
41  {
43  PrintNewLine();
44  }
45 
46  PrintHeader();
47  PrintTabs();
48  m_ProfilingDetails << std::quoted("Name") << ": " << std::quoted(workloadName);
50  PrintNewLine();
51  PrintTabs();
52  m_ProfilingDetails << std::quoted("GUID") << ": " << std::quoted(std::to_string(guid));
54  PrintNewLine();
55 
56  // Print tensor infos and related data types
57  PrintInfos(infos.m_InputTensorInfos, "Input");
58 
59  PrintInfos(infos.m_OutputTensorInfos, "Output");
60 
61  if ( infos.m_BiasTensorInfo.has_value())
62  {
63  PrintInfo(infos.m_BiasTensorInfo.value(), "Bias");
64  }
65  if ( infos.m_WeightsTensorInfo.has_value())
66  {
67  PrintInfo(infos.m_WeightsTensorInfo.value(), "Weights");
68  }
69  if ( infos.m_ConvolutionMethod.has_value())
70  {
71  PrintTabs();
72 
73  m_ProfilingDetails << std::quoted("Convolution Method") << ": "
74  << std::quoted(infos.m_ConvolutionMethod.value());
75 
77  PrintNewLine();
78  }
79 
80  ParameterStringifyFunction extractParams = [this](const std::string& name, const std::string& value) {
81  if (m_PrintSeparator)
82  {
84  PrintNewLine();
85  }
86  PrintTabs();
87  m_ProfilingDetails << std::quoted(name) << " : " << std::quoted(value);
88  m_PrintSeparator = true;
89  };
90 
92 
93  PrintNewLine();
94  PrintFooter();
95 
96  m_DetailsExist = true;
97  m_PrintSeparator = false;
98  }
99 
100  /// Get the ProfilingDetails
101  /// \return the ProfilingDetails
102  std::string GetProfilingDetails() const
103  {
104  return m_ProfilingDetails.str();
105  }
106 
108  {
109  return m_DetailsExist;
110  }
111 
112 private:
113  // Print tensor infos and related data types
114  void PrintInfo(const TensorInfo& info, const std::string& ioString)
115  {
116  const std::vector<TensorInfo> infoVect{ info };
117  PrintInfos(infoVect, ioString);
118  }
119 
120  void PrintInfos(const std::vector<TensorInfo>& infos, const std::string& ioString)
121  {
122  for ( size_t i = 0; i < infos.size(); i++ )
123  {
124  auto shape = infos[i].GetShape();
125  PrintTabs();
126 
127  m_ProfilingDetails << std::quoted(ioString + " " + std::to_string(i)) << ": ";
128 
129  PrintHeader();
130  PrintTabs();
131 
132  // Shape
133  m_ProfilingDetails << std::quoted("Shape") << ": \"[";
134  for ( unsigned int dim = 0; dim < shape.GetNumDimensions(); dim++ )
135  {
136  shape.GetNumDimensions() == dim + 1 ?
137  m_ProfilingDetails << shape[dim] << "]\"" : // true
138  m_ProfilingDetails << shape[dim] << ","; // false
139  }
140 
141  PrintSeparator();
142  PrintNewLine();
143 
144  // Data Type
145  PrintTabs();
146  m_ProfilingDetails << std::quoted("DataType") << ": "
147  << std::quoted(GetDataTypeName(infos[i].GetDataType()));
148 
149  PrintSeparator();
150  PrintNewLine();
151 
152  // Number of Dimensions
153  PrintTabs();
154  m_ProfilingDetails << std::quoted("Num Dims") << ": "
155  << std::quoted(std::to_string(shape.GetNumDimensions()));
156 
157 
158  // Close out the scope
159  PrintNewLine();
160  PrintFooter();
161  PrintSeparator();
162  PrintNewLine();
163  }
164  }
165 
166  /// Stores ProfilingDetails
167  std::ostringstream m_ProfilingDetails;
168  bool m_DetailsExist;
169  bool m_PrintSeparator;
170 
171 };
172 
173 } // namespace armnn
Optional< std::string > m_ConvolutionMethod
ProfilingDetails class records any details associated with the operator and passes on for outputting ...
void PrintHeader()
Definition: JsonUtils.hpp:58
ProfilingDetails()
Constructor.
Copyright (c) 2021 ARM Limited and Contributors.
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:202
std::vector< TensorInfo > m_InputTensorInfos
void PrintFooter()
Definition: JsonUtils.hpp:51
bool has_value() const noexcept
Definition: Optional.hpp:53
std::vector< TensorInfo > m_OutputTensorInfos
~ProfilingDetails() noexcept
Destructor.
std::string GetProfilingDetails() const
Get the ProfilingDetails.
Optional< TensorInfo > m_BiasTensorInfo
void PrintNewLine()
Definition: JsonUtils.hpp:46
void PrintSeparator()
Definition: JsonUtils.hpp:70
Contains information about TensorInfos of a layer.
void AddDetailsToString(const std::string &workloadName, const DescriptorType &desc, const WorkloadInfo &infos, const arm::pipe::ProfilingGuid guid)
Add to the ProfilingDetails.
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Optional< TensorInfo > m_WeightsTensorInfo