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