ArmNN
 20.02
PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp File Reference
#include "../TestUtils.hpp"
#include <Network.hpp>
#include <Optimizer.hpp>
#include <boost/test/unit_test.hpp>

Go to the source code of this file.

Functions

 BOOST_AUTO_TEST_CASE (PermuteAndBatchToSpaceAsDepthToSpaceOptimizerTest)
 Tests that the optimization performed by PermuteAndBatchToSpaceAsDepthToSpace is as expected. More...
 
 BOOST_AUTO_TEST_CASE (TransposeAndBatchToSpaceAsDepthToSpaceOptimizerTest)
 Tests that the optimization performed by PermuteAndBatchToSpaceAsDepthToSpace is as expected. More...
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE() [1/2]

BOOST_AUTO_TEST_CASE ( PermuteAndBatchToSpaceAsDepthToSpaceOptimizerTest  )

Tests that the optimization performed by PermuteAndBatchToSpaceAsDepthToSpace is as expected.

Note this does not ensure the correctness of the optimization - that is done in the below test.

Definition at line 87 of file PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp.

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

88 {
89  INetworkPtr network = CreateTestNetwork();
90  Graph graph = static_cast<Network*>(network.get())->GetGraph();
91 
92  // Confirm initial graph is as we expect
93  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<PermuteLayer>,
94  &IsLayerOfType<BatchToSpaceNdLayer>, &IsLayerOfType<OutputLayer>));
95 
96  // Perform the optimization which should merge the two layers into a DepthToSpace
98 
99  // Check that the replacement has been made as expected
100  auto checkDepthToSpace = [](const Layer* const layer) -> bool {
101  return IsLayerOfType<DepthToSpaceLayer>(layer) &&
102  static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_BlockSize == 2 &&
103  static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_DataLayout == DataLayout::NHWC &&
104  layer->GetOutputHandler().GetTensorInfo() == TensorInfo({ 1, 4, 6, 1 }, DataType::Float32);
105  };
106 
107  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, checkDepthToSpace,
108  &IsLayerOfType<OutputLayer>));
109 
110  // Check the new layer has the two merged layers listed as related layers
111  std::list<std::string> testRelatedLayers = { "batchToSpace", "permute" };
112  BOOST_TEST(CheckRelatedLayers<DepthToSpaceLayer>(graph, testRelatedLayers));
113 }
Optimizer::Optimizations MakeOptimizations(Args &&... args)
Definition: Optimizer.hpp:43
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:168
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
OptimizeForConnection< PermuteLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteLayer > > PermuteAndBatchToSpaceAsDepthToSpace
Private implementation of INetwork.
Definition: Network.hpp:28
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Definition: Layer.hpp:221
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
Definition: TestUtils.hpp:20
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:170
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
This layer represents a DepthToSpace operation.
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.

◆ BOOST_AUTO_TEST_CASE() [2/2]

BOOST_AUTO_TEST_CASE ( TransposeAndBatchToSpaceAsDepthToSpaceOptimizerTest  )

Tests that the optimization performed by PermuteAndBatchToSpaceAsDepthToSpace is as expected.

Note this does not ensure the correctness of the optimization - that is done in the below test.

Definition at line 117 of file PermuteAndBatchToSpaceAsDepthToSpaceTests.cpp.

References armnn::BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_SUITE_END(), Graph::cbegin(), Graph::cend(), CheckSequence(), armnn::CpuRef, IRuntime::Create(), armnn::Float32, armnn::MakeOptimizations(), armnn::NHWC, armnn::Optimize(), and Optimizer::Pass().

118 {
119  INetworkPtr network = CreateTransposeTestNetwork();
120  Graph graph = static_cast<Network*>(network.get())->GetGraph();
121 
122  // Confirm initial graph is as we expect
123  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<TransposeLayer>,
124  &IsLayerOfType<BatchToSpaceNdLayer>, &IsLayerOfType<OutputLayer>));
125 
126  // Perform the optimization which should merge the two layers into a DepthToSpace
128 
129  // Check that the replacement has been made as expected
130  auto checkDepthToSpace = [](const Layer* const layer) -> bool {
131  return IsLayerOfType<DepthToSpaceLayer>(layer) &&
132  static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_BlockSize == 2 &&
133  static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_DataLayout == DataLayout::NHWC &&
134  layer->GetOutputHandler().GetTensorInfo() == TensorInfo({ 1, 4, 6, 1 }, DataType::Float32);
135  };
136 
137  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, checkDepthToSpace,
138  &IsLayerOfType<OutputLayer>));
139 
140  // Check the new layer has the two merged layers listed as related layers
141  std::list<std::string> testRelatedLayers = { "batchToSpace", "permute" };
142  BOOST_TEST(CheckRelatedLayers<DepthToSpaceLayer>(graph, testRelatedLayers));
143 }
Optimizer::Optimizations MakeOptimizations(Args &&... args)
Definition: Optimizer.hpp:43
OptimizeForConnection< TransposeLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< TransposeLayer > > TransposeAndBatchToSpaceAsDepthToSpace
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:168
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
Private implementation of INetwork.
Definition: Network.hpp:28
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Definition: Layer.hpp:221
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
Definition: TestUtils.hpp:20
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:170
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
This layer represents a DepthToSpace operation.
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.