ArmNN
 25.11
Loading...
Searching...
No Matches
ConstantOperator.cpp File Reference
Include dependency graph for ConstantOperator.cpp:

Go to the source code of this file.

Functions

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

Function Documentation

◆ ConvertConstantToTosaOperator()

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

Definition at line 10 of file ConstantOperator.cpp.

13{
14 std::string outputName = std::string("constant_");
15 std::string blockName = std::string("Op_CONST_block_") + GetUniqueTosaMappingID();
16
17 std::vector<uint8_t> uint8Data;
18
19 // If a layer is present then the block will be used for execution, so names need to be unique.
20 // Also, set constant tensor data.
21 if(layer != nullptr)
22 {
23 outputName.append(std::to_string(layer->GetGuid()));
24 blockName.append(std::to_string(layer->GetGuid()));
25
26 auto constantLayer = PolymorphicDowncast<const armnn::ConstantLayer*>(layer);
27 auto tensorInfo = constantLayer->GetOutputSlot().GetTensorInfo();
28
29 uint8Data = ConvertConstantTensorDataToBuffer(constantLayer->m_LayerOutput);
30 }
31
32 auto* op = new TosaSerializationOperator(Op_CONST, Attribute_NONE, nullptr, {}, {outputName});
33
34 std::vector<int32_t> outputShape0;
35
36 if(isDepthwiseConv2dWeights)
37 {
38 // Constant weights are connected to a depthwise conv2d layer. From this get the depthwise conv2d input shape.
39 TensorShape inputShape =
41
42 unsigned int multiplier = outputs[0]->GetShape()[3]/inputShape[3];
43
44 // TOSA requires depthwise conv2d kernel to be converted from [1, H, W, C * M] to layout [H, W, C, M]
45 outputShape0 = {
46 static_cast<int32_t>(outputs[0]->GetShape()[1]),
47 static_cast<int32_t>(outputs[0]->GetShape()[2]),
48 static_cast<int32_t>(inputShape[3]),
49 static_cast<int32_t>(multiplier)
50 };
51 }
52 else
53 {
54 outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
55 }
56
57 DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
58
59 // Setup output tensor with constant tensor data if available.
60 auto* outputTensor0 = new TosaSerializationTensor(outputName, outputShape0, outputDType0, uint8Data);
61
62 return new TosaSerializationBasicBlock(blockName, // name
63 mainName, // region name
64 {op}, // operators
65 {outputTensor0}, // tensors
66 {}, // inputs
67 {outputName}); // outputs
68}
const std::string mainName
std::vector< uint8_t > ConvertConstantTensorDataToBuffer(const std::shared_ptr< ConstTensorHandle > &tensorHandle)
DType ArmNNToDType(const DataType &type)
std::string GetUniqueTosaMappingID()
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
Layer & GetOwningLayer() const
Definition Layer.hpp:53
const TensorInfo & GetTensorInfo() const override
Gets the TensorInfo for this InputSlot.
Definition Layer.cpp:614
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition Layer.hpp:337
const OutputSlot & GetOutputSlot(unsigned int index=0) const override
Get the const output slot handle by slot index.
Definition Layer.hpp:339
LayerGuid GetGuid() const final
Returns the unique id of the layer.
Definition Layer.hpp:343
const InputSlot * GetConnection(unsigned int index) const override
Definition Layer.cpp:83
const TensorShape & GetShape() const
Definition Tensor.hpp:193
DestType PolymorphicDowncast(SourceType *value)
Polymorphic downcast for build in pointers only.

References ArmNNToDType(), ConvertConstantTensorDataToBuffer(), OutputSlot::GetConnection(), Layer::GetGuid(), Layer::GetInputSlot(), Layer::GetOutputSlot(), InputSlot::GetOwningLayer(), TensorInfo::GetShape(), InputSlot::GetTensorInfo(), GetTosaTensorShape(), GetUniqueTosaMappingID(), mainName, and armnn::PolymorphicDowncast().

Referenced by GetTosaMapping().