ArmNN
 23.02
RangeTracker.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "RangeTracker.hpp"
7 #include "InternalTypes.hpp"
8 
9 namespace armnn
10 {
11 
12 void RangeTracker::SetRange(const armnn::IConnectableLayer* layer, unsigned int outputIdx, float min, float max)
13 {
14  auto& ranges = m_GuidToRangesMap[layer->GetGuid()];
15 
16  unsigned int numOfOutputSlots = layer->GetNumOutputSlots();
17  // output layers are a special case
18  if (numOfOutputSlots == 0)
19  {
20  ++numOfOutputSlots;
21  }
22  if (ranges.size() < numOfOutputSlots)
23  {
24  ranges.resize(numOfOutputSlots);
25  }
26  ranges[outputIdx] = std::make_pair(min, max);
27 }
28 
30 {
31  auto search = m_GuidToRangesMap.find(guid);
32  if (search == m_GuidToRangesMap.end())
33  {
34  if (IsInDynamicMode())
35  {
36  throw armnn::Exception("Have no entry for layer GUID [" + std::to_string(guid) + "]");
37  }
38  else
39  {
40  return DefaultRange();
41  }
42  }
43  return search->second.at(idx);
44 }
45 
46 void RangeTracker::RefineMin(LayerGuid guid, unsigned int idx, float newMin)
47 {
48  auto& currentMin = m_GuidToRangesMap.find(guid)->second.at(idx).first;
49  if (newMin < currentMin)
50  {
51  currentMin = newMin;
52  }
53 }
54 
55 void RangeTracker::RefineMax(LayerGuid guid, unsigned int idx, float newMax)
56 {
57  auto& currentMax = m_GuidToRangesMap.find(guid)->second.at(idx).second;
58  if (newMax > currentMax)
59  {
60  currentMax = newMax;
61  }
62 }
63 
64 void RangeTracker::ResetMinMax(LayerGuid guid, unsigned int idx, float newMin, float newMax)
65 {
66  auto minMaxPair = m_GuidToRangesMap.find(guid);
67  auto& currentMin = minMaxPair->second.at(idx).first;
68  auto& currentMax = minMaxPair->second.at(idx).second;
69 
70  currentMin = newMin;
71  currentMax = newMax;
72 }
73 
75 {
76  m_GuidToRangesMap.clear();
77 }
78 
79 } //namespace armnn
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::IConnectableLayer
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:68
armnn::RangeTracker::Reset
void Reset()
Definition: RangeTracker.cpp:74
armnn::RangeTracker::IsInDynamicMode
bool IsInDynamicMode() const
Definition: RangeTracker.hpp:49
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
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
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
RangeTracker.hpp
armnn::IConnectableLayer::GetNumOutputSlots
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
InternalTypes.hpp
armnn::IConnectableLayer::GetGuid
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
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::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
armnn::RangeTracker::MinMaxRange
std::pair< float, float > MinMaxRange
Definition: RangeTracker.hpp:22
LayerGuid
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
Definition: Types.hpp:26