ArmNN
 20.02
Assert.cpp File Reference
#include "armnnTfParser/ITfParser.hpp"
#include "ParserPrototxtFixture.hpp"
#include "test/GraphUtils.hpp"
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_FIXTURE_TEST_CASE (AssertSimpleTest, AssertSimpleFixture)
 
 BOOST_FIXTURE_TEST_CASE (AssertSimpleGraphStructureTest, AssertSimpleFixture)
 
 BOOST_FIXTURE_TEST_CASE (AssertTest, AssertFixture)
 
 BOOST_FIXTURE_TEST_CASE (AssertGraphStructureTest, AssertFixture)
 

Function Documentation

◆ BOOST_FIXTURE_TEST_CASE() [1/4]

BOOST_FIXTURE_TEST_CASE ( AssertSimpleTest  ,
AssertSimpleFixture   
)

Definition at line 93 of file Assert.cpp.

References ParserPrototxtFixture< TParser >::SetupSingleInputSingleOutput().

94 {
95  SetupSingleInputSingleOutput({ 1, 1, 1, 4 }, "Placeholder", "Add");
96  RunTest<4>({ 1.0f, 2.0f, 3.0f, 4.0f }, { 2.0f, 4.0f, 6.0f, 8.0f });
97 }

◆ BOOST_FIXTURE_TEST_CASE() [2/4]

BOOST_FIXTURE_TEST_CASE ( AssertSimpleGraphStructureTest  ,
AssertSimpleFixture   
)

Definition at line 99 of file Assert.cpp.

References armnn::Addition, CheckNumberOfInputSlot(), CheckNumberOfOutputSlot(), armnn::Float32, GetFirstLayerWithName(), Layer::GetType(), armnn::Input, IsConnected(), and ParserPrototxtFixture< TParser >::SetupOptimizedNetwork().

