ArmNN
 24.08
RsqrtOperator.cpp File Reference
#include "RsqrtOperator.hpp"
Include dependency graph for RsqrtOperator.cpp:

Go to the source code of this file.

Functions

TosaSerializationBasicBlock * ConvertRsqrtOperator (const Layer *layer, const std::vector< const TensorInfo * > &inputs, const std::vector< const TensorInfo * > &outputs, const ElementwiseUnaryDescriptor *unaryDescriptor)
 

Function Documentation

◆ ConvertRsqrtOperator()

TosaSerializationBasicBlock* ConvertRsqrtOperator ( const Layer layer,
const std::vector< const TensorInfo * > &  inputs,
const std::vector< const TensorInfo * > &  outputs,
const ElementwiseUnaryDescriptor unaryDescriptor 
)

Definition at line 8 of file RsqrtOperator.cpp.

12 {
13  if (unaryDescriptor->m_Operation != UnaryOperation::Rsqrt)
14  {
15  throw armnn::Exception("ConvertRsqrtOperator: Unsupported elementwise unary operation in descriptor.");
16  }
17 
18  std::string input0Name = std::string("input_");
19  std::string outputName = std::string("output0_");
20  std::string blockName = std::string("Op_RSQRT_block_") + GetUniqueTosaMappingID();
21 
22  // If a layer is present then the block will be used for execution, so input and output names need to be determined
23  // using the previous and following layers so the graph is connected correctly. For validation this doesn't matter.
24  if(layer != nullptr)
25  {
26  input0Name = GenerateUniqueInputName(layer->GetInputSlot(0));
27  outputName = GenerateUniqueOutputName(*layer);
28  }
29 
30  auto* op = new TosaSerializationOperator(tosa::Op_RSQRT,
31  Attribute_NONE,
32  nullptr,
33  {input0Name},
34  {outputName});
35 
36  std::vector<TosaSerializationTensor*> tensors;
37  // Only add input tensor if connected layer is an input layer.
38  // As intermediate or constant tensors will be created separately.
39  // There also can't be duplicate tensor.
40  if(input0Name.find("input_") != std::string::npos)
41  {
42  std::vector<int32_t> inputShape0 = GetTosaTensorShape(inputs[0]->GetShape());
43  DType inputDType0 = ArmNNToDType(inputs[0]->GetDataType());
44  tensors.push_back(new TosaSerializationTensor(input0Name, inputShape0, inputDType0, {}));
45  }
46 
47  std::vector<int32_t> outputShape0 = GetTosaTensorShape(outputs[0]->GetShape());
48  DType outputDType0 = ArmNNToDType(outputs[0]->GetDataType());
49 
50  tensors.push_back(new TosaSerializationTensor(outputName, outputShape0, outputDType0, {}));
51 
52  // operatorInputNames/operatorOutputNames ends up being the same as
53  // blockInputNames/blockOutputNames for one-to-one ArmNN to Tosa mappings
54  return new TosaSerializationBasicBlock(blockName, // name
55  mainName, // region name
56  {op}, // operators
57  tensors, // tensors
58  {input0Name}, // inputs
59  {outputName}); // outputs
60 }

References GenerateUniqueInputName(), GenerateUniqueOutputName(), Layer::GetInputSlot(), GetTosaTensorShape(), GetUniqueTosaMappingID(), and ElementwiseUnaryDescriptor::m_Operation.

Referenced by GetTosaMapping().

GenerateUniqueOutputName
std::string GenerateUniqueOutputName(const Layer &layer, uint32_t layerSlot=0)
Definition: TosaOperatorUtils.hpp:120
armnn::Layer::GetInputSlot
const InputSlot & GetInputSlot(unsigned int index) const override
Get a const input slot handle by slot index.
Definition: Layer.hpp:337
mainName
const std::string mainName
Definition: TosaOperatorUtils.hpp:19
ArmNNToDType
DType ArmNNToDType(const DataType &type)
Definition: TosaOperatorUtils.hpp:22
armnn::Exception
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
armnn::ElementwiseUnaryDescriptor::m_Operation
UnaryOperation m_Operation
Specifies the elementwiseUnary operation to execute.
Definition: Descriptors.hpp:145
GetTosaTensorShape
std::vector< int32_t > GetTosaTensorShape(const TensorShape &shape)
Definition: TosaOperatorUtils.hpp:79
GenerateUniqueInputName
std::string GenerateUniqueInputName(const armnn::InputSlot &slot)
Definition: TosaOperatorUtils.hpp:109
GetUniqueTosaMappingID
std::string GetUniqueTosaMappingID()
Definition: TosaOperatorUtils.hpp:138