// // Copyright © 2017 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // #include #include #include TEST_SUITE("Optimizer") { using namespace armnn::optimizations; TEST_CASE("MovePermuteUpTest") { const armnn::TensorInfo info({ 1, 5, 2, 3 }, armnn::DataType::Float32); const armnn::TensorInfo permuted({ 1, 3, 5, 2 }, armnn::DataType::Float32); armnn::Graph graph; armnn::LayerBindingId inputId = 0; armnn::Layer* head = graph.AddLayer(0, "output"); std::string permuteLayerName = "original_permute"; // Insert permute head = graph.InsertNewLayer(head->GetInputSlot(0), armnn::PermuteDescriptor({ 0, 2, 3, 1 }), permuteLayerName.c_str()); head->GetOutputHandler().SetTensorInfo(permuted); // Inserts layers that don't care about data format. head = graph.InsertNewLayer(head->GetInputSlot(0), armnn::ActivationDescriptor{}, ""); head->GetOutputHandler().SetTensorInfo(info); head = graph.InsertNewLayer(head->GetInputSlot(0), ""); head->GetOutputHandler().SetTensorInfo(info); // Inserts input for 2nd input of Addition. graph.InsertNewLayer(head->GetInputSlot(1), inputId++, "") ->GetOutputHandler() .SetTensorInfo(info); head = graph.InsertNewLayer(head->GetInputSlot(0), armnn::FakeQuantizationDescriptor{}, ""); head->GetOutputHandler().SetTensorInfo(info); head = graph.InsertNewLayer(head->GetInputSlot(0), ""); head->GetOutputHandler().SetTensorInfo(info); head = graph.InsertNewLayer(head->GetInputSlot(0), ""); head->GetOutputHandler().SetTensorInfo(info); head = graph.InsertNewLayer(head->GetInputSlot(0), ""); head->GetOutputHandler().SetTensorInfo(info); // Inserts input for 2nd input of Multiplication. graph.InsertNewLayer(head->GetInputSlot(1), inputId++, "") ->GetOutputHandler() .SetTensorInfo(info); // Inserts input. graph.InsertNewLayer(head->GetInputSlot(0), inputId++, "") ->GetOutputHandler() .SetTensorInfo(info); CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType)); armnn::Optimizer::Pass(graph, armnn::MakeOptimizations(MovePermuteUp())); // The permute is moved to the top. New permutes for layers with multiple inputs. CHECK(CheckSequence(graph.cbegin(), graph.cend(), &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType, &IsLayerOfType)); std::list testRelatedLayers = { permuteLayerName }; CHECK(CheckRelatedLayers(graph, testRelatedLayers)); } }