ArmNN  NotReleased
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)
 

Function Documentation

◆ BOOST_AUTO_TEST_CASE()

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 56 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().

57 {
58  INetworkPtr network = CreateTestNetwork();
59  Graph graph = static_cast<Network*>(network.get())->GetGraph();
60 
61  // Confirm initial graph is as we expect
62  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, &IsLayerOfType<PermuteLayer>,
63  &IsLayerOfType<BatchToSpaceNdLayer>, &IsLayerOfType<OutputLayer>));
64 
65  // Perform the optimization which should merge the two layers into a DepthToSpace
67 
68  // Check that the replacement has been made as expected
69  auto checkDepthToSpace = [](const Layer* const layer) -> bool {
70  return IsLayerOfType<DepthToSpaceLayer>(layer) &&
71  static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_BlockSize == 2 &&
72  static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_DataLayout == DataLayout::NHWC &&
73  layer->GetOutputHandler().GetTensorInfo() == TensorInfo({ 1, 4, 6, 1 }, DataType::Float32);
74  };
75 
76  BOOST_TEST(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType<InputLayer>, checkDepthToSpace,
77  &IsLayerOfType<OutputLayer>));
78 
79  // Check the new layer has the two merged layers listed as related layers
80  std::list<std::string> testRelatedLayers = { "batchToSpace", "permute" };
81  BOOST_TEST(CheckRelatedLayers<DepthToSpaceLayer>(graph, testRelatedLayers));
82 }
const OutputHandler & GetOutputHandler(unsigned int i=0) const
Definition: Layer.hpp:221
This layer represents a DepthToSpace operation.
OptimizeForConnection< PermuteLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl > PermuteAndBatchToSpaceAsDepthToSpace
static void Pass(Graph &graph, const Optimizations &optimizations)
Definition: Optimizer.cpp:16
const TensorInfo & GetTensorInfo() const
Gets the matching TensorInfo for the output.
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
Definition: TestUtils.hpp:20
Private implementation of INetwork.
Definition: Network.hpp:27
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:85
ConstIterator cbegin() const
Returns const iterator pointing to the beginning of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:168
Optimizer::Optimizations MakeOptimizations(Args &&... args)
Definition: Optimizer.hpp:43
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
Definition: Graph.hpp:170