2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2019 The TensorFlow Authors. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include "DepthToSpace.h"
20 #include "PALDepthToSpace.h"
22 namespace luci_interpreter
27 DepthToSpace::DepthToSpace(const Tensor *input, Tensor *output, const DepthToSpaceParams ¶ms)
28 : KernelWithParams<DepthToSpaceParams>({input}, {output}, params)
32 void DepthToSpace::configure()
34 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() == 4);
35 LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::FLOAT32 ||
36 output()->element_type() == DataType::U8)
37 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type())
38 const int block_size = params().block_size;
39 const int32_t input_height = input()->shape().dim(1);
40 const int32_t input_width = input()->shape().dim(2);
41 const int32_t input_channels = input()->shape().dim(3);
42 int32_t output_height = input_height * block_size;
43 int32_t output_width = input_width * block_size;
44 int32_t output_channels = input_channels / block_size / block_size;
46 LUCI_INTERPRETER_CHECK(input_height == output_height / block_size);
47 LUCI_INTERPRETER_CHECK(input_width == output_width / block_size);
48 LUCI_INTERPRETER_CHECK(input_channels == output_channels * block_size * block_size);
50 Shape output_shape(4);
51 output_shape.dim(0) = input()->shape().dim(0);
52 output_shape.dim(1) = output_height;
53 output_shape.dim(2) = output_width;
54 output_shape.dim(3) = output_channels;
56 // TODO: enable it only if kernel with dynamic shapes
57 output()->resize(output_shape);
60 void DepthToSpace::execute() const
62 tflite::DepthToSpaceParams op_params;
63 op_params.block_size = params().block_size;
64 switch (input()->element_type())
66 case DataType::FLOAT32:
67 luci_interpreter_pal::DepthToSpace(op_params, getTensorShape(input()),
68 getTensorData<float>(input()), getTensorShape(output()),
69 getTensorData<float>(output()));
72 luci_interpreter_pal::DepthToSpace(op_params, getTensorShape(input()),
73 getTensorData<uint8_t>(input()), getTensorShape(output()),
74 getTensorData<uint8_t>(output()));
77 assert(false && "Unsupported Type.");
81 } // namespace kernels
82 } // namespace luci_interpreter