ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
onert::backend::cpu::KernelGenerator Class Reference

#include <KernelGenerator.h>

Collaboration diagram for onert::backend::cpu::KernelGenerator:

Public Member Functions

 KernelGenerator (const ir::Graph &graph, const std::shared_ptr< TensorBuilder > &tensor_builder, const std::shared_ptr< basic::TensorRegistry > &tensor_reg, const std::shared_ptr< custom::IKernelBuilder > &kernel_builder, const std::shared_ptr< ExternalContext > &external_context)
 
std::unique_ptr< exec::FunctionSequencegenerate (ir::OperationIndex op_ind) override
 
void visit (const ir::operation::AddN &) override
 
void visit (const ir::operation::ArgMinMax &) override
 
void visit (const ir::operation::BatchMatMul &) override
 
void visit (const ir::operation::BatchToSpaceND &) override
 
void visit (const ir::operation::BinaryArithmetic &) override
 
void visit (const ir::operation::BroadcastTo &) override
 
void visit (const ir::operation::Comparison &) override
 
void visit (const ir::operation::Concat &) override
 
void visit (const ir::operation::Conv2D &) override
 
void visit (const ir::operation::Custom &node) override
 
void visit (const ir::operation::DepthToSpace &) override
 
void visit (const ir::operation::DepthwiseConv2D &) override
 
void visit (const ir::operation::Einsum &) override
 
void visit (const ir::operation::ElementwiseActivation &) override
 
void visit (const ir::operation::ElementwiseBinary &) override
 
void visit (const ir::operation::ElementwiseUnary &) override
 
void visit (const ir::operation::ExpandDims &) override
 
void visit (const ir::operation::Fill &) override
 
void visit (const ir::operation::FullyConnected &) override
 
void visit (const ir::operation::FusedBatchNorm &) override
 
void visit (const ir::operation::Gather &) override
 
void visit (const ir::operation::L2Normalization &) override
 
void visit (const ir::operation::LogSoftmax &) override
 
void visit (const ir::operation::LSTM &) override
 
void visit (const ir::operation::MatrixBandPart &) override
 
void visit (const ir::operation::DetectionPostProcess &) override
 
void visit (const ir::operation::OneHot &) override
 
void visit (const ir::operation::Pack &) override
 
void visit (const ir::operation::Pad &) override
 
void visit (const ir::operation::Pool2D &) override
 
void visit (const ir::operation::Pow &) override
 
void visit (const ir::operation::Range &) override
 
void visit (const ir::operation::Rank &) override
 
void visit (const ir::operation::Reduce &) override
 
void visit (const ir::operation::Reshape &) override
 
void visit (const ir::operation::ResizeBilinear &node) override
 
void visit (const ir::operation::Reverse &) override
 
void visit (const ir::operation::RmsNorm &) override
 
void visit (const ir::operation::RoPE &) override
 
void visit (const ir::operation::Select &) override
 
void visit (const ir::operation::Shape &) override
 
void visit (const ir::operation::Slice &) override
 
void visit (const ir::operation::Softmax &) override
 
void visit (const ir::operation::SpaceToBatchND &) override
 
void visit (const ir::operation::SpaceToDepth &) override
 
void visit (const ir::operation::Split &) override
 
void visit (const ir::operation::SplitV &) override
 
void visit (const ir::operation::SquaredDifference &) override
 
void visit (const ir::operation::Squeeze &) override
 
void visit (const ir::operation::StatelessRandomUniform &) override
 
void visit (const ir::operation::StridedSlice &) override
 
void visit (const ir::operation::Tile &) override
 
void visit (const ir::operation::Transpose &) override
 
void visit (const ir::operation::Unpack &) override
 
- Public Member Functions inherited from onert::backend::basic::KernelGeneratorBase
virtual ~KernelGeneratorBase ()=default
 
 KernelGeneratorBase (const ir::Graph &graph)
 
- Public Member Functions inherited from onert::ir::OperationVisitor
virtual ~OperationVisitor ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from onert::backend::basic::KernelGeneratorBase
std::unique_ptr< exec::IFunctionreleaseFunction ()
 
- Protected Attributes inherited from onert::backend::basic::KernelGeneratorBase
const ir::Graph_graph
 
std::unique_ptr< exec::IFunction_return_fn
 

Detailed Description

Definition at line 33 of file KernelGenerator.h.

Constructor & Destructor Documentation

◆ KernelGenerator()

onert::backend::cpu::KernelGenerator::KernelGenerator ( const ir::Graph graph,
const std::shared_ptr< TensorBuilder > &  tensor_builder,
const std::shared_ptr< basic::TensorRegistry > &  tensor_reg,
const std::shared_ptr< custom::IKernelBuilder > &  kernel_builder,
const std::shared_ptr< ExternalContext > &  external_context 
)

Member Function Documentation

◆ generate()

std::unique_ptr< exec::FunctionSequence > onert::backend::cpu::KernelGenerator::generate ( ir::OperationIndex  op_ind)
overridevirtual

Implements onert::backend::basic::KernelGeneratorBase.

Definition at line 241 of file KernelGenerator.cc.

242{
243 auto ret = std::make_unique<exec::FunctionSequence>();
244
245 assert(_tensor_builder->dynamicTensorManager());
246 assert(_tensor_reg);
247
248 // Prepare to handle dynamic tensors later
249 auto dyn_ctx = std::make_shared<exec::FunctionSequence::DynamicTensorCtx>();
250 {
251 dyn_ctx->op = &_operations_ctx.at(ind);
252 dyn_ctx->dynamic_shape_inferer = std::make_shared<exec::DynamicShapeInferer>(_tensor_reg);
253 }
254 ret->dynamic_tensor_ctx(dyn_ctx);
255
256 auto &op = _graph.operations().at(ind);
257 op.accept(*this);
258 assert(_return_fn); // _return_fn must have been generated
259 ret->append(std::move(_return_fn));
260
261 for (auto &&ind : (op.getInputs() | ir::Remove::UNDEFINED) + op.getOutputs())
262 {
263 auto tensor = _tensor_reg->getNativeTensor(ind);
264 if (tensor)
265 {
266 tensor->increase_ref();
267 }
268 }
269 return ret;
270}
std::unique_ptr< exec::IFunction > _return_fn
const Operations & operations() const override
Definition Graph.h:112
const Object & at(const Index &index) const
Get the object that is associated with the given index.

◆ visit() [1/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::AddN node)
override

Definition at line 272 of file KernelGenerator.cc.

273{
274 const auto output_index{node.getOutputs().at(0)};
275
276 std::vector<const IPortableTensor *> input_tensors;
277 for (const auto &input_idx : node.getInputs())
278 input_tensors.emplace_back(_tensor_reg->getPortableTensor(input_idx));
279
280 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
281
282 auto fn = std::make_unique<ops::AddNLayer>();
283
284 fn->configure(std::move(input_tensors), output_tensor);
285
286 _return_fn = std::move(fn);
287}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [2/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::ArgMinMax node)
override

Definition at line 996 of file KernelGenerator.cc.

997{
998 const auto output_index{node.getOutputs().at(0)};
999 const auto input_index{node.getInputs().at(ir::operation::ArgMinMax::INPUT)};
1000 const auto axis_index{node.getInputs().at(ir::operation::ArgMinMax::AXIS)};
1001
1002 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1003 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1004 auto axis_tensor = _tensor_reg->getPortableTensor(axis_index);
1005
1006 auto fn = std::make_unique<ops::ArgMinMaxLayer>();
1007
1008 fn->configure(input_tensor, output_tensor, axis_tensor, node.param().is_arg_max);
1009
1010 _return_fn = std::move(fn);
1011}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::ArgMinMax::Param::is_arg_max, and onert::ir::operation::ArgMinMax::param().

◆ visit() [3/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::BatchMatMul node)
override

Definition at line 1217 of file KernelGenerator.cc.

1218{
1219 const auto output_index{node.getOutputs().at(0)};
1220 const auto lhs_index{node.getInputs().at(ir::operation::BatchMatMul::LHS)};
1221 const auto rhs_index{node.getInputs().at(ir::operation::BatchMatMul::RHS)};
1222
1223 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1224 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
1225 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
1226
1227 const auto adj_x = node.param().adj_x;
1228 const auto adj_y = node.param().adj_y;
1229
1230 auto fn = std::make_unique<ops::BatchMatMulLayer>();
1231
1232 fn->configure(lhs_tensor, rhs_tensor, adj_x, adj_y, output_tensor);
1233 _return_fn = std::move(fn);
1234}

References onert::ir::operation::BatchMatMul::Param::adj_x, onert::ir::operation::BatchMatMul::Param::adj_y, onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::BatchMatMul::param().

◆ visit() [4/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::BatchToSpaceND node)
override

Definition at line 398 of file KernelGenerator.cc.

