ArmNN
 20.02
RangeTracker.hpp
Go to the documentation of this file.
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 <utility>
12 #include <unordered_map>
13 
14 namespace armnn
15 {
16 
18 {
19 public:
20  using MinMaxRange = std::pair<float, float>;
21 
22  /// Retrieve the Range for a particular output slot on a particular layer
23  MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const;
24 
25  /// Set the range for an output slot on a layer
26  void SetRange(const IConnectableLayer* layer, unsigned int outputIdx, float min, float max);
27 
28  /// Query function to check that the RangeTracker is empty.
29  bool IsEmpty() const { return m_GuidToRangesMap.empty(); }
30 
31  /// Query that there is an entry for a layer
32  bool HasRanges(LayerGuid guid) const { return m_GuidToRangesMap.find(guid) != m_GuidToRangesMap.end(); }
33 
34  /// Update min in RangeTracker with new_min if it is lower than current value
35  void RefineMin(LayerGuid guid, unsigned int slotIndex, float newMin);
36 
37  /// Update max in RangeTracker with new_max if it is greater than current value
38  void RefineMax(LayerGuid guid, unsigned int slotIndex, float newMax);
39 
40  /// Overwrite min and max in RangeTracker with newMin and newMax
41  void ResetMinMax(LayerGuid guid, unsigned int idx, float newMin, float newMax);
42 
43  void Reset();
44 
45  void SetDynamicMode(bool flag) { m_DynamicMode = flag; }
46 
47  bool IsInDynamicMode() const { return m_DynamicMode; }
48 
49 private:
50  using MinMaxRanges = std::vector<MinMaxRange>;
51 
52  /// Retrieve the default range
53  MinMaxRange DefaultRange() const { return std::make_pair(-15.0f, 15.0f); }
54 
55  /// Mapping from a layer Guid to an array of ranges for outputs
56  std::unordered_map<LayerGuid, MinMaxRanges> m_GuidToRangesMap;
57 
58  bool m_DynamicMode = false;
59 };
60 
61 } //namespace armnn
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
bool IsInDynamicMode() const
void ResetMinMax(LayerGuid guid, unsigned int idx, float newMin, float newMax)
Overwrite min and max in RangeTracker with newMin and newMax.
void RefineMax(LayerGuid guid, unsigned int slotIndex, float newMax)
Update max in RangeTracker with new_max if it is greater than current value.
Copyright (c) 2020 ARM Limited.
std::pair< float, float > MinMaxRange
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
void SetRange(const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
Set the range for an output slot on a layer.
bool HasRanges(LayerGuid guid) const
Query that there is an entry for a layer.
bool IsEmpty() const
Query function to check that the RangeTracker is empty.
void SetDynamicMode(bool flag)
void RefineMin(LayerGuid guid, unsigned int slotIndex, float newMin)
Update min in RangeTracker with new_min if it is lower than current value.