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 "AdditionOperator.hpp" |
| 7 | |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 8 | TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const Layer* layer, |
| 9 | const std::vector<const TensorInfo*>& inputs, |
| 10 | const std::vector<const TensorInfo*>& outputs) |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 11 | { |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 12 | std::string input0Name = std::string("input0_"); |
| 13 | std::string input1Name = std::string("input1_"); |
| 14 | std::string outputName = std::string("output0_"); |
| 15 | std::string blockName = std::string("Op_ADD_block_") + GetUniqueTosaMappingID(); |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 16 | |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 17 | // If a layer is present then the block will be used for execution, so input and output names need to be determined |
| 18 | // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter. |
| 19 | if(layer != nullptr) |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame] | 20 | { |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 21 | // Get the layers connected to the input slots and determine unique layer names. |
| 22 | Layer& connectedLayer0 = layer->GetInputSlot(0).GetConnectedOutputSlot()->GetOwningLayer(); |
| 23 | input0Name = GenerateUniqueName(connectedLayer0, 0); |
| 24 | |
| 25 | Layer& connectedLayer1 = layer->GetInputSlot(1).GetConnectedOutputSlot()->GetOwningLayer(); |
| 26 | input1Name = GenerateUniqueName(connectedLayer1, 1); |
| 27 | |
| 28 | // Get the layer connected to the output slot and determine unique layer name. |
| 29 | Layer& connectedOutputLayer = layer->GetOutputSlot().GetConnection(0)->GetOwningLayer(); |
| 30 | outputName = GenerateUniqueName(connectedOutputLayer, 0); |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 33 | auto* op = new TosaSerializationOperator(Op_ADD, |
| 34 | Attribute_NONE, |
| 35 | nullptr, |
| 36 | {input0Name, input1Name}, |
| 37 | {outputName}); |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 38 | |
| 39 | std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape()); |
| 40 | DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType()); |
| 41 | |
| 42 | std::vector<int32_t> inputShape1 = GetTosaTensorShape(inputs[1]->GetShape()); |
| 43 | DType inputDType1 = ArmNNToDType(inputs[1]->GetDataType()); |
| 44 | |
| 45 | std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape()); |
| 46 | DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType()); |
| 47 | |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 48 | auto* inputTensor0 = new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {}); |
| 49 | auto* inputTensor1 = new TosaSerializationTensor(input1Name, inputShape1, inputDType1, {}); |
| 50 | auto* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}); |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 51 | |
| 52 | // operatorInputNames/operatorOutputNames ends up being the same as |
Cathal Corbett | b30e655 | 2022-12-07 11:50:50 +0000 | [diff] [blame] | 53 | // blockInputNames/blockOutputNames for one-to-one ArmNN to TOSA mappings |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 54 | return new TosaSerializationBasicBlock(blockName, // name |
| 55 | {op}, // operators |
| 56 | {inputTensor0, inputTensor1, outputTensor0}, // tensors |
| 57 | {input0Name, input1Name}, // inputs |
| 58 | {outputName}); // outputs |
| 59 | } |