aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/ProfilingDetails.hpp
diff options
context:
space:
mode:
authorKeith Davis <keith.davis@arm.com>2021-07-20 11:25:22 +0100
committerKeith Davis <keith.davis@arm.com>2021-08-04 11:49:16 +0100
commit554fa09a0f3d6c9c572634c9d2de9bfb6c3218b0 (patch)
tree1820a2cadcc1f34667199acff2d044e5d2083ea2 /src/armnn/ProfilingDetails.hpp
parent96fd98c28441618fbdf9376fe46a368ef06b19e1 (diff)
downloadarmnn-554fa09a0f3d6c9c572634c9d2de9bfb6c3218b0.tar.gz
IVGCVSW-5980 JSON profiling output
* Add new ProfilingDetails class to construct operator details string * Add new macro which helps append layer details to ostream * Add ProfilingEnabled to NetworkProperties so that profiling can be realised when loading the network * Add further optional info to WorkloadInfo specific to convolutions * Generalise some JsonPrinter functions into JsonUtils for reusability * Remove explicit enabling of profiling within InferenceModel as it is done when loading network * Add ProfilingDetails macros to ConvolutionWorkloads for validation Signed-off-by: Keith Davis <keith.davis@arm.com> Change-Id: Ie84bc7dc667e72e6bcb635544f9ead7af1765690
Diffstat (limited to 'src/armnn/ProfilingDetails.hpp')
-rw-r--r--src/armnn/ProfilingDetails.hpp153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/armnn/ProfilingDetails.hpp b/src/armnn/ProfilingDetails.hpp
new file mode 100644
index 0000000000..7224aad592
--- /dev/null
+++ b/src/armnn/ProfilingDetails.hpp
@@ -0,0 +1,153 @@
+//
+// Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <iomanip>
+
+#include "armnn/Types.hpp"
+#include "armnn/TypesUtils.hpp"
+#include "armnn/backends/WorkloadInfo.hpp"
+
+#include "SerializeLayerParameters.hpp"
+#include "JsonUtils.hpp"
+
+namespace armnn
+{
+
+/// ProfilingDetails class records any details associated with the operator and passes on for outputting to the user
+class ProfilingDetails : public JsonUtils
+{
+public:
+ /// Constructor
+ ProfilingDetails() : JsonUtils(m_ProfilingDetails), m_DetailsExist(false)
+ {}
+
+ /// Destructor
+ ~ProfilingDetails() noexcept
+ {}
+
+ /// Add to the ProfilingDetails
+ template<typename DescriptorType>
+ void AddDetailsToString(const std::string& workloadName,
+ const DescriptorType& desc,
+ const WorkloadInfo& infos)
+ {
+ m_ProfilingDetails << std::quoted("Name") << ": " << std::quoted(workloadName) << " ";
+ PrintHeader();
+
+ // Print tensor infos and related data types
+ PrintInfos(infos.m_InputTensorInfos, "Input");
+
+ PrintInfos(infos.m_OutputTensorInfos, "Output");
+
+ if ( infos.m_BiasTensorInfo.has_value())
+ {
+ PrintInfo(infos.m_BiasTensorInfo.value(), "Bias");
+ }
+ if ( infos.m_BiasTensorInfo.has_value())
+ {
+ PrintInfo(infos.m_WeightsTensorInfo.value(), "Weights");
+ }
+ if ( infos.m_ConvolutionMethod.has_value())
+ {
+ PrintTabs();
+
+ m_ProfilingDetails << std::quoted("Convolution Method") << ": "
+ << std::quoted(infos.m_ConvolutionMethod.value());
+
+ PrintSeparator();
+ PrintNewLine();
+ }
+
+ ParameterStringifyFunction extractParams = [this](const std::string& name, const std::string& value) {
+ PrintTabs();
+ m_ProfilingDetails << std::quoted(name) << " : " << std::quoted(value);
+ if (name != "DataLayout") PrintSeparator();
+ PrintNewLine();
+ };
+
+ StringifyLayerParameters<DescriptorType>::Serialize(extractParams, desc);
+
+ PrintFooter();
+ PrintSeparator();
+ PrintNewLine();
+
+ m_DetailsExist = true;
+ }
+
+ /// Get the ProfilingDetails
+ /// \return the ProfilingDetails
+ std::string GetProfilingDetails() const
+ {
+ return m_ProfilingDetails.str();
+ }
+
+ bool DetailsExist()
+ {
+ return m_DetailsExist;
+ }
+
+private:
+ // Print tensor infos and related data types
+ void PrintInfo(const TensorInfo& info, const std::string& ioString)
+ {
+ const std::vector<TensorInfo> infoVect{ info };
+ PrintInfos(infoVect, ioString);
+ }
+
+ void PrintInfos(const std::vector<TensorInfo>& infos, const std::string& ioString)
+ {
+ for ( size_t i = 0; i < infos.size(); i++ )
+ {
+ auto shape = infos[i].GetShape();
+ PrintTabs();
+
+ m_ProfilingDetails << std::quoted(ioString + " " + std::to_string(i)) << ": ";
+
+ PrintHeader();
+ PrintTabs();
+
+ // Shape
+ m_ProfilingDetails << std::quoted("Shape") << ": \"[";
+ for ( unsigned int dim = 0; dim < shape.GetNumDimensions(); dim++ )
+ {
+ shape.GetNumDimensions() == dim + 1 ?
+ m_ProfilingDetails << shape[dim] << "]\"" : // true
+ m_ProfilingDetails << shape[dim] << ","; // false
+ }
+
+ PrintSeparator();
+ PrintNewLine();
+
+ // Data Type
+ PrintTabs();
+ m_ProfilingDetails << std::quoted("DataType") << ": "
+ << std::quoted(GetDataTypeName(infos[i].GetDataType()));
+
+ PrintSeparator();
+ PrintNewLine();
+
+ // Number of Dimensions
+ PrintTabs();
+ m_ProfilingDetails << std::quoted("Num Dims") << ": "
+ << std::quoted(std::to_string(shape.GetNumDimensions()));
+
+
+ // Close out the scope
+ PrintNewLine();
+ PrintFooter();
+ PrintSeparator();
+ PrintNewLine();
+ }
+ }
+
+ /// Stores ProfilingDetails
+ std::ostringstream m_ProfilingDetails;
+ bool m_DetailsExist;
+
+};
+
+} // namespace armnn