1 /*
2  * Copyright (C) 2020 The Android Open Source Project
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 #include <android/hardware/neuralnetworks/1.3/types.h>
18 #include <nnapi/OperandTypes.h>
19 #include <nnapi/OperationTypes.h>
20 #include <nnapi/Types.h>
21 #include <type_traits>
22 
23 namespace {
24 
25 #define COMPARE_ENUMS_TYPES(lhsType, rhsType)                                                   \
26     static_assert(                                                                              \
27             std::is_same_v<                                                                     \
28                     std::underlying_type_t<::android::hardware::neuralnetworks::V1_3::lhsType>, \
29                     std::underlying_type_t<::android::nn::rhsType>>,                            \
30             "::android::hardware::neuralnetworks::V1_3::" #lhsType                              \
31             " does not have the same underlying type as ::android::nn::" #rhsType)
32 
33 COMPARE_ENUMS_TYPES(OperandType, OperandType);
34 COMPARE_ENUMS_TYPES(OperationType, OperationType);
35 COMPARE_ENUMS_TYPES(Priority, Priority);
36 COMPARE_ENUMS_TYPES(OperandLifeTime, Operand::LifeTime);
37 COMPARE_ENUMS_TYPES(ErrorStatus, ErrorStatus);
38 
39 #undef COMPARE_ENUMS_TYPES
40 
41 #define COMPARE_ENUMS_FULL(symbol, lhsType, rhsType)                                             \
42     static_assert(                                                                               \
43             static_cast<                                                                         \
44                     std::underlying_type_t<::android::hardware::neuralnetworks::V1_3::lhsType>>( \
45                     ::android::hardware::neuralnetworks::V1_3::lhsType::symbol) ==               \
46                     static_cast<std::underlying_type_t<::android::nn::rhsType>>(                 \
47                             ::android::nn::rhsType::symbol),                                     \
48             "::android::hardware::neuralnetworks::V1_3::" #lhsType "::" #symbol                  \
49             " does not match ::android::nn::" #rhsType "::" #symbol)
50 
51 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, OperandType, OperandType)
52 
53 COMPARE_ENUMS(FLOAT32);
54 COMPARE_ENUMS(INT32);
55 COMPARE_ENUMS(UINT32);
56 COMPARE_ENUMS(TENSOR_FLOAT32);
57 COMPARE_ENUMS(TENSOR_INT32);
58 COMPARE_ENUMS(TENSOR_QUANT8_ASYMM);
59 COMPARE_ENUMS(BOOL);
60 COMPARE_ENUMS(TENSOR_QUANT16_SYMM);
61 COMPARE_ENUMS(TENSOR_FLOAT16);
62 COMPARE_ENUMS(TENSOR_BOOL8);
63 COMPARE_ENUMS(FLOAT16);
64 COMPARE_ENUMS(TENSOR_QUANT8_SYMM_PER_CHANNEL);
65 COMPARE_ENUMS(TENSOR_QUANT16_ASYMM);
66 COMPARE_ENUMS(TENSOR_QUANT8_SYMM);
67 COMPARE_ENUMS(TENSOR_QUANT8_ASYMM_SIGNED);
68 COMPARE_ENUMS(SUBGRAPH);
69 COMPARE_ENUMS(OEM);
70 COMPARE_ENUMS(TENSOR_OEM_BYTE);
71 
72 #undef COMPARE_ENUMS
73 
74 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, OperationType, OperationType)
75 
76 COMPARE_ENUMS(ADD);
77 COMPARE_ENUMS(AVERAGE_POOL_2D);
78 COMPARE_ENUMS(CONCATENATION);
79 COMPARE_ENUMS(CONV_2D);
80 COMPARE_ENUMS(DEPTHWISE_CONV_2D);
81 COMPARE_ENUMS(DEPTH_TO_SPACE);
82 COMPARE_ENUMS(DEQUANTIZE);
83 COMPARE_ENUMS(EMBEDDING_LOOKUP);
84 COMPARE_ENUMS(FLOOR);
85 COMPARE_ENUMS(FULLY_CONNECTED);
86 COMPARE_ENUMS(HASHTABLE_LOOKUP);
87 COMPARE_ENUMS(L2_NORMALIZATION);
88 COMPARE_ENUMS(L2_POOL_2D);
89 COMPARE_ENUMS(LOCAL_RESPONSE_NORMALIZATION);
90 COMPARE_ENUMS(LOGISTIC);
91 COMPARE_ENUMS(LSH_PROJECTION);
92 COMPARE_ENUMS(LSTM);
93 COMPARE_ENUMS(MAX_POOL_2D);
94 COMPARE_ENUMS(MUL);
95 COMPARE_ENUMS(RELU);
96 COMPARE_ENUMS(RELU1);
97 COMPARE_ENUMS(RELU6);
98 COMPARE_ENUMS(RESHAPE);
99 COMPARE_ENUMS(RESIZE_BILINEAR);
100 COMPARE_ENUMS(RNN);
101 COMPARE_ENUMS(SOFTMAX);
102 COMPARE_ENUMS(SPACE_TO_DEPTH);
103 COMPARE_ENUMS(SVDF);
104 COMPARE_ENUMS(TANH);
105 COMPARE_ENUMS(BATCH_TO_SPACE_ND);
106 COMPARE_ENUMS(DIV);
107 COMPARE_ENUMS(MEAN);
108 COMPARE_ENUMS(PAD);
109 COMPARE_ENUMS(SPACE_TO_BATCH_ND);
110 COMPARE_ENUMS(SQUEEZE);
111 COMPARE_ENUMS(STRIDED_SLICE);
112 COMPARE_ENUMS(SUB);
113 COMPARE_ENUMS(TRANSPOSE);
114 COMPARE_ENUMS(ABS);
115 COMPARE_ENUMS(ARGMAX);
116 COMPARE_ENUMS(ARGMIN);
117 COMPARE_ENUMS(AXIS_ALIGNED_BBOX_TRANSFORM);
118 COMPARE_ENUMS(BIDIRECTIONAL_SEQUENCE_LSTM);
119 COMPARE_ENUMS(BIDIRECTIONAL_SEQUENCE_RNN);
120 COMPARE_ENUMS(BOX_WITH_NMS_LIMIT);
121 COMPARE_ENUMS(CAST);
122 COMPARE_ENUMS(CHANNEL_SHUFFLE);
123 COMPARE_ENUMS(DETECTION_POSTPROCESSING);
124 COMPARE_ENUMS(EQUAL);
125 COMPARE_ENUMS(EXP);
126 COMPARE_ENUMS(EXPAND_DIMS);
127 COMPARE_ENUMS(GATHER);
128 COMPARE_ENUMS(GENERATE_PROPOSALS);
129 COMPARE_ENUMS(GREATER);
130 COMPARE_ENUMS(GREATER_EQUAL);
131 COMPARE_ENUMS(GROUPED_CONV_2D);
132 COMPARE_ENUMS(HEATMAP_MAX_KEYPOINT);
133 COMPARE_ENUMS(INSTANCE_NORMALIZATION);
134 COMPARE_ENUMS(LESS);
135 COMPARE_ENUMS(LESS_EQUAL);
136 COMPARE_ENUMS(LOG);
137 COMPARE_ENUMS(LOGICAL_AND);
138 COMPARE_ENUMS(LOGICAL_NOT);
139 COMPARE_ENUMS(LOGICAL_OR);
140 COMPARE_ENUMS(LOG_SOFTMAX);
141 COMPARE_ENUMS(MAXIMUM);
142 COMPARE_ENUMS(MINIMUM);
143 COMPARE_ENUMS(NEG);
144 COMPARE_ENUMS(NOT_EQUAL);
145 COMPARE_ENUMS(PAD_V2);
146 COMPARE_ENUMS(POW);
147 COMPARE_ENUMS(PRELU);
148 COMPARE_ENUMS(QUANTIZE);
149 COMPARE_ENUMS(QUANTIZED_16BIT_LSTM);
150 COMPARE_ENUMS(RANDOM_MULTINOMIAL);
151 COMPARE_ENUMS(REDUCE_ALL);
152 COMPARE_ENUMS(REDUCE_ANY);
153 COMPARE_ENUMS(REDUCE_MAX);
154 COMPARE_ENUMS(REDUCE_MIN);
155 COMPARE_ENUMS(REDUCE_PROD);
156 COMPARE_ENUMS(REDUCE_SUM);
157 COMPARE_ENUMS(ROI_ALIGN);
158 COMPARE_ENUMS(ROI_POOLING);
159 COMPARE_ENUMS(RSQRT);
160 COMPARE_ENUMS(SELECT);
161 COMPARE_ENUMS(SIN);
162 COMPARE_ENUMS(SLICE);
163 COMPARE_ENUMS(SPLIT);
164 COMPARE_ENUMS(SQRT);
165 COMPARE_ENUMS(TILE);
166 COMPARE_ENUMS(TOPK_V2);
167 COMPARE_ENUMS(TRANSPOSE_CONV_2D);
168 COMPARE_ENUMS(UNIDIRECTIONAL_SEQUENCE_LSTM);
169 COMPARE_ENUMS(UNIDIRECTIONAL_SEQUENCE_RNN);
170 COMPARE_ENUMS(RESIZE_NEAREST_NEIGHBOR);
171 COMPARE_ENUMS(QUANTIZED_LSTM);
172 COMPARE_ENUMS(IF);
173 COMPARE_ENUMS(WHILE);
174 COMPARE_ENUMS(ELU);
175 COMPARE_ENUMS(HARD_SWISH);
176 COMPARE_ENUMS(FILL);
177 COMPARE_ENUMS(RANK);
178 COMPARE_ENUMS(OEM_OPERATION);
179 
180 #undef COMPARE_ENUMS
181 
182 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, Priority, Priority)
183 
184 COMPARE_ENUMS(LOW);
185 COMPARE_ENUMS(MEDIUM);
186 COMPARE_ENUMS(HIGH);
187 
188 #undef COMPARE_ENUMS
189 
190 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, OperandLifeTime, Operand::LifeTime)
191 
192 COMPARE_ENUMS(TEMPORARY_VARIABLE);
193 COMPARE_ENUMS(SUBGRAPH_INPUT);
194 COMPARE_ENUMS(SUBGRAPH_OUTPUT);
195 COMPARE_ENUMS(CONSTANT_COPY);
196 COMPARE_ENUMS(CONSTANT_REFERENCE);
197 COMPARE_ENUMS(NO_VALUE);
198 COMPARE_ENUMS(SUBGRAPH);
199 
200 #undef COMPARE_ENUMS
201 
202 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, ErrorStatus, ErrorStatus)
203 
204 COMPARE_ENUMS(NONE);
205 COMPARE_ENUMS(DEVICE_UNAVAILABLE);
206 COMPARE_ENUMS(GENERAL_FAILURE);
207 COMPARE_ENUMS(OUTPUT_INSUFFICIENT_SIZE);
208 COMPARE_ENUMS(INVALID_ARGUMENT);
209 COMPARE_ENUMS(MISSED_DEADLINE_TRANSIENT);
210 COMPARE_ENUMS(MISSED_DEADLINE_PERSISTENT);
211 COMPARE_ENUMS(RESOURCE_EXHAUSTED_TRANSIENT);
212 COMPARE_ENUMS(RESOURCE_EXHAUSTED_PERSISTENT);
213 
214 #undef COMPARE_ENUMS
215 
216 #undef COMPARE_ENUMS_FULL
217 
218 }  // anonymous namespace
219