ONE - On-device Neural Engine
Loading...
Searching...
No Matches
DepthToSpace.cpp
Go to the documentation of this file.
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 "
DepthToSpace.h
"
18
#include "
Utils.h
"
19
#include "PALDepthToSpace.h"
20
21
namespace
luci_interpreter
22
{
23
namespace
kernels
24
{
25
26
DepthToSpace::DepthToSpace
(
const
Tensor
*input,
Tensor
*output,
const
DepthToSpaceParams
¶ms)
27
:
KernelWithParams
<
DepthToSpaceParams
>({
input
}, {output}, params)
28
{
29
}
30
31
void
DepthToSpace::configure
()
32
{
33
LUCI_INTERPRETER_CHECK
(
input
()->shape().num_dims() == 4);
34
LUCI_INTERPRETER_CHECK
(
output
()->element_type() == DataType::FLOAT32 ||
35
output
()->element_type() == DataType::U8)
36
LUCI_INTERPRETER_CHECK
(
input
()->element_type() ==
output
()->element_type())
37
const
int
block_size =
params
().
block_size
;
38
const
int32_t input_height =
input
()->
shape
().
dim
(1);
39
const
int32_t input_width =
input
()->
shape
().
dim
(2);
40
const
int32_t input_channels =
input
()->
shape
().
dim
(3);
41
int32_t output_height = input_height * block_size;
42
int32_t output_width = input_width * block_size;
43
int32_t output_channels = input_channels / block_size / block_size;
44
45
LUCI_INTERPRETER_CHECK
(input_height == output_height / block_size);
46
LUCI_INTERPRETER_CHECK
(input_width == output_width / block_size);
47
LUCI_INTERPRETER_CHECK
(input_channels == output_channels * block_size * block_size);
48
49
Shape
output_shape
(4);
50
output_shape
.dim(0) =
input
()->
shape
().
dim
(0);
51
output_shape
.dim(1) = output_height;
52
output_shape
.dim(2) = output_width;
53
output_shape
.dim(3) = output_channels;
54
55
output
()->
resize
(
output_shape
);
56
}
57
58
void
DepthToSpace::execute
()
const
59
{
60
tflite::DepthToSpaceParams op_params;
61
op_params.block_size =
params
().
block_size
;
62
switch
(
input
()->element_type())
63
{
64
case
DataType::FLOAT32:
65
luci_interpreter_pal::DepthToSpace(op_params,
getTensorShape
(
input
()),
66
getTensorData<float>(
input
()),
getTensorShape
(
output
()),
67
getTensorData<float>(
output
()));
68
break
;
69
case
DataType::U8:
70
luci_interpreter_pal::DepthToSpace(op_params,
getTensorShape
(
input
()),
71
getTensorData<uint8_t>(
input
()),
getTensorShape
(
output
()),
72
getTensorData<uint8_t>(
output
()));
73
break
;
74
default
:
75
throw
std::runtime_error(
"luci-intp DepthToSpace Unsupported Type."
);
76
}
77
}
78
79
}
// namespace kernels
80
}
// namespace luci_interpreter
luci_interpreter::KernelWithParams
Definition
Kernel.h:58
luci_interpreter::KernelWithParams< DepthToSpaceParams >::params
const DepthToSpaceParams & params() const
Definition
Kernel.h:67
luci_interpreter::Shape
Definition
Tensor.h:33
luci_interpreter::Shape::dim
int32_t dim(int i) const
Definition
Tensor.h:41
luci_interpreter::Tensor
Definition
Tensor.h:101
luci_interpreter::Tensor::resize
void resize(const Shape &new_shape)
Definition
Tensor.cpp:56
luci_interpreter::Tensor::shape
const Shape & shape() const
Definition
Tensor.h:107
luci_interpreter::kernels::DepthToSpace::configure
void configure() override
Definition
DepthToSpace.cpp:31
luci_interpreter::kernels::DepthToSpace::execute
void execute() const override
Definition
DepthToSpace.cpp:58
luci_interpreter::kernels::DepthToSpace::output
Tensor * output() const
Definition
DepthToSpace.h:36
luci_interpreter::kernels::DepthToSpace::input
const Tensor * input() const
Definition
DepthToSpace.h:35
luci_interpreter::kernels::DepthToSpace::DepthToSpace
DepthToSpace(const Tensor *input, Tensor *output, const DepthToSpaceParams ¶ms)
Definition
DepthToSpace.cpp:26
LUCI_INTERPRETER_CHECK
#define LUCI_INTERPRETER_CHECK(cond)
Definition
Utils.h:36
output_shape
const luci_interpreter::RuntimeShape output_shape
Definition
PALComparisons.h:32
luci_interpreter::kernels::getTensorShape
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition
Utils.h:194
luci_interpreter
Definition
BuddyMemoryManager.h:22
DepthToSpace.h
Utils.h
This file contains utility macro.
luci_interpreter::DepthToSpaceParams
Definition
KernelParams.h:77
luci_interpreter::DepthToSpaceParams::block_size
int block_size
Definition
KernelParams.h:78
compiler
luci-interpreter
src
kernels
DepthToSpace.cpp
Generated by
1.9.8