ONE - On-device Neural Engine
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
22{
23
24PadLayer::PadLayer() : cpu::ops::PadLayer(), _back_prop_input{nullptr}, _back_prop_output{nullptr}
25{
26 // DO NOTHING
27}
28
29template <typename T> void PadLayer::depad()
30{
31 assert(_pad->data_type() == onert::ir::DataType::INT32);
32 assert(_pad->buffer());
33 const auto pad_data = reinterpret_cast<const int32_t *>(_pad->buffer());
34 auto pad_rank = _pad->getShape().dim(0);
35 nnfw::cker::train::Depad<T>(pad_data, pad_rank, getShape(_back_prop_output),
36 getBuffer<T>(_back_prop_output), getShape(_back_prop_input),
37 getBuffer<T>(_back_prop_input));
38}
39
41 const IPortableTensor *back_prop_output)
42{
43 _back_prop_input = back_prop_input;
44 _back_prop_output = back_prop_output;
45}
46
48
50{
51 switch (_back_prop_output->data_type())
52 {
53 case OperandType::FLOAT32:
54 depad<float>();
55 break;
56 case OperandType::QUANT_UINT8_ASYMM:
57 depad<uint8_t>();
58 break;
59 case OperandType::QUANT_INT8_ASYMM:
60 depad<int8_t>();
61 break;
62 default:
63 throw std::runtime_error{"Pad: unsupported data type"};
64 }
65}
66
67} // namespace onert::backend::train::ops
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:45
void forward(bool training) override
Definition PadLayer.cc:47
void configureBackward(IPortableTensor *back_prop_input, const IPortableTensor *back_prop_output)
Definition PadLayer.cc:40
nnfw::cker::Shape getShape(const IPortableTensor *tensor)
Get shape of tensor.