ArmNN
 24.02
ConstantOperator.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "ConstantOperator.hpp"
7 
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
40  mainName, // region name
41  {op}, // operators
42  {outputTensor0}, // tensors
43  {}, // inputs
44  {outputName}); // outputs
45 }
ConvertConstantTensorDataToBuffer
std::vector< uint8_t > ConvertConstantTensorDataToBuffer(const std::shared_ptr< ConstTensorHandle > &tensorHandle)
Definition: TosaOperatorUtils.hpp:289
ConvertConstantToTosaOperator
TosaSerializationBasicBlock * ConvertConstantToTosaOperator(const Layer *layer, const std::vector< const TensorInfo * > &outputs)
Definition: ConstantOperator.cpp:10
armnn::Layer
Definition: Layer.hpp:230
mainName
const std::string mainName
Definition: TosaOperatorUtils.hpp:19
ArmNNToDType
DType ArmNNToDType(const DataType &type)
Definition: TosaOperatorUtils.hpp:22
armnn::Layer::GetGuid
LayerGuid GetGuid() const final
Returns the unique id of the layer.
Definition: Layer.hpp:343
ConstantOperator.hpp
ConstantLayer.hpp
GetTosaTensorShape
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
Definition: TosaOperatorUtils.hpp:52
GetUniqueTosaMappingID
std::string GetUniqueTosaMappingID()
Definition: TosaOperatorUtils.hpp:100