399{
400 const auto output_index{node.getOutputs().at(0)};
401 const auto input_index{node.getInputs().at(ir::operation::BatchToSpaceND::INPUT)};
402 const auto block_size_index{node.getInputs().at(ir::operation::BatchToSpaceND::BLOCK_SIZE)};
403
404 auto output_alloc = _tensor_reg->getPortableTensor(output_index);
405 auto input_alloc = _tensor_reg->getPortableTensor(input_index);
406 auto block_size_alloc = _tensor_reg->getPortableTensor(block_size_index);
407
408 auto fn = std::make_unique<ops::BatchToSpaceNDLayer>();
409
410 IPortableTensor *crops_alloc = nullptr;
411 const auto NNApiInputs = 2;
412
413 if (node.getInputs().size() != NNApiInputs)
414 {
415 const auto crops_data_index{node.getInputs().at(ir::operation::BatchToSpaceND::CROPS_DATA)};
416 crops_alloc = _tensor_reg->getPortableTensor(crops_data_index);
417 }
418
419 fn->configure(input_alloc, output_alloc, block_size_alloc, crops_alloc);
420
421 _return_fn = std::move(fn);
422}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::OperandIndexSequence::size().

◆ visit() [5/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::BinaryArithmetic node)
override

Definition at line 520 of file KernelGenerator.cc.

521{
522 const auto ofm_index{node.getOutputs().at(0)};
523 const auto lhs_index{node.getInputs().at(ir::operation::BinaryArithmetic::Input::LHS)};
524 const auto rhs_index{node.getInputs().at(ir::operation::BinaryArithmetic::Input::RHS)};
525
526 const auto activation = node.param().activation;
527
528 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
529 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
530 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
531
532 auto fn = std::make_unique<ops::BinaryArithmeticLayer>();
533
534 fn->configure(lhs_tensor, rhs_tensor, ofm_tensor, activation,
535 convertArithmeticType(node.param().arithmetic_type));
536
537 _return_fn = std::move(fn);
538}

References onert::ir::operation::BinaryArithmetic::Param::activation, onert::ir::operation::BinaryArithmetic::Param::arithmetic_type, onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::BinaryArithmetic::param().

◆ visit() [6/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::BroadcastTo node)
override

Definition at line 1236 of file KernelGenerator.cc.

1237{
1238 const auto output_index{node.getOutputs().at(0)};
1239 const auto input_index{node.getInputs().at(ir::operation::BroadcastTo::INPUT)};
1240 const auto shape_index{node.getInputs().at(ir::operation::BroadcastTo::SHAPE)};
1241
1242 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1243 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1244 auto shape_tensor = _tensor_reg->getPortableTensor(shape_index);
1245
1246 auto fn = std::make_unique<ops::BroadcastToLayer>();
1247
1248 fn->configure(input_tensor, shape_tensor, output_tensor);
1249
1250 _return_fn = std::move(fn);
1251}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [7/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Comparison node)
override

Definition at line 540 of file KernelGenerator.cc.

541{
542 const auto ofm_index{node.getOutputs().at(0)};
543 const auto lhs_index{node.getInputs().at(ir::operation::Comparison::Input::INPUT0)};
544 const auto rhs_index{node.getInputs().at(ir::operation::Comparison::Input::INPUT1)};
545
546 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
547 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
548 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
549
550 auto comparison_type = node.param().comparison_type;
551
552 auto fn = std::make_unique<ops::CompareLayer>();
553
554 fn->configure(lhs_tensor, rhs_tensor, comparison_type, ofm_tensor);
555
556 _return_fn = std::move(fn);
557}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Comparison::Param::comparison_type, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::Comparison::param().

◆ visit() [8/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Concat node)
override

Definition at line 378 of file KernelGenerator.cc.

379{
380 const auto ofm_index{node.getOutputs().at(0)};
381
382 const auto rank = _ctx.at(ofm_index).shape().rank();
383 const auto axis = ops::getAxis(rank, node.param().axis);
384
385 auto output_tensor = _tensor_reg->getPortableTensor(ofm_index);
386
387 std::vector<const IPortableTensor *> input_tensors;
388 for (const auto &ifm_idx : node.getInputs())
389 input_tensors.emplace_back(_tensor_reg->getPortableTensor(ifm_idx));
390
391 auto fn = std::make_unique<ops::ConcatLayer>();
392
393 fn->configure(input_tensors, axis, output_tensor);
394
395 _return_fn = std::move(fn);
396}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Concat::Param::axis, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::Concat::param().

◆ visit() [9/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Conv2D node)
override

Definition at line 289 of file KernelGenerator.cc.

290{
291 using ir::operation::Conv2D;
292
293 const auto ofm_index{node.getOutputs().at(0)};
294 const auto ifm_index{node.getInputs().at(Conv2D::Input::INPUT)};
295 const auto ker_index{node.getInputs().at(Conv2D::Input::KERNEL)};
296 const auto bias_index{node.getInputs().at(Conv2D::Input::BIAS)};
297
298 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
299 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
300 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
301 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
302
303 const auto stride = node.param().stride;
304 const auto activation = node.param().activation;
305 const auto &param_padding = node.param().padding;
306 const auto dilation = node.param().dilation;
307
308 const bool is_cacheable_weights = ker_tensor->is_constant();
309
310 auto fn = std::make_unique<ops::ConvolutionLayer>();
311
312 if (_ctx.at(ifm_index).info().isDynamic() || _ctx.at(ker_index).info().isDynamic())
313 {
314 fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, param_padding.param.left,
315 param_padding.param.right, param_padding.param.top, param_padding.param.bottom,
316 stride.horizontal, stride.vertical, dilation.width_factor, dilation.height_factor,
317 activation, ofm_tensor, is_cacheable_weights);
318
319 _return_fn = std::move(fn);
320 return;
321 }
322 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
323 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
324 // Kernel format is [depth_out, kernel_height, kernel_width, depth_in].
325 const auto &ker_shape = _ctx.at(ker_index).shape();
326 const auto ker_height = ker_shape.dim(1);
327 const auto ker_width = ker_shape.dim(2);
328
329 const auto padding =
330 ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height,
331 dilation.width_factor, dilation.height_factor);
332
333 fn->configure(ifm_tensor, ker_tensor, bias_tensor, param_padding.type, padding.left,
334 padding.right, padding.top, padding.bottom, stride.horizontal, stride.vertical,
335 dilation.width_factor, dilation.height_factor, activation, ofm_tensor,
336 is_cacheable_weights);
337
338 _return_fn = std::move(fn);
339}
const ExplicitPadding calculatePadding(const Padding &padding, const FeatureShape &ifm_shape, const FeatureShape &ofm_shape, const Stride &stride, uint32_t kw, uint32_t kh, uint32_t dwf=1, uint32_t dhf=1)
Definition Padding.cc:131
CLTensor ker_tensor
CLTensor bias_tensor

References onert::ir::operation::Conv2D::Param::activation, onert::ir::OperandIndexSequence::at(), bias_tensor, onert::ir::operation::Conv2D::Param::dilation, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), ker_tensor, onert::ir::operation::Conv2D::Param::padding, onert::ir::operation::Conv2D::param(), and onert::ir::operation::Conv2D::Param::stride.

◆ visit() [10/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Custom node)
override

Definition at line 623 of file KernelGenerator.cc.

624{
625 auto fill_op_info = [&](const ir::OperandIndexSequence &opSeq,
626 std::vector<custom::TypeInfo> &types,
627 std::vector<IPortableTensor *> &tensors) {
628 for (const auto &idx : opSeq)
629 {
630 const auto &operand = _ctx.at(idx);
631 types.emplace_back(custom::TypeInfo{operand.shape(), operand.typeInfo().type()});
632 auto in_tensor = _tensor_reg->getPortableTensor(idx);
633 tensors.emplace_back(in_tensor);
634 }
635 };
636
637 backend::custom::CustomKernelConfigParams params{};
638
639 fill_op_info(node.getInputs(), params.input_types, params.input_tensors);
640 fill_op_info(node.getOutputs(), params.output_types, params.output_tensors);
641
642 params.userdata = node.userdata().data;
643 params.userdata_size = node.userdata().size;
644
645 auto fn = _kernel_builder->buildKernel(node.id(), std::move(params));
646
647 _return_fn = std::move(fn);
648}

References onert::ir::operation::Custom::Userdata::data, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::Custom::id(), onert::backend::custom::TypeInfo::shape, onert::ir::operation::Custom::Userdata::size, and onert::ir::operation::Custom::userdata().

◆ visit() [11/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::DepthToSpace node)
override

Definition at line 1310 of file KernelGenerator.cc.

1311{
1312 const auto input_index{node.getInputs().at(ir::operation::DepthToSpace::Input::INPUT)};
1313 const auto output_index{node.getOutputs().at(0)};
1314 auto block_size = node.param().block_size;
1315
1316 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1317 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1318
1319 auto fn = std::make_unique<ops::DepthToSpaceLayer>();
1320
1321 fn->configure(input_tensor, block_size, output_tensor);
1322 _return_fn = std::move(fn);
1323}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::DepthToSpace::Param::block_size, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::DepthToSpace::param().

◆ visit() [12/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::DepthwiseConv2D node)
override

Definition at line 341 of file KernelGenerator.cc.

