blob: 68ec00e7f8bcea985ce7e2d882264b7c04f2c401 [file] [log] [blame]
Keith Davis554fa092021-07-20 11:25:22 +01001//
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"
12#include "armnn/backends/WorkloadInfo.hpp"
13
14#include "SerializeLayerParameters.hpp"
15#include "JsonUtils.hpp"
16
17namespace armnn
18{
19
20/// ProfilingDetails class records any details associated with the operator and passes on for outputting to the user
21class ProfilingDetails : public JsonUtils
22{
23public:
24 /// Constructor
Keith Davisde68d7d2021-11-03 11:02:29 +000025 ProfilingDetails() : JsonUtils(m_ProfilingDetails), m_DetailsExist(false), m_PrintSeparator(false)
Keith Davis554fa092021-07-20 11:25:22 +010026 {}
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,
Keith Davis5a64f222021-08-04 10:35:20 +010036 const WorkloadInfo& infos,
Cathal Corbett5aa9fd72022-02-25 15:33:28 +000037 const arm::pipe::ProfilingGuid guid)
Keith Davis554fa092021-07-20 11:25:22 +010038 {
Keith Davisec22ad22021-10-22 14:17:19 +010039 // Once details exist, we can assume we're on the second iteration of details
40 if (m_DetailsExist)
41 {
42 PrintSeparator();
43 PrintNewLine();
44 }
45
Keith Davis554fa092021-07-20 11:25:22 +010046 PrintHeader();
Keith Davisde68d7d2021-11-03 11:02:29 +000047 PrintTabs();
48 m_ProfilingDetails << std::quoted("Name") << ": " << std::quoted(workloadName);
49 PrintSeparator();
50 PrintNewLine();
Keith Davis5a64f222021-08-04 10:35:20 +010051 PrintTabs();
52 m_ProfilingDetails << std::quoted("GUID") << ": " << std::quoted(std::to_string(guid));
53 PrintSeparator();
54 PrintNewLine();
55
Keith Davis554fa092021-07-20 11:25:22 +010056 // 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 }
Mike Kelly80211a42021-08-12 14:18:05 +010065 if ( infos.m_WeightsTensorInfo.has_value())
Keith Davis554fa092021-07-20 11:25:22 +010066 {
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
76 PrintSeparator();
77 PrintNewLine();
78 }
79
80 ParameterStringifyFunction extractParams = [this](const std::string& name, const std::string& value) {
Keith Davisde68d7d2021-11-03 11:02:29 +000081 if (m_PrintSeparator)
82 {
83 PrintSeparator();
84 PrintNewLine();
85 }
Keith Davis554fa092021-07-20 11:25:22 +010086 PrintTabs();
87 m_ProfilingDetails << std::quoted(name) << " : " << std::quoted(value);
Keith Davisde68d7d2021-11-03 11:02:29 +000088 m_PrintSeparator = true;
Keith Davis554fa092021-07-20 11:25:22 +010089 };
90
91 StringifyLayerParameters<DescriptorType>::Serialize(extractParams, desc);
92
Keith Davisde68d7d2021-11-03 11:02:29 +000093 PrintNewLine();
Keith Davis554fa092021-07-20 11:25:22 +010094 PrintFooter();
Keith Davis554fa092021-07-20 11:25:22 +010095
96 m_DetailsExist = true;
Keith Davisde68d7d2021-11-03 11:02:29 +000097 m_PrintSeparator = false;
Keith Davis554fa092021-07-20 11:25:22 +010098 }
99
100 /// Get the ProfilingDetails
101 /// \return the ProfilingDetails
102 std::string GetProfilingDetails() const
103 {
104 return m_ProfilingDetails.str();
105 }
106
107 bool DetailsExist()
108 {
109 return m_DetailsExist;
110 }
111
112private:
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;
Keith Davisde68d7d2021-11-03 11:02:29 +0000169 bool m_PrintSeparator;
Keith Davis554fa092021-07-20 11:25:22 +0100170
171};
172
173} // namespace armnn