Imported Upstream version 1.7.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / TileLayer.cc
1 /*
2  * Copyright (c) 2020 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 "TileLayer.h"
18
19 #include "OperationUtils.h"
20
21 #include <cker/operation/Tile.h>
22
23 namespace onert
24 {
25 namespace backend
26 {
27 namespace cpu
28 {
29 namespace ops
30 {
31
32 TileLayer::TileLayer() : _input(nullptr), _multipliers(nullptr), _output(nullptr)
33 {
34   // DO NOTHING
35 }
36
37 void TileLayer::tileFloat32()
38 {
39   TileOneDimension(getTensorShape(_input), reinterpret_cast<const float *>(_input->buffer()),
40                    reinterpret_cast<const int *>(_multipliers->buffer()),
41                    reinterpret_cast<float *>(_output->buffer()), 0);
42 }
43
44 void TileLayer::tileQuant8()
45 {
46   // cker quant8 tile is not implemented yet
47   throw std::runtime_error{"NYI"};
48 }
49
50 void TileLayer::configure(const IPortableTensor *input, const IPortableTensor *multipliers,
51                           IPortableTensor *output)
52 {
53   _input = input;
54   _multipliers = multipliers;
55   _output = output;
56 }
57
58 void TileLayer::run()
59 {
60   if (_input->data_type() == OperandType::FLOAT32)
61   {
62     tileFloat32();
63   }
64   else if (_input->data_type() == OperandType::QUANT_UINT8_ASYMM)
65   {
66     tileQuant8();
67   }
68   else
69   {
70     throw std::runtime_error{"Tile: unsupported data type"};
71   }
72 }
73
74 } // namespace ops
75 } // namespace cpu
76 } // namespace backend
77 } // namespace onert