342{
343 using ir::operation::DepthwiseConv2D;
344
345 const auto ofm_index{node.getOutputs().at(0)};
346 const auto ifm_index{node.getInputs().at(DepthwiseConv2D::Input::INPUT)};
347 const auto ker_index{node.getInputs().at(DepthwiseConv2D::Input::KERNEL)};
348 const auto bias_index{node.getInputs().at(DepthwiseConv2D::Input::BIAS)};
349
350 const auto stride = node.param().stride;
351 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
352 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
353 // Kernel format is [1, kernel_height, kernel_width, depth_out].
354 const auto &ker_shape = _ctx.at(ker_index).shape();
355 const auto ker_height = ker_shape.dim(1);
356 const auto ker_width = ker_shape.dim(2);
357 const auto dilation_width = node.param().dilation.width_factor;
358 const auto dilation_height = node.param().dilation.height_factor;
359 const auto padding = ir::calculatePadding(node.param().padding, ifm_shape, ofm_shape, stride,
360 ker_width, ker_height, dilation_width, dilation_height);
361 const auto multiplier = node.param().multiplier;
362 const auto activation = node.param().activation;
363
364 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
365 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
366 auto ker_tensor = _tensor_reg->getPortableTensor(ker_index);
367 auto bias_tensor = _tensor_reg->getPortableTensor(bias_index);
368
369 auto fn = std::make_unique<ops::DepthwiseConvolutionLayer>();
370
371 fn->configure(ifm_tensor, ker_tensor, bias_tensor, padding.left, padding.right, padding.top,
372 padding.bottom, stride.horizontal, stride.vertical, multiplier, dilation_width,
373 dilation_height, activation, ofm_tensor, _external_context);
374
375 _return_fn = std::move(fn);
376}

References onert::ir::operation::DepthwiseConv2D::Param::activation, onert::ir::OperandIndexSequence::at(), bias_tensor, onert::ir::operation::DepthwiseConv2D::Param::dilation, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::Dilation::height_factor, ker_tensor, onert::ir::operation::DepthwiseConv2D::Param::multiplier, onert::ir::operation::DepthwiseConv2D::Param::padding, onert::ir::operation::DepthwiseConv2D::param(), onert::ir::operation::DepthwiseConv2D::Param::stride, and onert::ir::Dilation::width_factor.

◆ visit() [13/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::DetectionPostProcess node)
override

Definition at line 1172 of file KernelGenerator.cc.

1173{
1174 using NMS = ir::operation::DetectionPostProcess;
1175
1176 ops::DetectionPostProcessLayer::DetectionPostProcessParameters parameters;
1177 parameters.scales.y = node.param().scale.y_scale;
1178 parameters.scales.x = node.param().scale.x_scale;
1179 parameters.scales.w = node.param().scale.w_scale;
1180 parameters.scales.h = node.param().scale.h_scale;
1181
1182 parameters.iou_threshold = node.param().iou_threshold;
1183 parameters.score_threshold = node.param().score_threshold;
1184 parameters.max_boxes_per_class = node.param().max_boxes_per_class;
1185 parameters.max_detections = node.param().max_detections;
1186 parameters.num_classes = node.param().num_classes;
1187 parameters.center_box_format = node.param().center_size_boxes;
1188 parameters.max_classes_per_detection = node.param().max_classes_per_detection;
1189
1190 auto boxes_index = node.getInputs().at(NMS::Input::BOXES);
1191 auto scores_index = node.getInputs().at(NMS::Input::SCORES);
1192 auto anchors_index = node.getInputs().at(NMS::Input::INPUT_ANCHORS);
1193
1194 auto o_classes_index = node.getOutputs().at(NMS::Output::BOX_CLASSES);
1195 auto o_coords_index = node.getOutputs().at(NMS::Output::BOX_COORDS);
1196 auto o_scores_index = node.getOutputs().at(NMS::Output::BOX_SCORES);
1197 auto o_num_selected_index = node.getOutputs().at(NMS::Output::NUM_SELECTED);
1198
1199 parameters.boxes_descr = _ctx.at(boxes_index).shape().dims();
1200 parameters.scrores_descr = _ctx.at(scores_index).shape().dims();
1201
1202 parameters.boxes_input = _tensor_reg->getPortableTensor(boxes_index);
1203 parameters.scores_input = _tensor_reg->getPortableTensor(scores_index);
1204 parameters.anchors_input = _tensor_reg->getPortableTensor(anchors_index);
1205
1206 parameters.box_classes_output = _tensor_reg->getPortableTensor(o_classes_index);
1207 parameters.box_coords_output = _tensor_reg->getPortableTensor(o_coords_index);
1208 parameters.box_scores_output = _tensor_reg->getPortableTensor(o_scores_index);
1209 parameters.num_selections_output = _tensor_reg->getPortableTensor(o_num_selected_index);
1210
1211 auto fn = std::make_unique<ops::DetectionPostProcessLayer>();
1212 fn->configure(std::move(parameters));
1213
1214 _return_fn = std::move(fn);
1215}

References onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::anchors_input, onert::ir::OperandIndexSequence::at(), onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::box_classes_output, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::box_coords_output, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::box_scores_output, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::boxes_descr, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::boxes_input, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::center_box_format, onert::ir::operation::DetectionPostProcess::Param::center_size_boxes, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::backend::cpu::ops::DetectionPostProcessLayer::CenterSizeBox::h, onert::ir::operation::DetectionPostProcess::Scale::h_scale, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::iou_threshold, onert::ir::operation::DetectionPostProcess::Param::iou_threshold, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::max_boxes_per_class, onert::ir::operation::DetectionPostProcess::Param::max_boxes_per_class, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::max_classes_per_detection, onert::ir::operation::DetectionPostProcess::Param::max_classes_per_detection, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::max_detections, onert::ir::operation::DetectionPostProcess::Param::max_detections, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::num_classes, onert::ir::operation::DetectionPostProcess::Param::num_classes, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::num_selections_output, onert::ir::operation::DetectionPostProcess::param(), onert::ir::operation::DetectionPostProcess::Param::scale, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::scales, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::score_threshold, onert::ir::operation::DetectionPostProcess::Param::score_threshold, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::scores_input, onert::backend::cpu::ops::DetectionPostProcessLayer::DetectionPostProcessParameters::scrores_descr, onert::backend::cpu::ops::DetectionPostProcessLayer::CenterSizeBox::w, onert::ir::operation::DetectionPostProcess::Scale::w_scale, onert::backend::cpu::ops::DetectionPostProcessLayer::CenterSizeBox::x, onert::ir::operation::DetectionPostProcess::Scale::x_scale, onert::backend::cpu::ops::DetectionPostProcessLayer::CenterSizeBox::y, and onert::ir::operation::DetectionPostProcess::Scale::y_scale.

◆ visit() [14/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Einsum node)
override

Definition at line 605 of file KernelGenerator.cc.

606{
607 const auto ofm_index{node.getOutputs().at(0)};
608
609 auto output_tensor = _tensor_reg->getPortableTensor(ofm_index);
610 std::vector<const IPortableTensor *> input_tensors;
611 for (const auto &ifm_idx : node.getInputs())
612 input_tensors.emplace_back(_tensor_reg->getPortableTensor(ifm_idx));
613
614 const auto &equation = node.param().equation;
615
616 auto fn = std::make_unique<ops::EinsumLayer>();
617
618 fn->configure(input_tensors, equation, output_tensor);
619
620 _return_fn = std::move(fn);
621}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Einsum::Param::equation, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::Einsum::param().

◆ visit() [15/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::ElementwiseActivation node)
override

Definition at line 650 of file KernelGenerator.cc.

651{
652 const auto output_index{node.getOutputs().at(0)};
654
655 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
656 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
657
658 auto fn = std::make_unique<ops::ElementwiseActivationLayer>();
659
660 fn->configure(input_tensor, output_tensor, node.param().alpha, node.param().beta,
661 node.param().approximate, convertElementwiseActivationType(node.param().op_type));
662
663 _return_fn = std::move(fn);
664}

References onert::ir::operation::ElementwiseActivation::Param::alpha, onert::ir::operation::ElementwiseActivation::Param::approximate, onert::ir::OperandIndexSequence::at(), onert::ir::operation::ElementwiseActivation::Param::beta, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::ElementwiseActivation::Param::op_type, and onert::ir::operation::ElementwiseActivation::param().

◆ visit() [16/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::ElementwiseBinary node)
override

Definition at line 666 of file KernelGenerator.cc.

667{
668 const auto output_index{node.getOutputs().at(0)};
669 const auto lhs_index{node.getInputs().at(ir::operation::ElementwiseBinary::Input::LHS)};
670 const auto rhs_index{node.getInputs().at(ir::operation::ElementwiseBinary::Input::RHS)};
671
672 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
673 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
674 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
675
676 auto fn = std::make_unique<ops::ElementwiseBinaryLayer>();
677
678 fn->configure(lhs_tensor, rhs_tensor, output_tensor,
679 convertElementwiseBinaryType(node.param().op_type));
680
681 _return_fn = std::move(fn);
682}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::ElementwiseBinary::Param::op_type, and onert::ir::operation::ElementwiseBinary::param().

◆ visit() [17/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::ElementwiseUnary node)
override

Definition at line 684 of file KernelGenerator.cc.

