From 9c9d5b9d796d243d88bd7a7aebb2e7e6c467e3a4 Mon Sep 17 00:00:00 2001 From: Cathal Corbett Date: Wed, 17 Aug 2022 17:30:16 +0100 Subject: IVGCVSW-7133 Add TosaMappings backbone structure with support for Addition TosaMappings operator. Signed-off-by: Cathal Corbett Change-Id: Ibea0cf625b3af4ab38e8b985f7a129c983ca9659 --- src/backends/tosaCommon/TosaMappings.hpp | 81 ++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/backends/tosaCommon/TosaMappings.hpp (limited to 'src/backends/tosaCommon/TosaMappings.hpp') diff --git a/src/backends/tosaCommon/TosaMappings.hpp b/src/backends/tosaCommon/TosaMappings.hpp new file mode 100644 index 0000000000..5728ff3203 --- /dev/null +++ b/src/backends/tosaCommon/TosaMappings.hpp @@ -0,0 +1,81 @@ +// +// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// SPDX-License-Identifier: MIT +// + +#pragma once + +#include + +#include +#include "operatorMappings/AdditionOperator.hpp" + +using namespace armnn; +using namespace tosa; + +// From the input armnn::Layer, set the corresponding data field in the +// tosa::TosaSerializationTensor where constant tensor data exists in the armnn::Layer. +void SetBasicBlockConstantTensorData(Layer* layer, TosaSerializationBasicBlock* /*basicBlock*/) +{ + switch (layer->GetType()) + { + case LayerType::Convolution2d: + { + // ToDo: using Convolution2d as an example as it has constant tensors for weights and bias. + // ToDo: manually set TosaOperator data of basicBlock where constant tensors exist. + } + default: + // If no switch statement for layer, no constant tensors exist in that layer, return + return; + } +} + +// Populates a tosa::TosaSerializationBasicBlock from constructing +// tosa::TosaSerializationOperator(s) and tosa::TosaSerializationTensor(s) +// based on the input armnn::LayerType and associated armnn::TensorInfos and armnn::Descriptor. +// +// If an armnn::LayerType does not have a tosa mapping or the mapping is not implemented in ArmNN, +// an empty tosa::TosaSerializationBasicBlock() is returned with operator tosa::Op_UNKNOWN. +TosaSerializationBasicBlock* GetTosaMapping(const LayerType type, + const std::vector& inputs, + const std::vector& outputs, + const BaseDescriptor& /*descriptor*/) +{ + switch (type) + { + case LayerType::Addition: + { + return ConvertAdditionToTosaOperator(inputs, outputs); + } + default: + { + // empty basic block when no tosa mapping implemented/exists + TosaSerializationOperator* op = new TosaSerializationOperator(Op_UNKNOWN, Attribute_NONE, nullptr, {}, {}); + return new TosaSerializationBasicBlock("", {op}, {}, {}, {}); + } + } +} + +// Function called in armnn::OptimizeSubgraphView() when access to armnn::Layer is available +// and there is an option to set tosa basic block data from constant layer tenors available from the input layer. +TosaSerializationBasicBlock* GetTosaMappingFromLayer(Layer* layer) +{ + std::vector inputs; + for (auto inputSlot : layer->GetInputSlots()) + { + inputs.push_back(&inputSlot.GetConnection()->GetTensorInfo()); + } + + std::vector outputs; + for (auto& outputSlot : layer->GetOutputSlots()) + { + outputs.push_back(&outputSlot.GetTensorInfo()); + } + + TosaSerializationBasicBlock* basicBlock = GetTosaMapping(layer->GetType(), + inputs, + outputs, + layer->GetParameters()); + SetBasicBlockConstantTensorData(layer, basicBlock); + return basicBlock; +} -- cgit v1.2.1