Shared function for the below tests, so that we test the same network in both cases.
Shared function for the below tests, so that we test the same network in both cases.
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.
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.
23 std::unique_ptr<NetworkImpl> CreateTestNetworkImpl()
25 std::unique_ptr<NetworkImpl> network(
new NetworkImpl());
27 auto input = network->AddInputLayer(0,
"input");
29 input->GetOutputSlot(0).SetTensorInfo(inputInfo);
34 permute->GetOutputSlot(0).SetTensorInfo(permuteInfo);
35 input->GetOutputSlot(0).Connect(permute->GetInputSlot(0));
41 auto batchToSpace = network->AddBatchToSpaceNdLayer(batchToSpaceDesc,
"batchToSpace");
43 batchToSpace->GetOutputSlot(0).SetTensorInfo(batchToSpaceInfo);
44 permute->GetOutputSlot(0).Connect(batchToSpace->GetInputSlot(0));
46 auto output = network->AddOutputLayer(0,
"output");
47 batchToSpace->GetOutputSlot(0).Connect(output->GetInputSlot(0));
53 std::unique_ptr<NetworkImpl> CreateTransposeTestNetworkImpl()
56 std::unique_ptr<NetworkImpl> network(
new NetworkImpl());
58 auto input = network->AddInputLayer(0,
"input");
60 input->GetOutputSlot(0).SetTensorInfo(inputInfo);
65 permute->GetOutputSlot(0).SetTensorInfo(permuteInfo);
66 input->GetOutputSlot(0).Connect(permute->GetInputSlot(0));
72 auto batchToSpace = network->AddBatchToSpaceNdLayer(batchToSpaceDesc,
"batchToSpace");
74 batchToSpace->GetOutputSlot(0).SetTensorInfo(batchToSpaceInfo);
75 permute->GetOutputSlot(0).Connect(batchToSpace->GetInputSlot(0));
77 auto output = network->AddOutputLayer(0,
"output");
78 batchToSpace->GetOutputSlot(0).Connect(output->GetInputSlot(0));
87 TEST_CASE(
"PermuteAndBatchToSpaceAsDepthToSpaceOptimizerTest")
89 std::unique_ptr<NetworkImpl> network = CreateTestNetworkImpl();
90 Graph graph = network.get()->GetGraph();
94 &IsLayerOfType<BatchToSpaceNdLayer>, &IsLayerOfType<OutputLayer>));
100 auto checkDepthToSpace = [](
const Layer*
const layer) ->
bool {
101 return IsLayerOfType<DepthToSpaceLayer>(layer) &&
102 static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_BlockSize == 2 &&
108 &IsLayerOfType<OutputLayer>));
111 std::list<std::string> testRelatedLayers = {
"batchToSpace",
"permute" };
112 CHECK(CheckRelatedLayers<DepthToSpaceLayer>(graph, testRelatedLayers));
117 TEST_CASE(
"TransposeAndBatchToSpaceAsDepthToSpaceOptimizerTest")
119 std::unique_ptr<NetworkImpl> network = CreateTransposeTestNetworkImpl();
120 Graph graph = network.get()->GetGraph();
124 &IsLayerOfType<BatchToSpaceNdLayer>, &IsLayerOfType<OutputLayer>));
130 auto checkDepthToSpace = [](
const Layer*
const layer) ->
bool {
131 return IsLayerOfType<DepthToSpaceLayer>(layer) &&
132 static_cast<const DepthToSpaceLayer*>(layer)->GetParameters().m_BlockSize == 2 &&
138 &IsLayerOfType<OutputLayer>));
141 std::list<std::string> testRelatedLayers = {
"batchToSpace",
"permute" };
142 CHECK(CheckRelatedLayers<DepthToSpaceLayer>(graph, testRelatedLayers));
146 #if defined(ARMNNREF_ENABLED) 154 auto input = network->AddInputLayer(0,
"input");
156 input->GetOutputSlot(0).SetTensorInfo(inputInfo);
161 permute->GetOutputSlot(0).SetTensorInfo(permuteInfo);
162 input->GetOutputSlot(0).Connect(permute->GetInputSlot(0));
168 auto batchToSpace = network->AddBatchToSpaceNdLayer(batchToSpaceDesc,
"batchToSpace");
170 batchToSpace->GetOutputSlot(0).SetTensorInfo(batchToSpaceInfo);
171 permute->GetOutputSlot(0).Connect(batchToSpace->GetInputSlot(0));
173 auto output = network->AddOutputLayer(0,
"output");
174 batchToSpace->GetOutputSlot(0).Connect(output->GetInputSlot(0));
185 auto input = network->AddInputLayer(0,
"input");
187 input->GetOutputSlot(0).SetTensorInfo(inputInfo);
192 permute->GetOutputSlot(0).SetTensorInfo(permuteInfo);
193 input->GetOutputSlot(0).Connect(permute->GetInputSlot(0));
199 auto batchToSpace = network->AddBatchToSpaceNdLayer(batchToSpaceDesc,
"batchToSpace");
201 batchToSpace->GetOutputSlot(0).SetTensorInfo(batchToSpaceInfo);
202 permute->GetOutputSlot(0).Connect(batchToSpace->GetInputSlot(0));
204 auto output = network->AddOutputLayer(0,
"output");
205 batchToSpace->GetOutputSlot(0).Connect(output->GetInputSlot(0));
212 TEST_CASE(
"PermuteAndBatchToSpaceAsDepthToSpaceCorrectnessTest")
221 CHECK(
CheckSequence(optGraph.cbegin(), optGraph.cend(), &IsLayerOfType<InputLayer>,
222 &IsLayerOfType<DepthToSpaceLayer>, &IsLayerOfType<OutputLayer>));
226 runtime->LoadNetwork(netId, std::move(optimizedNetwork));
228 std::vector<float> inputData{
231 1.0f, 2.0f, 3.0f, 4.0f, 10.0f, 20.0f, 30.0f, 40.0f, 100.0f, 200.0f, 300.0f, 400.0f,
232 -1.0f, -2.0f, -3.0f, -4.0f, -10.0f, -20.0f, -30.0f, -40.0f, -100.0f, -200.0f, -300.0f, -400.0f,
237 std::vector<float> outputData(4 * 6);
240 runtime->EnqueueWorkload(netId, inputs, outputs);
244 std::vector<float> expectedOutput = {
247 1.0f, 2.0f, 10.0f, 20.0f, 100.0f, 200.0f,
248 3.0f, 4.0f, 30.0f, 40.0f, 300.0f, 400.0f,
250 -1.0f, -2.0f, -10.0f, -20.0f, -100.0f, -200.0f,
251 -3.0f, -4.0f, -30.0f, -40.0f, -300.0f, -400.0f,
254 CHECK(outputData == expectedOutput);
259 TEST_CASE(
"TransposeAndBatchToSpaceAsDepthToSpaceCorrectnessTest")
261 INetworkPtr network = CreateTransposeTestNetwork();
268 CHECK(
CheckSequence(optGraph.cbegin(), optGraph.cend(), &IsLayerOfType<InputLayer>,
269 &IsLayerOfType<DepthToSpaceLayer>, &IsLayerOfType<OutputLayer>));
273 runtime->LoadNetwork(netId, std::move(optimizedNetwork));
275 std::vector<float> inputData{
278 1.0f, 2.0f, 3.0f, 4.0f, 10.0f, 20.0f, 30.0f, 40.0f, 100.0f, 200.0f, 300.0f, 400.0f,
279 -1.0f, -2.0f, -3.0f, -4.0f, -10.0f, -20.0f, -30.0f, -40.0f, -100.0f, -200.0f, -300.0f, -400.0f,
284 std::vector<float> outputData(4 * 6);
287 runtime->EnqueueWorkload(netId, inputs, outputs);
291 std::vector<float> expectedOutput = {
294 1.0f, 2.0f, 10.0f, 20.0f, 100.0f, 200.0f,
295 3.0f, 4.0f, 30.0f, 40.0f, 300.0f, 400.0f,
297 -1.0f, -2.0f, -10.0f, -20.0f, -100.0f, -200.0f,
298 -3.0f, -4.0f, -30.0f, -40.0f, -300.0f, -400.0f,
301 CHECK(outputData == expectedOutput);
static IRuntimePtr Create(const CreationOptions &options)
CPU Execution: Reference C++ kernels.
Optimizer::Optimizations MakeOptimizations(Args &&... args)
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...
static void Pass(Graph &graph, const Optimizations &optimizations)
std::unique_ptr< IRuntime, void(*)(IRuntime *runtime)> IRuntimePtr
DataLayout m_DataLayout
The data layout to be used (NCHW, NHWC).
std::vector< std::pair< LayerBindingId, class ConstTensor > > InputTensors
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
Private implementation of INetwork.
A tensor defined by a TensorInfo (shape and data type) and a mutable backing store.
OptimizeForConnection< PermuteLayer, BatchToSpaceNdLayer, PermuteAndBatchToSpaceAsDepthToSpaceImpl< PermuteLayer > > PermuteAndBatchToSpaceAsDepthToSpace
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
std::vector< unsigned int > m_BlockShape
Block shape values.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
std::vector< std::pair< LayerBindingId, class Tensor > > OutputTensors
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Graph & GetGraphForTesting(IOptimizedNetwork *optNet)
bool CheckSequence(const armnn::Graph::ConstIterator first, const armnn::Graph::ConstIterator last)
A TransposeDescriptor for the TransposeLayer.
ConstIterator cend() const
Returns const iterator pointing to the end of the list. Lowercase for range-based for loops...
armnn::INetworkPtr CreateTestNetwork(armnn::TensorInfo &inputTensorInfo)
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
static INetworkPtr Create(NetworkOptions networkOptions={})
This layer represents a DepthToSpace operation.
A PermuteDescriptor for the PermuteLayer.