ONE - On-device Neural Engine
Loading...
Searching...
No Matches
Pack.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
3 * Copyright 2017 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 __NNFW_CKER_PACK_H__
19#define __NNFW_CKER_PACK_H__
20
21#include "cker/Shape.h"
22#include "cker/Types.h"
23
24namespace nnfw
25{
26namespace cker
27{
28
29template <typename Scalar>
30inline void Pack(const PackParams &params, const Scalar *const *input_data,
31 const Shape &output_shape, Scalar *output_data)
32{
33 const int dimensions = output_shape.DimensionsCount();
34 int axis = params.axis;
35 int inputs_count = params.inputs_count;
36
37 int outer_size = 1;
38 for (int i = 0; i < axis; i++)
39 {
40 outer_size *= output_shape.Dims(i);
41 }
42 int copy_size = 1;
43 for (int i = params.axis + 1; i < dimensions; i++)
44 {
45 copy_size *= output_shape.Dims(i);
46 }
47
48 for (int i = 0; i < inputs_count; ++i)
49 {
50 for (int k = 0; k < outer_size; k++)
51 {
52 const Scalar *input_ptr = input_data[i] + copy_size * k;
53 int loc = k * inputs_count * copy_size + i * copy_size;
54 memcpy(output_data + loc, input_ptr, copy_size * sizeof(Scalar));
55 }
56 }
57}
58
59} // namespace cker
60} // namespace nnfw
61
62#endif // __NNFW_CKER_PACK_H__
const luci_interpreter::RuntimeShape output_shape
void Pack(const PackParams &params, const Scalar *const *input_data, const Shape &output_shape, Scalar *output_data)
Definition Pack.h:30
Definition topk_v2.h:30
uint16_t inputs_count
Definition Types.h:129