ArmNN
 21.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
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:62
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.
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
void RefineMin(LayerGuid guid, unsigned int slotIndex, float newMin)
Update min in RangeTracker with new_min if it is lower than current value.