ArmNN
 24.02
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  {
38  inputInfos.push_back(&infos[0]);
39  outputInfos.push_back(&infos[1]);
40  break;
41  case LayerType::Input:
42  case LayerType::Output:
43  return true;
48  // Setup inputs and outputs
49  inputInfos.push_back(&infos[0]);
50  inputInfos.push_back(&infos[1]);
51  outputInfos.push_back(&infos[2]);
52  break;
53  case LayerType::Concat:
54  for (unsigned int i = 0; i < infos.size() - 1; ++i)
55  {
56  inputInfos.push_back(&infos[i]);
57  }
58  outputInfos.push_back(&infos.back());
59  break;
61  outputInfos.push_back(&infos[0]);
62  break;
64  {
65  inputInfos.push_back(&infos[0]); // input
66  outputInfos.push_back(&infos[1]); // output
67  inputInfos.push_back(&infos[2]); // weights
68 
69  auto conv2dDesc = PolymorphicDowncast<const Convolution2dDescriptor*>(&descriptor);
70  if(conv2dDesc->m_BiasEnabled)
71  {
72  inputInfos.push_back(&infos[3]); // bias
73  }
74  break;
75  }
79  case LayerType::Reshape:
80  case LayerType::Resize:
81  case LayerType::Slice:
83  {
84  inputInfos.push_back(&infos[0]);
85  outputInfos.push_back(&infos[1]);
86  break;
87  }
89  {
90  inputInfos.push_back(&infos[0]);
91  for (unsigned int i = 1; i < infos.size(); ++i)
92  {
93  outputInfos.push_back(&infos[i]);
94  }
95  break;
96  }
98  {
99  inputInfos.push_back(&infos[0]); // input
100  outputInfos.push_back(&infos[1]); // output
101  inputInfos.push_back(&infos[2]); // weights
102 
103  auto conv2dDesc = PolymorphicDowncast<const TransposeConvolution2dDescriptor*>(&descriptor);
104  if(conv2dDesc->m_BiasEnabled)
105  {
106  inputInfos.push_back(&infos[3]); // bias
107  }
108  break;
109  }
110  default:
111  // Default to false for all unsupported layers.
112  return false;
113  }
114 
115  auto mappings = GetTosaMapping(nullptr, type, inputInfos, outputInfos, descriptor);
116  if (mappings->GetName() == "")
117  {
118  // There currently isn't a TOSA mapping for this layer, as the default was returned.
119  return false;
120  }
121 
122  TosaSerializationHandler handler;
123 
124  // Add all mappings to main block.
125  auto* block = new TosaSerializationBasicBlock("main",
126  "main",
127  mappings->GetOperators(),
128  mappings->GetTensors(),
129  mappings->GetInputs(),
130  mappings->GetOutputs());
131 
132  std::vector<TosaSerializationBasicBlock*> blocks;
133  blocks.emplace_back(block);
134 
135  // Add blocks to the main region.
136  auto* region = new TosaSerializationRegion("main", blocks);
137  handler.GetRegions().emplace_back(region);
138 
139  GraphStatus status;
140  TosaReference::IModelRunner runner;
141 
142 #if !defined(TOSA_REFERENCE_MODEL_OUTPUT)
143  // There currently isn't a way to disable the output from the TOSA Reference Model, but it does have a file pointer
144  // to write debug output to, so set this to /dev/null (if it exists on the system) to hide the output.
145  func_debug_t funcDebug;
146 
147  FILE* file = fopen("/dev/null", "w");
148  funcDebug.func_debug_file = (file == nullptr) ? stderr : file;
149 
150  runner.setFuncDebug(funcDebug);
151 #endif
152 
153  // Initialise the model runner with the TosaSerializationHandler, which runs validation on the mapping.
154  status = runner.initialize(handler);
155 
156 #if !defined(TOSA_REFERENCE_MODEL_OUTPUT)
157  // Reset FuncDebug as they can persist across multiple IModelRunner instances.
158  funcDebug.func_debug_file = stderr;
159  runner.setFuncDebug(funcDebug);
160 #endif
161 
162  if(status == GraphStatus::TOSA_ERROR || status == GraphStatus::TOSA_UNPREDICTABLE)
163  {
164  return false;
165  }
166  else
167  {
168  return true;
169  }
170 }

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


The documentation for this class was generated from the following files:
armnn::LayerType::Splitter
@ Splitter
armnn::LayerType::Transpose
@ Transpose
armnn::LayerType::ElementwiseUnary
@ ElementwiseUnary
armnn::LayerType::ElementwiseBinary
@ ElementwiseBinary
armnn::LayerType::Slice
@ Slice
armnn::LayerType::Subtraction
@ Subtraction
armnn::LayerType::Concat
@ Concat
armnn::LayerType::TransposeConvolution2d
@ TransposeConvolution2d
armnn::LayerType::Quantize
@ Quantize
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::Resize
@ Resize
armnn::LayerType::Convolution2d
@ Convolution2d
armnn::LayerType::Activation
@ Activation
armnn::LayerType::Output
@ Output
armnn::LayerType::Constant
@ Constant