ONE - On-device Neural Engine
Loading...
Searching...
No Matches
onert::backend::cpu::ops::ElementwiseBinaryLayer Class Reference

#include <ElementwiseBinaryLayer.h>

Collaboration diagram for onert::backend::cpu::ops::ElementwiseBinaryLayer:

Public Member Functions

 ElementwiseBinaryLayer ()
 
void configure (const IPortableTensor *lhs, const IPortableTensor *rhs, IPortableTensor *output, const ElementwiseBinaryType op_type)
 
void run () override
 
- Public Member Functions inherited from onert::exec::IFunction
virtual ~IFunction ()=default
 
virtual void prepare ()
 

Detailed Description

Definition at line 43 of file ElementwiseBinaryLayer.h.

Constructor & Destructor Documentation

◆ ElementwiseBinaryLayer()

onert::backend::cpu::ops::ElementwiseBinaryLayer::ElementwiseBinaryLayer ( )
inline

Definition at line 46 of file ElementwiseBinaryLayer.h.

46 : _lhs(nullptr), _rhs(nullptr), _output(nullptr)
47 {
48 // DO NOTHING
49 }

Member Function Documentation

◆ configure()

void onert::backend::cpu::ops::ElementwiseBinaryLayer::configure ( const IPortableTensor lhs,
const IPortableTensor rhs,
IPortableTensor output,
const ElementwiseBinaryType  op_type 
)

Definition at line 125 of file ElementwiseBinaryLayer.cc.

127{
128 assert(lhs != nullptr);
129 assert(rhs != nullptr);
130 assert(output != nullptr);
131
132 _lhs = lhs;
133 _rhs = rhs;
134 _output = output;
135
136 switch (op_type)
137 {
139 if (_lhs->data_type() == OperandType::FLOAT32)
140 {
141 _kernel = FloorDivGeneric<float>;
142 }
143 else if (_lhs->data_type() == OperandType::INT32)
144 {
145 _kernel = FloorDivGeneric<int32_t>;
146 }
147 else
148 {
149 throw std::runtime_error{"Max: unsupported data type"};
150 }
151 break;
153 if (_lhs->data_type() == OperandType::FLOAT32)
154 {
155 _kernel = FloorModGeneric<float>;
156 }
157 else if (_lhs->data_type() == OperandType::INT64)
158 {
159 _kernel = FloorModGeneric<int64_t>;
160 }
161 else
162 {
163 throw std::runtime_error{"FloorMod: unsupported data type"};
164 }
165 break;
167 if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
168 {
169 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
170 _kernel = logicalAndGeneric<bool>;
171 }
172 else
173 {
174 throw std::runtime_error{"LogicalOr: Unsupported data type"};
175 }
176 break;
178 if ((_lhs->data_type() == OperandType::BOOL8) && (_rhs->data_type() == OperandType::BOOL8))
179 {
180 static_assert(sizeof(bool) == 1, "cpu backend supports bool type which is 1 byte");
181 _kernel = logicalOrGeneric<bool>;
182 }
183 else
184 {
185 throw std::runtime_error{"LogicalOr: Unsupported data type"};
186 }
187 break;
189 if (_lhs->data_type() == OperandType::QUANT_UINT8_ASYMM)
190 {
191 if (!haveSameQauntInfo(_lhs, _rhs, _output))
192 {
193 throw std::runtime_error("Max NYI for quantized");
194 }
195 _kernel = maximumGeneric<uint8_t>;
196 }
197 else if (_lhs->data_type() == OperandType::FLOAT32)
198 {
199 _kernel = maximumGeneric<float>;
200 }
201 else
202 {
203 throw std::runtime_error{"Max: unsupported data type"};
204 }
205 break;
207 if (_lhs->data_type() == OperandType::QUANT_UINT8_ASYMM)
208 {
209 if (!haveSameQauntInfo(_lhs, _rhs, _output))
210 {
211 throw std::runtime_error("Min NYI for quantized");
212 }
213 _kernel = minimumGeneric<uint8_t>;
214 }
215 else if (_lhs->data_type() == OperandType::INT32)
216 {
217 _kernel = minimumGeneric<int32_t>;
218 }
219 else if (_lhs->data_type() == OperandType::FLOAT32)
220 {
221 _kernel = minimumGeneric<float>;
222 }
223 else
224 {
225 throw std::runtime_error{"Min: unsupported data type"};
226 }
227 break;
228 default:
229 throw std::runtime_error{"ElementwiseBinary: Unsupported ElementwiseBinary type"};
230 }
231}
ir::DataType data_type() const override final

References onert::backend::IPortableTensor::data_type(), onert::backend::cpu::ops::kFloorDiv, onert::backend::cpu::ops::kFloorMod, onert::backend::cpu::ops::kLogicalAnd, onert::backend::cpu::ops::kLogicalOr, onert::backend::cpu::ops::kMax, and onert::backend::cpu::ops::kMin.

◆ run()

void onert::backend::cpu::ops::ElementwiseBinaryLayer::run ( )
overridevirtual

Implements onert::exec::IFunction.

Definition at line 233 of file ElementwiseBinaryLayer.cc.

233{ _kernel(_lhs, _rhs, _output); }

Referenced by package.infer.session::inference().


The documentation for this class was generated from the following files: