2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include "kernels/DepthwiseConv2D.h"
21 namespace luci_interpreter
24 std::unique_ptr<Kernel> build_kernel_CircleDepthwiseConv2D(std::vector<const Tensor *> &&inputs,
25 std::vector<Tensor *> &&outputs,
26 const uint32_t op_index,
27 KernelBuilder &builder)
29 assert(inputs.size() == 3);
31 const Tensor *input = inputs.at(0);
32 const Tensor *filter = inputs.at(1);
33 const Tensor *bias = inputs.at(2);
34 Tensor *output = outputs.at(0);
36 circle::OperatorT oper_t;
37 builder.get_circle_reader()->operators()[op_index]->UnPackTo(&oper_t);
38 const auto *options = oper_t.builtin_options.AsDepthwiseConv2DOptions();
40 DepthwiseConv2DParams params{};
41 params.padding = luci_padding(options->padding);
42 params.depth_multiplier = options->depth_multiplier;
43 params.stride_height = options->stride_h;
44 params.stride_width = options->stride_w;
45 params.dilation_height_factor = options->dilation_h_factor;
46 params.dilation_width_factor = options->dilation_w_factor;
47 params.activation = luci_actfunc(options->fused_activation_function);
49 // It is unknown what data will be stored in scratchpad tensor,
50 // using UINT8 as a most general option
51 auto scratchpad = std::make_unique<Tensor>(DataType::U8, Shape({}), nullptr);
52 scratchpad->set_data_buffer(nullptr);
53 // TODO move tensors offset initialization to one place
54 // TODO handle with StaticManager
55 Tensor *tmp = builder.get_runtime_graph()->addTensor(std::move(scratchpad));
57 return std::make_unique<kernels::DepthwiseConv2D>(input, filter, bias, output, tmp, params);
60 } // namespace luci_interpreter