ArmNN
 22.02
PermuteAsReshapeTests.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 PermuteAsReshapeTests.cpp.

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

15 {
16 using namespace armnn::optimizations;
17 
18 TEST_CASE("PermuteAsReshapeTest")
19 {
20  armnn::Graph graph;
21 
22  std::string permuteLayerName = "permute";
23 
24  const armnn::TensorInfo infoIn({ 1, 2, 3, 1 }, armnn::DataType::Float32);
25  const armnn::TensorInfo infoOut({ 1, 1, 2, 3 }, armnn::DataType::Float32);
26 
27  auto output = graph.AddLayer<armnn::OutputLayer>(0, "output");
28 
29  graph.InsertNewLayer<armnn::InputLayer>(output->GetInputSlot(0), 0, "input")
30  ->GetOutputHandler()
31  .SetTensorInfo(infoIn);
32 
33  // Inserts permute.
34  graph
35  .InsertNewLayer<armnn::PermuteLayer>(output->GetInputSlot(0), armnn::PermuteDescriptor({ 0, 2, 3, 1 }),
36  permuteLayerName.c_str())
37  ->GetOutputHandler()
38  .SetTensorInfo(infoOut);
39 
40  CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>,
41  &IsLayerOfType<armnn::PermuteLayer>, &IsLayerOfType<armnn::OutputLayer>));
42 
44 
45  // The permute is replaced by an equivalent reshape.
46 
47  auto checkReshape = [&infoOut](const armnn::Layer* const layer) -> bool {
48  const auto reshapeLayer = static_cast<const armnn::ReshapeLayer*>(layer);
49  return IsLayerOfType<armnn::ReshapeLayer>(layer) &&
50  (reshapeLayer->GetParameters().m_TargetShape == infoOut.GetShape()) &&
51  (reshapeLayer->GetOutputHandler().GetTensorInfo().GetShape() == infoOut.GetShape());
52  };
53 
54  CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<armnn::InputLayer>, checkReshape,
55  &IsLayerOfType<armnn::OutputLayer>));
56 
57  std::list<std::string> testRelatedLayers = { permuteLayerName };
58  CHECK(CheckRelatedLayers<armnn::ReshapeLayer>(graph, testRelatedLayers));
59 }
60 
61 }
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
LayerT * AddLayer(Args &&... args)
Adds a new layer, of type LayerType, to the graph constructed with the arguments passed.
Definition: Graph.hpp:420
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:177
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
This layer represents a reshape operation.
This layer represents a permutation operation.
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
OptimizeForType< PermuteLayer, PermuteAsReshapeImpl > PermuteAsReshape
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: InputLayer.hpp:13
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:179
LayerT * InsertNewLayer(InputSlot &insertBefore, Args &&... args)
Inserts a new layer between the output slot currently connected to insertBefore and insertBefore itse...
Definition: Graph.hpp:434
A PermuteDescriptor for the PermuteLayer.