Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "RangeTracker.hpp" |
Jim Flynn | f92dfce | 2019-05-02 11:33:25 +0100 | [diff] [blame] | 7 | #include "InternalTypes.hpp" |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | |
Jim Flynn | f92dfce | 2019-05-02 11:33:25 +0100 | [diff] [blame] | 12 | void RangeTracker::SetRange(const armnn::IConnectableLayer* layer, unsigned int outputIdx, float min, float max) |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 13 | { |
| 14 | auto& ranges = m_GuidToRangesMap[layer->GetGuid()]; |
| 15 | |
Jim Flynn | f92dfce | 2019-05-02 11:33:25 +0100 | [diff] [blame] | 16 | unsigned int numOfOutputSlots = layer->GetNumOutputSlots(); |
| 17 | // output layers are a special case |
| 18 | if (numOfOutputSlots == 0) |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 19 | { |
Jim Flynn | f92dfce | 2019-05-02 11:33:25 +0100 | [diff] [blame] | 20 | ++numOfOutputSlots; |
| 21 | } |
| 22 | if (ranges.size() < numOfOutputSlots) |
| 23 | { |
| 24 | ranges.resize(numOfOutputSlots); |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 25 | } |
| 26 | ranges[outputIdx] = std::make_pair(min, max); |
| 27 | } |
| 28 | |
Cathal Corbett | 5aa9fd7 | 2022-02-25 15:33:28 +0000 | [diff] [blame^] | 29 | RangeTracker::MinMaxRange RangeTracker::GetRange(LayerGuid guid, unsigned int idx) const |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 30 | { |
| 31 | auto search = m_GuidToRangesMap.find(guid); |
| 32 | if (search == m_GuidToRangesMap.end()) |
| 33 | { |
Jim Flynn | f92dfce | 2019-05-02 11:33:25 +0100 | [diff] [blame] | 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 | } |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 42 | } |
| 43 | return search->second.at(idx); |
| 44 | } |
| 45 | |
Jim Flynn | f92dfce | 2019-05-02 11:33:25 +0100 | [diff] [blame] | 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 | |
| 74 | void RangeTracker::Reset() |
| 75 | { |
| 76 | m_GuidToRangesMap.clear(); |
| 77 | } |
| 78 | |
Derek Lamberti | 8a4ca10 | 2019-02-08 17:54:20 +0000 | [diff] [blame] | 79 | } //namespace armnn |