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) 2019 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
19#include <cker/operation/Pad.h>
20
22{
23
25 : _input(nullptr), _pad(nullptr), _value(nullptr), _output(nullptr), _constantValueData()
26{
27 // DO NOTHING
28}
29
30template <typename T> void PadLayer::padImpl(const T *constant_value_data)
31{
32 assert(_pad->data_type() == onert::ir::DataType::INT32);
33 assert(_pad->buffer());
34 const auto pad_data = reinterpret_cast<const int32_t *>(_pad->buffer());
35 auto pad_rank = _pad->getShape().dim(0);
36 nnfw::cker::Pad<T>(pad_data, pad_rank, getShape(_input), getBuffer<T>(_input), getShape(_output),
37 getBuffer<T>(_output), constant_value_data);
38}
39
41 const IPortableTensor *value, IPortableTensor *output)
42{
43 _input = input;
44 _pad = pad;
45 _value = value;
46 _output = output;
47}
48
50{
51 if (_value != nullptr) // isPadV2
52 {
53 assert(_value->buffer());
54 _constantValueData.v = reinterpret_cast<const void *>(_value->buffer());
55 }
56
57 switch (_input->data_type())
58 {
59 case OperandType::FLOAT32:
60 padImpl<float>(_constantValueData.f);
61 break;
62 case OperandType::QUANT_UINT8_ASYMM:
63 if (_constantValueData.u8 == nullptr)
64 {
65 uint8_t pad_value = static_cast<uint8_t>(_output->data_zero_point());
66 padImpl<uint8_t>(&pad_value);
67 }
68 else
69 {
70 padImpl<uint8_t>(_constantValueData.u8);
71 }
72 break;
73 case OperandType::QUANT_INT8_ASYMM:
74 if (_constantValueData.i8 == nullptr)
75 {
76 int8_t pad_value = static_cast<int8_t>(_output->data_zero_point());
77 padImpl<int8_t>(&pad_value);
78 }
79 else
80 {
81 padImpl<int8_t>(_constantValueData.i8);
82 }
83 break;
84 default:
85 throw std::runtime_error{"Pad: unsupported data type"};
86 }
87}
88
89} // namespace onert::backend::cpu::ops
A tensor class that is portable for other backends.
int32_t data_zero_point() const override final
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 * _input
Definition PadLayer.h:44
const IPortableTensor * _value
Definition PadLayer.h:46
void padImpl(const T *constant_value_data)
Definition PadLayer.cc:30
const IPortableTensor * _pad
Definition PadLayer.h:45
void configure(const IPortableTensor *input, const IPortableTensor *pad, const IPortableTensor *value, IPortableTensor *output)
Definition PadLayer.cc:40
nnfw::cker::Shape getShape(const IPortableTensor *tensor)