ArmNN
 20.02
SquashEqualSiblingsTests.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "../TestUtils.hpp"
7 
8 #include <Optimizer.hpp>
9 
10 #include <boost/test/unit_test.hpp>
11 
12 using namespace armnn;
13 
15 using namespace armnn::optimizations;
16 
17 BOOST_AUTO_TEST_CASE(SquashEqualSiblingsTest)
18 {
19  armnn::Graph graph;
20 
21  armnn::LayerBindingId outputId = 0;
22 
23  const armnn::TensorInfo info({ 1, 2, 3, 5 }, armnn::DataType::Float32);
24  const armnn::TensorInfo permuted({ 1, 5, 2, 3 }, armnn::DataType::Float32);
25 
26  auto input = graph.AddLayer<armnn::InputLayer>(0, "input");
28 
29  // Inserts equal permutes, equal reshapes and something else.
30  const armnn::PermuteDescriptor permDesc({ 0, 2, 3, 1 });
31  const armnn::ReshapeDescriptor reshapeDesc{ { 1, 3, 1, 5 } };
32 
33  armnn::Layer* layer;
34 
35  layer = graph.AddLayer<armnn::PermuteLayer>(permDesc, "");
36  layer->GetOutputSlot().SetTensorInfo(permuted);
37  layer->GetOutputSlot().Connect(graph.AddLayer<armnn::OutputLayer>(outputId++, "")->GetInputSlot(0));
38  input->GetOutputSlot().Connect(layer->GetInputSlot(0));
39 
40  layer = graph.AddLayer<armnn::ReshapeLayer>(reshapeDesc, "");
41  layer->GetOutputSlot().Connect(graph.AddLayer<armnn::OutputLayer>(outputId++, "")->GetInputSlot(0));
42  input->GetOutputSlot().Connect(layer->GetInputSlot(0));
43 
44  layer = graph.AddLayer<armnn::FloorLayer>("");
45  layer->GetOutputSlot().Connect(graph.AddLayer<armnn::OutputLayer>(outputId++, "")->GetInputSlot(0));
46  input->GetOutputSlot().Connect(layer->GetInputSlot(0));
47 
48  layer = graph.AddLayer<armnn::ReshapeLayer>(reshapeDesc, "");
49  layer->GetOutputSlot().Connect(graph.AddLayer<armnn::OutputLayer>(outputId++, "")->GetInputSlot(0));
50  input->GetOutputSlot().Connect(layer->GetInputSlot(0));
51 
52  layer = graph.AddLayer<armnn::PermuteLayer>(permDesc, "");
53  layer->GetOutputSlot().SetTensorInfo(permuted);
54  layer->GetOutputSlot().Connect(graph.AddLayer<armnn::OutputLayer>(outputId++, "")->GetInputSlot(0));
55  input->GetOutputSlot().Connect(layer->GetInputSlot(0));
56 
57  BOOST_TEST(CheckSequence(
58  graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>, &IsLayerOfType<armnn::PermuteLayer>,
59  &IsLayerOfType<armnn::ReshapeLayer>, &IsLayerOfType<armnn::FloorLayer>, &IsLayerOfType<armnn::ReshapeLayer>,
60  &IsLayerOfType<armnn::PermuteLayer>, &IsLayerOfType<armnn::OutputLayer>, &IsLayerOfType<armnn::OutputLayer>,
61  &IsLayerOfType<armnn::OutputLayer>, &IsLayerOfType<armnn::OutputLayer>, &IsLayerOfType<armnn::OutputLayer>));
62 
64 
65  // The permutes and reshapes are squashed.
66 
67  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>,
68  &IsLayerOfType<armnn::PermuteLayer>, &IsLayerOfType<armnn::ReshapeLayer>,
69  &IsLayerOfType<armnn::FloorLayer>, &IsLayerOfType<armnn::OutputLayer>,
70  &IsLayerOfType<armnn::OutputLayer>, &IsLayerOfType<armnn::OutputLayer>,
71  &IsLayerOfType<armnn::OutputLayer>, &IsLayerOfType<armnn::OutputLayer>));
72 }
73 
OptimizeForConnection< Layer, PermuteLayer, SquashEqualSiblingsImpl< PermuteLayer > > SquashEqualPermuteSiblings
BOOST_AUTO_TEST_SUITE(TensorflowLiteParser)
Optimizer::Optimizations MakeOptimizations(Args &&... args)
Definition: Optimizer.hpp:43
A ReshapeDescriptor for the ReshapeLayer.
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:397
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:168
int Connect(InputSlot &destination)
Definition: Layer.cpp:79
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
This layer represents a reshape operation.
OptimizeForConnection< Layer, ReshapeLayer, SquashEqualSiblingsImpl< ReshapeLayer > > SquashEqualReshapeSiblings
Copyright (c) 2020 ARM Limited.
This layer represents a permutation operation.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:171
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:310
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
BOOST_AUTO_TEST_CASE(CheckConvolution2dLayer)
This layer represents a floor operation.
Definition: FloorLayer.hpp:13
BOOST_AUTO_TEST_SUITE_END()
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
Definition: TestUtils.hpp:20
void SetTensorInfo(const TensorInfo &tensorInfo) override
Definition: Layer.cpp:58
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:312
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:170
A PermuteDescriptor for the PermuteLayer.