ArmNN
 22.05
OptimizeInversePermutesTests.cpp File Reference
#include <TestUtils.hpp>
#include <Optimizer.hpp>
#include <doctest/doctest.h>

Go to the source code of this file.

Functions

 TEST_SUITE ("Optimizer")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "Optimizer"  )

Definition at line 14 of file OptimizeInversePermutesTests.cpp.

References Graph::AddLayer(), Graph::cbegin(), Graph::cend(), CheckSequence(), Graph::InsertNewLayer(), armnn::MakeOptimizations(), and Optimizer::Pass().

15 {
16 using namespace armnn::optimizations;
17 
18 TEST_CASE("OptimizeInversePermutesTest")
19 {
20  armnn::Graph graph;
21 
22  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
23 
24  graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input");
25 
26  // Inserts two permutes, one the inverse of the other.
27  graph.InsertNewLayer<armnn::PermuteLayer>(output->GetInputSlot(0), armnn::PermuteDescriptor({ 0, 2, 3, 1 }),
28  "perm0231");
29  graph.InsertNewLayer<armnn::PermuteLayer>(output->GetInputSlot(0), armnn::PermuteDescriptor({ 0, 3, 1, 2 }),
30  "perm0312");
31 
32  CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>,
33  &IsLayerOfType<armnn::PermuteLayer>, &IsLayerOfType<armnn::PermuteLayer>,
34  &IsLayerOfType<armnn::OutputLayer>));
35 
37 
38  // The permutes are removed.
39  CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>,
40  &IsLayerOfType<armnn::OutputLayer>));
41 }
42 
43 TEST_CASE("OptimizeInverseTransposesTest")
44 {
45  armnn::Graph graph;
46 
47  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
48 
49  graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input");
50 
51  // Inserts two permutes, one the inverse of the other.
52  graph.InsertNewLayer<armnn::TransposeLayer>(output->GetInputSlot(0),
53  armnn::TransposeDescriptor({ 0, 3, 1, 2 }),
54  "transpose0312");
55  graph.InsertNewLayer<armnn::TransposeLayer>(output->GetInputSlot(0),
56  armnn::TransposeDescriptor({ 0, 2, 3, 1 }),
57  "transpose0231");
58 
59  CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>,
60  &IsLayerOfType<armnn::TransposeLayer>, &IsLayerOfType<armnn::TransposeLayer>,
61  &IsLayerOfType<armnn::OutputLayer>));
62 
64 
65  // The permutes are removed.
66  CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>,
67  &IsLayerOfType<armnn::OutputLayer>));
68 }
69 
70 }
OptimizeForConnection< PermuteLayer, PermuteLayer, OptimizeInversePermutesImpl< PermuteLayer > > OptimizeInversePermutes
Optimizer::Optimizations MakeOptimizations(Args &&... args)
Definition: Optimizer.hpp:43
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
Definition: TestUtils.hpp:21
OptimizeForConnection< TransposeLayer, TransposeLayer, OptimizeInversePermutesImpl< TransposeLayer > > OptimizeInverseTransposes
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:425
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:179
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
This layer represents a permutation operation.
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
This layer represents a transpose operation.
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
A TransposeDescriptor for the TransposeLayer.
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:181
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:440
A PermuteDescriptor for the PermuteLayer.