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 | |
| 8 | TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const std::vector<const TensorInfo*>& inputs, |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame] | 9 | const std::vector<const TensorInfo*>& outputs, |
| 10 | bool isMain) |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 11 | { |
| 12 | // A helper function with static global variables ensures uniqueness |
| 13 | // for dynamically generating input, output and block names |
| 14 | std::string input0Name = std::string("Op_ADD_input0_") + GetUniqueTosaMappingID(); |
| 15 | std::string input1Name = std::string("Op_ADD_input1_") + GetUniqueTosaMappingID(); |
| 16 | std::string outputName = std::string("Op_ADD_output0_") + GetUniqueTosaMappingID(); |
| 17 | std::string blockName = std::string("Op_ADD_block_") + GetUniqueTosaMappingID(); |
| 18 | |
Matthew Sloyan | 5c54c38 | 2022-11-09 16:28:51 +0000 | [diff] [blame] | 19 | // If it's the first block, overwrite block name with main. |
| 20 | if (isMain) |
| 21 | { |
| 22 | blockName = std::string("main"); |
| 23 | } |
| 24 | |
Matthew Sloyan | 164bf4f | 2022-10-28 18:02:17 +0100 | [diff] [blame] | 25 | TosaSerializationOperator* op = new TosaSerializationOperator(Op_ADD, |
| 26 | Attribute_NONE, |
| 27 | nullptr, |
| 28 | {input0Name, input1Name}, |
| 29 | {outputName}); |
| 30 | |
| 31 | std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape()); |
| 32 | DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType()); |
| 33 | |
| 34 | std::vector<int32_t> inputShape1 = GetTosaTensorShape(inputs[1]->GetShape()); |
| 35 | DType inputDType1 = ArmNNToDType(inputs[1]->GetDataType()); |
| 36 | |
| 37 | std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape()); |
| 38 | DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType()); |
| 39 | |
| 40 | TosaSerializationTensor* inputTensor0 = new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {}); |
| 41 | TosaSerializationTensor* inputTensor1 = new TosaSerializationTensor(input1Name, inputShape1, inputDType1, {}); |
| 42 | TosaSerializationTensor* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}); |
| 43 | |
| 44 | // operatorInputNames/operatorOutputNames ends up being the same as |
| 45 | // blockInputNames/blockOutputNames for one-to-one ArmNN to Tosa mappings |
| 46 | return new TosaSerializationBasicBlock(blockName, // name |
| 47 | {op}, // operators |
| 48 | {inputTensor0, inputTensor1, outputTensor0}, // tensors |
| 49 | {input0Name, input1Name}, // inputs |
| 50 | {outputName}); // outputs |
| 51 | } |