From 541880fcf4572887e57658a508623fb5f95ac554 Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Mon, 16 May 2022 15:20:56 +0100 Subject: IVGCVSW-6147 ConstTensorsAsInput: Optimizer - FusePermuteIntoConstLayer * No trailing permute layer after a constant layer * Unit test for optimization Signed-off-by: Cathal Corbett Change-Id: I0d098f5af41d2c55df7cef1ccfb848093320ddc1 --- src/armnnOnnxParser/OnnxParser.cpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/armnnOnnxParser/OnnxParser.cpp') diff --git a/src/armnnOnnxParser/OnnxParser.cpp b/src/armnnOnnxParser/OnnxParser.cpp index 4eaf63653b..60bd962db7 100644 --- a/src/armnnOnnxParser/OnnxParser.cpp +++ b/src/armnnOnnxParser/OnnxParser.cpp @@ -1043,15 +1043,24 @@ void OnnxParserImpl::AddConvLayerWithDepthwiseConv(const onnx::NodeProto& node, desc.m_BiasEnabled = convDesc.m_BiasEnabled; armnn::IConnectableLayer* layer = m_Network->AddDepthwiseConvolution2dLayer(desc, node.name().c_str()); - std::vector tensorIndexes= {node.input(0), node.input(1)}; - - // weights come in as [O,1,H,W] from ONNX and need to be converted to ArmNNs dephtwise weights layout [1,H,W,O] - armnn::PermutationVector perVec {3,0,1,2}; - auto weightTensor = CreateConstTensor(node.input(1), perVec); + std::string permuteStr = "permute_" + node.input(1); + std::vector tensorIndexes= {node.input(0), permuteStr}; + auto weightTensor = CreateConstTensor(node.input(1)); IConnectableLayer* weightsLayer = m_Network->AddConstantLayer(weightTensor.first); + + // weights come in as [O,1,H,W] from ONNX and need to be converted to ArmNNs depthwise weights layout [1,H,W,O] + armnn::PermutationVector perVec {3, 0, 1, 2}; + TensorInfo weightsPermuted = armnnUtils::Permuted(weightTensor.first.GetInfo(), perVec); + + // Inserts NewLayer so layers don't need to be re-sorted. + IConnectableLayer* permuteLayer = m_Network->AddPermuteLayer(PermuteDescriptor(perVec), + "permute_layer"); + permuteLayer->GetOutputSlot(0).SetTensorInfo(weightsPermuted); + permuteLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u)); + weightsLayer->GetOutputSlot(0).SetTensorInfo(weightTensor.first.GetInfo()); - weightsLayer->GetOutputSlot(0).Connect(layer->GetInputSlot(1u)); + weightsLayer->GetOutputSlot(0).Connect(permuteLayer->GetInputSlot(0u)); if (node.input_size() == 3) { @@ -1076,7 +1085,7 @@ void OnnxParserImpl::AddConvLayerWithDepthwiseConv(const onnx::NodeProto& node, auto outputInfo = ComputeOutputInfo({ node.output(0) }, layer, { m_TensorsInfo[node.input(0)].m_info->GetShape(), - weightTensor.first.GetInfo().GetShape() }); + weightsPermuted.GetShape() }); layer->GetOutputSlot(0).SetTensorInfo(outputInfo[0]); -- cgit v1.2.1