ArmNN
 24.02
TestUtils.hpp File Reference
#include <armnn/INetwork.hpp>
#include <Graph.hpp>
#include <Runtime.hpp>
Include dependency graph for TestUtils.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  LayerNameAndTypeCheck
 

Namespaces

 armnn
 Copyright (c) 2021 ARM Limited and Contributors.
 

Functions

void Connect (armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex=0, unsigned int toIndex=0)
 
template<typename LayerT >
bool IsLayerOfType (const armnn::Layer *const layer)
 
bool CheckSequence (const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
 
template<typename U , typename... Us>
bool CheckSequence (const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last, U &&u, Us &&... us)
 Checks each unary function in Us evaluates true for each correspondent layer in the sequence [first, last). More...
 
template<typename LayerT >
bool CheckRelatedLayers (armnn::Graph &graph, const std::list< std::string > &testRelatedLayers)
 
GraphGetGraphForTesting (IOptimizedNetwork *optNet)
 
ModelOptionsGetModelOptionsForTesting (IOptimizedNetwork *optNet)
 
arm::pipe::IProfilingService & GetProfilingService (armnn::RuntimeImpl *runtime)
 

Function Documentation

◆ CheckRelatedLayers()

bool CheckRelatedLayers ( armnn::Graph graph,
const std::list< std::string > &  testRelatedLayers 
)

Definition at line 52 of file TestUtils.hpp.

53 {
54  for (auto& layer : graph)
55  {
56  if (layer->GetType() == armnn::LayerEnumOf<LayerT>())
57  {
58  auto& relatedLayers = layer->GetRelatedLayerNames();
59  if (!std::equal(relatedLayers.begin(), relatedLayers.end(), testRelatedLayers.begin(),
60  testRelatedLayers.end()))
61  {
62  return false;
63  }
64  }
65  }
66 
67  return true;
68 }

◆ CheckSequence() [1/2]

bool CheckSequence ( const armnn::Graph::ConstIterator  first,
const armnn::Graph::ConstIterator  last 
)
inline

Definition at line 39 of file TestUtils.hpp.

40 {
41  return (first == last);
42 }

Referenced by CheckSequence().

◆ CheckSequence() [2/2]

bool CheckSequence ( const armnn::Graph::ConstIterator  first,
const armnn::Graph::ConstIterator  last,
U &&  u,
Us &&...  us 
)

Checks each unary function in Us evaluates true for each correspondent layer in the sequence [first, last).

Definition at line 46 of file TestUtils.hpp.

47 {
48  return u(*first) && CheckSequence(std::next(first), last, us...);
49 }

References CheckSequence().

◆ Connect()

void Connect ( armnn::IConnectableLayer from,
armnn::IConnectableLayer to,
const armnn::TensorInfo tensorInfo,
unsigned int  fromIndex = 0,
unsigned int  toIndex = 0 
)

Definition at line 14 of file TestUtils.cpp.

16 {
17  ARMNN_ASSERT(from);
18  ARMNN_ASSERT(to);
19 
20  try
21  {
22  from->GetOutputSlot(fromIndex).Connect(to->GetInputSlot(toIndex));
23  }
24  catch (const std::out_of_range& exc)
25  {
26  std::ostringstream message;
27 
28  if (to->GetType() == armnn::LayerType::FullyConnected && toIndex == 2)
29  {
30  message << "Tried to connect bias to FullyConnected layer when bias is not enabled: ";
31  }
32 
33  message << "Failed to connect to input slot "
34  << toIndex
35  << " on "
37  << " layer "
38  << std::quoted(to->GetName())
39  << " as the slot does not exist or is unavailable";
40  throw LayerValidationException(message.str());
41  }
42 
43  from->GetOutputSlot(fromIndex).SetTensorInfo(tensorInfo);
44 }

References ARMNN_ASSERT, IOutputSlot::Connect(), armnn::FullyConnected, IConnectableLayer::GetInputSlot(), armnn::GetLayerTypeAsCString(), IConnectableLayer::GetName(), IConnectableLayer::GetOutputSlot(), IConnectableLayer::GetType(), and IOutputSlot::SetTensorInfo().

◆ IsLayerOfType()

bool IsLayerOfType ( const armnn::Layer *const  layer)

Definition at line 34 of file TestUtils.hpp.

35 {
36  return (layer->GetType() == armnn::LayerEnumOf<LayerT>());
37 }

References Layer::GetType().

ARMNN_ASSERT
#define ARMNN_ASSERT(COND)
Definition: Assert.hpp:14
armnn::GetLayerTypeAsCString
const char * GetLayerTypeAsCString(LayerType type)
Definition: InternalTypes.cpp:13
armnn::IConnectableLayer::GetName
virtual const char * GetName() const =0
Returns the name of the layer.
armnn::IOutputSlot::SetTensorInfo
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
armnn::LayerValidationException
Definition: Exceptions.hpp:105
armnn::IConnectableLayer::GetType
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.
armnn::LayerType::FullyConnected
@ FullyConnected
armnn::Layer::GetType
LayerType GetType() const override
Returns the armnn::LayerType of this layer.
Definition: Layer.hpp:286
armnn::IOutputSlot::Connect
virtual int Connect(IInputSlot &destination)=0
armnn::IConnectableLayer::GetOutputSlot
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
armnn::IConnectableLayer::GetInputSlot
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
CheckSequence
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
Definition: TestUtils.hpp:39