685{
686 const auto output_index{node.getOutputs().at(0)};
687 const auto input_index{node.getInputs().at(ir::operation::ElementwiseUnary::Input::INPUT)};
688
689 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
690 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
691
692 if (node.param().op_type == ir::operation::ElementwiseUnary::Type::QUANTIZE)
693 {
694 auto fn = std::make_unique<ops::QuantizeLayer>();
695 fn->configure(input_tensor, output_tensor);
696 _return_fn = std::move(fn);
697 }
698 else
699 {
700 auto fn = std::make_unique<ops::ElementwiseUnaryLayer>();
701 fn->configure(input_tensor, output_tensor, convertElementwiseUnaryType(node.param().op_type));
702 _return_fn = std::move(fn);
703 }
704}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::ElementwiseUnary::Param::op_type, and onert::ir::operation::ElementwiseUnary::param().

◆ visit() [18/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::ExpandDims node)
override

Definition at line 706 of file KernelGenerator.cc.

707{
708 const auto output_index{node.getOutputs().at(0)};
709 const auto input_index{node.getInputs().at(ir::operation::ExpandDims::Input::INPUT)};
710 // AXIS input is used for output shape inference
711
712 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
713 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
714
715 auto fn = std::make_unique<ops::ExpandDimsLayer>();
716
717 fn->configure(input_tensor, output_tensor);
718
719 _return_fn = std::move(fn);
720}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [19/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Fill node)
override

Definition at line 424 of file KernelGenerator.cc.

425{
426 const auto output_index{node.getOutputs().at(0)};
427 // SHAPE input is used for shape inference
428 const auto value_index{node.getInputs().at(ir::operation::Fill::Input::VALUE)};
429
430 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
431 auto value_tensor = _tensor_reg->getPortableTensor(value_index);
432
433 auto fn = std::make_unique<ops::FillLayer>();
434
435 fn->configure(value_tensor, output_tensor);
436
437 _return_fn = std::move(fn);
438}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [20/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::FullyConnected node)
override

Definition at line 440 of file KernelGenerator.cc.

441{
442 using ir::operation::FullyConnected;
443
444 const auto output_index{node.getOutputs().at(0)};
445 const auto input_index{node.getInputs().at(FullyConnected::Input::INPUT)};
446 const auto weight_index{node.getInputs().at(FullyConnected::Input::WEIGHT)};
447 const auto bias_index{node.getInputs().at(FullyConnected::Input::BIAS)};
448 const auto activation = node.param().activation;
449 const auto weights_format = node.param().weights_format;
450
451 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
452 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
453 auto weight_tensor = _tensor_reg->getPortableTensor(weight_index);
454 auto bias_tensor = bias_index.undefined() ? nullptr : _tensor_reg->getPortableTensor(bias_index);
455
456 auto fn = std::make_unique<ops::FullyConnectedLayer>();
457
458 fn->configure(input_tensor, weight_tensor, bias_tensor, activation, weights_format, output_tensor,
459 _external_context);
460
461 _return_fn = std::move(fn);
462}

References onert::ir::operation::FullyConnected::Param::activation, onert::ir::OperandIndexSequence::at(), bias_tensor, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::FullyConnected::param(), and onert::ir::operation::FullyConnected::Param::weights_format.

◆ visit() [21/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::FusedBatchNorm node)
override

Definition at line 1253 of file KernelGenerator.cc.

1254{
1255 const auto ofm_index{node.getOutputs().at(0)};
1256
1257 auto output_tensor = _tensor_reg->getPortableTensor(ofm_index);
1258 std::vector<const IPortableTensor *> input_tensors;
1259 for (const auto &ifm_idx : node.getInputs())
1260 input_tensors.emplace_back(_tensor_reg->getPortableTensor(ifm_idx));
1261
1262 const auto epsilon = node.param().epsilon;
1263 const auto is_training = node.param().is_training;
1264 const auto &data_format = node.param().data_format;
1265
1266 auto fn = std::make_unique<ops::FusedBatchNormLayer>();
1267
1268 fn->configure(input_tensors, epsilon, is_training, data_format, output_tensor);
1269
1270 _return_fn = std::move(fn);
1271}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::FusedBatchNorm::Param::data_format, onert::ir::operation::FusedBatchNorm::Param::epsilon, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::FusedBatchNorm::Param::is_training, and onert::ir::operation::FusedBatchNorm::param().

◆ visit() [22/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Gather node)
override

Definition at line 559 of file KernelGenerator.cc.

560{
561 const auto output_index{node.getOutputs().at(0)};
562 const auto input_index{node.getInputs().at(ir::operation::Gather::Input::INPUT)};
563 const auto indices_index{node.getInputs().at(ir::operation::Gather::Input::INDICES)};
564
565 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
566 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
567 auto indices_tensor = _tensor_reg->getPortableTensor(indices_index);
568
569 const auto rank = _ctx.at(input_index).shape().rank();
570 const auto axis = ops::getAxis(rank, node.param().axis);
571
572 auto fn = std::make_unique<ops::GatherLayer>();
573
574 fn->configure(input_tensor, indices_tensor, output_tensor, axis, _external_context.get());
575
576 _return_fn = std::move(fn);
577}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Gather::Param::axis, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::Gather::param().

◆ visit() [23/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::L2Normalization node)
override

Definition at line 1056 of file KernelGenerator.cc.

1057{
1058 const auto output_index{node.getOutputs().at(0)};
1059 const auto input_index{node.getInputs().at(0)};
1060
1061 auto output_alloc = _tensor_reg->getPortableTensor(output_index);
1062 auto input_alloc = _tensor_reg->getPortableTensor(input_index);
1063
1064 auto fn = std::make_unique<ops::L2NormLayer>();
1065
1066 fn->configure(input_alloc, output_alloc);
1067
1068 _return_fn = std::move(fn);
1069}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [24/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::LogSoftmax node)
override

Definition at line 1273 of file KernelGenerator.cc.

1274{
1275 const auto output_index{node.getOutputs().at(0)};
1276 const auto input_index{node.getInputs().at(ir::operation::LogSoftmax::Input::INPUT)};
1277
1278 const auto beta = node.param().beta;
1279 const auto axis = node.param().axis;
1280
1281 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1282 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1283
1284 auto fn = std::make_unique<ops::LogSoftMaxLayer>();
1285
1286 fn->configure(input_tensor, beta, axis, output_tensor);
1287
1288 _return_fn = std::move(fn);
1289}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::LogSoftmax::Param::axis, onert::ir::operation::LogSoftmax::Param::beta, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::LogSoftmax::param().

◆ visit() [25/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::LSTM node)
override

Definition at line 1380 of file KernelGenerator.cc.

