ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALConcatenation.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2020 The TensorFlow Authors. All Rights Reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef ONERT_MICRO_EXECUTE_PAL_CONCATENATION_H
19#define ONERT_MICRO_EXECUTE_PAL_CONCATENATION_H
20
21#include "PALUtils.h"
22
23namespace onert_micro
24{
25namespace execute
26{
27namespace pal
28{
29template <typename Scalar>
30OMStatus Concatenation(core::ConcatenationParams &params, std::vector<uint32_t> &input_shapes,
31 std::vector<const Scalar *> &input_data,
32 const core::OMRuntimeShape &output_shape, Scalar *output_data)
33{
34 int axis = params.axis;
35 int inputs_count = params.num_inputs;
36 const int concat_dimensions = output_shape.dimensionsCount();
37
38 int64_t concat_size = 0;
39 for (int i = 0; i < inputs_count; i++)
40 {
41 concat_size += input_shapes[i];
42 }
43 int64_t outer_size = 1;
44 for (int i = 0; i < axis; ++i)
45 {
46 outer_size *= output_shape.dims(i);
47 }
48 // For all input arrays,
49 int64_t base_inner_size = 1;
50 for (int i = axis + 1; i < concat_dimensions; ++i)
51 {
52 base_inner_size *= output_shape.dims(i);
53 }
54
55 Scalar *output_ptr = output_data;
56 for (int k = 0; k < outer_size; k++)
57 {
58 for (int i = 0; i < inputs_count; ++i)
59 {
60 const int copy_size = input_shapes[i] * base_inner_size;
61 const Scalar *input_ptr = input_data[i] + k * copy_size;
62 memcpy(output_ptr, input_ptr, copy_size * sizeof(Scalar));
63 output_ptr += copy_size;
64 }
65 }
66
67 return Ok;
68}
69
70} // namespace pal
71} // namespace execute
72} // namespace onert_micro
73
74#endif // ONERT_MICRO_EXECUTE_PAL_CONCATENATION_H
int32_t dimensionsCount() const
Definition Tensor.h:106
int32_t dims(int i) const
Definition Tensor.h:108
const luci_interpreter::RuntimeShape output_shape
OMStatus Concatenation(core::ConcatenationParams &params, std::vector< uint32_t > &input_shapes, std::vector< const Scalar * > &input_data, const core::OMRuntimeShape &output_shape, Scalar *output_data)