aboutsummaryrefslogtreecommitdiff
path: root/src/armnn/ProfilingDetails.hpp
blob: 2f9a8f00e386fcbe967644bc3a9669bbdcf52170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
//
// 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,
                            const profiling::ProfilingGuid guid)
    {
        m_ProfilingDetails << std::quoted("Name") << ": " << std::quoted(workloadName) << " ";
        PrintHeader();

        PrintTabs();
        m_ProfilingDetails << std::quoted("GUID") << ": " << std::quoted(std::to_string(guid));
        PrintSeparator();
        PrintNewLine();

        // 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