ONE - On-device Neural Engine
Loading...
Searching...
No Matches
AveragePool2D.cpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021 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 "Builders.h"
18
21
22namespace luci_interpreter
23{
24
25std::unique_ptr<Kernel> build_kernel_CircleAveragePool2D(const luci::CircleNode *circle_node,
26 KernelBuilderHelper &helper)
27{
28 const auto *node = loco::must_cast<const luci::CircleAveragePool2D *>(circle_node);
29 assert(node->arity() == 1);
30
31 const Tensor *input = helper.getInputTensor(node->value());
32 Tensor *output = helper.getOutputTensor(node);
33
34 Pool2DParams params{};
35 params.padding = node->padding();
36 params.filter_height = node->filter()->h();
37 params.filter_width = node->filter()->w();
38 params.stride_height = node->stride()->h();
39 params.stride_width = node->stride()->w();
40 params.activation = node->fusedActivationFunction();
41
42 // It is unknown what data will be stored in scratchpad tensor,
43 // using UINT8 as a most general option
44 auto scratchpad = std::make_unique<Tensor>(DataType::U8, Shape({}), AffineQuantization{}, "");
45 scratchpad->set_observable(false);
46 scratchpad->set_data_buffer(nullptr);
47 // If node has execution plan then read memory offsets for scratchpad temporary tensor
48 // from the beginning of shared memory buffer.
49 // Used in Static Memory Manager.
50 // TODO move tensors offset initialization to one place
52 {
53 const auto execution_plan = luci::get_execution_plan(node);
54 // Check whether the offset for the current CircleConv2D temporary was found.
55 if (execution_plan.offsets().size() > 1)
56 // If this is true, then we keep this offset in scratchpad.
57 scratchpad->set_offset(execution_plan.offsets().at(1));
58 }
59 Tensor *tmp = helper.getRuntimeGraph(node->graph())->addTensor(std::move(scratchpad));
60
61 return std::make_unique<kernels::AveragePool2D>(input, output, tmp, params);
62}
63
64} // namespace luci_interpreter
Tensor * getOutputTensor(const loco::Node *node) const
RuntimeGraph * getRuntimeGraph(const loco::Graph *graph) const
const Tensor * getInputTensor(const loco::Node *node) const
Tensor * addTensor(std::unique_ptr< Tensor > &&tensor)
std::unique_ptr< Kernel > build_kernel_CircleAveragePool2D(const luci::CircleNode *circle_node, KernelBuilderHelper &helper)
bool has_execution_plan(const luci::CircleNode *circle_node)
luci::CircleNodeExecutionPlan get_execution_plan(const luci::CircleNode *circle_node)