ArmNN
 23.08
TosaRefLayerSupport Class Reference

#include <TosaRefLayerSupport.hpp>

Inheritance diagram for TosaRefLayerSupport:
[legend]
Collaboration diagram for TosaRefLayerSupport:
[legend]

Public Member Functions

bool IsLayerSupported (const LayerType &type, const std::vector< TensorInfo > &infos, const BaseDescriptor &descriptor, const Optional< LstmInputParamsInfo > &lstmParamsInfo, const Optional< QuantizedLstmInputParamsInfo > &, Optional< std::string & > reasonIfUnsupported) const override
 Default implementation of the ILayerSupport interface, Backends should implement this as a switch statement for each of their LayerTypes calling their specific backend implementation of IsXXXLayerSupported. More...
 

Additional Inherited Members

- Protected Member Functions inherited from ILayerSupport
 ILayerSupport ()
 
virtual ~ILayerSupport ()
 

Detailed Description

Definition at line 12 of file TosaRefLayerSupport.hpp.

Member Function Documentation

◆ IsLayerSupported()

bool IsLayerSupported ( const LayerType type,
const std::vector< TensorInfo > &  infos,
const BaseDescriptor descriptor,
const Optional< LstmInputParamsInfo > &  lstmParamsInfo,
const Optional< QuantizedLstmInputParamsInfo > &  quantizedLstmParamsInfo,
Optional< std::string & >  reasonIfUnsupported 
) const
overridevirtual

Default implementation of the ILayerSupport interface, Backends should implement this as a switch statement for each of their LayerTypes calling their specific backend implementation of IsXXXLayerSupported.

Reimplemented from ILayerSupport.

Definition at line 21 of file TosaRefLayerSupport.cpp.

27 {
28  IgnoreUnused(lstmParamsInfo);
29  IgnoreUnused(quantizedLstmInputParamsInfo);
30  IgnoreUnused(reasonIfUnsupported);
31 
32  std::vector<const TensorInfo*> inputInfos;
33  std::vector<const TensorInfo*> outputInfos;
34 
35  switch (type)
36  {
37  case LayerType::Input:
38  case LayerType::Output:
39  return true;
43  // Setup inputs and outputs
44  inputInfos.push_back(&infos[0]);
45  inputInfos.push_back(&infos[1]);
46  outputInfos.push_back(&infos[2]);
47  break;
48  case LayerType::Concat:
49  for (unsigned int i = 0; i < infos.size() - 1; ++i)
50  {
51  inputInfos.push_back(&infos[i]);
52  }
53  outputInfos.push_back(&infos.back());
54  break;
56  outputInfos.push_back(&infos[0]);
57  break;
59  {
60  inputInfos.push_back(&infos[0]); // input
61  outputInfos.push_back(&infos[1]); // output
62  inputInfos.push_back(&infos[2]); // weights
63 
64  auto conv2dDesc = PolymorphicDowncast<const Convolution2dDescriptor*>(&descriptor);
65  if(conv2dDesc->m_BiasEnabled)
66  {
67  inputInfos.push_back(&infos[3]); // bias
68  }
69  break;
70  }
73  case LayerType::Reshape:
74  case LayerType::Slice:
76  inputInfos.push_back(&infos[0]);
77  outputInfos.push_back(&infos[1]);
78  break;
80  {
81  inputInfos.push_back(&infos[0]); // input
82  outputInfos.push_back(&infos[1]); // output
83  inputInfos.push_back(&infos[2]); // weights
84 
85  auto conv2dDesc = PolymorphicDowncast<const TransposeConvolution2dDescriptor*>(&descriptor);
86  if(conv2dDesc->m_BiasEnabled)
87  {
88  inputInfos.push_back(&infos[3]); // bias
89  }
90  break;
91  }
92  default:
93  // Default to false for all unsupported layers.
94  return false;
95  }
96 
97  auto mappings = GetTosaMapping(nullptr, type, inputInfos, outputInfos, descriptor);
98  if (mappings->GetName() == "")
99  {
100  // There currently isn't a TOSA mapping for this layer, as the default was returned.
101  return false;
102  }
103 
104  TosaSerializationHandler handler;
105 
106  // Add mappings to main block as the TOSA Reference Model requires the graph to be in one block called main.
107  auto* block = new TosaSerializationBasicBlock("main",
108  mappings->GetOperators(),
109  mappings->GetTensors(),
110  mappings->GetInputs(),
111  mappings->GetOutputs());
112  handler.GetBlocks().emplace_back(block);
113 
114  GraphStatus status;
115  TosaReference::IModelRunner runner;
116 
117 #if !defined(TOSA_REFERENCE_MODEL_OUTPUT)
118  // There currently isn't a way to disable the output from the TOSA Reference Model, but it does have a file pointer
119  // to write debug output to, so set this to /dev/null (if it exists on the system) to hide the output.
120  func_debug_t funcDebug;
121 
122  FILE* file = fopen("/dev/null", "w");
123  funcDebug.func_debug_file = (file == nullptr) ? stderr : file;
124 
125  runner.setFuncDebug(funcDebug);
126 #endif
127 
128  // Initialise the model runner with the TosaSerializationHandler, which runs validation on the mapping.
129  status = runner.initialize(handler);
130 
131 #if !defined(TOSA_REFERENCE_MODEL_OUTPUT)
132  // Reset FuncDebug as they can persist across multiple IModelRunner instances.
133  funcDebug.func_debug_file = stderr;
134  runner.setFuncDebug(funcDebug);
135 #endif
136 
137  if(status == GraphStatus::TOSA_ERROR || status == GraphStatus::TOSA_UNPREDICTABLE)
138  {
139  return false;
140  }
141  else
142  {
143  return true;
144  }
145 }

References armnn::Addition, armnn::Concat, armnn::Constant, armnn::Convolution2d, armnn::ElementwiseUnary, GetTosaMapping(), armnn::IgnoreUnused(), armnn::Input, armnn::Multiplication, armnn::Output, armnn::Pooling2d, armnn::Reshape, armnn::Slice, armnn::Subtraction, armnn::Transpose, and armnn::TransposeConvolution2d.


The documentation for this class was generated from the following files:
armnn::LayerType::Transpose
@ Transpose
armnn::LayerType::ElementwiseUnary
@ ElementwiseUnary
armnn::LayerType::Slice
@ Slice
armnn::LayerType::Subtraction
@ Subtraction
armnn::LayerType::Concat
@ Concat
armnn::LayerType::TransposeConvolution2d
@ TransposeConvolution2d
armnn::LayerType::Multiplication
@ Multiplication
armnn::LayerType::Addition
@ Addition
GetTosaMapping
TosaSerializationBasicBlock * GetTosaMapping(const Layer *layer, const LayerType type, const std::vector< const TensorInfo * > &inputs, const std::vector< const TensorInfo * > &outputs, const BaseDescriptor &descriptor)
Definition: TosaMappings.cpp:18
armnn::LayerType::Pooling2d
@ Pooling2d
armnn::LayerType::Reshape
@ Reshape
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::LayerType::Input
@ Input
armnn::LayerType::Convolution2d
@ Convolution2d
armnn::LayerType::Output
@ Output
armnn::LayerType::Constant
@ Constant