ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Concat.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#include "exec/NopFunction.h"
22
24{
25
26void Validator::visit(const ir::operation::Concat &) { _supported = true; }
27
28void KernelGenerator::visit(const ir::operation::Concat &node)
29{
30 const auto ofm_index{node.getOutputs().at(0)};
31
32 std::vector<ir::OperandIndex> input_indexes;
33
34 for (const auto &input : node.getInputs())
35 input_indexes.emplace_back(input);
36
37 const auto axis = node.param().axis;
38
39 // Concat elimination check
40 bool eliminated = _tensor_builder->areSubTensorsOf(ofm_index, node.getInputs());
41 if (eliminated)
42 {
43 // If concat eliminated, return a NOP IFunction
44 VERBOSE(acl_cl_KernelGenerator_Concat) << "Concat eliminated" << std::endl;
45 _return_fn = std::make_unique<exec::NopFunction>();
46 return;
47 }
48
49 auto output_tensor = _tensor_reg->getAclTensor(ofm_index);
50 std::vector<const ::arm_compute::ICLTensor *> input_tensors;
51 for (const auto &ifm_ind : input_indexes)
52 input_tensors.emplace_back(_tensor_reg->getAclTensor(ifm_ind)->handle());
53
54 std::unique_ptr<::arm_compute::IFunction> fn;
55 if (input_indexes.size() < 2)
56 {
57 ::arm_compute::ICLTensor *input_tesor =
58 _tensor_reg->getAclTensor(input_indexes.at(0))->handle();
59
60 fn = acl_common::generateLayer<arm_compute::CLCopy>(input_tesor, output_tensor->handle());
61 }
62 else
63 {
64 const auto rank = _ctx.at(ofm_index).shape().rank();
65 const auto fixed_axis = acl_common::ToARMComputeAxis(rank, axis).value();
66 fn = acl_common::generateLayer<::arm_compute::CLConcatenateLayer>(
67 input_tensors, output_tensor->handle(), fixed_axis);
68 }
69
71}
72
73} // namespace onert::backend::acl_cl
This file defines NopFunction.
std::unique_ptr< exec::IFunction > _return_fn
const Object & at(const Index &index) const
Get the object that is associated with the given index.
#define VERBOSE(name, lv)
Definition Log.h:71
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