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