ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Pad.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::Pad &) { _supported = true; }
26
27void KernelGenerator::visit(const ir::operation::Pad &node)
28{
29 const auto input_index{node.getInputs().at(ir::operation::Pad::Input::INPUT)};
30 const auto pad_index{node.getInputs().at(ir::operation::Pad::Input::PAD)};
31 const auto output_index{node.getOutputs().at(0)};
32 assert(_ctx.at(pad_index).data());
33
34 auto rank = _ctx.at(input_index).shape().rank();
35 auto pad_base = _ctx.at(pad_index).data()->base();
36
37 auto input_type = _ctx.at(input_index).typeInfo();
38 auto data_type = acl_common::asDataType(input_type.type());
39 auto quant_info = ::arm_compute::QuantizationInfo(input_type.scale(), input_type.zero_point());
40 const auto pixel_value = ::arm_compute::PixelValue(0, data_type, quant_info);
41
42 auto input = _tensor_reg->getAclTensor(input_index)->handle();
43 auto output = _tensor_reg->getAclTensor(output_index)->handle();
44
45 ::arm_compute::PaddingList padding_list;
46 padding_list.resize(rank);
47 for (int32_t n = 0; n < rank; ++n)
48 {
49 const int32_t *from = reinterpret_cast<const int32_t *>(pad_base) + (n * 2);
50
51 const auto axis = acl_common::ToARMComputeAxis(rank, n).value();
52 padding_list[axis] = ::arm_compute::PaddingInfo{from[0], from[1]};
53 }
54
55 // Disable applied dim_correction
56 const auto &input_tensor = _tensor_reg->getAclTensor(input_index);
57 if (input_tensor->num_dimensions() != input_tensor->info()->num_dimensions())
58 {
59 // This means that high dimension's value is 1 and input tensor is applied dim_correction
61 }
62
63 auto fn =
64 acl_common::generateLayer<arm_compute::CLPadLayerEx>(input, output, padding_list, pixel_value);
65
66 // NOTE Do not revert disabling applied dim_correction for 4D.
67 // It would produce a mistach of result by incorrect offset_first_element in
68 // ICLKernel::add_tensor_argument<3>().
69 // We have to disable applied dim_correction and not to revert enabling for the kernel that slices
70 // 4D to 3D because slicing arm_compute::Window can causes incorrect offset_first_element if the
71 // used tensor is 4D and the tensor's high dimention is 1
72 if (input_tensor->num_dimensions() < 4 && input_tensor->dimension(0) == 1)
73 {
75 }
76
78}
79
80} // 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.
ARMComputeAxis ToARMComputeAxis(uint32_t rank, uint32_t axis)
Definition Swizzle.h:45
void enableDimCorrection(IACLTensor *tensor)
std::unique_ptr< AclFunction > asAclFunction(std::unique_ptr<::arm_compute::IFunction > &&layer)
Definition Convert.cc:246
::arm_compute::DataType asDataType(const ir::DataType type)
Definition Convert.cc:71
void disableDimCorrection(IACLTensor *tensor)