100 {
101  auto optimized = SetupOptimizedNetwork({ { "Placeholder", { 1, 1, 1, 4 } } }, { "Add" });
102 
103  auto optimizedNetwork = boost::polymorphic_downcast<armnn::OptimizedNetwork*>(optimized.get());
104  auto graph = optimizedNetwork->GetGraph();
105 
106  BOOST_TEST((graph.GetNumInputs() == 1));
107  BOOST_TEST((graph.GetNumOutputs() == 1));
108  BOOST_TEST((graph.GetNumLayers() == 3));
109 
110  armnn::Layer* inputLayer = GetFirstLayerWithName(graph, "Placeholder");
111  BOOST_TEST((inputLayer->GetType() == armnn::LayerType::Input));
112  BOOST_TEST(CheckNumberOfInputSlot(inputLayer, 0));
113  BOOST_TEST(CheckNumberOfOutputSlot(inputLayer, 1));
114 
115  armnn::Layer* addLayer = GetFirstLayerWithName(graph, "Add");
116  BOOST_TEST((addLayer->GetType() == armnn::LayerType::Addition));
117  BOOST_TEST(CheckNumberOfInputSlot(addLayer, 2));
118  BOOST_TEST(CheckNumberOfOutputSlot(addLayer, 1));
119 
121  BOOST_TEST(IsConnected(inputLayer, addLayer, 0, 0, tensorInfo));
122  BOOST_TEST(IsConnected(inputLayer, addLayer, 0, 1, tensorInfo));
123 
124  for (auto&& outputLayer : graph.GetOutputLayers())
125  {
126  BOOST_TEST(IsConnected(addLayer, const_cast<armnn::OutputLayer*>(outputLayer), 0, 0, tensorInfo));
127  }
128 }
armnn::Layer * GetFirstLayerWithName(armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:20
bool IsConnected(armnn::Layer *srcLayer, armnn::Layer *destLayer, unsigned int srcSlot, unsigned int destSlot, const armnn::TensorInfo &expectedTensorInfo)
Definition: GraphUtils.cpp:42
LayerType GetType() const
Definition: Layer.hpp:259
bool CheckNumberOfInputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:32
bool CheckNumberOfOutputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:37

◆ BOOST_FIXTURE_TEST_CASE() [3/4]

BOOST_FIXTURE_TEST_CASE ( AssertTest  ,
AssertFixture   
)

Definition at line 237 of file Assert.cpp.

238 {
239  Setup({ { "Input0", { 1, 1, 2, 2 } },
240  { "Input1", { 1, 1, 2, 2 } } },
241  { "Output" });
242 
243  RunTest<4>({ { "Input0", { 4.0f, 3.0f,
244  2.0f, 1.0f } },
245 
246  { "Input1", { 1.0f, 2.0f,
247  3.0f, 4.0f } } },
248 
249  { { "Output", { 7.0f, 4.0f,
250  1.0f, -2.0f } } });
251 }

◆ BOOST_FIXTURE_TEST_CASE() [4/4]

BOOST_FIXTURE_TEST_CASE ( AssertGraphStructureTest  ,
AssertFixture   
)

Definition at line 253 of file Assert.cpp.

References armnn::Addition, BOOST_AUTO_TEST_SUITE_END(), CheckNumberOfInputSlot(), CheckNumberOfOutputSlot(), armnn::Float32, GetFirstLayerWithName(), Layer::GetType(), armnn::Input, IsConnected(), and armnn::Subtraction.

254 {
255  auto optimized = SetupOptimizedNetwork({ { "Input0", { 1, 1, 2, 2 } },
256  { "Input1", { 1, 1, 2, 2 } } },
257  { "Output" });
258 
259  auto optimizedNetwork = boost::polymorphic_downcast<armnn::OptimizedNetwork*>(optimized.get());
260  auto graph = optimizedNetwork->GetGraph();
261 
262  BOOST_TEST((graph.GetNumInputs() == 2));
263  BOOST_TEST((graph.GetNumOutputs() == 1));
264  BOOST_TEST((graph.GetNumLayers() == 5));
265 
266  armnn::Layer* inputLayer0 = GetFirstLayerWithName(graph, "Input0");
267  BOOST_TEST((inputLayer0->GetType() == armnn::LayerType::Input));
268  BOOST_TEST(CheckNumberOfInputSlot(inputLayer0, 0));
269  BOOST_TEST(CheckNumberOfOutputSlot(inputLayer0, 1));
270 
271  armnn::Layer* inputLayer1 = GetFirstLayerWithName(graph, "Input1");
272  BOOST_TEST((inputLayer1->GetType() == armnn::LayerType::Input));
273  BOOST_TEST(CheckNumberOfInputSlot(inputLayer1, 0));
274  BOOST_TEST(CheckNumberOfOutputSlot(inputLayer1, 1));
275 
276  armnn::Layer* subLayer = GetFirstLayerWithName(graph, "Sub");
277  BOOST_TEST((subLayer->GetType() == armnn::LayerType::Subtraction));
278  BOOST_TEST(CheckNumberOfInputSlot(subLayer, 2));
279  BOOST_TEST(CheckNumberOfOutputSlot(subLayer, 1));
280 
281  armnn::Layer* addLayer = GetFirstLayerWithName(graph, "Output");
282  BOOST_TEST((addLayer->GetType() == armnn::LayerType::Addition));
283  BOOST_TEST(CheckNumberOfInputSlot(addLayer, 2));
284  BOOST_TEST(CheckNumberOfOutputSlot(addLayer, 1));
285 
287  BOOST_TEST(IsConnected(inputLayer0, subLayer, 0, 0, tensorInfo));
288  BOOST_TEST(IsConnected(inputLayer1, subLayer, 0, 1, tensorInfo));
289  BOOST_TEST(IsConnected(inputLayer0, addLayer, 0, 0, tensorInfo));
290  BOOST_TEST(IsConnected(subLayer, addLayer, 0, 1, tensorInfo));
291 
292  for (auto&& outputLayer : graph.GetOutputLayers())
293  {
294  BOOST_TEST(IsConnected(addLayer, const_cast<armnn::OutputLayer*>(outputLayer), 0, 0, tensorInfo));
295  }
296 }
armnn::Layer * GetFirstLayerWithName(armnn::Graph &graph, const std::string &name)
Definition: GraphUtils.cpp:20
bool IsConnected(armnn::Layer *srcLayer, armnn::Layer *destLayer, unsigned int srcSlot, unsigned int destSlot, const armnn::TensorInfo &expectedTensorInfo)
Definition: GraphUtils.cpp:42
LayerType GetType() const
Definition: Layer.hpp:259
bool CheckNumberOfInputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:32
bool CheckNumberOfOutputSlot(armnn::Layer *layer, unsigned int num)
Definition: GraphUtils.cpp:37