ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Conv2D.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2025 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 "../KernelGenerator.h"
18#include "../Validator.h"
19
20#include <AclKernelGen.h>
21
23{
24
25void Validator::visit(const ir::operation::Conv2D &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::Conv2D &node)
28{
29 using ir::operation::Conv2D;
30
31 const auto ofm_index{node.getOutputs().at(0)};
32 const auto ifm_index{node.getInputs().at(Conv2D::Input::INPUT)};
33 const auto ker_index{node.getInputs().at(Conv2D::Input::KERNEL)};
34 const auto bias_index{node.getInputs().at(Conv2D::Input::BIAS)};
35
36 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
37 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
38 // Kernel format is [depth_out, kernel_height, kernel_width, depth_in].
39 const auto &ker_shape = _ctx.at(ker_index).shape();
40 const auto ker_height = ker_shape.dim(1);
41 const auto ker_width = ker_shape.dim(2);
42
43 const auto stride = node.param().stride;
44 const auto padding =
45 ir::calculatePadding(node.param().padding, ifm_shape, ofm_shape, stride, ker_width, ker_height);
46 const auto activation = node.param().activation;
47
48 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_index);
49 auto ifm_tensor = _tensor_reg->getAclTensor(ifm_index);
50 auto ker_tensor = _tensor_reg->getAclTensor(ker_index);
51 auto bias_tensor = _tensor_reg->getAclTensor(bias_index);
52
53 const auto conv_info = acl_common::asPadStrideInfo(padding, stride);
54 const auto act_info = acl_common::asActivationLayerInfo(activation);
55
56 auto fn = acl_common::generateLayer<arm_compute::NEConvolutionLayer>(
57 _tensor_builder->acl_tensor_manager()->internal_buffer_manager(), ifm_tensor->handle(),
58 ker_tensor->handle(), bias_tensor->handle(), ofm_tensor->handle(), conv_info,
59 ::arm_compute::WeightsInfo(), ::arm_compute::Size2D(1U, 1U), act_info);
60
62}
63
64} // namespace onert::backend::acl_neon
std::unique_ptr< exec::IFunction > _return_fn
const Object & at(const Index &index) const
Get the object that is associated with the given index.
::arm_compute::ActivationLayerInfo asActivationLayerInfo(const ir::Activation act_code)
Definition Convert.cc:131
::arm_compute::PadStrideInfo asPadStrideInfo(const ir::ExplicitPadding &padding, const ir::Stride &stride)
Definition Convert.cc:119
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246
const ExplicitPadding calculatePadding(const Padding &padding, const FeatureShape &ifm_shape, const FeatureShape &ofm_shape, const Stride &stride, uint32_t kw, uint32_t kh, uint32_t dwf=1, uint32_t dhf=1)
Definition Padding.cc:131
CLTensor ker_tensor
CLTensor bias_tensor