ArmNN
 20.11
RangeTracker Class Reference

#include <RangeTracker.hpp>

Public Types

using MinMaxRange = std::pair< float, float >
 

Public Member Functions

MinMaxRange GetRange (LayerGuid guid, unsigned int idx) const
 Retrieve the Range for a particular output slot on a particular layer. More...
 
void SetRange (const IConnectableLayer *layer, unsigned int outputIdx, float min, float max)
 Set the range for an output slot on a layer. More...
 
bool IsEmpty () const
 Query function to check that the RangeTracker is empty. More...
 
bool HasRanges (LayerGuid guid) const
 Query that there is an entry for a layer. More...
 
void RefineMin (LayerGuid guid, unsigned int slotIndex, float newMin)
 Update min in RangeTracker with new_min if it is lower than current value. More...
 
void RefineMax (LayerGuid guid, unsigned int slotIndex, float newMax)
 Update max in RangeTracker with new_max if it is greater than current value. More...
 
void ResetMinMax (LayerGuid guid, unsigned int idx, float newMin, float newMax)
 Overwrite min and max in RangeTracker with newMin and newMax. More...
 
void Reset ()
 
void SetDynamicMode (bool flag)
 
bool IsInDynamicMode () const
 

Detailed Description

Definition at line 17 of file RangeTracker.hpp.

Member Typedef Documentation

◆ MinMaxRange

using MinMaxRange = std::pair<float, float>

Definition at line 20 of file RangeTracker.hpp.

Member Function Documentation

◆ GetRange()

RangeTracker::MinMaxRange GetRange ( armnn::LayerGuid  guid,
unsigned int  idx 
) const

Retrieve the Range for a particular output slot on a particular layer.

Definition at line 29 of file RangeTracker.cpp.

References RangeTracker::IsInDynamicMode().

Referenced by armnn::BOOST_AUTO_TEST_CASE(), DynamicQuantizationVisitor::DynamicQuantizationVisitor(), NetworkQuantizer::GetMinMaxRange(), QuantizerVisitor::QuantizerVisitor(), StaticRangeVisitor::StaticRangeVisitor(), StaticRangeVisitor::VisitConcatLayer(), and DynamicQuantizationVisitor::VisitConcatLayer().

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 }
bool IsInDynamicMode() const
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46

◆ HasRanges()

bool HasRanges ( LayerGuid  guid) const
inline

Query that there is an entry for a layer.

Definition at line 32 of file RangeTracker.hpp.

References RangeTracker::RefineMax(), RangeTracker::RefineMin(), RangeTracker::Reset(), and RangeTracker::ResetMinMax().

Referenced by armnn::BOOST_AUTO_TEST_CASE().

32 { return m_GuidToRangesMap.find(guid) != m_GuidToRangesMap.end(); }

◆ IsEmpty()

bool IsEmpty ( ) const
inline

Query function to check that the RangeTracker is empty.

Definition at line 29 of file RangeTracker.hpp.

Referenced by armnn::BOOST_AUTO_TEST_CASE().

29 { return m_GuidToRangesMap.empty(); }

◆ IsInDynamicMode()

bool IsInDynamicMode ( ) const
inline

Definition at line 47 of file RangeTracker.hpp.

Referenced by RangeTracker::GetRange().

47 { return m_DynamicMode; }

◆ 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 at line 55 of file RangeTracker.cpp.

Referenced by RangeTracker::HasRanges().

56 {
57  auto& currentMax = m_GuidToRangesMap.find(guid)->second.at(idx).second;
58  if (newMax > currentMax)
59  {
60  currentMax = newMax;
61  }
62 }

◆ 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 at line 46 of file RangeTracker.cpp.

Referenced by RangeTracker::HasRanges().

47 {
48  auto& currentMin = m_GuidToRangesMap.find(guid)->second.at(idx).first;
49  if (newMin < currentMin)
50  {
51  currentMin = newMin;
52  }
53 }

◆ Reset()

void Reset ( )

Definition at line 74 of file RangeTracker.cpp.

Referenced by RangeTracker::HasRanges().

75 {
76  m_GuidToRangesMap.clear();
77 }

◆ ResetMinMax()

void ResetMinMax ( LayerGuid  guid,
unsigned int  idx,
float  newMin,
float  newMax 
)

Overwrite min and max in RangeTracker with newMin and newMax.

Definition at line 64 of file RangeTracker.cpp.

Referenced by RangeTracker::HasRanges().

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 }

◆ SetDynamicMode()

void SetDynamicMode ( bool  flag)
inline

Definition at line 45 of file RangeTracker.hpp.

45 { m_DynamicMode = flag; }

◆ SetRange()

void SetRange ( const IConnectableLayer layer,
unsigned int  outputIdx,
float  min,
float  max 
)

Set the range for an output slot on a layer.

Definition at line 12 of file RangeTracker.cpp.

References IConnectableLayer::GetGuid(), and IConnectableLayer::GetNumOutputSlots().

Referenced by DynamicQuantizationVisitor::DynamicQuantizationVisitor(), StaticRangeVisitor::StaticRangeVisitor(), and OverrideInputRangeVisitor::VisitInputLayer().

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 }

The documentation for this class was generated from the following files: