blob: 71d2012cbc631fc9796558ac2fa52e50f8af91b0 [file] [log] [blame]
Matthew Sloyan164bf4f2022-10-28 18:02:17 +01001//
2// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "TosaMappings.hpp"
7
8using namespace armnn;
9using namespace tosa;
10
11void 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
26TosaSerializationBasicBlock* GetTosaMapping(const LayerType type,
27 const std::vector<const TensorInfo*>& inputs,
28 const std::vector<const TensorInfo*>& outputs,
Matthew Sloyan5c54c382022-11-09 16:28:51 +000029 const BaseDescriptor& /*descriptor*/,
30 bool isMain = false)
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010031{
32 switch (type)
33 {
34 case LayerType::Addition:
35 {
Matthew Sloyan5c54c382022-11-09 16:28:51 +000036 return ConvertAdditionToTosaOperator(inputs, outputs, isMain);
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010037 }
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 Sloyan5c54c382022-11-09 16:28:51 +000047TosaSerializationBasicBlock* GetTosaMappingFromLayer(Layer* layer, bool isMain = false)
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010048{
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 Sloyan5c54c382022-11-09 16:28:51 +000064 layer->GetParameters(),
65 isMain);
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010066 SetBasicBlockConstantTensorData(layer, basicBlock);
67 return basicBlock;
68}