Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / runtime / onert / backend / cpu / ops / BatchToSpaceNDLayer.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 "BatchToSpaceNDLayer.h"
18
19 #include <cker/operation/BatchToSpaceND.h>
20
21 namespace onert
22 {
23 namespace backend
24 {
25 namespace cpu
26 {
27 namespace ops
28 {
29
30 BatchToSpaceNDLayer::BatchToSpaceNDLayer()
31   : _input(nullptr), _output(nullptr), _block_shape(nullptr), _crops(nullptr)
32 {
33   // DO NOTHING
34 }
35
36 template <typename T> void BatchToSpaceNDLayer::batchToSpaceNDGeneric()
37 {
38   const int32_t NNapiCrops[]{0, 0, 0, 0};
39   const int32_t *_crops_buffer;
40
41   if (_crops == nullptr)
42   {
43     _crops_buffer = NNapiCrops;
44   }
45   else
46   {
47     _crops_buffer = getBuffer<int32_t>(_crops);
48   }
49   nnfw::cker::BatchToSpaceND<T>(getShape(_input), getBuffer<T>(_input),
50                                 getBuffer<int32_t>(_block_shape), _crops_buffer, getShape(_output),
51                                 getBuffer<T>(_output));
52 }
53
54 void BatchToSpaceNDLayer::configure(const IPortableTensor *input, IPortableTensor *output,
55                                     IPortableTensor *block_shape, IPortableTensor *crops)
56 {
57   _output = output;
58   _input = input;
59   _block_shape = block_shape;
60   _crops = crops;
61 }
62
63 void BatchToSpaceNDLayer::run()
64 {
65   if (_output->data_type() == OperandType::FLOAT32)
66   {
67     batchToSpaceNDGeneric<float>();
68   }
69   else if (_output->data_type() == OperandType::QUANT_UINT8_ASYMM)
70   {
71     batchToSpaceNDGeneric<uint8_t>();
72   }
73   else
74   {
75     throw std::runtime_error{"NYI"};
76   }
77 }
78
79 } // namespace ops
80 } // namespace cpu
81 } // namespace backend
82 } // namespace onert