ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PadLayer.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 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 "PadLayer.h"
18
20
21namespace onert
22{
23namespace backend
24{
25namespace train
26{
27namespace ops
28{
29
30PadLayer::PadLayer() : cpu::ops::PadLayer(), _back_prop_input{nullptr}, _back_prop_output{nullptr}
31{
32 // DO NOTHING
33}
34
35template <typename T> void PadLayer::depad()
36{
37 assert(_pad->data_type() == onert::ir::DataType::INT32);
38 assert(_pad->buffer());
39 const auto pad_data = reinterpret_cast<const int32_t *>(_pad->buffer());
40 auto pad_rank = _pad->getShape().dim(0);
41 nnfw::cker::train::Depad<T>(pad_data, pad_rank, getShape(_back_prop_output),
42 getBuffer<T>(_back_prop_output), getShape(_back_prop_input),
43 getBuffer<T>(_back_prop_input));
44}
45
47 const IPortableTensor *back_prop_output)
48{
49 _back_prop_input = back_prop_input;
50 _back_prop_output = back_prop_output;
51}
52
54
56{
57 switch (_back_prop_output->data_type())
58 {
59 case OperandType::FLOAT32:
60 depad<float>();
61 break;
62 case OperandType::QUANT_UINT8_ASYMM:
63 depad<uint8_t>();
64 break;
65 case OperandType::QUANT_INT8_ASYMM:
66 depad<int8_t>();
67 break;
68 default:
69 throw std::runtime_error{"Pad: unsupported data type"};
70 }
71}
72
73} // namespace ops
74} // namespace train
75} // namespace backend
76} // namespace onert
A tensor class that is portable for other backends.
ir::DataType data_type() const override final
ir::Shape getShape() const override final
Get ir::Shape of tensor.
virtual uint8_t * buffer() const =0
const IPortableTensor * _pad
Definition PadLayer.h:51
void forward(bool training) override
Definition PadLayer.cc:53
void configureBackward(IPortableTensor *back_prop_input, const IPortableTensor *back_prop_output)
Definition PadLayer.cc:46
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
Get shape of tensor.