Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2022 Arm Ltd and Contributors. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ConstantOperator.hpp" |
| 7 | |
| 8 | #include <layers/ConstantLayer.hpp> |
| 9 | |
| 10 | TosaSerializationBasicBlock* ConvertConstantToTosaOperator(const Layer* layer, |
| 11 | const std::vector<const TensorInfo*>& outputs) |
| 12 | { |
| 13 | std::string outputName = std::string("constant_"); |
| 14 | std::string blockName = std::string("Op_CONST_block_") + GetUniqueTosaMappingID(); |
| 15 | |
| 16 | std::vector<uint8_t> uint8Data; |
| 17 | |
| 18 | // If a layer is present then the block will be used for execution, so names need to be unique. |
| 19 | // Also, set constant tensor data. |
| 20 | if(layer != nullptr) |
| 21 | { |
| 22 | outputName.append(std::to_string(layer->GetGuid())); |
| 23 | blockName.append(std::to_string(layer->GetGuid())); |
| 24 | |
| 25 | auto constantLayer = PolymorphicDowncast<const armnn::ConstantLayer*>(layer); |
| 26 | auto tensorInfo = constantLayer->GetOutputSlot().GetTensorInfo(); |
| 27 | |
| 28 | uint8Data = ConvertConstantTensorDataToBuffer(constantLayer->m_LayerOutput); |
| 29 | } |
| 30 | |
| 31 | auto* op = new TosaSerializationOperator(Op_CONST, Attribute_NONE, nullptr, {}, {outputName}); |
| 32 | |
| 33 | std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape()); |
| 34 | DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType()); |
| 35 | |
| 36 | // Setup output tensor with constant tensor data if available. |
| 37 | auto* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, uint8Data); |
| 38 | |
| 39 | return new TosaSerializationBasicBlock(blockName, // name |
Narumol Prangnawarat | ad323af | 2023-09-29 17:00:38 +0100 | [diff] [blame] | 40 | mainName, // region name |
Matthew Sloyan | c5fe6e7 | 2022-11-25 16:10:00 +0000 | [diff] [blame] | 41 | {op}, // operators |
| 42 | {outputTensor0}, // tensors |
| 43 | {}, // inputs |
| 44 | {outputName}); // outputs |
| 45 | } |