Imported Upstream version 1.8.0
[platform/core/ml/nnfw.git] / compute / cker / include / cker / TensorUtils.h
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_TENSOR_UTILS_H__
19 #define __NNFW_CKER_TENSOR_UTILS_H__
20
21 #include "cker/Types.h"
22 #include "cker/PortableTensorUtils.h"
23 #include "cker/NeonTensorUtils.h"
24 #include "cker/neon/neon_check.h"
25
26 #include <cstring>
27 #include <cmath>
28
29 namespace nnfw
30 {
31 namespace cker
32 {
33
34 void VectorBatchVectorAssign(const float *vector, int v_size, int n_batch, float *batch_vector)
35 {
36   PortableVectorBatchVectorAssign(vector, v_size, n_batch, batch_vector);
37 }
38
39 bool IsZeroVector(const float *vector, int v_size)
40 {
41   return NEON_OR_PORTABLE(IsZeroVector, vector, v_size);
42 }
43
44 void ApplyActivationToVector(const float *vector, int v_size,
45                              FusedActivationFunctionType activation, float *result)
46 {
47   PortableApplyActivationToVector(vector, v_size, activation, result);
48 }
49
50 void SymmetricQuantizeFloats(const float *values, const int size, int8_t *quantized_values,
51                              float *min, float *max, float *scaling_factor)
52 {
53   return NEON_OR_PORTABLE(SymmetricQuantizeFloats, values, size, quantized_values, min, max,
54                           scaling_factor);
55 }
56
57 void MatrixBatchVectorMultiplyAccumulate(const int8_t *matrix, const int m_rows, const int m_cols,
58                                          const int8_t *vector, const float *scaling_factors,
59                                          int n_batch, float *result, int result_stride)
60 {
61   NEON_OR_PORTABLE(MatrixBatchVectorMultiplyAccumulate, matrix, m_rows, m_cols, vector,
62                    scaling_factors, n_batch, result, result_stride);
63 }
64
65 void MatrixBatchVectorMultiplyAccumulate(const float *matrix, int m_rows, int m_cols,
66                                          const float *vector, int n_batch, float *result,
67                                          int result_stride)
68 {
69   NEON_OR_PORTABLE(MatrixBatchVectorMultiplyAccumulate, matrix, m_rows, m_cols, vector, n_batch,
70                    result, result_stride);
71 }
72
73 void MatrixBatchVectorMultiplyAccumulate(const int8_t *matrix, const int m_rows, const int m_cols,
74                                          const int8_t *vectors, const float *scaling_factors,
75                                          int n_batch, int32_t *scratch, float *result,
76                                          int result_stride, ruy::Context *ruy_context)
77 {
78   NEON_OR_PORTABLE(MatrixBatchVectorMultiplyAccumulate, matrix, m_rows, m_cols, vectors,
79                    scaling_factors, n_batch, scratch, result, result_stride, ruy_context);
80 }
81
82 void ZeroVector(float *vector, int v_size) { PortableZeroVector(vector, v_size); }
83
84 } // namespace cker
85 } // namespace nnfw
86
87 #endif // __NNFW_CKER_TENSOR_UTILS_H__