Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / ResizeBilinearLayer.cc
1 /*
2  * Copyright (c) 2018 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 #include "OperationUtils.h"
17 #include "ResizeBilinearLayer.h"
18 #include "cker/operation/ResizeBilinear.h"
19 #include <cker/Types.h>
20
21 namespace onert
22 {
23 namespace backend
24 {
25 namespace cpu
26 {
27 namespace ops
28 {
29
30 ResizeBilinearLayer::ResizeBilinearLayer()
31     : _input(nullptr), _output(nullptr), _output_height(0), _output_width(0), _align_corners(false),
32       _half_pixel_centers(false)
33 {
34   // DO NOTHING
35 }
36
37 void ResizeBilinearLayer::configure(const IPortableTensor *input, IPortableTensor *output,
38                                     int32_t output_height, int32_t output_width, bool align_corners,
39                                     bool half_pixel_centers)
40 {
41   _input = input;
42   _output = output;
43   _output_height = output_height;
44   _output_width = output_width;
45   _align_corners = align_corners;
46   _half_pixel_centers = half_pixel_centers;
47 }
48
49 void ResizeBilinearLayer::run()
50 {
51   nnfw::cker::ResizeBilinearParams params;
52   params.align_corners = _align_corners;
53   params.half_pixel_centers = _half_pixel_centers;
54   params.output_height = _output_height;
55   params.output_width = _output_width;
56
57   switch (_input->data_type())
58   {
59     case OperandType::FLOAT32:
60       nnfw::cker::ResizeBilinear(
61           params, getTensorShape(_input), reinterpret_cast<const float *>(_input->buffer()),
62           getTensorShape(_output), reinterpret_cast<float *>(_output->buffer()));
63       break;
64
65     case OperandType::QUANT_UINT8_ASYMM:
66       nnfw::cker::ResizeBilinear(
67           params, getTensorShape(_input), reinterpret_cast<const uint8_t *>(_input->buffer()),
68           getTensorShape(_output), reinterpret_cast<uint8_t *>(_output->buffer()));
69       break;
70
71     case OperandType::UINT8:
72     case OperandType::BOOL8:
73     case OperandType::FLOAT16:
74     case OperandType::INT32:
75     case OperandType::INT64:
76     case OperandType::QUANT_INT8_SYMM:
77       std::runtime_error("ResizeBilinear NYI");
78       break;
79     default:
80       std::runtime_error("ResizeBilinear unsupported data type");
81   }
82 }
83
84 } // namespace ops
85 } // namespace cpu
86 } // namespace backend
87 } // namespace onert