ArmNN
 21.08
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)
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 profiling::ProfilingGuid guid)
38  {
39  m_ProfilingDetails << std::quoted("Name") << ": " << std::quoted(workloadName) << " ";
40  PrintHeader();
41 
42  PrintTabs();
43  m_ProfilingDetails << std::quoted("GUID") << ": " << std::quoted(std::to_string(guid));
45  PrintNewLine();
46 
47  // Print tensor infos and related data types
48  PrintInfos(infos.m_InputTensorInfos, "Input");
49 
50  PrintInfos(infos.m_OutputTensorInfos, "Output");
51 
52  if ( infos.m_BiasTensorInfo.has_value())
53  {
54  PrintInfo(infos.m_BiasTensorInfo.value(), "Bias");
55  }
56  if ( infos.m_WeightsTensorInfo.has_value())
57  {
58  PrintInfo(infos.m_WeightsTensorInfo.value(), "Weights");
59  }
60  if ( infos.m_ConvolutionMethod.has_value())
61  {
62  PrintTabs();
63 
64  m_ProfilingDetails << std::quoted("Convolution Method") << ": "
65  << std::quoted(infos.m_ConvolutionMethod.value());
66 
68  PrintNewLine();
69  }
70 
71  ParameterStringifyFunction extractParams = [this](const std::string& name, const std::string& value) {
72  PrintTabs();
73  m_ProfilingDetails << std::quoted(name) << " : " << std::quoted(value);
74  if (name != "DataLayout") PrintSeparator();
75  PrintNewLine();
76  };
77 
79 
80  PrintFooter();
82  PrintNewLine();
83 
84  m_DetailsExist = true;
85  }
86 
87  /// Get the ProfilingDetails
88  /// \return the ProfilingDetails
89  std::string GetProfilingDetails() const
90  {
91  return m_ProfilingDetails.str();
92  }
93 
94  bool DetailsExist()
95  {
96  return m_DetailsExist;
97  }
98 
99 private:
100  // Print tensor infos and related data types
101  void PrintInfo(const TensorInfo& info, const std::string& ioString)
102  {
103  const std::vector<TensorInfo> infoVect{ info };
104  PrintInfos(infoVect, ioString);
105  }
106 
107  void PrintInfos(const std::vector<TensorInfo>& infos, const std::string& ioString)
108  {
109  for ( size_t i = 0; i < infos.size(); i++ )
110  {
111  auto shape = infos[i].GetShape();
112  PrintTabs();
113 
114  m_ProfilingDetails << std::quoted(ioString + " " + std::to_string(i)) << ": ";
115 
116  PrintHeader();
117  PrintTabs();
118 
119  // Shape
120  m_ProfilingDetails << std::quoted("Shape") << ": \"[";
121  for ( unsigned int dim = 0; dim < shape.GetNumDimensions(); dim++ )
122  {
123  shape.GetNumDimensions() == dim + 1 ?
124  m_ProfilingDetails << shape[dim] << "]\"" : // true
125  m_ProfilingDetails << shape[dim] << ","; // false
126  }
127 
128  PrintSeparator();
129  PrintNewLine();
130 
131  // Data Type
132  PrintTabs();
133  m_ProfilingDetails << std::quoted("DataType") << ": "
134  << std::quoted(GetDataTypeName(infos[i].GetDataType()));
135 
136  PrintSeparator();
137  PrintNewLine();
138 
139  // Number of Dimensions
140  PrintTabs();
141  m_ProfilingDetails << std::quoted("Num Dims") << ": "
142  << std::quoted(std::to_string(shape.GetNumDimensions()));
143 
144 
145  // Close out the scope
146  PrintNewLine();
147  PrintFooter();
148  PrintSeparator();
149  PrintNewLine();
150  }
151  }
152 
153  /// Stores ProfilingDetails
154  std::ostringstream m_ProfilingDetails;
155  bool m_DetailsExist;
156 
157 };
158 
159 } // 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
void AddDetailsToString(const std::string &workloadName, const DescriptorType &desc, const WorkloadInfo &infos, const profiling::ProfilingGuid guid)
Add to the ProfilingDetails.
ProfilingDetails()
Constructor.
Copyright (c) 2021 ARM Limited and Contributors.
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:193
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.
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Optional< TensorInfo > m_WeightsTensorInfo