2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "BatchToSpaceNDLayer.h"
19 #include <cker/operation/BatchToSpaceND.h>
30 BatchToSpaceNDLayer::BatchToSpaceNDLayer()
31 : _input(nullptr), _output(nullptr), _block_shape(nullptr), _crops(nullptr)
36 template <typename T> void BatchToSpaceNDLayer::batchToSpaceNDGeneric()
38 const int32_t NNapiCrops[]{0, 0, 0, 0};
39 const int32_t *_crops_buffer;
41 if (_crops == nullptr)
43 _crops_buffer = NNapiCrops;
47 _crops_buffer = reinterpret_cast<const int32_t *>(_crops->buffer());
49 nnfw::cker::BatchToSpaceND<T>(
50 getTensorShape(_input), reinterpret_cast<const T *>(_input->buffer()),
51 reinterpret_cast<const int32_t *>(_block_shape->buffer()), _crops_buffer,
52 getTensorShape(_output), reinterpret_cast<T *>(_output->buffer()));
55 void BatchToSpaceNDLayer::configure(const IPortableTensor *input, IPortableTensor *output,
56 IPortableTensor *block_shape, IPortableTensor *crops)
60 _block_shape = block_shape;
64 void BatchToSpaceNDLayer::run()
66 if (_output->data_type() == OperandType::FLOAT32)
68 batchToSpaceNDGeneric<float>();
70 else if (_output->data_type() == OperandType::QUANT_UINT8_ASYMM)
72 batchToSpaceNDGeneric<uint8_t>();
76 throw std::runtime_error{"NYI"};
82 } // namespace backend