ArmNN
 22.05.01
ConvertConstPermuteLayersToConstLayersTest.cpp File Reference
#include "LayersFwd.hpp"
#include <Network.hpp>
#include <doctest/doctest.h>
#include <Optimizer.hpp>
#include <TestUtils.hpp>

Go to the source code of this file.

Functions

 TEST_SUITE ("Optimizer")
 

Function Documentation

◆ TEST_SUITE()

TEST_SUITE ( "Optimizer"  )

Definition at line 12 of file ConvertConstPermuteLayersToConstLayersTest.cpp.

References Graph::AddLayer(), Graph::cbegin(), Graph::cend(), CheckSequence(), OutputSlot::Connect(), armnn::Float32, Layer::GetInputSlot(), TensorInfo::GetNumElements(), Layer::GetOutputSlot(), TensorInfo::GetShape(), OutputSlot::GetTensorInfo(), ConstantLayer::m_LayerOutput, armnn::MakeOptimizations(), Optimizer::Pass(), armnnUtils::Permuted(), and OutputSlot::SetTensorInfo().

13 {
14 using namespace armnn;
15 using namespace armnn::optimizations;
16 
17 TEST_CASE("ConvertConstPermuteToConst")
18 {
19  Graph graph;
20  const unsigned int shape[] = {1, 2, 2, 3};
21 
22  const TensorInfo constTensorInfo(4, shape, DataType::Float32, 1.0, 0, true);
23 
24  ConstantLayer* constant = graph.AddLayer<ConstantLayer>("constant");
25  std::vector<float> constantValues(constTensorInfo.GetNumElements(), 4.5f);
26  ConstTensor constTensor(constTensorInfo, constantValues.data());
27  constant->m_LayerOutput = std::make_shared<ScopedTensorHandle>(constTensor);
28  constant->GetOutputSlot().SetTensorInfo(constTensorInfo);
29 
30  PermuteDescriptor desc({ 0, 2, 3, 1 });
31  PermuteLayer* permuteLayer = graph.AddLayer<PermuteLayer>(desc, "permute");
32  TensorInfo infoPermuted = armnnUtils::Permuted(constTensorInfo, { 0, 2, 3, 1 });
33  permuteLayer->GetOutputSlot().SetTensorInfo(infoPermuted);
34 
35  OutputLayer* output = graph.AddLayer<OutputLayer>(0, "output");
36 
37  // Connect up constant -> permute -> output
38  constant->GetOutputSlot().Connect(permuteLayer->GetInputSlot(0));
39  permuteLayer->GetOutputSlot().Connect(output->GetInputSlot(0));
40 
41  CHECK(CheckSequence(graph.cbegin(), graph.cend(),
42  &IsLayerOfType<ConstantLayer>,
43  &IsLayerOfType<PermuteLayer>,
44  &IsLayerOfType<OutputLayer>));
45 
47 
48  CHECK(CheckSequence(graph.cbegin(), graph.cend(),
49  &IsLayerOfType<ConstantLayer>,
50  &IsLayerOfType<OutputLayer>));
51 
52  TensorShape tensorShape = constant->GetOutputSlot(0).GetTensorInfo().GetShape();
53  CHECK(tensorShape[0] == shape[0]);
54  CHECK(tensorShape[1] == shape[3]);
55  CHECK(tensorShape[2] == shape[1]);
56  CHECK(tensorShape[3] == shape[2]);
57 
58 }
59 
60 }
A layer that the constant data can be bound to.
const TensorShape & GetShape() const
Definition: Tensor.hpp:191
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
std::shared_ptr< ConstTensorHandle > m_LayerOutput
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
int Connect(InputSlot &destination)
Definition: Layer.cpp:112
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
Copyright (c) 2021 ARM Limited and Contributors.
This layer represents a permutation operation.
OptimizeForConnection< ConstantLayer, PermuteLayer, ConvertConstPermuteLayersToConstLayers > FusePermuteIntoConstLayer
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:322
A layer user-provided data can be bound to (e.g. inputs, outputs).
Definition: OutputLayer.hpp:13
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:327
void SetTensorInfo(const TensorInfo &tensorInfo) override
Definition: Layer.cpp:87
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition: Layer.hpp:324
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:181
const TensorInfo & GetTensorInfo() const override
Definition: Layer.cpp:92
armnn::TensorShape Permuted(const armnn::TensorShape &srcShape, const armnn::PermutationVector &mappings)
Definition: Permute.cpp:98
A PermuteDescriptor for the PermuteLayer.