1381{
1382 const auto scratch_buffer_index{
1383 node.getOutputs().at(ir::operation::LSTM::Output::SCRATCH_BUFFER)};
1384 const auto output_state_out_index{
1385 node.getOutputs().at(ir::operation::LSTM::Output::OUTPUT_STATE_OUT)};
1386 const auto cell_state_out_index{
1387 node.getOutputs().at(ir::operation::LSTM::Output::CELL_STATE_OUT)};
1388 const auto output_index{node.getOutputs().at(ir::operation::LSTM::Output::OUTPUT)};
1389
1390 const auto input_index{node.getInputs().at(ir::operation::LSTM::Input::INPUT)};
1391 const auto input_to_input_weights_index{
1392 node.getInputs().at(ir::operation::LSTM::Input::INPUT_TO_INPUT_WEIGHTS)}; // optional
1393 const auto input_to_forget_weights_index{
1395 const auto input_to_cell_weights_index{
1397 const auto input_to_output_weights_index{
1399 const auto recurrent_to_input_weights_index{
1400 node.getInputs().at(ir::operation::LSTM::Input::RECURRENT_TO_INPUT_WEIGHTS)}; // optional
1401 const auto recurrent_to_forget_weights_index{
1403 const auto recurrent_to_cell_weights_index{
1405 const auto recurrent_to_output_weights_index{
1407 const auto cell_to_input_weights_index{
1408 node.getInputs().at(ir::operation::LSTM::Input::CELL_TO_INPUT_WEIGHTS)}; // optional
1409 const auto cell_to_forget_weights_index{
1410 node.getInputs().at(ir::operation::LSTM::Input::CELL_TO_FORGET_WEIGHTS)}; // optional
1411 const auto cell_to_output_weights_index{
1412 node.getInputs().at(ir::operation::LSTM::Input::CELL_TO_OUTPUT_WEIGHTS)}; // optional
1413 const auto input_gate_bias_index{
1414 node.getInputs().at(ir::operation::LSTM::Input::INPUT_GATE_BIAS)};
1415 const auto forget_gate_bias_index{
1417 const auto cell_gate_bias_index{node.getInputs().at(ir::operation::LSTM::Input::CELL_BIAS)};
1418 const auto output_gate_bias_index{
1420 const auto projection_weights_index{
1421 node.getInputs().at(ir::operation::LSTM::Input::PROJECTION_WEIGHTS)}; // optional
1422 const auto projection_bias_index{
1423 node.getInputs().at(ir::operation::LSTM::Input::PROJECTION_BIAS)}; // optional
1424 const auto output_state_in_index{
1425 node.getInputs().at(ir::operation::LSTM::Input::OUTPUT_STATE_IN)};
1426 const auto cell_state_in_index{node.getInputs().at(ir::operation::LSTM::Input::CELL_STATE_IN)};
1427 const auto time_major = node.param().time_major;
1428
1429 // NOTE The input_to_input_weights and the recurrent_to_input_weights do not exist in CIFG.
1430 // has_input_to_input_weights && has_recurrent_to_input_weights: no CIFG
1431 // !(has_input_to_input_weights && has_recurrent_to_input_weights): CIFG
1432 // NOTE The cell_to_input_weights does not exist in non-peephole although regular LSTM(non-CIFG).
1433 bool has_input_to_input_weights = _ctx.exist(input_to_input_weights_index) &&
1434 (_ctx.at(input_to_input_weights_index).shape().dim(0) != 0 &&
1435 _ctx.at(input_to_input_weights_index).shape().dim(1) != 0);
1436 bool has_recurrent_to_input_weights =
1437 _ctx.exist(recurrent_to_input_weights_index) &&
1438 (_ctx.at(recurrent_to_input_weights_index).shape().dim(0) != 0 &&
1439 _ctx.at(recurrent_to_input_weights_index).shape().dim(1) != 0);
1440
1441 // NOTE The cell_to_forget_weights and the cell_to_output_weights exist in peephole.
1442 // But the cell_to_input_weights does not exist in regular CIFG although peephole.
1443 // has_cell_to_forget_weights && has_cell_to_output_weights: peephole
1444 // !(has_cell_to_forget_weights && has_cell_to_output_weights): no peephole
1445 bool has_cell_to_forget_weights = _ctx.exist(cell_to_forget_weights_index) &&
1446 _ctx.at(cell_to_forget_weights_index).shape().dim(0) != 0;
1447 bool has_cell_to_output_weights = _ctx.exist(cell_to_output_weights_index) &&
1448 _ctx.at(cell_to_output_weights_index).shape().dim(0) != 0;
1449
1450 bool has_input_gate_bias =
1451 _ctx.exist(input_gate_bias_index) && _ctx.at(input_gate_bias_index).shape().dim(0);
1452
1453 bool has_projection_weights = _ctx.exist(projection_weights_index) &&
1454 (_ctx.at(projection_weights_index).shape().dim(0) != 0 &&
1455 _ctx.at(projection_weights_index).shape().dim(1) != 0);
1456 bool has_projection_bias =
1457 _ctx.exist(projection_bias_index) && _ctx.at(projection_bias_index).shape().dim(0);
1458
1459 auto scratch_buffer_tensor = _ctx.exist(scratch_buffer_index)
1460 ? _tensor_reg->getPortableTensor(scratch_buffer_index)
1461 : nullptr; // optional
1462 auto output_state_out_tensor = _ctx.exist(output_state_out_index)
1463 ? _tensor_reg->getPortableTensor(output_state_out_index)
1464 : nullptr; // optional
1465 auto cell_state_out_tensor = _ctx.exist(cell_state_out_index)
1466 ? _tensor_reg->getPortableTensor(cell_state_out_index)
1467 : nullptr; // optional
1468 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1469
1470 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1471
1472 auto input_to_input_weights_tensor =
1473 has_input_to_input_weights ? _tensor_reg->getPortableTensor(input_to_input_weights_index)
1474 : nullptr; // optional
1475 auto input_to_forget_weights_tensor =
1476 _tensor_reg->getPortableTensor(input_to_forget_weights_index);
1477 auto input_to_cell_weights_tensor = _tensor_reg->getPortableTensor(input_to_cell_weights_index);
1478 auto input_to_output_weights_tensor =
1479 _tensor_reg->getPortableTensor(input_to_output_weights_index);
1480 auto recurrent_to_input_weights_tensor =
1481 has_recurrent_to_input_weights
1482 ? _tensor_reg->getPortableTensor(recurrent_to_input_weights_index)
1483 : nullptr; // optional
1484 auto recurrent_to_forget_weights_tensor =
1485 _tensor_reg->getPortableTensor(recurrent_to_forget_weights_index);
1486 auto recurrent_to_cell_weights_tensor =
1487 _tensor_reg->getPortableTensor(recurrent_to_cell_weights_index);
1488 auto recurrent_to_output_weights_tensor =
1489 _tensor_reg->getPortableTensor(recurrent_to_output_weights_index);
1490
1491 auto cell_to_input_weights_tensor = _tensor_reg->getPortableTensor(cell_to_input_weights_index);
1492 auto cell_to_forget_weights_tensor =
1493 has_cell_to_forget_weights ? _tensor_reg->getPortableTensor(cell_to_forget_weights_index)
1494 : nullptr; // optional
1495 auto cell_to_output_weights_tensor =
1496 has_cell_to_output_weights ? _tensor_reg->getPortableTensor(cell_to_output_weights_index)
1497 : nullptr; // optional
1498
1499 auto input_gate_bias_tensor =
1500 has_input_gate_bias ? _tensor_reg->getPortableTensor(input_gate_bias_index) : nullptr;
1501 auto forget_gate_bias_tensor = _tensor_reg->getPortableTensor(forget_gate_bias_index);
1502 auto cell_gate_bias_tensor = _tensor_reg->getPortableTensor(cell_gate_bias_index);
1503 auto output_gate_bias_tensor = _tensor_reg->getPortableTensor(output_gate_bias_index);
1504 auto output_state_in_tensor = _tensor_reg->getPortableTensor(output_state_in_index);
1505 auto cell_state_in_tensor = _tensor_reg->getPortableTensor(cell_state_in_index);
1506
1507 auto projection_weights_tensor = has_projection_weights
1508 ? _tensor_reg->getPortableTensor(projection_weights_index)
1509 : nullptr; // optional
1510 auto projection_bias_tensor = has_projection_bias
1511 ? _tensor_reg->getPortableTensor(projection_bias_index)
1512 : nullptr; // optional
1513
1514 IPortableTensor *input_layer_norm_weights_tensor = nullptr;
1515 IPortableTensor *forget_layer_norm_weights_tensor = nullptr;
1516 IPortableTensor *cell_layer_norm_weights_tensor = nullptr;
1517 IPortableTensor *output_layer_norm_weights_tensor = nullptr;
1518 if (node.getInputs().size() == 24)
1519 {
1520 const auto input_layer_norm_weights_index{
1522 const auto forget_layer_norm_weights_index{
1524 const auto cell_layer_norm_weights_index{
1526 const auto output_layer_norm_weights_index{
1528
1529 input_layer_norm_weights_tensor =
1530 _tensor_reg->getPortableTensor(input_layer_norm_weights_index);
1531 forget_layer_norm_weights_tensor =
1532 _tensor_reg->getPortableTensor(forget_layer_norm_weights_index);
1533 cell_layer_norm_weights_tensor = _tensor_reg->getPortableTensor(cell_layer_norm_weights_index);
1534 output_layer_norm_weights_tensor =
1535 _tensor_reg->getPortableTensor(output_layer_norm_weights_index);
1536 }
1537
1538 auto fn = std::make_unique<ops::LSTMLayer>();
1539
1540 fn->configure(
1541 input_tensor, input_to_input_weights_tensor, input_to_forget_weights_tensor,
1542 input_to_cell_weights_tensor, input_to_output_weights_tensor, recurrent_to_input_weights_tensor,
1543 recurrent_to_forget_weights_tensor, recurrent_to_cell_weights_tensor,
1544 recurrent_to_output_weights_tensor, cell_to_input_weights_tensor, cell_to_forget_weights_tensor,
1545 cell_to_output_weights_tensor, input_layer_norm_weights_tensor,
1546 forget_layer_norm_weights_tensor, cell_layer_norm_weights_tensor,
1547 output_layer_norm_weights_tensor,
1548 /*aux_input=*/nullptr,
1549 /*aux_input_to_input_weights=*/nullptr,
1550 /*aux_input_to_forget_weights=*/nullptr,
1551 /*aux_input_to_cell_weights=*/nullptr,
1552 /*aux_input_to_output_weights=*/nullptr, input_gate_bias_tensor, forget_gate_bias_tensor,
1553 cell_gate_bias_tensor, output_gate_bias_tensor, projection_weights_tensor,
1554 projection_bias_tensor, output_state_in_tensor, cell_state_in_tensor, node.param(),
1555 /*forward_sequence=*/true, time_major,
1556 /*output_offset=*/0, scratch_buffer_tensor, output_state_out_tensor, cell_state_out_tensor,
1557 output_tensor,
1558 !_ctx.at(output_state_in_index).info().isVariable() /* means empty buffer on frontend now */,
1559 !_ctx.at(cell_state_in_index).info().isVariable());
1560
1561 _return_fn = std::move(fn);
1562}
bool exist(const Index &index) const
Get the object that is associated with the given index.

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::LSTM::param(), onert::ir::OperandIndexSequence::size(), and onert::ir::operation::LSTM::Param::time_major.

◆ visit() [26/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::MatrixBandPart node)
override

Definition at line 1154 of file KernelGenerator.cc.

1155{
1156 const auto output_index{node.getOutputs().at(0)};
1157 const auto input_index{node.getInputs().at(ir::operation::MatrixBandPart::INPUT)};
1158 const auto num_lower_index{node.getInputs().at(ir::operation::MatrixBandPart::NUM_LOWER_DIAG)};
1159 const auto num_upper_index{node.getInputs().at(ir::operation::MatrixBandPart::NUM_UPPER_DIAG)};
1160
1161 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1162 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1163 auto num_lower_tensor = _tensor_reg->getPortableTensor(num_lower_index);
1164 auto num_upper_tensor = _tensor_reg->getPortableTensor(num_upper_index);
1165
1166 auto fn = std::make_unique<ops::MatrixBandPartLayer>();
1167
1168 fn->configure(input_tensor, num_lower_tensor, num_upper_tensor, output_tensor);
1169 _return_fn = std::move(fn);
1170}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [27/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::OneHot node)
override

Definition at line 579 of file KernelGenerator.cc.

580{
581 const auto output_index{node.getOutputs().at(0)};
582 const auto indices_index{node.getInputs().at(ir::operation::OneHot::INDICES)};
583 const auto depth_index{node.getInputs().at(ir::operation::OneHot::Input::DEPTH)};
584 const auto onvalue_index{node.getInputs().at(ir::operation::OneHot::Input::ON_VALUE)};
585 const auto offvalue_index{node.getInputs().at(ir::operation::OneHot::Input::OFF_VALUE)};
586
587 const auto axis = node.param().axis;
588
589 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
590 auto indices_tensor = _tensor_reg->getPortableTensor(indices_index);
591 auto depth_tensor = _tensor_reg->getPortableTensor(depth_index);
592 auto onvalue_tensor = _tensor_reg->getPortableTensor(onvalue_index);
593 auto offvalue_tensor = _tensor_reg->getPortableTensor(offvalue_index);
594
595 assert(indices_tensor->data_type() == OperandType::INT32);
596 assert(axis <= static_cast<int>(indices_tensor->getShape().rank()));
597
598 auto fn = std::make_unique<ops::OneHotLayer>();
599
600 fn->configure(indices_tensor, depth_tensor, onvalue_tensor, offvalue_tensor, output_tensor, axis);
601
602 _return_fn = std::move(fn);
603}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::OneHot::Param::axis, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::OneHot::param().

◆ visit() [28/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Pack node)
override

Definition at line 722 of file KernelGenerator.cc.

723{
724 const auto ofm_index{node.getOutputs().at(0)};
725
726 const auto rank = _ctx.at(ofm_index).shape().rank();
727 const auto axis = ops::getAxis(rank, node.param().axis);
728
729 assert(-rank <= axis && axis < rank);
730
731 auto output_tensor = _tensor_reg->getPortableTensor(ofm_index);
732
733 std::vector<const IPortableTensor *> input_tensors;
734 for (const auto &ifm_idx : node.getInputs())
735 input_tensors.emplace_back(_tensor_reg->getPortableTensor(ifm_idx));
736
737 auto fn = std::make_unique<ops::PackLayer>();
738
739 fn->configure(input_tensors, axis, output_tensor);
740
741 _return_fn = std::move(fn);
742}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Pack::Param::axis, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::Pack::param().

◆ visit() [29/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Pad node)
override

Definition at line 768 of file KernelGenerator.cc.

769{
770 const auto input_index{node.getInputs().at(ir::operation::Pad::Input::INPUT)};
771 const auto pad_index{node.getInputs().at(ir::operation::Pad::Input::PAD)};
772 const auto output_index{node.getOutputs().at(0)};
773
774 auto input = _tensor_reg->getPortableTensor(input_index);
775 auto pad = _tensor_reg->getPortableTensor(pad_index);
776 auto output = _tensor_reg->getPortableTensor(output_index);
777
778 auto fn = std::make_unique<ops::PadLayer>();
779
780 IPortableTensor *value = nullptr;
781 if (node.getInputs().size() == 3) // isPadV2
782 {
783 const auto value_index{node.getInputs().at(ir::operation::Pad::Input::VALUE)};
784 value = _tensor_reg->getPortableTensor(value_index);
785 }
786
787 fn->configure(input, pad, value, output);
788 _return_fn = std::move(fn);
789}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::OperandIndexSequence::size().

◆ visit() [30/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Pool2D node)
override

Definition at line 1013 of file KernelGenerator.cc.

1014{
1015 const auto ofm_index{node.getOutputs().at(0)};
1016 const auto ifm_index{node.getInputs().at(ir::operation::Pool2D::Input::INPUT)};
1017
1018 const auto kh = node.param().kh;
1019 const auto kw = node.param().kw;
1020 const auto stride = node.param().stride;
1021 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
1022 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
1023 const auto padding =
1024 ir::calculatePadding(node.param().padding, ifm_shape, ofm_shape, stride, kw, kh);
1025 const auto activation = node.param().activation;
1026
1027 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
1028 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
1029
1030 auto fn = std::make_unique<ops::PoolLayer>();
1031
1032 fn->configure(ifm_tensor, padding.left, padding.right, padding.top, padding.bottom,
1033 stride.horizontal, stride.vertical, kw, kh, activation, ofm_tensor,
1034 convertPoolType(node.param().op_type));
1035
1036 _return_fn = std::move(fn);
1037}
arm_compute::PoolingType convertPoolType(ir::operation::Pool2D::PoolType pool_type_ir)
Definition Convert.cc:279

References onert::ir::operation::Pool2D::Param::activation, onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::Pool2D::Param::kh, onert::ir::operation::Pool2D::Param::kw, onert::ir::operation::Pool2D::Param::op_type, onert::ir::operation::Pool2D::Param::padding, onert::ir::operation::Pool2D::param(), and onert::ir::operation::Pool2D::Param::stride.

◆ visit() [31/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Pow node)
override

Definition at line 1039 of file KernelGenerator.cc.

1040{
1041 const auto output_index{node.getOutputs().at(0)};
1042 const auto lhs_index{node.getInputs().at(ir::operation::Pow::LHS)};
1043 const auto rhs_index{node.getInputs().at(ir::operation::Pow::RHS)};
1044
1045 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1046 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
1047 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
1048
1049 auto fn = std::make_unique<ops::PowLayer>();
1050
1051 fn->configure(lhs_tensor, rhs_tensor, ir::Activation::NONE, output_tensor);
1052
1053 _return_fn = std::move(fn);
1054}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [32/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Range node)
override

Definition at line 1071 of file KernelGenerator.cc.

1072{
1073 const auto output_index{node.getOutputs().at(0)};
1074 const auto start_index{node.getInputs().at(ir::operation::Range::START)};
1075 const auto limit_index{node.getInputs().at(ir::operation::Range::LIMIT)};
1076 const auto delta_index{node.getInputs().at(ir::operation::Range::DELTA)};
1077
1078 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1079 auto start_tensor = _tensor_reg->getPortableTensor(start_index);
1080 auto limit_tensor = _tensor_reg->getPortableTensor(limit_index);
1081 auto delta_tensor = _tensor_reg->getPortableTensor(delta_index);
1082
1083 auto fn = std::make_unique<ops::RangeLayer>();
1084
1085 fn->configure(start_tensor, limit_tensor, delta_tensor, output_tensor);
1086 _return_fn = std::move(fn);
1087}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [33/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Rank node)
override

Definition at line 1089 of file KernelGenerator.cc.

1090{
1091 const auto ofm_index{node.getOutputs().at(0)};
1092 const auto ifm_index{node.getInputs().at(ir::operation::Shape::Input::INPUT)};
1093
1094 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
1095 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
1096
1097 auto fn = std::make_unique<ops::RankLayer>();
1098
1099 fn->configure(ifm_tensor, ofm_tensor);
1100
1101 _return_fn = std::move(fn);
1102}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [34/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Reduce node)
override

Definition at line 808 of file KernelGenerator.cc.

809{
810 const auto output_index{node.getOutputs().at(0)};
811 const auto input_index{node.getInputs().at(ir::operation::Reduce::Input::INPUT)};
812 const auto axes_index{node.getInputs().at(ir::operation::Reduce::Input::AXES)};
813
814 const auto keep_dims = node.param().keep_dims;
815 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
816 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
817 auto axes_tensor = _tensor_reg->getPortableTensor(axes_index);
818
819 if (node.param().reduce_type == ir::operation::Reduce::ReduceType::MEAN)
820 {
821 auto fn = std::make_unique<ops::MeanLayer>();
822
823 fn->configure(input_tensor, axes_tensor, output_tensor, keep_dims);
824
825 _return_fn = std::move(fn);
826 }
827 else
828 {
829 auto fn = std::make_unique<ops::ReduceLayer>();
830
831 const auto reduce_type = convertReduceType(node.param().reduce_type);
832 fn->configure(input_tensor, axes_tensor, output_tensor, reduce_type, keep_dims);
833
834 _return_fn = std::move(fn);
835 }
836}
arm_compute::ReductionOperation convertReduceType(ir::operation::Reduce::ReduceType reduce_type_ir)
Definition Convert.cc:294

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::Reduce::Param::keep_dims, onert::ir::operation::Reduce::param(), and onert::ir::operation::Reduce::Param::reduce_type.

◆ visit() [35/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Reshape node)
override

Definition at line 464 of file KernelGenerator.cc.

465{
466 const auto output_index{node.getOutputs().at(0)};
467 const auto input_index{node.getInputs().at(ir::operation::Reshape::Input::INPUT)};
468
469 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
470 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
471
472 // optional 2nd input
473 IPortableTensor *shape_tensor = nullptr;
474
475 if (node.getInputs().size() == 2)
476 {
477 const auto shape_index{node.getInputs().at(ir::operation::Reshape::Input::SHAPE)};
478 shape_tensor = _tensor_reg->getPortableTensor(shape_index);
479 }
480
481 auto fn = std::make_unique<ops::ReshapeLayer>();
482
483 fn->configure(input_tensor, shape_tensor, output_tensor);
484 _return_fn = std::move(fn);
485}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::OperandIndexSequence::size().

◆ visit() [36/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::ResizeBilinear node)
override

Definition at line 939 of file KernelGenerator.cc.

940{
941 const auto output_index{node.getOutputs().at(0)};
942 const auto input_index{node.getInputs().at(ir::operation::ResizeBilinear::INPUT)};
943
944 auto align_corners = node.param().align_corners;
945 auto half_pixel_centers = node.param().half_pixel_centers;
946
947 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
948 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
949
950 auto fn = std::make_unique<ops::ResizeBilinearLayer>();
951
952 if (node.getInputs().size() == 1)
953 {
954 fn->configure(input_tensor, output_tensor, node.param().height_out, node.param().width_out,
955 align_corners, half_pixel_centers);
956 }
957 else
958 {
959 assert(node.getInputs().size() == 2);
960 const auto size_index{node.getInputs().at(ir::operation::ResizeBilinear::SIZE)};
961 auto size_tensor = _tensor_reg->getPortableTensor(size_index);
962 if (size_tensor->is_constant())
963 {
964 auto size_vec = _ctx.at(size_index).asVector<int32_t>();
965 const auto height_out = size_vec[0];
966 const auto width_out = size_vec[1];
967 fn->configure(input_tensor, output_tensor, height_out, width_out, align_corners,
968 half_pixel_centers);
969 }
970 else
971 {
972 fn->configure(input_tensor, output_tensor, size_tensor, align_corners, half_pixel_centers);
973 }
974 }
975
976 _return_fn = std::move(fn);
977}

References onert::ir::operation::ResizeBilinear::Param::align_corners, onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::ResizeBilinear::Param::half_pixel_centers, onert::ir::operation::ResizeBilinear::Param::height_out, onert::ir::operation::ResizeBilinear::param(), onert::ir::OperandIndexSequence::size(), and onert::ir::operation::ResizeBilinear::Param::width_out.

◆ visit() [37/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Reverse node)
override

Definition at line 979 of file KernelGenerator.cc.

980{
981 const auto output_index{node.getOutputs().at(0)};
982 const auto input_index{node.getInputs().at(ir::operation::Reverse::INPUT)};
983 const auto axis_index{node.getInputs().at(ir::operation::Reverse::AXIS)};
984
985 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
986 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
987 auto axis_tensor = _tensor_reg->getPortableTensor(axis_index);
988
989 auto fn = std::make_unique<ops::ReverseLayer>();
990
991 fn->configure(input_tensor, axis_tensor, output_tensor);
992
993 _return_fn = std::move(fn);
994}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [38/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::RmsNorm node)
override

Definition at line 1104 of file KernelGenerator.cc.

1105{
1106 const auto ofm_index{node.getOutputs().at(0)};
1107 const auto ifm_index{node.getInputs().at(ir::operation::RmsNorm::Input::INPUT)};
1108 const auto gamma_index{node.getInputs().at(ir::operation::RmsNorm::Input::GAMMA)};
1109
1110 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
1111 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
1112 auto gamma_tensor = _tensor_reg->getPortableTensor(gamma_index);
1113 auto epsilon = node.param().epsilon;
1114
1115 auto fn = std::make_unique<ops::RmsNormLayer>();
1116
1117 fn->configure(ifm_tensor, gamma_tensor, epsilon, ofm_tensor);
1118
1119 _return_fn = std::move(fn);
1120}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::RmsNorm::Param::epsilon, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::RmsNorm::param().

◆ visit() [39/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::RoPE node)
override

Definition at line 1564 of file KernelGenerator.cc.

1565{
1566 const auto input_index{node.getInputs().at(ir::operation::RoPE::Input::INPUT)};
1567 const auto sin_table{node.getInputs().at(ir::operation::RoPE::Input::SIN_TABLE)};
1568 const auto cos_table{node.getInputs().at(ir::operation::RoPE::Input::COS_TABLE)};
1569 const auto output_index{node.getOutputs().at(ir::operation::RoPE::Output::OUTPUT)};
1570
1571 auto mode = ops::getRoPEMode(node.param().mode);
1572
1573 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1574 auto sin_tensor = _tensor_reg->getPortableTensor(sin_table);
1575 auto cos_tensor = _tensor_reg->getPortableTensor(cos_table);
1576 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1577
1578 auto fn = std::make_unique<ops::RoPELayer>();
1579
1580 fn->configure(input_tensor, sin_tensor, cos_tensor, mode, output_tensor);
1581 _return_fn = std::move(fn);
1582}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::RoPE::Param::mode, and onert::ir::operation::RoPE::param().

◆ visit() [40/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Select node)
override

Definition at line 838 of file KernelGenerator.cc.

839{
840 const auto output_index{node.getOutputs().at(0)};
841 const auto condition_index{node.getInputs().at(ir::operation::Select::Input::CONDITION)};
842 const auto true_index{node.getInputs().at(ir::operation::Select::Input::INPUT_TRUE)};
843 const auto false_index{node.getInputs().at(ir::operation::Select::Input::INPUT_FALSE)};
844
845 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
846 auto condition_tensor = _tensor_reg->getPortableTensor(condition_index);
847 auto true_tensor = _tensor_reg->getPortableTensor(true_index);
848 auto false_tensor = _tensor_reg->getPortableTensor(false_index);
849
850 auto fn = std::make_unique<ops::SelectLayer>();
851
852 fn->configure(condition_tensor, true_tensor, false_tensor, output_tensor);
853
854 _return_fn = std::move(fn);
855}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [41/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Shape node)
override

Definition at line 924 of file KernelGenerator.cc.

925{
926 const auto ofm_index{node.getOutputs().at(0)};
927 const auto ifm_index{node.getInputs().at(ir::operation::Shape::Input::INPUT)};
928
929 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
930 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
931
932 auto fn = std::make_unique<ops::ShapeLayer>();
933
934 fn->configure(ifm_tensor, ofm_tensor);
935
936 _return_fn = std::move(fn);
937}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [42/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Slice node)
override

Definition at line 857 of file KernelGenerator.cc.

858{
859 const auto output_index{node.getOutputs().at(0)};
860 const auto input_index{node.getInputs().at(ir::operation::Slice::Input::INPUT)};
861 const auto begins_index{node.getInputs().at(ir::operation::Slice::Input::BEGINS)};
862 const auto sizes_index{node.getInputs().at(ir::operation::Slice::Input::SIZES)};
863
864 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
865 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
866 auto begins_tensor = _tensor_reg->getPortableTensor(begins_index);
867 auto sizes_tensor = _tensor_reg->getPortableTensor(sizes_index);
868
869 auto fn = std::make_unique<ops::SliceLayer>();
870
871 fn->configure(input_tensor, begins_tensor, sizes_tensor, output_tensor);
872
873 _return_fn = std::move(fn);
874}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [43/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Softmax node)
override

Definition at line 503 of file KernelGenerator.cc.

504{
505 const auto output_index{node.getOutputs().at(0)};
506 const auto input_index{node.getInputs().at(ir::operation::Softmax::Input::INPUT)};
507
508 const auto beta = node.param().beta;
509
510 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
511 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
512
513 auto fn = std::make_unique<ops::SoftMaxLayer>();
514
515 fn->configure(input_tensor, beta, output_tensor);
516
517 _return_fn = std::move(fn);
518}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Softmax::Param::beta, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::Softmax::param().

◆ visit() [44/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::SpaceToBatchND node)
override

Definition at line 1291 of file KernelGenerator.cc.

1292{
1293 const auto output_index{node.getOutputs().at(0)};
1294 const auto input_index{node.getInputs().at(ir::operation::SpaceToBatchND::INPUT)};
1295 const auto block_shape_index{node.getInputs().at(ir::operation::SpaceToBatchND::BLOCK_SIZE)};
1296 const auto padding_index{node.getInputs().at(ir::operation::SpaceToBatchND::PADDINGS)};
1297
1298 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1299 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1300 auto block_shape_tensor = _tensor_reg->getPortableTensor(block_shape_index);
1301 auto padding_tensor = _tensor_reg->getPortableTensor(padding_index);
1302
1303 auto fn = std::make_unique<ops::SpaceToBatchNDLayer>();
1304
1305 fn->configure(input_tensor, block_shape_tensor, padding_tensor, output_tensor);
1306
1307 _return_fn = std::move(fn);
1308}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [45/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::SpaceToDepth node)
override

Definition at line 1325 of file KernelGenerator.cc.

1326{
1327 const auto input_index{node.getInputs().at(ir::operation::SpaceToDepth::Input::INPUT)};
1328 const auto output_index{node.getOutputs().at(0)};
1329 auto block_size = node.param().block_size;
1330
1331 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1332 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1333
1334 auto fn = std::make_unique<ops::SpaceToDepthLayer>();
1335
1336 fn->configure(input_tensor, block_size, output_tensor);
1337 _return_fn = std::move(fn);
1338}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::SpaceToDepth::Param::block_size, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), and onert::ir::operation::SpaceToDepth::param().

◆ visit() [46/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Split node)
override

Definition at line 902 of file KernelGenerator.cc.

903{
904 const auto num_splits = node.param().num_splits;
905 assert(num_splits == static_cast<int>(node.getOutputs().size()));
906
907 const auto input_idx{node.getInputs().at(ir::operation::Split::Input::INPUT)};
908 const auto axis_idx{node.getInputs().at(ir::operation::Split::Input::AXIS)};
909
910 auto in_tensor = _tensor_reg->getPortableTensor(input_idx);
911 auto axis_tensor = _tensor_reg->getPortableTensor(axis_idx);
912
913 std::vector<IPortableTensor *> out_tensors;
914 for (const auto &output_idx : node.getOutputs())
915 out_tensors.emplace_back(_tensor_reg->getPortableTensor(output_idx));
916
917 auto fn = std::make_unique<ops::SplitLayer>();
918
919 fn->configure(in_tensor, axis_tensor, num_splits, out_tensors);
920
921 _return_fn = std::move(fn);
922}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::Split::Param::num_splits, onert::ir::operation::Split::param(), and onert::ir::OperandIndexSequence::size().

◆ visit() [47/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::SplitV node)
override

Definition at line 1356 of file KernelGenerator.cc.

1357{
1358 const auto num_splits = node.param().num_splits;
1359 assert(num_splits == static_cast<int>(node.getOutputs().size()));
1360
1361 const auto input_idx{node.getInputs().at(ir::operation::SplitV::Input::INPUT)};
1362 const auto size_splits{node.getInputs().at(ir::operation::SplitV::Input::SIZE_SPLITS)};
1363 const auto split_dim{node.getInputs().at(ir::operation::SplitV::Input::SPLIT_DIM)};
1364
1365 auto in_tensor = _tensor_reg->getPortableTensor(input_idx);
1366 auto in_size_splits = _tensor_reg->getPortableTensor(size_splits);
1367 auto in_split_dim = _tensor_reg->getPortableTensor(split_dim);
1368
1369 std::vector<IPortableTensor *> out_tensors;
1370 for (const auto &output_idx : node.getOutputs())
1371 out_tensors.emplace_back(_tensor_reg->getPortableTensor(output_idx));
1372
1373 auto fn = std::make_unique<ops::SplitVLayer>();
1374
1375 fn->configure(in_tensor, in_size_splits, in_split_dim, num_splits, out_tensors);
1376
1377 _return_fn = std::move(fn);
1378}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::SplitV::Param::num_splits, onert::ir::operation::SplitV::param(), and onert::ir::OperandIndexSequence::size().

◆ visit() [48/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::SquaredDifference node)
override

Definition at line 1122 of file KernelGenerator.cc.

1123{
1124 const auto ofm_index{node.getOutputs().at(0)};
1125 const auto lhs_index{node.getInputs().at(ir::operation::SquaredDifference::Input::LHS)};
1126 const auto rhs_index{node.getInputs().at(ir::operation::SquaredDifference::Input::RHS)};
1127
1128 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
1129 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
1130 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
1131
1132 auto fn = std::make_unique<ops::SqDiffLayer>();
1133
1134 fn->configure(lhs_tensor, rhs_tensor, ofm_tensor);
1135 _return_fn = std::move(fn);
1136}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [49/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Squeeze node)
override

Definition at line 487 of file KernelGenerator.cc.

488{
489 const auto output_index{node.getOutputs().at(0)};
490 const auto input_index{node.getInputs().at(ir::operation::Squeeze::Input::INPUT)};
491
492 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
493 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
494
495 // Squeeze can share same kernel with reshape
496 auto fn = std::make_unique<ops::ReshapeLayer>();
497
498 fn->configure(input_tensor, nullptr, output_tensor);
499
500 _return_fn = std::move(fn);
501}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [50/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::StatelessRandomUniform node)
override

Definition at line 1340 of file KernelGenerator.cc.

1341{
1342 const auto output_index{node.getOutputs().at(0)};
1343 const auto shape_index{node.getInputs().at(ir::operation::StatelessRandomUniform::SHAPE)};
1344 const auto seed_index{node.getInputs().at(ir::operation::StatelessRandomUniform::SEED)};
1345
1346 auto output_alloc = _tensor_reg->getPortableTensor(output_index);
1347 auto shape_alloc = _tensor_reg->getPortableTensor(shape_index);
1348 auto seed_alloc = _tensor_reg->getPortableTensor(seed_index);
1349
1350 auto fn = std::make_unique<ops::StatelessRandomUniformLayer>();
1351
1352 fn->configure(shape_alloc, seed_alloc, output_alloc);
1353 _return_fn = std::move(fn);
1354}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [51/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::StridedSlice node)
override

Definition at line 876 of file KernelGenerator.cc.

877{
878 const auto output_index{node.getOutputs().at(0)};
879 const auto input_index{node.getInputs().at(ir::operation::StridedSlice::Input::INPUT)};
880 const auto starts_index{node.getInputs().at(ir::operation::StridedSlice::Input::STARTS)};
881 const auto ends_index{node.getInputs().at(ir::operation::StridedSlice::Input::ENDS)};
882 const auto strides_index{node.getInputs().at(ir::operation::StridedSlice::Input::STRIDES)};
883
884 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
885 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
886 auto starts_tensor = _tensor_reg->getPortableTensor(starts_index);
887 auto ends_tensor = _tensor_reg->getPortableTensor(ends_index);
888 auto strides_tensor = _tensor_reg->getPortableTensor(strides_index);
889
890 auto begin_mask = node.param().begin_mask;
891 auto end_mask = node.param().end_mask;
892 auto shrink_axis_mask = node.param().shrink_axis_mask;
893
894 auto fn = std::make_unique<ops::StridedSliceLayer>();
895
896 fn->configure(input_tensor, starts_tensor, ends_tensor, strides_tensor, output_tensor, begin_mask,
897 end_mask, shrink_axis_mask);
898
899 _return_fn = std::move(fn);
900}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::StridedSlice::Param::begin_mask, onert::ir::operation::StridedSlice::Param::end_mask, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::StridedSlice::param(), and onert::ir::operation::StridedSlice::Param::shrink_axis_mask.

◆ visit() [52/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Tile node)
override

Definition at line 1138 of file KernelGenerator.cc.

1139{
1140 const auto output_index{node.getOutputs().at(0)};
1141 const auto input_index{node.getInputs().at(ir::operation::Tile::INPUT)};
1142 const auto multiples_index{node.getInputs().at(ir::operation::Tile::MULTIPLES)};
1143
1144 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
1145 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
1146 auto multiples_tensor = _tensor_reg->getPortableTensor(multiples_index);
1147
1148 auto fn = std::make_unique<ops::TileLayer>();
1149
1150 fn->configure(input_tensor, multiples_tensor, output_tensor);
1151 _return_fn = std::move(fn);
1152}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [53/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Transpose node)
override

Definition at line 791 of file KernelGenerator.cc.

792{
793 const auto output_index{node.getOutputs().at(0)};
794 const auto input_index{node.getInputs().at(ir::operation::Transpose::Input::INPUT)};
795 const auto perm_index{node.getInputs().at(ir::operation::Transpose::Input::PERMUTATION)};
796
797 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
798 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
799 auto perm_tensor = _tensor_reg->getPortableTensor(perm_index);
800
801 auto fn = std::make_unique<ops::TransposeLayer>();
802
803 fn->configure(input_tensor, perm_tensor, output_tensor);
804
805 _return_fn = std::move(fn);
806}

References onert::ir::OperandIndexSequence::at(), onert::ir::Operation::getInputs(), and onert::ir::Operation::getOutputs().

◆ visit() [54/54]

void onert::backend::cpu::KernelGenerator::visit ( const ir::operation::Unpack node)
override

Definition at line 744 of file KernelGenerator.cc.

745{
746 const auto input_index{node.getInputs().at(0)};
747
748 const auto rank = _ctx.at(input_index).shape().rank();
749 const auto axis = ops::getAxis(rank, node.param().axis);
750
751 assert(rank == 0 || (-rank <= axis && axis < rank));
752
753 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
754
755 std::vector<IPortableTensor *> output_tensors;
756 for (const auto &output_idx : node.getOutputs())
757 output_tensors.emplace_back(_tensor_reg->getPortableTensor(output_idx));
758
759 auto fn = std::make_unique<ops::UnpackLayer>();
760
761 uint32_t axis_resolved = (axis < 0 ? axis + rank : axis);
762
763 fn->configure(input_tensor, axis_resolved, node.param().num, output_tensors);
764
765 _return_fn = std::move(fn);
766}

References onert::ir::OperandIndexSequence::at(), onert::ir::operation::Unpack::Param::axis, onert::ir::Operation::getInputs(), onert::ir::Operation::getOutputs(), onert::ir::operation::Unpack::Param::num, and onert::ir::operation::Unpack::param().


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