Imported Upstream version 1.4.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / kernel / PadLayer.cc
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
21 namespace onert
22 {
23 namespace backend
24 {
25 namespace cpu
26 {
27 namespace kernel
28 {
29
30 PadLayer::PadLayer()
31     : _input(nullptr), _output(nullptr), _padData(), _padRank(), _constantValueData()
32 {
33   // DO NOTHING
34 }
35
36 void PadLayer::padFloat32()
37 {
38   nnfw::cker::Pad(_padData, _padRank, convertTensorToCkerShape(_input),
39                   reinterpret_cast<const float *>(_input->buffer()),
40                   convertTensorToCkerShape(_output), reinterpret_cast<float *>(_output->buffer()),
41                   _constantValueData.f);
42 }
43 void PadLayer::padQuant8() { throw std::runtime_error("Quantized Pad isn't supported NYI"); }
44
45 void PadLayer::configure(const operand::Tensor *input, operand::Tensor *output,
46                          const int32_t *padData, int32_t padRank, uint8_t *constantValueData)
47 {
48   _input = input;
49   _output = output;
50   _padData = padData;
51   _padRank = padRank;
52   _constantValueData.u8 = constantValueData;
53 }
54
55 void PadLayer::run()
56 {
57   if (_input->data_type() == OperandType::FLOAT32)
58   {
59     padFloat32();
60   }
61   else if (_input->data_type() == OperandType::QUANT8_ASYMM)
62   {
63     padQuant8();
64   }
65 }
66
67 } // namespace kernel
68 } // namespace cpu
69 } // namespace backend
70 } // namespace onert