ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
KernelGenerator.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 Samsung Electronics Co., Ltd. All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "KernelGenerator.h"
18
20#include "ops/BinaryArithmeticLayer.h"
21#include "ops/ConvolutionLayer.h"
22#include "ops/DepthwiseConvolutionLayer.h"
23#include "ops/ElementwiseActivationLayer.h"
24#include "ops/FullyConnectedLayer.h"
27#include "ops/MeanLayer.h"
28#include "ops/GradientApplier.h"
29#include "ops/PadLayer.h"
30#include "ops/PoolLayer.h"
31#include "ops/ReshapeLayer.h"
32#include "ops/SoftMaxLayer.h"
33
34#include <backend/Backend.h>
35#include <backend/IConfig.h>
36#include <memory>
37#include <util/logging.h>
39
40#include <stdexcept>
41
43{
44
45namespace
46{
47ops::ElementwiseActivationType
48convertElementwiseActivationType(ir::operation::ElementwiseActivation::Type type_ir)
49{
50 switch (type_ir)
51 {
54 default:
55 throw std::runtime_error("train KernelGenerator : Not supported operation yet");
56 }
57}
58
60{
61 switch (type_ir)
62 {
63 // TODO Implement AVG PoolType
68 default:
69 throw std::runtime_error("train KernelGenerator : Not supported operation yet");
70 }
71}
72
73std::unique_ptr<ops::BackPropAccumulator>
74generateBackPropAccumulator(const IPortableTensor *disposable, BackPropTensor *gradient)
75{
76 auto update_fn = std::make_unique<ops::BackPropAccumulator>(disposable, gradient);
77 return update_fn;
78}
79
80void appendBackPropAccumulators(const ir::train::ITrainableOperation &op,
81 const ir::OperationIndex &op_index, TensorRegistry *tensor_reg,
82 exec::train::TrainableFnSequence *seq)
83{
84 if (!op.isRequiredForBackward())
85 return;
86
87 for (const auto &input_index : (op.getInputs() | ir::Remove::UNDEFINED))
88 {
89 const auto disposable =
90 tensor_reg->getDisposableBackPropTensor(DisposableTensorIndex{op_index, input_index});
91 if (disposable != nullptr)
92 {
93 auto back_prop = tensor_reg->getBackPropTensor(input_index);
94 assert(back_prop);
95 seq->append(generateBackPropAccumulator(disposable, back_prop));
96 }
97 }
98}
99
100std::unique_ptr<ops::GradientApplier>
101generateGradientApplier(const exec::train::optimizer::Optimizer *optimizer,
102 const IPortableTensor *gradient, ITrainableTensor *trainable)
103{
104 auto update_fn = std::make_unique<ops::GradientApplier>();
105 update_fn->configure(optimizer, gradient, trainable);
106 return update_fn;
107}
108} // namespace
109
110std::unique_ptr<exec::train::TrainableFnSequence> KernelGenerator::generate(ir::OperationIndex idx)
111{
112 // NOTE This function is related to planning tensors. If you change this function, you should
113 // also consider to change planning tensors.
114
115 auto ret = std::make_unique<exec::train::TrainableFnSequence>();
116
117 const auto &op = _tgraph.operation(idx);
118
119 // NOTE appendBackPropAccumulators() must be called before appending _return_fn to
120 // TrainableFnSequence as long as both are appended to the same TrainableFnSequence.
121 appendBackPropAccumulators(op, idx, _tensor_reg.get(), ret.get());
122
123 op.accept(*this);
124 assert(_return_fn);
125 ret->append(std::move(_return_fn));
126
127 for (auto &&update_fn : _update_funcs)
128 ret->append(std::move(update_fn));
129 _update_funcs.clear();
130
131 for (auto &&ind : (op.getInputs() | ir::Remove::UNDEFINED) + op.getOutputs())
132 {
133 auto tensor = _tensor_reg->getNonConstTensor(ind);
134 if (tensor)
135 {
136 tensor->increase_ref();
137 }
138 }
139 return ret;
140}
141
143 const std::shared_ptr<TensorRegistry> &tensor_reg,
144 const std::shared_ptr<ExternalContext> &external_context,
146 : backend::train::KernelGeneratorBase{tgraph}, _tensor_reg{tensor_reg},
147 _external_context(external_context), _optimizer{optimizer}, _update_funcs{}, _node_to_idx{}
148{
149 tgraph.operations().iterate(
150 [&](const onert::ir::OperationIndex &idx, const onert::ir::IOperation &op) {
151 assert(_node_to_idx.find(&op) == _node_to_idx.end());
152 _node_to_idx[&op] = idx;
153 });
154}
155
157{
159
160 const auto output_index{node.getOutputs().at(0)};
161 const auto lhs_index{node.getInputs().at(BinaryArithmetic::Input::LHS)};
162 const auto rhs_index{node.getInputs().at(BinaryArithmetic::Input::RHS)};
163
164 const auto arithmetic_type = node.param().arithmetic_type;
165 const auto activation = node.param().activation;
166
167 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
168 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
169 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
170
171 auto fn = std::make_unique<ops::BinaryArithmeticLayer>();
172 fn->configure(lhs_tensor, rhs_tensor, output_tensor, activation,
173 static_cast<cpu::ops::ArithmeticType>(arithmetic_type));
174
175 if (node.isRequiredForBackward())
176 {
177 auto back_prop_output_tensor = getBackPropOut(output_index);
178 auto back_prop_lhs_tensor = getBackPropIn(node, lhs_index);
179 auto back_prop_rhs_tensor = getBackPropIn(node, rhs_index);
180
181 fn->configureBackward(back_prop_lhs_tensor, back_prop_rhs_tensor, back_prop_output_tensor,
182 activation, static_cast<train::ops::ArithmeticType>(arithmetic_type));
183 }
184 _return_fn = std::move(fn);
185}
186
188{
190
191 const auto out_index{node.getOutputs().at(0)};
192 const auto in_index{node.getInputs().at(Conv2D::Input::INPUT)};
193 const auto ker_index{node.getInputs().at(Conv2D::Input::KERNEL)};
194 const auto bias_index{node.getInputs().at(Conv2D::Input::BIAS)};
195
196 auto out_tensor = _tensor_reg->getPortableTensor(out_index);
197 auto in_tensor = _tensor_reg->getPortableTensor(in_index);
198 auto ker_tensor = _tensor_reg->getTrainableTensor(ker_index);
199 auto bias_tensor = _tensor_reg->getTrainableTensor(bias_index);
200
201 // Generate kernel
202 const auto stride = node.param().stride;
203 const auto activation = node.param().activation;
204 const auto &param_padding = node.param().padding;
205 const auto dilation = node.param().dilation;
206 auto fn = std::make_unique<ops::ConvolutionLayer>();
207
208 auto &operands = _tgraph.operands();
209 const auto ifm_shape = operands.at(in_index).shape().asFeature();
210 const auto ofm_shape = operands.at(out_index).shape().asFeature();
211 // Kernel format is [depth_out, kernel_height, kernel_width, depth_in].
212 const auto &ker_shape = operands.at(ker_index).shape();
213 const auto ker_height = ker_shape.dim(1);
214 const auto ker_width = ker_shape.dim(2);
215
216 const auto padding =
217 ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height,
218 dilation.width_factor, dilation.height_factor);
219
220 const bool is_cacheable_weights = false;
221 fn->configure(in_tensor, ker_tensor, bias_tensor, param_padding.type, padding.left, padding.right,
222 padding.top, padding.bottom, stride.horizontal, stride.vertical,
223 dilation.width_factor, dilation.height_factor, activation, out_tensor,
224 is_cacheable_weights);
225
226 auto ker_grad_tensor = _tensor_reg->getGradientTensor(ker_index);
227 auto bias_grad_tensor = _tensor_reg->getGradientTensor(bias_index);
228
229 if (node.isRequiredForBackward())
230 {
231
232 auto out_back_prop_tensor = getBackPropOut(out_index);
233 auto in_back_prop_tensor = getBackPropIn(node, in_index);
234
235 fn->configureBackward(ker_tensor, in_back_prop_tensor, ker_grad_tensor, bias_grad_tensor,
236 out_back_prop_tensor, activation);
237
238 // Generate GradientApplier
239 if (bias_tensor)
240 _update_funcs.emplace_back(
241 generateGradientApplier(_optimizer, bias_grad_tensor, bias_tensor));
242 _update_funcs.emplace_back(generateGradientApplier(_optimizer, ker_grad_tensor, ker_tensor));
243 }
244
245 _return_fn = std::move(fn);
246}
247
249{
251
252 const auto ofm_index{node.getOutputs().at(0)};
253 const auto ifm_index{node.getInputs().at(DepthwiseConv2D::Input::INPUT)};
254 const auto ker_index{node.getInputs().at(DepthwiseConv2D::Input::KERNEL)};
255 const auto bias_index{node.getInputs().at(DepthwiseConv2D::Input::BIAS)};
256
257 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
258 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
259 auto ker_tensor = _tensor_reg->getTrainableTensor(ker_index);
260 auto bias_tensor = _tensor_reg->getTrainableTensor(bias_index);
261
262 const auto stride = node.param().stride;
263 const auto &operands = _tgraph.operands();
264 const auto ofm_shape = operands.at(ofm_index).shape().asFeature();
265 const auto ifm_shape = operands.at(ifm_index).shape().asFeature();
266 // Kernel format is [1, kernel_height, kernel_width, depth_out].
267 const auto &ker_shape = operands.at(ker_index).shape();
268 const auto ker_height = ker_shape.dim(1);
269 const auto ker_width = ker_shape.dim(2);
270 const auto dilation_width = node.param().dilation.width_factor;
271 const auto dilation_height = node.param().dilation.height_factor;
272 const auto padding = ir::calculatePadding(node.param().padding, ifm_shape, ofm_shape, stride,
273 ker_width, ker_height, dilation_width, dilation_height);
274 const auto multiplier = node.param().multiplier;
275 const auto activation = node.param().activation;
276
277 auto fn = std::make_unique<ops::DepthwiseConvolutionLayer>();
278
279 fn->configure(ifm_tensor, ker_tensor, bias_tensor, padding.left, padding.right, padding.top,
280 padding.bottom, stride.horizontal, stride.vertical, multiplier, dilation_width,
281 dilation_height, activation, ofm_tensor, _external_context);
282
283 if (node.isRequiredForBackward())
284 {
285 auto ker_grad_tensor = _tensor_reg->getGradientTensor(ker_index);
286 auto bias_grad_tensor = _tensor_reg->getGradientTensor(bias_index);
287
288 auto ofm_back_prop_tensor = getBackPropOut(ofm_index);
289 auto ifm_back_prop_tensor = getBackPropIn(node, ifm_index);
290
291 fn->configureBackward(ifm_back_prop_tensor, ker_grad_tensor, bias_grad_tensor,
292 ofm_back_prop_tensor, activation);
293
294 // Generate GradientApplier
295 if (bias_tensor)
296 _update_funcs.emplace_back(
297 generateGradientApplier(_optimizer, bias_grad_tensor, bias_tensor));
298 _update_funcs.emplace_back(generateGradientApplier(_optimizer, ker_grad_tensor, ker_tensor));
299 }
300
301 _return_fn = std::move(fn);
302}
303
305{
307
308 const auto output_index{node.getOutputs().at(0)};
309 const auto input_index{node.getInputs().at(ElementwiseActivation::Input::INPUT)};
310
311 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
312 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
313
314 auto fn = std::make_unique<ops::ElementwiseActivationLayer>();
315
316 auto convertToInferActivationType = [](const ir::operation::ElementwiseActivation::Type &type) {
317 switch (type)
318 {
321 default:
322 throw std::invalid_argument("Unsupported ElementwiseActivation::Type");
323 }
324 };
325
326 fn->configure(input_tensor, output_tensor, node.param().alpha, node.param().beta,
327 convertToInferActivationType(node.param().op_type));
328
329 if (node.isRequiredForBackward())
330 {
331 auto back_prop_input_tensor = getBackPropIn(node, input_index);
332 auto back_prop_output_tensor = getBackPropOut(output_index);
333
334 fn->configureBackward(input_tensor, back_prop_input_tensor, back_prop_output_tensor,
335 node.param().alpha, node.param().beta,
336 convertElementwiseActivationType(node.param().op_type));
337 }
338
339 _return_fn = std::move(fn);
340}
341
343{
345
346 const auto out_index{node.getOutputs().at(0)};
347 const auto in_index{node.getInputs().at(FullyConnected::Input::INPUT)};
348 const auto weights_index{node.getInputs().at(FullyConnected::Input::WEIGHT)};
349 const auto bias_index{node.getInputs().at(FullyConnected::Input::BIAS)};
350
351 auto out_tensor = _tensor_reg->getPortableTensor(out_index);
352 auto in_tensor = _tensor_reg->getPortableTensor(in_index);
353 auto weights_tensor = _tensor_reg->getTrainableTensor(weights_index);
354 auto bias_tensor = _tensor_reg->getTrainableTensor(bias_index);
355
356 // Generate kernel
357 const auto activation = node.param().activation;
358 const auto weights_format = node.param().weights_format;
359
360 auto fn = std::make_unique<ops::FullyConnectedLayer>();
361
362 fn->configure(in_tensor, weights_tensor, bias_tensor, activation, weights_format, out_tensor,
363 _external_context);
364
365 if (node.isRequiredForBackward())
366 {
367 auto out_back_prop_tensor = getBackPropOut(out_index);
368 auto in_back_prop_tensor = getBackPropIn(node, in_index);
369 auto weights_grad_tensor = _tensor_reg->getGradientTensor(weights_index);
370 auto bias_grad_tensor = _tensor_reg->getGradientTensor(bias_index);
371
372 fn->configureBackward(in_tensor, weights_tensor, out_tensor, in_back_prop_tensor,
373 weights_grad_tensor, bias_grad_tensor, out_back_prop_tensor, activation,
374 weights_format);
375
376 // Generate GradientAppliers
377 if (bias_tensor)
378 _update_funcs.emplace_back(
379 generateGradientApplier(_optimizer, bias_grad_tensor, bias_tensor));
380 _update_funcs.emplace_back(
381 generateGradientApplier(_optimizer, weights_grad_tensor, weights_tensor));
382 }
383
384 _return_fn = std::move(fn);
385}
386
388{
390
391 const auto output_index{node.getOutputs().at(0)};
392 const auto y_pred_index{node.getInputs().at(Loss::Y_PRED)};
393 const auto y_true_index{node.getInputs().at(Loss::Y_TRUE)};
394
395 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
396 auto y_pred_tensor = _tensor_reg->getPortableTensor(y_pred_index);
397 auto y_true_tensor = _tensor_reg->getPortableTensor(y_true_index);
398
399 // TODO Use BackPropTensor directly instead of DisposableTensor if y_pred is always used by only
400 // loss
401 auto back_prop_y_pred_tensor = getBackPropIn(node, y_pred_index);
402
403 const auto loss_code = node.param().loss_code;
404 const auto &loss_param = node.param().loss_param;
405 const auto reduction_type = node.param().reduction_type;
406
407 switch (loss_code)
408 {
410 {
411 auto fn = std::make_unique<ops::LossMeanSquaredErrorLayer>();
412 fn->configure(y_pred_tensor, y_true_tensor, output_tensor, back_prop_y_pred_tensor,
413 reduction_type);
414 _return_fn = std::move(fn);
415 break;
416 }
418 {
419 const auto y_pred_op_code = node.y_pred_op_code();
420 bool is_normalization_required = (y_pred_op_code != ir::OpCode::Softmax);
421 const auto cce_params = std::get_if<ir::train::CategoricalCrossentropyParam>(&loss_param);
422 if (!cce_params)
423 {
424 throw std::runtime_error("LossLayer: Expected loss_param to be "
425 "CategoricalCrossentropyParam but found a different type.");
426 }
427 auto fn = std::make_unique<ops::LossCategoricalCrossentropyLayer>();
428 fn->configure(y_pred_tensor, y_true_tensor, output_tensor, back_prop_y_pred_tensor,
429 reduction_type, cce_params->axis, cce_params->label_smoothing,
430 is_normalization_required);
431 _return_fn = std::move(fn);
432 break;
433 }
434 default:
435 throw std::runtime_error("LossLayer: unsupported loss type");
436 }
437}
438
440{
441 const auto input_index{node.getInputs().at(ir::operation::Pad::Input::INPUT)};
442 const auto pad_index{node.getInputs().at(ir::operation::Pad::Input::PAD)};
443 const auto output_index{node.getOutputs().at(0)};
444
445 auto input = _tensor_reg->getPortableTensor(input_index);
446 auto pad = _tensor_reg->getPortableTensor(pad_index);
447 auto output = _tensor_reg->getPortableTensor(output_index);
448
449 auto fn = std::make_unique<ops::PadLayer>();
450
451 IPortableTensor *value = nullptr;
452 if (node.getInputs().size() == 3) // isPadV2
453 {
454 const auto value_index{node.getInputs().at(ir::operation::Pad::Input::VALUE)};
455 value = _tensor_reg->getPortableTensor(value_index);
456 }
457
458 fn->configure(input, pad, value, output);
459 if (node.isRequiredForBackward())
460 {
461 auto out_back_prop_tensor = getBackPropOut(output_index);
462 auto in_back_prop_tensor = getBackPropIn(node, input_index);
463 fn->configureBackward(in_back_prop_tensor, out_back_prop_tensor);
464 }
465 _return_fn = std::move(fn);
466}
467
469{
471
472 const auto output_index{node.getOutputs().at(0)};
473 const auto input_index{node.getInputs().at(0)};
474
475 const auto &operands = _tgraph.operands();
476 const auto &ofm_shape = operands.at(output_index).shape();
477 const auto &ifm_shape = operands.at(input_index).shape();
478
479 if (ifm_shape.rank() != 4)
480 {
481 throw std::runtime_error(node.name() + " only supports 4D tensor as input");
482 }
483
484 // calculate padding
485 const auto stride = node.param().stride;
486 const auto kh = node.param().kh;
487 const auto kw = node.param().kw;
488 const auto padding = ir::calculatePadding(node.param().padding, ifm_shape.asFeature(),
489 ofm_shape.asFeature(), stride, kw, kh);
490
491 auto out_tensor = _tensor_reg->getPortableTensor(output_index);
492 auto in_tensor = _tensor_reg->getPortableTensor(input_index);
493
494 const auto activation = node.param().activation;
495 const auto pool_type = convertPoolType(node.param().op_type);
496
497 auto fn = std::make_unique<ops::PoolLayer>();
498
499 auto convertToInferPoolType = [](const train::ops::PoolType &pool_type) {
500 switch (pool_type)
501 {
506 default:
507 throw std::runtime_error("PoolLayer: Unsupported pool type yet");
508 }
509 };
510
511 fn->configure(in_tensor, padding.left, padding.right, padding.top, padding.bottom,
512 stride.horizontal, stride.vertical, kw, kh, activation, out_tensor,
513 convertToInferPoolType(pool_type));
514
515 if (node.isRequiredForBackward())
516 {
517 auto out_back_prop_tensor = getBackPropOut(output_index);
518 auto in_back_prop_tensor = getBackPropIn(node, input_index);
519 fn->configureBackward(padding.left, padding.right, padding.top, padding.bottom,
520 stride.horizontal, stride.vertical, kw, kh, activation, pool_type,
521 out_tensor, in_back_prop_tensor, out_back_prop_tensor);
522 }
523
524 _return_fn = std::move(fn);
525}
526
528{
530
531 const auto output_index{node.getOutputs().at(0)};
532 const auto input_index{node.getInputs().at(Reduce::Input::INPUT)};
533 const auto axes_index{node.getInputs().at(Reduce::Input::AXES)};
534
535 const auto keep_dims = node.param().keep_dims;
536
537 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
538 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
539 auto axes_tensor = _tensor_reg->getPortableTensor(axes_index);
540
542 {
543 auto fn = std::make_unique<ops::MeanLayer>();
544 fn->configure(input_tensor, axes_tensor, output_tensor, keep_dims);
545 if (node.isRequiredForBackward())
546 {
547 auto back_prop_output_tensor = getBackPropOut(output_index);
548 auto back_prop_input_tensor = getBackPropIn(node, input_index);
549 fn->configureBackward(back_prop_input_tensor, back_prop_output_tensor);
550 }
551 _return_fn = std::move(fn);
552 }
553 else
554 {
555 throw std::runtime_error("ReduceLayer: unsupported reduce type");
556 }
557}
558
560{
562
563 const auto output_index{node.getOutputs().at(0)};
564 const auto input_index{node.getInputs().at(ir::operation::Reshape::Input::INPUT)};
565
566 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
567 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
568
569 // optional 2nd input
570 IPortableTensor *shape_tensor = nullptr;
571
572 if (node.getInputs().size() == 2)
573 {
574 const auto shape_index{node.getInputs().at(ir::operation::Reshape::Input::SHAPE)};
575 shape_tensor = _tensor_reg->getPortableTensor(shape_index);
576 }
577
578 auto fn = std::make_unique<ops::ReshapeLayer>();
579
580 fn->configure(input_tensor, shape_tensor, output_tensor);
581 if (node.isRequiredForBackward())
582 {
583 auto output_back_prop_tensor = getBackPropOut(output_index);
584 auto input_back_prop_tensor = getBackPropIn(node, input_index);
585 fn->configureBackward(input_back_prop_tensor, output_back_prop_tensor);
586 }
587 _return_fn = std::move(fn);
588}
589
591{
593
594 const auto output_index{node.getOutputs().at(0)};
595 const auto input_index{node.getInputs().at(ir::operation::Softmax::Input::INPUT)};
596
597 const auto beta = node.param().beta;
598
599 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
600 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
601
602 auto fn = std::make_unique<ops::SoftMaxLayer>();
603
604 fn->configure(input_tensor, beta, output_tensor);
605
606 if (node.isRequiredForBackward())
607 {
608 auto output_back_prop_tensor = getBackPropOut(output_index);
609 auto input_back_prop_tensor = getBackPropIn(node, input_index);
610 fn->configureBackward(input_back_prop_tensor, output_back_prop_tensor);
611 }
612 _return_fn = std::move(fn);
613}
614
615IPortableTensor *KernelGenerator::getBackPropIn(const ir::IOperation &node,
616 const ir::OperandIndex &operand_index)
617{
618 const auto &op_index = _node_to_idx[&node];
619 const auto backwarding_operand_index = ir::train::TrainingOperandIndex{operand_index, false};
620
621 const auto disposable_tensor =
622 _tensor_reg->getDisposableBackPropTensor(DisposableTensorIndex{op_index, operand_index});
623 if (disposable_tensor != nullptr)
624 {
625 [[maybe_unused]] const auto &training_usedefs =
626 _tgraph.trainingUseDefs().at(backwarding_operand_index);
627 assert(std::count_if(training_usedefs.getTrainingDefs().begin(),
628 training_usedefs.getTrainingDefs().end(),
629 [&](const ir::train::TrainingOperationIndex &op_index) {
630 return _tgraph.operation(op_index.index()).isRequiredForBackward();
631 }) > 1);
632
633 return disposable_tensor;
634 }
635 else
636 return _tensor_reg->getBackPropTensor(operand_index);
637}
638
639IPortableTensor *KernelGenerator::getBackPropOut(const ir::OperandIndex &output_index)
640{
641 return _tensor_reg->getBackPropTensor(output_index);
642}
643
644} // namespace onert::backend::train
A tensor class that is portable for other backends.
std::unique_ptr< exec::train::ITrainableFunction > _return_fn
const ir::train::TrainableGraph & _tgraph
std::unique_ptr< exec::train::TrainableFnSequence > generate(ir::OperationIndex op_ind) override
KernelGenerator(const ir::train::TrainableGraph &tgraph, const std::shared_ptr< TensorRegistry > &tensor_reg, const std::shared_ptr< ExternalContext > &external_context, const exec::train::optimizer::Optimizer *optimizer)
void visit(const ir::train::operation::BinaryArithmetic &) override
Base class for all optimizers.
Definition Optimizer.h:37
const OperandIndex & at(IOIndex set_index) const
const OperandIndexSequence & getOutputs() const override
Definition Operation.h:53
OperandIndexSequence & getInputs()
Definition Operation.h:51
const Param & param() const
Definition Conv2D.h:56
const Param & param() const
Definition Pool2D.h:64
std::string name() const override
Definition Pool2D.cc:33
const Param & param() const
Definition Reduce.h:63
const Param & param() const
Definition Softmax.h:49
const ITrainableOperation & operation(OperationIndex index) const
const Operations & operations() const override
const Operands & operands() const override
const UseDefChains & trainingUseDefs() const
virtual bool isRequiredForBackward() const final
Class that provides index of tensor for training.
Definition Index.h:34
const LossInfo & param() const
Definition Loss.h:45
ir::OpCode y_pred_op_code() const
Definition Loss.h:46
void iterate(const std::function< void(const Index &, const Object &)> &fn) const
Iterate over the container with given function.
const Object & at(const Index &index) const
Get the object that is associated with the given index.
arm_compute::PoolingType convertPoolType(ir::operation::Pool2D::PoolType pool_type_ir)
Definition Convert.cc:279
Tensor BackPropTensor
Definition Tensor.h:43
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
::onert::util::Index< uint32_t, OperationIndexTag > OperationIndex
Definition Index.h:30
::onert::util::Index< uint32_t, OperandIndexTag > OperandIndex
Definition Index.h:33
CLTensor ker_tensor
CLTensor bias_tensor
FullyConnectedWeightsFormat weights_format
LossReductionType reduction_type
Definition LossInfo.h:44
std::variant< std::monostate, CategoricalCrossentropyParam > loss_param
Definition LossInfo.h:45