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 = _tensor_reg->getAclTensor(input_index)->handle();
38 auto output = _tensor_reg->getAclTensor(output_index)->handle();
39
40 ::arm_compute::PaddingList padding_list;
41 padding_list.resize(rank);
42 for (int32_t n = 0; n < rank; ++n)
43 {
44 const int32_t *from = reinterpret_cast<const int32_t *>(pad_base) + (n * 2);
45
46 const auto axis = acl_common::ToARMComputeAxis(rank, n).value();
47 padding_list[axis] = ::arm_compute::PaddingInfo{from[0], from[1]};
48 }
49
50 [[maybe_unused]] const auto input_type = _ctx.at(input_index).typeInfo();
51 assert(input->info()->data_type() == acl_common::asDataType(input_type.type()));
52 assert(input->info()->quantization_info() ==
53 ::arm_compute::QuantizationInfo(input_type.scale(), input_type.zero_point()));
54 const auto pixel_value =
55 ::arm_compute::PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
56
57 auto fn =
58 acl_common::generateLayer<arm_compute::NEPadLayer>(input, output, padding_list, pixel_value);
59
61}
62
63} // 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.
ARMComputeAxis ToARMComputeAxis(uint32_t rank, uint32_t axis)
Definition Swizzle.h:45
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