ONE - On-device Neural Engine
Loading...
Searching...
No Matches
LocalResponseNormalization.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 "kernels/LocalResponseNormalization.h"
18
19#include "kernels/Utils.h"
20
22
23namespace luci_interpreter
24{
25
26namespace kernels
27{
28
30 const Tensor *input, Tensor *output, const LocalResponseNormalizationParams &params)
31 : KernelWithParams<LocalResponseNormalizationParams>({input}, {output}, params)
32{
33}
34
35void LocalResponseNormalization::configure()
36{
37 LUCI_INTERPRETER_CHECK(input()->shape().num_dims() == 4);
38 LUCI_INTERPRETER_CHECK(output()->element_type() == DataType::FLOAT32);
39 LUCI_INTERPRETER_CHECK(input()->element_type() == output()->element_type());
40 // TODO: enable it only if kernel with dynamic shapes
41 output()->resize(input()->shape());
42}
43
44void LocalResponseNormalization::execute() const
45{
46 switch (output()->element_type())
47 {
48 case DataType::FLOAT32:
49 tflite::LocalResponseNormalizationParams op_params;
50 op_params.range = params().radius;
51 op_params.bias = params().bias;
52 op_params.alpha = params().alpha;
53 op_params.beta = params().beta;
54 luci_interpreter_pal::LocalResponseNormalization(
55 op_params, getTensorShape(input()), getTensorData<float>(input()), getTensorShape(output()),
56 getTensorData<float>(output()));
57 break;
58 default:
59 assert(false && "Unsupported type.");
60 }
61}
62
63} // namespace kernels
64} // namespace luci_interpreter
LocalResponseNormalization(const Tensor *input, Tensor *output, const LocalResponseNormalizationParams &params)
#define LUCI_INTERPRETER_CHECK(cond)
Definition Utils.h:36
tflite::RuntimeShape getTensorShape(const Tensor *tensor)
Definition Utils.h:194