ONE - On-device Neural Engine
Loading...
Searching...
No Matches
TransposeConv.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::TransposeConv &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::TransposeConv &node)
28{
29 const auto ofm_index{node.getOutputs().at(0)};
30 const auto ker_index{node.getInputs().at(ir::operation::TransposeConv::Input::KERNEL)};
31 const auto ifm_index{node.getInputs().at(ir::operation::TransposeConv::Input::INPUT)};
32
33 const auto ofm_shape = _ctx.at(ofm_index).shape().asFeature();
34 const auto ifm_shape = _ctx.at(ifm_index).shape().asFeature();
35 const auto ker_shape = _ctx.at(ker_index).shape().asFeature();
36
37 const auto stride = node.param().stride;
38
39 assert((node.param().padding.type == ir::PaddingType::SAME) ||
40 (node.param().padding.type == ir::PaddingType::VALID));
41 auto padding = ir::calculatePadding(node.param().padding, ofm_shape, ifm_shape, stride,
42 ker_shape.W, ker_shape.H);
43 uint32_t invalid_horizontal = 0;
44 uint32_t invalid_vertical = 0;
45 if (node.param().padding.type == ir::PaddingType::VALID)
46 {
47 invalid_horizontal =
48 ofm_shape.W - (1 + (ifm_shape.W - 1) * stride.horizontal) - (ker_shape.W - 1);
49 invalid_vertical = ofm_shape.H - (1 + (ifm_shape.H - 1) * stride.vertical) - (ker_shape.H - 1);
50 }
51
52 auto ofm_tensor = _tensor_reg->getAclTensor(ofm_index);
53 auto ifm_tensor = _tensor_reg->getAclTensor(ifm_index);
54 auto ker_tensor = _tensor_reg->getAclTensor(ker_index);
55
56 const auto tconv_info = acl_common::asPadStrideInfo(padding, stride);
57
58 auto fn = acl_common::generateLayer<arm_compute::CLTransposeConvLayer>(
59 _tensor_builder->acl_tensor_manager()->internal_buffer_manager(), ifm_tensor->handle(),
60 ker_tensor->handle(), nullptr, ofm_tensor->handle(), tconv_info, invalid_horizontal,
61 invalid_vertical);
62
64}
65
66} // namespace onert::backend::acl_cl
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::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