ArmNN
 24.08
ProfilingDetails.hpp
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 
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 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));
53 
54  // From this point onwards everything is potentially optional so we must be careful of separators and new lines.
55 
56  // Print tensor infos and related data types
57  if (!infos.m_InputTensorInfos.empty())
58  {
60  PrintNewLine();
61  // Only add separator and new line if there is an output tensor info.
62  PrintInfos(infos.m_InputTensorInfos, "Input", !infos.m_OutputTensorInfos.empty());
63  }
64 
65  if (!infos.m_OutputTensorInfos.empty())
66  {
67  // Don't add a separator as we don't know what's next.
68  PrintInfos(infos.m_OutputTensorInfos, "Output", false);
69  }
70 
71  if (infos.m_BiasTensorInfo.has_value())
72  {
74  PrintNewLine();
75  PrintInfo(infos.m_BiasTensorInfo.value(), "Bias", false);
76  }
77 
78  if (infos.m_WeightsTensorInfo.has_value())
79  {
81  PrintNewLine();
82  PrintInfo(infos.m_WeightsTensorInfo.value(), "Weights", false);
83  }
84 
85  if (infos.m_ConvolutionMethod.has_value())
86  {
88  PrintNewLine();
89  PrintTabs();
90 
91  m_ProfilingDetails << std::quoted("Convolution Method") << ": "
92  << std::quoted(infos.m_ConvolutionMethod.value());
93  }
94 
95  ParameterStringifyFunction extractParams = [this](const std::string& name, const std::string& value) {
96  // Always begin with a separator and new line.
98  PrintNewLine();
99  PrintTabs();
100  m_ProfilingDetails << std::quoted(name) << " : " << std::quoted(value);
101  };
102 
104 
105  PrintNewLine();
106  PrintFooter();
107 
108  m_DetailsExist = true;
109  }
110 
111  /// Get the ProfilingDetails
112  /// \return the ProfilingDetails
113  std::string GetProfilingDetails() const
114  {
115  return m_ProfilingDetails.str();
116  }
117 
119  {
120  return m_DetailsExist;
121  }
122 
123 private:
124  // Print tensor infos and related data types
125  void PrintInfo(const TensorInfo& info, const std::string& ioString, bool addSeparator = true)
126  {
127  const std::vector<TensorInfo> infoVect{ info };
128  PrintInfos(infoVect, ioString, addSeparator);
129  }
130 
131  void PrintInfos(const std::vector<TensorInfo>& infos, const std::string& ioString, bool addSeparator = true)
132  {
133  for ( size_t i = 0; i < infos.size(); i++ )
134  {
135  auto shape = infos[i].GetShape();
136  PrintTabs();
137 
138  m_ProfilingDetails << std::quoted(ioString + " " + std::to_string(i)) << ": ";
139 
140  PrintHeader();
141  PrintTabs();
142 
143  // Shape
144  m_ProfilingDetails << std::quoted("Shape") << ": \"[";
145  for ( unsigned int dim = 0; dim < shape.GetNumDimensions(); dim++ )
146  {
147  shape.GetNumDimensions() == dim + 1 ?
148  m_ProfilingDetails << shape[dim] << "]\"" : // true
149  m_ProfilingDetails << shape[dim] << ","; // false
150  }
151 
152  PrintSeparator();
153  PrintNewLine();
154 
155  // Data Type
156  PrintTabs();
157  m_ProfilingDetails << std::quoted("DataType") << ": "
158  << std::quoted(GetDataTypeName(infos[i].GetDataType()));
159 
160  PrintSeparator();
161  PrintNewLine();
162 
163  // Number of Dimensions
164  PrintTabs();
165  m_ProfilingDetails << std::quoted("Num Dims") << ": "
166  << std::quoted(std::to_string(shape.GetNumDimensions()));
167 
168 
169  // Close out the scope
170  PrintNewLine();
171  PrintFooter();
172  // For the last element we will consider the value of addSeparator.
173  if ((i < infos.size() - 1) || (addSeparator))
174  {
175  PrintSeparator();
176  PrintNewLine();
177  }
178  }
179  }
180 
181  /// Stores ProfilingDetails
182  std::ostringstream m_ProfilingDetails;
183  bool m_DetailsExist;
184 
185 };
186 
187 } // namespace armnn
armnn::ProfilingDetails::AddDetailsToString
void AddDetailsToString(const std::string &workloadName, const DescriptorType &desc, const WorkloadInfo &infos, const arm::pipe::ProfilingGuid guid)
Add to the ProfilingDetails.
Definition: ProfilingDetails.hpp:34
SerializeLayerParameters.hpp
armnn::ProfilingDetails::~ProfilingDetails
~ProfilingDetails() noexcept
Destructor.
Definition: ProfilingDetails.hpp:29
armnn::JsonUtils::PrintNewLine
void PrintNewLine()
Definition: JsonUtils.hpp:46
JsonUtils.hpp
TypesUtils.hpp
armnn::TensorInfo
Definition: Tensor.hpp:152
armnn::GetDataTypeName
constexpr const char * GetDataTypeName(DataType dataType)
Definition: TypesUtils.hpp:233
armnn::ProfilingDetails::GetProfilingDetails
std::string GetProfilingDetails() const
Get the ProfilingDetails.
Definition: ProfilingDetails.hpp:113
armnn::ProfilingDetails::ProfilingDetails
ProfilingDetails()
Constructor.
Definition: ProfilingDetails.hpp:25
armnn::WorkloadInfo::m_ConvolutionMethod
Optional< std::string > m_ConvolutionMethod
Definition: WorkloadInfo.hpp:23
armnn::WorkloadInfo::m_OutputTensorInfos
std::vector< TensorInfo > m_OutputTensorInfos
Definition: WorkloadInfo.hpp:19
armnn::WorkloadInfo::m_WeightsTensorInfo
Optional< TensorInfo > m_WeightsTensorInfo
Definition: WorkloadInfo.hpp:21
armnn::WorkloadInfo::m_BiasTensorInfo
Optional< TensorInfo > m_BiasTensorInfo
Definition: WorkloadInfo.hpp:22
armnn::WorkloadInfo
Contains information about TensorInfos of a layer.
Definition: WorkloadInfo.hpp:16
armnn::ProfilingDetails::DetailsExist
bool DetailsExist()
Definition: ProfilingDetails.hpp:118
armnn::ParameterStringifyFunction
std::function< void(const std::string &name, const std::string &value)> ParameterStringifyFunction
Definition: SerializeLayerParameters.hpp:14
armnn::StringifyLayerParameters::Serialize
static void Serialize(ParameterStringifyFunction &, const LayerParameter &)
Definition: SerializeLayerParameters.hpp:25
armnn::BoostLogSeverityMapping::info
@ info
armnn::ProfilingDetails
ProfilingDetails class records any details associated with the operator and passes on for outputting ...
Definition: ProfilingDetails.hpp:21
armnn::JsonUtils
Definition: JsonUtils.hpp:16
armnn::WorkloadInfo::m_InputTensorInfos
std::vector< TensorInfo > m_InputTensorInfos
Definition: WorkloadInfo.hpp:18
armnn::JsonUtils::PrintHeader
void PrintHeader()
Definition: JsonUtils.hpp:58
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Types.hpp
armnn::JsonUtils::PrintFooter
void PrintFooter()
Definition: JsonUtils.hpp:51
armnn::JsonUtils::PrintSeparator
void PrintSeparator()
Definition: JsonUtils.hpp:70
WorkloadInfo.hpp
armnn::OptionalReferenceSwitch::value
const T & value() const
Definition: Optional.hpp:146
armnn::OptionalBase::has_value
bool has_value() const noexcept
Definition: Optional.hpp:53
armnn::JsonUtils::PrintTabs
void PrintTabs()
Definition: JsonUtils.hpp:23