Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "TosaMappings.hpp" |
| 7 | |
| 8 | using namespace armnn; |
| 9 | using namespace tosa; |
| 10 | |
| 11 | void SetBasicBlockConstantTensorData(Layer* layer, TosaSerializationBasicBlock* /*basicBlock*/) |
| 12 | { |
| 13 | switch (layer->GetType()) |
| 14 | { |
| 15 | case LayerType::Convolution2d: |
| 16 | { |
| 17 | // ToDo: using Convolution2d as an example as it has constant tensors for weights and bias. |
| 18 | // ToDo: manually set TosaOperator data of basicBlock where constant tensors exist. |
| 19 | } |
| 20 | default: |
| 21 | // If no switch statement for layer, no constant tensors exist in that layer, return |
| 22 | return; |
| 23 | } |
| 24 | } |
| 25 | |
| 26 | TosaSerializationBasicBlock* GetTosaMapping(const LayerType type, |
| 27 | const std::vector<const TensorInfo*>& inputs, |
| 28 | const std::vector<const TensorInfo*>& outputs, |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame^] | 29 | const BaseDescriptor& /*descriptor*/, |
| 30 | bool isMain = false) |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 31 | { |
| 32 | switch (type) |
| 33 | { |
| 34 | case LayerType::Addition: |
| 35 | { |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame^] | 36 | return ConvertAdditionToTosaOperator(inputs, outputs, isMain); |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 37 | } |
| 38 | default: |
| 39 | { |
| 40 | // empty basic block when no tosa mapping implemented/exists |
| 41 | TosaSerializationOperator* op = new TosaSerializationOperator(Op_UNKNOWN, Attribute_NONE, nullptr, {}, {}); |
| 42 | return new TosaSerializationBasicBlock("", {op}, {}, {}, {}); |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame^] | 47 | TosaSerializationBasicBlock* GetTosaMappingFromLayer(Layer* layer, bool isMain = false) |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 48 | { |
| 49 | std::vector<const TensorInfo*> inputs; |
| 50 | for (auto inputSlot : layer->GetInputSlots()) |
| 51 | { |
| 52 | inputs.push_back(&inputSlot.GetConnection()->GetTensorInfo()); |
| 53 | } |
| 54 | |
| 55 | std::vector<const TensorInfo*> outputs; |
| 56 | for (auto& outputSlot : layer->GetOutputSlots()) |
| 57 | { |
| 58 | outputs.push_back(&outputSlot.GetTensorInfo()); |
| 59 | } |
| 60 | |
| 61 | TosaSerializationBasicBlock* basicBlock = GetTosaMapping(layer->GetType(), |
| 62 | inputs, |
| 63 | outputs, |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame^] | 64 | layer->GetParameters(), |
| 65 | isMain); |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 66 | SetBasicBlockConstantTensorData(layer, basicBlock); |
| 67 | return basicBlock; |
| 68 | } |