ArmNN
 22.11
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 <common/include/ProfilingGuid.hpp>
12 
13 #include <utility>
14 #include <unordered_map>
15 
16 namespace armnn
17 {
18 
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.
31  bool IsEmpty() const { return m_GuidToRangesMap.empty(); }
32 
33  /// Query that there is an entry for a layer
34  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 
47  void SetDynamicMode(bool flag) { m_DynamicMode = flag; }
48 
49  bool IsInDynamicMode() const { return m_DynamicMode; }
50 
51 private:
52  using MinMaxRanges = std::vector<MinMaxRange>;
53 
54  /// Retrieve the default range
55  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
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:68
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) 2021 ARM Limited and Contributors.
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.
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
Definition: Types.hpp:26
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.