ArmNN
 24.08
LayerSupportCommon.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
9 #include <armnn/Types.hpp>
10 #include <armnn/Tensor.hpp>
11 #include <armnn/Optional.hpp>
12 
13 namespace armnn
14 {
15 
16 template<typename T, typename V>
17 void SetValueChecked(Optional<T&> optionalRef, V&& val)
18 {
19  if (optionalRef)
20  {
21  optionalRef.value() = val;
22  }
23 }
24 
25 template<typename Float16Func, typename Float32Func, typename Uint8Func, typename Int32Func, typename BooleanFunc,
26  typename ... Params>
28  DataType dataType,
29  Float16Func float16FuncPtr,
30  Float32Func float32FuncPtr,
31  Uint8Func uint8FuncPtr,
32  Int32Func int32FuncPtr,
33  BooleanFunc booleanFuncPtr,
34  Params&&... params)
35 {
36  switch(dataType)
37  {
38  case DataType::Float16:
39  return float16FuncPtr(reasonIfUnsupported, std::forward<Params>(params)...);
40  case DataType::Float32:
41  return float32FuncPtr(reasonIfUnsupported, std::forward<Params>(params)...);
42  case DataType::QAsymmU8:
43  return uint8FuncPtr(reasonIfUnsupported, std::forward<Params>(params)...);
44  case DataType::Signed32:
45  return int32FuncPtr(reasonIfUnsupported, std::forward<Params>(params)...);
46  case DataType::Boolean:
47  return booleanFuncPtr(reasonIfUnsupported, std::forward<Params>(params)...);
48  default:
49  return false;
50  }
51 }
52 
53 template<typename ... Params>
54 bool TrueFunc(Optional<std::string&> reasonIfUnsupported, Params&&... params)
55 {
56  IgnoreUnused(reasonIfUnsupported);
57  IgnoreUnused(params...);
58  return true;
59 }
60 
61 template<typename ... Params>
62 bool FalseFunc(Optional<std::string&> reasonIfUnsupported, Params&&... params)
63 {
64  IgnoreUnused(reasonIfUnsupported);
65  IgnoreUnused(params...);
66  return false;
67 }
68 
69 template<typename ... Params>
70 bool FalseFuncF16(Optional<std::string&> reasonIfUnsupported, Params&&... params)
71 {
72  IgnoreUnused(params...);
73  SetValueChecked(reasonIfUnsupported, "Layer is not supported with float16 data type");
74  return false;
75 }
76 
77 template<typename ... Params>
78 bool FalseFuncF32(Optional<std::string&> reasonIfUnsupported, Params&&... params)
79 {
80  IgnoreUnused(params...);
81  SetValueChecked(reasonIfUnsupported, "Layer is not supported with float32 data type");
82  return false;
83 }
84 
85 template<typename ... Params>
86 bool FalseFuncU8(Optional<std::string&> reasonIfUnsupported, Params&&... params)
87 {
88  IgnoreUnused(params...);
89  SetValueChecked(reasonIfUnsupported, "Layer is not supported with 8-bit data type");
90  return false;
91 }
92 
93 template<typename ... Params>
94 bool FalseFuncI32(Optional<std::string&> reasonIfUnsupported, Params&&... params)
95 {
96  IgnoreUnused(params...);
97  SetValueChecked(reasonIfUnsupported, "Layer is not supported with int32 data type");
98  return false;
99 }
100 
101 template<typename ... Params>
102 bool FalseInputFuncF32(Optional<std::string&> reasonIfUnsupported, Params&&... params)
103 {
104  IgnoreUnused(params...);
105  SetValueChecked(reasonIfUnsupported, "Layer is not supported with float32 data type input");
106  return false;
107 }
108 
109 template<typename ... Params>
110 bool FalseInputFuncF16(Optional<std::string&> reasonIfUnsupported, Params&&... params)
111 {
112  IgnoreUnused(params...);
113  SetValueChecked(reasonIfUnsupported, "Layer is not supported with float16 data type input");
114  return false;
115 }
116 
117 template<typename ... Params>
118 bool FalseOutputFuncF32(Optional<std::string&> reasonIfUnsupported, Params&&... params)
119 {
120  IgnoreUnused(params...);
121  SetValueChecked(reasonIfUnsupported, "Layer is not supported with float32 data type output");
122  return false;
123 }
124 
125 template<typename ... Params>
126 bool FalseOutputFuncF16(Optional<std::string&> reasonIfUnsupported, Params&&... params)
127 {
128  IgnoreUnused(params...);
129  SetValueChecked(reasonIfUnsupported, "Layer is not supported with float16 data type output");
130  return false;
131 }
132 
133 }
armnn::FalseOutputFuncF32
bool FalseOutputFuncF32(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:118
armnn::DataType::Boolean
@ Boolean
armnn::Optional
Definition: Optional.hpp:270
armnn::DataType::Float32
@ Float32
armnn::DataType::QAsymmU8
@ QAsymmU8
IgnoreUnused.hpp
armnn::TrueFunc
bool TrueFunc(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:54
Optional.hpp
armnn::DataType::Float16
@ Float16
armnn::DataType
DataType
Definition: Types.hpp:48
DescriptorsFwd.hpp
armnn::FalseFuncF32
bool FalseFuncF32(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:78
armnn::FalseFuncI32
bool FalseFuncI32(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:94
armnn::FalseFunc
bool FalseFunc(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:62
armnn::DataType::Signed32
@ Signed32
armnn::FalseInputFuncF32
bool FalseInputFuncF32(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:102
armnn::FalseOutputFuncF16
bool FalseOutputFuncF16(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:126
Tensor.hpp
armnn::IgnoreUnused
void IgnoreUnused(Ts &&...)
Definition: IgnoreUnused.hpp:14
armnn::IsSupportedForDataTypeGeneric
bool IsSupportedForDataTypeGeneric(Optional< std::string & > reasonIfUnsupported, DataType dataType, Float16Func float16FuncPtr, Float32Func float32FuncPtr, Uint8Func uint8FuncPtr, Int32Func int32FuncPtr, BooleanFunc booleanFuncPtr, Params &&... params)
Definition: LayerSupportCommon.hpp:27
armnn
Copyright (c) 2021 ARM Limited and Contributors.
Definition: 01_00_quick_start.dox:6
Types.hpp
armnn::SetValueChecked
void SetValueChecked(Optional< T & > optionalRef, V &&val)
Definition: LayerSupportCommon.hpp:17
armnn::FalseInputFuncF16
bool FalseInputFuncF16(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:110
armnn::FalseFuncF16
bool FalseFuncF16(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:70
armnn::OptionalReferenceSwitch< std::is_reference< T >::value, T >::value
const T & value() const
Definition: Optional.hpp:146
armnn::FalseFuncU8
bool FalseFuncU8(Optional< std::string & > reasonIfUnsupported, Params &&... params)
Definition: LayerSupportCommon.hpp:86