ONE - On-device Neural Engine
Loading...
Searching...
No Matches
PALConcatenation.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2023 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 LUCI_INTERPRETER_PAL_CONCATENATION_H
19#define LUCI_INTERPRETER_PAL_CONCATENATION_H
20
21#include "Params.h"
22#include "PALUtils.h"
23
25{
26
27template <typename Scalar>
28inline void Concatenation(const ConcatenationParams &params,
29 const luci_interpreter::RuntimeShape *const *input_shapes,
30 const Scalar *const *input_data,
31 const luci_interpreter::RuntimeShape &output_shape, Scalar *output_data)
32{
33 int axis = params.axis;
34 int inputs_count = params.inputs_count;
35 const int concat_dimensions = output_shape.dimensionsCount();
36
37 int64_t concat_size = 0;
38 for (int i = 0; i < inputs_count; i++)
39 {
40 concat_size += input_shapes[i]->dims(axis);
41 }
42 int64_t outer_size = 1;
43 for (int i = 0; i < axis; ++i)
44 {
45 outer_size *= output_shape.dims(i);
46 }
47 // For all input arrays,
48 // FlatSize() = outer_size * Dims(axis) * base_inner_size;
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]->dims(axis) * 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
68} // namespace luci_interpreter_pal
69
70#endif // LUCI_INTERPRETER_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
void Concatenation(const ConcatenationParams &params, const luci_interpreter::RuntimeShape *const *input_shapes, const Scalar *const *input_data, const luci_interpreter::RuntimeShape &output_shape, Scalar *output_data)