ArmNN
 24.02
ConstantOperator.hpp File Reference
Include dependency graph for ConstantOperator.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

TosaSerializationBasicBlock * ConvertConstantToTosaOperator (const Layer *layer, const std::vector< const TensorInfo * > &outputs)
 

Function Documentation

◆ ConvertConstantToTosaOperator()

TosaSerializationBasicBlock* ConvertConstantToTosaOperator ( const Layer layer,
const std::vector< const TensorInfo * > &  outputs 
)

Definition at line 10 of file ConstantOperator.cpp.

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 }

References ConvertConstantTensorDataToBuffer(), Layer::GetGuid(), GetTosaTensorShape(), and GetUniqueTosaMappingID().

Referenced by GetTosaMapping().

ConvertConstantTensorDataToBuffer
std::vector< uint8_t > ConvertConstantTensorDataToBuffer(const std::shared_ptr< ConstTensorHandle > &tensorHandle)
Definition: TosaOperatorUtils.hpp:289
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
GetTosaTensorShape
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
Definition: TosaOperatorUtils.hpp:52
GetUniqueTosaMappingID
std::string GetUniqueTosaMappingID()
Definition: TosaOperatorUtils.hpp:100