• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/INetwork.hpp>
9 #include <armnn/Types.hpp>
10 
11 #include <common/include/ProfilingGuid.hpp>
12 
13 #include <utility>
14 #include <unordered_map>
15 
16 namespace armnn
17 {
18 
19 class RangeTracker
20 {
21 public:
22     using MinMaxRange  = std::pair<float, float>;
23 
24     /// Retrieve the Range for a particular output slot on a particular layer
25     MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const;
26 
27     /// Set the range for an output slot on a layer
28     void SetRange(const IConnectableLayer* layer, unsigned int outputIdx, float min, float max);
29 
30     /// Query function to check that the RangeTracker is empty.
IsEmpty() const31     bool IsEmpty() const { return m_GuidToRangesMap.empty(); }
32 
33     /// Query that there is an entry for a layer
HasRanges(LayerGuid guid) const34     bool HasRanges(LayerGuid guid) const { return m_GuidToRangesMap.find(guid) != m_GuidToRangesMap.end(); }
35 
36     /// Update min in RangeTracker with new_min if it is lower than current value
37     void RefineMin(LayerGuid guid, unsigned int slotIndex, float newMin);
38 
39     /// Update max in RangeTracker with new_max if it is greater than current value
40     void RefineMax(LayerGuid guid, unsigned int slotIndex, float newMax);
41 
42     /// Overwrite min and max in RangeTracker with newMin and newMax
43     void ResetMinMax(LayerGuid guid, unsigned int idx, float newMin, float newMax);
44 
45     void Reset();
46 
SetDynamicMode(bool flag)47     void SetDynamicMode(bool flag) { m_DynamicMode = flag; }
48 
IsInDynamicMode() const49     bool IsInDynamicMode() const { return m_DynamicMode; }
50 
51 private:
52     using MinMaxRanges = std::vector<MinMaxRange>;
53 
54     /// Retrieve the default range
DefaultRange() const55     MinMaxRange DefaultRange() const { return std::make_pair(-15.0f, 15.0f); }
56 
57     /// Mapping from a layer Guid to an array of ranges for outputs
58     std::unordered_map<LayerGuid, MinMaxRanges> m_GuidToRangesMap;
59 
60     bool m_DynamicMode = false;
61 };
62 
63 } //namespace armnn