• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2021-2022 Huawei Technologies Co., Ltd
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 #ifndef MINDSPORE_NNACL_COMMON_H_
18 #define MINDSPORE_NNACL_COMMON_H_
19 
20 #include <stddef.h>
21 #include "nnacl/errorcode.h"
22 #include "nnacl/op_base.h"
23 #include "nnacl/tensor_c.h"
24 
25 bool CheckShaleValid(TensorC **tensors, int tensors_size);
26 bool CheckInferShapeDone(TensorC **in, int in_size, TensorC **out, int out_size);
27 
28 #define EPSILON_VALUE 1e-6
29 
30 enum NNACLLshProjectionType {
31   LshProjectionType_UNKNOWN = 0,
32   LshProjectionType_SPARSE = 1,
33   LshProjectionType_DENSE = 2,
34   LshProjectionType_MIN = LshProjectionType_UNKNOWN,
35   LshProjectionType_MAX = LshProjectionType_DENSE
36 };
37 
38 typedef struct VectorC {
39   int *data_;
40   size_t size_;
41   size_t max_size_;
42   size_t per_malloc_size_;
43 } VectorC;
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 int CheckAugmentNull(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
50                      const OpParameter *parameter);
51 int CheckAugmentNullSize(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
52                          const OpParameter *parameter, size_t inputs_size_obj, size_t outputs_size_obj);
53 int CheckAugmentNullSizeInputTwo(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs,
54                                  size_t outputs_size, const OpParameter *parameter, size_t inputs_size_obj_0,
55                                  size_t inputs_size_obj_1, size_t outputs_size_obj);
56 int CheckAugmentNullInputSize(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
57                               const OpParameter *parameter, size_t inputs_size_obj);
58 int CheckAugmentNullOutputSize(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
59                                const OpParameter *parameter, size_t outputs_size_obj);
60 int CheckAugmentWithMinSize(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
61                             const OpParameter *parameter, size_t inputs_size_obj, size_t outputs_size_obj);
62 void SetDataTypeFormat(TensorC *dst, const TensorC *src);
63 
64 void SetShapeTensor(TensorC *dst, const TensorC *src);
65 void SetShapeArray(TensorC *dst, const int *src, size_t src_size);
66 void ShapeSet(int *dst_shape, size_t *dst_shape_size, const int *src_shape, size_t src_shape_size);
67 bool Int64ShapeSet(int *dst_shape, size_t *dst_shape_size, const int64_t *src_shape, size_t src_shape_size);
68 void ShapePush(int *shape, size_t *shape_size, int value);
69 int GetInt32DataFromTensor(const TensorC *tensor, int *result, size_t *result_size);
70 int ShapeInsert(int *shape, size_t *shape_size, int index, int value);
71 int ShapeErase(int *shape, size_t *shape_size, int index);
72 bool ShapeEqual(const int *shape0, size_t shape0_size, const int *shape1, size_t shape1_size);
73 
74 void iswap(int *a, int *b);
75 
76 int imin(int a, int b);
77 int imax(int a, int b);
78 
79 int CommonInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
80                      OpParameter *parameter);
81 int CommonGradInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
82                          OpParameter *parameter);
83 int CommonInferShapeWithOneInput(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs,
84                                  size_t outputs_size, OpParameter *parameter);
85 int CommonInferShapeWithNHWC(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
86                              OpParameter *parameter);
87 int FftInferShape(const TensorC *const *inputs, size_t inputs_size, TensorC **outputs, size_t outputs_size,
88                   const OpParameter *parameter);
89 bool InferFlag(const TensorC *const *inputs, size_t inputs_size);
90 #ifdef __cplusplus
91 }
92 #endif
93 
94 #endif  // MINDSPORE_NNACL_COMMON__H_
95