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
SetRange(const armnn::IConnectableLayer * layer,unsigned int outputIdx,float min,float max)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
GetRange(LayerGuid guid,unsigned int idx) const29 RangeTracker::MinMaxRange RangeTracker::GetRange(LayerGuid guid, unsigned int idx) const
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
RefineMin(LayerGuid guid,unsigned int idx,float newMin)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
RefineMax(LayerGuid guid,unsigned int idx,float newMax)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
ResetMinMax(LayerGuid guid,unsigned int idx,float newMin,float newMax)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
Reset()74 void RangeTracker::Reset()
75 {
76 m_GuidToRangesMap.clear();
77 }
78
79 } //namespace armnn