blob: 796797728eef05cdc257ddbffab31316e69b0743 [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 "AdditionOperator.hpp"
7
8TosaSerializationBasicBlock* ConvertAdditionToTosaOperator(const std::vector<const TensorInfo*>& inputs,
Matthew Sloyan5c54c382022-11-09 16:28:51 +00009 const std::vector<const TensorInfo*>& outputs,
10 bool isMain)
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010011{
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 Sloyan5c54c382022-11-09 16:28:51 +000019 // If it's the first block, overwrite block name with main.
20 if (isMain)
21 {
22 blockName = std::string("main");
23 }
24
Matthew Sloyan164bf4f2022-10-28 18:02:17 +010025 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}