ONE - On-device Neural Engine
Loading...
Searching...
No Matches
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
42namespace onert
43{
44namespace backend
45{
46namespace train
47{
48
49namespace
50{
51ops::ElementwiseActivationType
52convertElementwiseActivationType(ir::operation::ElementwiseActivation::Type type_ir)
53{
54 switch (type_ir)
55 {
58 default:
59 throw std::runtime_error("train KernelGenerator : Not supported operation yet");
60 }
61}
62
64{
65 switch (type_ir)
66 {
67 // TODO Implement AVG PoolType
72 default:
73 throw std::runtime_error("train KernelGenerator : Not supported operation yet");
74 }
75}
76
77std::unique_ptr<ops::BackPropAccumulator>
78generateBackPropAccumulator(const IPortableTensor *disposable, BackPropTensor *gradient)
79{
80 auto update_fn = std::make_unique<ops::BackPropAccumulator>(disposable, gradient);
81 return update_fn;
82}
83
84void appendBackPropAccumulators(const ir::train::ITrainableOperation &op,
85 const ir::OperationIndex &op_index, TensorRegistry *tensor_reg,
86 exec::train::TrainableFnSequence *seq)
87{
88 if (!op.isRequiredForBackward())
89 return;
90
91 for (const auto &input_index : (op.getInputs() | ir::Remove::UNDEFINED))
92 {
93 const auto disposable =
94 tensor_reg->getDisposableBackPropTensor(DisposableTensorIndex{op_index, input_index});
95 if (disposable != nullptr)
96 {
97 auto back_prop = tensor_reg->getBackPropTensor(input_index);
98 assert(back_prop);
99 seq->append(generateBackPropAccumulator(disposable, back_prop));
100 }
101 }
102}
103
104std::unique_ptr<ops::GradientApplier>
105generateGradientApplier(const exec::train::optimizer::Optimizer *optimizer,
106 const IPortableTensor *gradient, ITrainableTensor *trainable)
107{
108 auto update_fn = std::make_unique<ops::GradientApplier>();
109 update_fn->configure(optimizer, gradient, trainable);
110 return update_fn;
111}
112} // namespace
113
114std::unique_ptr<exec::train::TrainableFnSequence> KernelGenerator::generate(ir::OperationIndex idx)
115{
116 // NOTE This function is related to planning tensors. If you change this function, you should
117 // also consider to change planning tensors.
118
119 auto ret = std::make_unique<exec::train::TrainableFnSequence>();
120
121 const auto &op = _tgraph.operation(idx);
122
123 // NOTE appendBackPropAccumulators() must be called before appending _return_fn to
124 // TrainableFnSequence as long as both are appended to the same TrainableFnSequence.
125 appendBackPropAccumulators(op, idx, _tensor_reg.get(), ret.get());
126
127 op.accept(*this);
128 assert(_return_fn);
129 ret->append(std::move(_return_fn));
130
131 for (auto &&update_fn : _update_funcs)
132 ret->append(std::move(update_fn));
133 _update_funcs.clear();
134
135 for (auto &&ind : (op.getInputs() | ir::Remove::UNDEFINED) + op.getOutputs())
136 {
137 auto tensor = _tensor_reg->getNonConstTensor(ind);
138 if (tensor)
139 {
140 tensor->increase_ref();
141 }
142 }
143 return ret;
144}
145
147 const std::shared_ptr<TensorRegistry> &tensor_reg,
148 const std::shared_ptr<ExternalContext> &external_context,
149 const exec::train::optimizer::Optimizer *optimizer)
150 : backend::train::KernelGeneratorBase{tgraph}, _tensor_reg{tensor_reg},
151 _external_context(external_context), _optimizer{optimizer}, _update_funcs{}, _node_to_idx{}
152{
153 tgraph.operations().iterate(
154 [&](const onert::ir::OperationIndex &idx, const onert::ir::IOperation &op) {
155 assert(_node_to_idx.find(&op) == _node_to_idx.end());
156 _node_to_idx[&op] = idx;
157 });
158}
159
161{
163
164 const auto output_index{node.getOutputs().at(0)};
165 const auto lhs_index{node.getInputs().at(BinaryArithmetic::Input::LHS)};
166 const auto rhs_index{node.getInputs().at(BinaryArithmetic::Input::RHS)};
167
168 const auto arithmetic_type = node.param().arithmetic_type;
169 const auto activation = node.param().activation;
170
171 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
172 auto lhs_tensor = _tensor_reg->getPortableTensor(lhs_index);
173 auto rhs_tensor = _tensor_reg->getPortableTensor(rhs_index);
174
175 auto fn = std::make_unique<ops::BinaryArithmeticLayer>();
176 fn->configure(lhs_tensor, rhs_tensor, output_tensor, activation,
177 static_cast<cpu::ops::ArithmeticType>(arithmetic_type));
178
179 if (node.isRequiredForBackward())
180 {
181 auto back_prop_output_tensor = getBackPropOut(output_index);
182 auto back_prop_lhs_tensor = getBackPropIn(node, lhs_index);
183 auto back_prop_rhs_tensor = getBackPropIn(node, rhs_index);
184
185 fn->configureBackward(back_prop_lhs_tensor, back_prop_rhs_tensor, back_prop_output_tensor,
186 activation, static_cast<train::ops::ArithmeticType>(arithmetic_type));
187 }
188 _return_fn = std::move(fn);
189}
190
192{
194
195 const auto out_index{node.getOutputs().at(0)};
196 const auto in_index{node.getInputs().at(Conv2D::Input::INPUT)};
197 const auto ker_index{node.getInputs().at(Conv2D::Input::KERNEL)};
198 const auto bias_index{node.getInputs().at(Conv2D::Input::BIAS)};
199
200 auto out_tensor = _tensor_reg->getPortableTensor(out_index);
201 auto in_tensor = _tensor_reg->getPortableTensor(in_index);
202 auto ker_tensor = _tensor_reg->getTrainableTensor(ker_index);
203 auto bias_tensor = _tensor_reg->getTrainableTensor(bias_index);
204
205 // Generate kernel
206 const auto stride = node.param().stride;
207 const auto activation = node.param().activation;
208 const auto &param_padding = node.param().padding;
209 const auto dilation = node.param().dilation;
210 auto fn = std::make_unique<ops::ConvolutionLayer>();
211
212 auto &operands = _tgraph.operands();
213 const auto ifm_shape = operands.at(in_index).shape().asFeature();
214 const auto ofm_shape = operands.at(out_index).shape().asFeature();
215 // Kernel format is [depth_out, kernel_height, kernel_width, depth_in].
216 const auto &ker_shape = operands.at(ker_index).shape();
217 const auto ker_height = ker_shape.dim(1);
218 const auto ker_width = ker_shape.dim(2);
219
220 const auto padding =
221 ir::calculatePadding(param_padding, ifm_shape, ofm_shape, stride, ker_width, ker_height,
222 dilation.width_factor, dilation.height_factor);
223
224 const bool is_cacheable_weights = false;
225 fn->configure(in_tensor, ker_tensor, bias_tensor, param_padding.type, padding.left, padding.right,
226 padding.top, padding.bottom, stride.horizontal, stride.vertical,
227 dilation.width_factor, dilation.height_factor, activation, out_tensor,
228 is_cacheable_weights);
229
230 auto ker_grad_tensor = _tensor_reg->getGradientTensor(ker_index);
231 auto bias_grad_tensor = _tensor_reg->getGradientTensor(bias_index);
232
233 if (node.isRequiredForBackward())
234 {
235
236 auto out_back_prop_tensor = getBackPropOut(out_index);
237 auto in_back_prop_tensor = getBackPropIn(node, in_index);
238
239 fn->configureBackward(ker_tensor, in_back_prop_tensor, ker_grad_tensor, bias_grad_tensor,
240 out_back_prop_tensor, activation);
241
242 // Generate GradientApplier
243 if (bias_tensor)
244 _update_funcs.emplace_back(
245 generateGradientApplier(_optimizer, bias_grad_tensor, bias_tensor));
246 _update_funcs.emplace_back(generateGradientApplier(_optimizer, ker_grad_tensor, ker_tensor));
247 }
248
249 _return_fn = std::move(fn);
250}
251
253{
255
256 const auto ofm_index{node.getOutputs().at(0)};
257 const auto ifm_index{node.getInputs().at(DepthwiseConv2D::Input::INPUT)};
258 const auto ker_index{node.getInputs().at(DepthwiseConv2D::Input::KERNEL)};
259 const auto bias_index{node.getInputs().at(DepthwiseConv2D::Input::BIAS)};
260
261 auto ofm_tensor = _tensor_reg->getPortableTensor(ofm_index);
262 auto ifm_tensor = _tensor_reg->getPortableTensor(ifm_index);
263 auto ker_tensor = _tensor_reg->getTrainableTensor(ker_index);
264 auto bias_tensor = _tensor_reg->getTrainableTensor(bias_index);
265
266 const auto stride = node.param().stride;
267 const auto &operands = _tgraph.operands();
268 const auto ofm_shape = operands.at(ofm_index).shape().asFeature();
269 const auto ifm_shape = operands.at(ifm_index).shape().asFeature();
270 // Kernel format is [1, kernel_height, kernel_width, depth_out].
271 const auto &ker_shape = operands.at(ker_index).shape();
272 const auto ker_height = ker_shape.dim(1);
273 const auto ker_width = ker_shape.dim(2);
274 const auto dilation_width = node.param().dilation.width_factor;
275 const auto dilation_height = node.param().dilation.height_factor;
276 const auto padding = ir::calculatePadding(node.param().padding, ifm_shape, ofm_shape, stride,
277 ker_width, ker_height, dilation_width, dilation_height);
278 const auto multiplier = node.param().multiplier;
279 const auto activation = node.param().activation;
280
281 auto fn = std::make_unique<ops::DepthwiseConvolutionLayer>();
282
283 fn->configure(ifm_tensor, ker_tensor, bias_tensor, padding.left, padding.right, padding.top,
284 padding.bottom, stride.horizontal, stride.vertical, multiplier, dilation_width,
285 dilation_height, activation, ofm_tensor, _external_context);
286
287 if (node.isRequiredForBackward())
288 {
289 auto ker_grad_tensor = _tensor_reg->getGradientTensor(ker_index);
290 auto bias_grad_tensor = _tensor_reg->getGradientTensor(bias_index);
291
292 auto ofm_back_prop_tensor = getBackPropOut(ofm_index);
293 auto ifm_back_prop_tensor = getBackPropIn(node, ifm_index);
294
295 fn->configureBackward(ifm_back_prop_tensor, ker_grad_tensor, bias_grad_tensor,
296 ofm_back_prop_tensor, activation);
297
298 // Generate GradientApplier
299 if (bias_tensor)
300 _update_funcs.emplace_back(
301 generateGradientApplier(_optimizer, bias_grad_tensor, bias_tensor));
302 _update_funcs.emplace_back(generateGradientApplier(_optimizer, ker_grad_tensor, ker_tensor));
303 }
304
305 _return_fn = std::move(fn);
306}
307
309{
311
312 const auto output_index{node.getOutputs().at(0)};
313 const auto input_index{node.getInputs().at(ElementwiseActivation::Input::INPUT)};
314
315 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
316 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
317
318 auto fn = std::make_unique<ops::ElementwiseActivationLayer>();
319
320 auto convertToInferActivationType = [](const ir::operation::ElementwiseActivation::Type &type) {
321 switch (type)
322 {
325 default:
326 throw std::invalid_argument("Unsupported ElementwiseActivation::Type");
327 }
328 };
329
330 fn->configure(input_tensor, output_tensor, node.param().alpha, node.param().beta,
331 convertToInferActivationType(node.param().op_type));
332
333 if (node.isRequiredForBackward())
334 {
335 auto back_prop_input_tensor = getBackPropIn(node, input_index);
336 auto back_prop_output_tensor = getBackPropOut(output_index);
337
338 fn->configureBackward(input_tensor, back_prop_input_tensor, back_prop_output_tensor,
339 node.param().alpha, node.param().beta,
340 convertElementwiseActivationType(node.param().op_type));
341 }
342
343 _return_fn = std::move(fn);
344}
345
347{
349
350 const auto out_index{node.getOutputs().at(0)};
351 const auto in_index{node.getInputs().at(FullyConnected::Input::INPUT)};
352 const auto weights_index{node.getInputs().at(FullyConnected::Input::WEIGHT)};
353 const auto bias_index{node.getInputs().at(FullyConnected::Input::BIAS)};
354
355 auto out_tensor = _tensor_reg->getPortableTensor(out_index);
356 auto in_tensor = _tensor_reg->getPortableTensor(in_index);
357 auto weights_tensor = _tensor_reg->getTrainableTensor(weights_index);
358 auto bias_tensor = _tensor_reg->getTrainableTensor(bias_index);
359
360 // Generate kernel
361 const auto activation = node.param().activation;
362 const auto weights_format = node.param().weights_format;
363
364 auto fn = std::make_unique<ops::FullyConnectedLayer>();
365
366 fn->configure(in_tensor, weights_tensor, bias_tensor, activation, weights_format, out_tensor,
367 _external_context);
368
369 if (node.isRequiredForBackward())
370 {
371 auto out_back_prop_tensor = getBackPropOut(out_index);
372 auto in_back_prop_tensor = getBackPropIn(node, in_index);
373 auto weights_grad_tensor = _tensor_reg->getGradientTensor(weights_index);
374 auto bias_grad_tensor = _tensor_reg->getGradientTensor(bias_index);
375
376 fn->configureBackward(in_tensor, weights_tensor, out_tensor, in_back_prop_tensor,
377 weights_grad_tensor, bias_grad_tensor, out_back_prop_tensor, activation,
378 weights_format);
379
380 // Generate GradientAppliers
381 if (bias_tensor)
382 _update_funcs.emplace_back(
383 generateGradientApplier(_optimizer, bias_grad_tensor, bias_tensor));
384 _update_funcs.emplace_back(
385 generateGradientApplier(_optimizer, weights_grad_tensor, weights_tensor));
386 }
387
388 _return_fn = std::move(fn);
389}
390
392{
394
395 const auto output_index{node.getOutputs().at(0)};
396 const auto y_pred_index{node.getInputs().at(Loss::Y_PRED)};
397 const auto y_true_index{node.getInputs().at(Loss::Y_TRUE)};
398
399 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
400 auto y_pred_tensor = _tensor_reg->getPortableTensor(y_pred_index);
401 auto y_true_tensor = _tensor_reg->getPortableTensor(y_true_index);
402
403 // TODO Use BackPropTensor directly instead of DisposableTensor if y_pred is always used by only
404 // loss
405 auto back_prop_y_pred_tensor = getBackPropIn(node, y_pred_index);
406
407 auto loss_code = node.param().loss_code;
408 auto loss_param = node.param().loss_param;
409 const auto reduction_type = node.param().reduction_type;
410
411 switch (loss_code)
412 {
414 {
415 auto fn = std::make_unique<ops::LossMeanSquaredErrorLayer>();
416 fn->configure(y_pred_tensor, y_true_tensor, output_tensor, back_prop_y_pred_tensor,
417 reduction_type);
418 _return_fn = std::move(fn);
419 break;
420 }
422 {
423 const auto y_pred_op_code = node.y_pred_op_code();
424 bool is_normalization_required = (y_pred_op_code != ir::OpCode::Softmax);
425 auto fn = std::make_unique<ops::LossCategoricalCrossentropyLayer>();
426 fn->configure(y_pred_tensor, y_true_tensor, output_tensor, back_prop_y_pred_tensor,
427 reduction_type, loss_param.cce.axis, loss_param.cce.label_smoothing,
428 is_normalization_required);
429 _return_fn = std::move(fn);
430 break;
431 }
432 default:
433 throw std::runtime_error("LossLayer: unsupported loss type");
434 break;
435 }
436}
437
439{
440 const auto input_index{node.getInputs().at(ir::operation::Pad::Input::INPUT)};
441 const auto pad_index{node.getInputs().at(ir::operation::Pad::Input::PAD)};
442 const auto output_index{node.getOutputs().at(0)};
443
444 auto input = _tensor_reg->getPortableTensor(input_index);
445 auto pad = _tensor_reg->getPortableTensor(pad_index);
446 auto output = _tensor_reg->getPortableTensor(output_index);
447
448 auto fn = std::make_unique<ops::PadLayer>();
449
450 IPortableTensor *value = nullptr;
451 if (node.getInputs().size() == 3) // isPadV2
452 {
453 const auto value_index{node.getInputs().at(ir::operation::Pad::Input::VALUE)};
454 value = _tensor_reg->getPortableTensor(value_index);
455 }
456
457 fn->configure(input, pad, value, output);
458 if (node.isRequiredForBackward())
459 {
460 auto out_back_prop_tensor = getBackPropOut(output_index);
461 auto in_back_prop_tensor = getBackPropIn(node, input_index);
462 fn->configureBackward(in_back_prop_tensor, out_back_prop_tensor);
463 }
464 _return_fn = std::move(fn);
465}
466
468{
470
471 const auto output_index{node.getOutputs().at(0)};
472 const auto input_index{node.getInputs().at(0)};
473
474 const auto &operands = _tgraph.operands();
475 const auto &ofm_shape = operands.at(output_index).shape();
476 const auto &ifm_shape = operands.at(input_index).shape();
477
478 if (ifm_shape.rank() != 4)
479 {
480 throw std::runtime_error(node.name() + " only supports 4D tensor as input");
481 }
482
483 // calculate padding
484 const auto stride = node.param().stride;
485 const auto kh = node.param().kh;
486 const auto kw = node.param().kw;
487 const auto padding = ir::calculatePadding(node.param().padding, ifm_shape.asFeature(),
488 ofm_shape.asFeature(), stride, kw, kh);
489
490 auto out_tensor = _tensor_reg->getPortableTensor(output_index);
491 auto in_tensor = _tensor_reg->getPortableTensor(input_index);
492
493 const auto activation = node.param().activation;
494 const auto pool_type = convertPoolType(node.param().op_type);
495
496 auto fn = std::make_unique<ops::PoolLayer>();
497
498 auto convertToInferPoolType = [](const train::ops::PoolType &pool_type) {
499 switch (pool_type)
500 {
505 default:
506 throw std::runtime_error("PoolLayer: Unsupported pool type yet");
507 }
508 };
509
510 fn->configure(in_tensor, padding.left, padding.right, padding.top, padding.bottom,
511 stride.horizontal, stride.vertical, kw, kh, activation, out_tensor,
512 convertToInferPoolType(pool_type));
513
514 if (node.isRequiredForBackward())
515 {
516 auto out_back_prop_tensor = getBackPropOut(output_index);
517 auto in_back_prop_tensor = getBackPropIn(node, input_index);
518 fn->configureBackward(padding.left, padding.right, padding.top, padding.bottom,
519 stride.horizontal, stride.vertical, kw, kh, activation, pool_type,
520 out_tensor, in_back_prop_tensor, out_back_prop_tensor);
521 }
522
523 _return_fn = std::move(fn);
524}
525
527{
529
530 const auto output_index{node.getOutputs().at(0)};
531 const auto input_index{node.getInputs().at(Reduce::Input::INPUT)};
532 const auto axes_index{node.getInputs().at(Reduce::Input::AXES)};
533
534 const auto keep_dims = node.param().keep_dims;
535
536 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
537 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
538 auto axes_tensor = _tensor_reg->getPortableTensor(axes_index);
539
541 {
542 auto fn = std::make_unique<ops::MeanLayer>();
543 fn->configure(input_tensor, axes_tensor, output_tensor, keep_dims);
544 if (node.isRequiredForBackward())
545 {
546 auto back_prop_output_tensor = getBackPropOut(output_index);
547 auto back_prop_input_tensor = getBackPropIn(node, input_index);
548 fn->configureBackward(back_prop_input_tensor, back_prop_output_tensor);
549 }
550 _return_fn = std::move(fn);
551 }
552 else
553 {
554 throw std::runtime_error("ReduceLayer: unsupported reduce type");
555 }
556}
557
559{
561
562 const auto output_index{node.getOutputs().at(0)};
563 const auto input_index{node.getInputs().at(ir::operation::Reshape::Input::INPUT)};
564
565 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
566 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
567
568 // optional 2nd input
569 IPortableTensor *shape_tensor = nullptr;
570
571 if (node.getInputs().size() == 2)
572 {
573 const auto shape_index{node.getInputs().at(ir::operation::Reshape::Input::SHAPE)};
574 shape_tensor = _tensor_reg->getPortableTensor(shape_index);
575 }
576
577 auto fn = std::make_unique<ops::ReshapeLayer>();
578
579 fn->configure(input_tensor, shape_tensor, output_tensor);
580 if (node.isRequiredForBackward())
581 {
582 auto output_back_prop_tensor = getBackPropOut(output_index);
583 auto input_back_prop_tensor = getBackPropIn(node, input_index);
584 fn->configureBackward(input_back_prop_tensor, output_back_prop_tensor);
585 }
586 _return_fn = std::move(fn);
587}
588
590{
592
593 const auto output_index{node.getOutputs().at(0)};
594 const auto input_index{node.getInputs().at(ir::operation::Softmax::Input::INPUT)};
595
596 const auto beta = node.param().beta;
597
598 auto output_tensor = _tensor_reg->getPortableTensor(output_index);
599 auto input_tensor = _tensor_reg->getPortableTensor(input_index);
600
601 auto fn = std::make_unique<ops::SoftMaxLayer>();
602
603 fn->configure(input_tensor, beta, output_tensor);
604
605 if (node.isRequiredForBackward())
606 {
607 auto output_back_prop_tensor = getBackPropOut(output_index);
608 auto input_back_prop_tensor = getBackPropIn(node, input_index);
609 fn->configureBackward(input_back_prop_tensor, output_back_prop_tensor);
610 }
611 _return_fn = std::move(fn);
612}
613
614IPortableTensor *KernelGenerator::getBackPropIn(const ir::IOperation &node,
615 const ir::OperandIndex &operand_index)
616{
617 const auto &op_index = _node_to_idx[&node];
618 const auto backwarding_operand_index = ir::train::TrainingOperandIndex{operand_index, false};
619
620 const auto disposable_tensor =
621 _tensor_reg->getDisposableBackPropTensor(DisposableTensorIndex{op_index, operand_index});
622 if (disposable_tensor != nullptr)
623 {
624 [[maybe_unused]] const auto &training_usedefs =
625 _tgraph.trainingUseDefs().at(backwarding_operand_index);
626 assert(std::count_if(training_usedefs.getTrainingDefs().begin(),
627 training_usedefs.getTrainingDefs().end(),
628 [&](const ir::train::TrainingOperationIndex &op_index) {
629 return _tgraph.operation(op_index.index()).isRequiredForBackward();
630 }) > 1);
631
632 return disposable_tensor;
633 }
634 else
635 return _tensor_reg->getBackPropTensor(operand_index);
636}
637
638IPortableTensor *KernelGenerator::getBackPropOut(const ir::OperandIndex &output_index)
639{
640 return _tensor_reg->getBackPropTensor(output_index);
641}
642
643} // namespace train
644} // namespace backend
645} // namespace onert
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:43
const OperandIndex & at(IOIndex set_index) const
const OperandIndexSequence & getOutputs() const override
Definition Operation.h:55
OperandIndexSequence & getInputs()
Definition Operation.h:53
const Param & param() const
Definition Conv2D.h:60
const Param & param() const
Definition Pool2D.h:68
std::string name() const override
Definition Pool2D.cc:37
const Param & param() const
Definition Reduce.h:67
const Param & param() const
Definition Softmax.h:53
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:38
const LossInfo & param() const
Definition Loss.h:51
ir::OpCode y_pred_op_code() const
Definition Loss.h:52
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:283
Tensor BackPropTensor
Definition Tensor.h:47
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:133
::onert::util::Index< uint32_t, OperationIndexTag > OperationIndex
Definition Index.h:32
::onert::util::Index< uint32_t, OperandIndexTag > OperandIndex
Definition Index.h:35
FullyConnectedWeightsFormat weights_format
union onert::ir::train::LossInfo::LossParam loss_param
LossReductionType reduction_type
Definition LossInfo.h:45