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