ArmNN
 24.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 <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
armnn::RangeTracker::SetDynamicMode
void SetDynamicMode(bool flag)
Definition: RangeTracker.hpp:47
armnn::RangeTracker::MinMaxRange
std::pair< float, float > MinMaxRange
Definition: RangeTracker.hpp:22
armnn::RangeTracker::IsEmpty
bool IsEmpty() const
Query function to check that the RangeTracker is empty.
Definition: RangeTracker.hpp:31
INetwork.hpp
armnn::RangeTracker::RefineMax
void RefineMax(LayerGuid guid, unsigned int slotIndex, float newMax)
Update max in RangeTracker with new_max if it is greater than current value.
Definition: RangeTracker.cpp:55
armnn::RangeTracker
Definition: RangeTracker.hpp:19
armnn::RangeTracker::HasRanges
bool HasRanges(LayerGuid guid) const
Query that there is an entry for a layer.
Definition: RangeTracker.hpp:34
armnn::RangeTracker::RefineMin
void RefineMin(LayerGuid guid, unsigned int slotIndex, float newMin)
Update min in RangeTracker with new_min if it is lower than current value.
Definition: RangeTracker.cpp:46
armnn::RangeTracker::GetRange
MinMaxRange GetRange(LayerGuid guid, unsigned int idx) const
Retrieve the Range for a particular output slot on a particular layer.
Definition: RangeTracker.cpp:29
LayerGuid
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
Definition: Types.hpp:26
armnn::RangeTracker::IsInDynamicMode
bool IsInDynamicMode() const
Definition: RangeTracker.hpp:49
armnn::RangeTracker::SetRange
void SetRange(const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
Set the range for an output slot on a layer.
Definition: RangeTracker.cpp:12
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Types.hpp
armnn::IConnectableLayer
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:80
armnn::RangeTracker::Reset
void Reset()
Definition: RangeTracker.cpp:74
armnn::RangeTracker::ResetMinMax
void ResetMinMax(LayerGuid guid, unsigned int idx, float newMin, float newMax)
Overwrite min and max in RangeTracker with newMin and newMax.
Definition: RangeTracker.cpp:64