ArmNN
 24.02
CommonTestUtils.cpp File Reference
Include dependency graph for CommonTestUtils.cpp:

Go to the source code of this file.

Functions

SubgraphView::InputSlots CreateInputsFrom (Layer *layer, std::vector< unsigned int > ignoreSlots)
 
SubgraphView::InputSlots CreateInputsFrom (const std::vector< Layer * > &layers, std::vector< unsigned int > ignoreSlots)
 
SubgraphView::OutputSlots CreateOutputsFrom (const std::vector< Layer * > &layers)
 
SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom (SubgraphView::InputSlots &&inputs, SubgraphView::OutputSlots &&outputs, SubgraphView::Layers &&layers)
 
armnn::IBackendInternalUniquePtr CreateBackendObject (const armnn::BackendId &backendId)
 
armnn::TensorShape MakeTensorShape (unsigned int batches, unsigned int channels, unsigned int height, unsigned int width, armnn::DataLayout layout)
 

Function Documentation

◆ CreateBackendObject()

armnn::IBackendInternalUniquePtr CreateBackendObject ( const armnn::BackendId backendId)

Definition at line 72 of file CommonTestUtils.cpp.

73 {
74  auto& backendRegistry = BackendRegistryInstance();
75  auto backendFactory = backendRegistry.GetFactory(backendId);
76  auto backendObjPtr = backendFactory();
77 
78  return backendObjPtr;
79 }

References armnn::BackendRegistryInstance().

◆ CreateInputsFrom() [1/2]

SubgraphView::InputSlots CreateInputsFrom ( const std::vector< Layer * > &  layers,
std::vector< unsigned int >  ignoreSlots 
)

Definition at line 31 of file CommonTestUtils.cpp.

33 {
35  for (auto&& layer: layers)
36  {
37  for (auto&& it = layer->BeginInputSlots(); it != layer->EndInputSlots(); ++it)
38  {
39  if (std::find(ignoreSlots.begin(), ignoreSlots.end(), it->GetSlotIndex()) != ignoreSlots.end())
40  {
41  continue;
42  }
43  else
44  {
45  result.push_back(&(*it));
46  }
47  }
48  }
49  return result;
50 }

◆ CreateInputsFrom() [2/2]

SubgraphView::InputSlots CreateInputsFrom ( Layer layer,
std::vector< unsigned int >  ignoreSlots 
)

Definition at line 12 of file CommonTestUtils.cpp.

14 {
16  for (auto&& it = layer->BeginInputSlots(); it != layer->EndInputSlots(); ++it)
17  {
18  if (std::find(ignoreSlots.begin(), ignoreSlots.end(), it->GetSlotIndex()) != ignoreSlots.end())
19  {
20  continue;
21  }
22  else
23  {
24  result.push_back(&(*it));
25  }
26  }
27  return result;
28 }

References Layer::BeginInputSlots(), and Layer::EndInputSlots().

◆ CreateOutputsFrom()

SubgraphView::OutputSlots CreateOutputsFrom ( const std::vector< Layer * > &  layers)

Definition at line 52 of file CommonTestUtils.cpp.

53 {
55  for (auto && layer : layers)
56  {
57  for (auto&& it = layer->BeginOutputSlots(); it != layer->EndOutputSlots(); ++it)
58  {
59  result.push_back(&(*it));
60  }
61  }
62  return result;
63 }

◆ CreateSubgraphViewFrom()

SubgraphView::SubgraphViewPtr CreateSubgraphViewFrom ( SubgraphView::InputSlots &&  inputs,
SubgraphView::OutputSlots &&  outputs,
SubgraphView::Layers &&  layers 
)

Definition at line 65 of file CommonTestUtils.cpp.

68 {
69  return std::make_unique<SubgraphView>(std::move(inputs), std::move(outputs), std::move(layers));
70 }

◆ MakeTensorShape()

armnn::TensorShape MakeTensorShape ( unsigned int  batches,
unsigned int  channels,
unsigned int  height,
unsigned int  width,
armnn::DataLayout  layout 
)

Definition at line 81 of file CommonTestUtils.cpp.

86 {
87  using namespace armnn;
88  switch (layout)
89  {
90  case DataLayout::NCHW:
91  return TensorShape{ batches, channels, height, width };
92  case DataLayout::NHWC:
93  return TensorShape{ batches, height, width, channels };
94  default:
95  throw InvalidArgumentException(std::string("Unsupported data layout: ") + GetDataLayoutName(layout));
96  }
97 }

References armnn::GetDataLayoutName(), armnn::NCHW, and armnn::NHWC.

armnn::DataLayout::NHWC
@ NHWC
armnn::GetDataLayoutName
constexpr const char * GetDataLayoutName(DataLayout dataLayout)
Definition: TypesUtils.hpp:253
armnn::SubgraphView::InputSlots
std::vector< InputSlot * > InputSlots
Definition: SubgraphView.hpp:57
armnn::TensorShape
Definition: Tensor.hpp:20
armnn::BackendRegistryInstance
BackendRegistry & BackendRegistryInstance()
Definition: BackendRegistry.cpp:15
armnn::InvalidArgumentException
Definition: Exceptions.hpp:80
armnn::Layer::EndInputSlots
std::vector< InputSlot >::iterator EndInputSlots()
Definition: Layer.hpp:263
armnn::Layer::BeginInputSlots
std::vector< InputSlot >::iterator BeginInputSlots()
Definition: Layer.hpp:262
armnn::SubgraphView::OutputSlots
std::vector< OutputSlot * > OutputSlots
Definition: SubgraphView.hpp:59
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
armnn::DataLayout::NCHW
@ NCHW