Michael Butler | b98aa6d | 2020-02-22 22:37:59 -0800 | [diff] [blame^] | 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.2/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(type) \ |
| 26 | static_assert(std::is_same_v< \ |
| 27 | std::underlying_type_t<::android::hardware::neuralnetworks::V1_2::type>, \ |
| 28 | std::underlying_type_t<::android::nn::type>>, \ |
| 29 | "::android::hardware::neuralnetworks::V1_2::" #type \ |
| 30 | " does not have the same underlying type as ::android::nn::" #type) |
| 31 | |
| 32 | COMPARE_ENUMS_TYPES(OperandType); |
| 33 | COMPARE_ENUMS_TYPES(OperationType); |
| 34 | COMPARE_ENUMS_TYPES(DeviceType); |
| 35 | COMPARE_ENUMS_TYPES(MeasureTiming); |
| 36 | |
| 37 | #undef COMPARE_ENUMS_TYPES |
| 38 | |
| 39 | #define COMPARE_ENUMS_FULL(symbol, type) \ |
| 40 | static_assert( \ |
| 41 | static_cast<std::underlying_type_t<::android::hardware::neuralnetworks::V1_2::type>>( \ |
| 42 | ::android::hardware::neuralnetworks::V1_2::type::symbol) == \ |
| 43 | static_cast<std::underlying_type_t<::android::nn::type>>( \ |
| 44 | ::android::nn::type::symbol), \ |
| 45 | "::android::hardware::neuralnetworks::V1_2::" #type "::" #symbol \ |
| 46 | " does not match ::android::nn::" #type "::" #symbol) |
| 47 | |
| 48 | #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, OperandType) |
| 49 | |
| 50 | COMPARE_ENUMS(FLOAT32); |
| 51 | COMPARE_ENUMS(INT32); |
| 52 | COMPARE_ENUMS(UINT32); |
| 53 | COMPARE_ENUMS(TENSOR_FLOAT32); |
| 54 | COMPARE_ENUMS(TENSOR_INT32); |
| 55 | COMPARE_ENUMS(TENSOR_QUANT8_ASYMM); |
| 56 | COMPARE_ENUMS(BOOL); |
| 57 | COMPARE_ENUMS(TENSOR_QUANT16_SYMM); |
| 58 | COMPARE_ENUMS(TENSOR_FLOAT16); |
| 59 | COMPARE_ENUMS(TENSOR_BOOL8); |
| 60 | COMPARE_ENUMS(FLOAT16); |
| 61 | COMPARE_ENUMS(TENSOR_QUANT8_SYMM_PER_CHANNEL); |
| 62 | COMPARE_ENUMS(TENSOR_QUANT16_ASYMM); |
| 63 | COMPARE_ENUMS(TENSOR_QUANT8_SYMM); |
| 64 | COMPARE_ENUMS(OEM); |
| 65 | COMPARE_ENUMS(TENSOR_OEM_BYTE); |
| 66 | |
| 67 | #undef COMPARE_ENUMS |
| 68 | |
| 69 | #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, OperationType) |
| 70 | |
| 71 | COMPARE_ENUMS(ADD); |
| 72 | COMPARE_ENUMS(AVERAGE_POOL_2D); |
| 73 | COMPARE_ENUMS(CONCATENATION); |
| 74 | COMPARE_ENUMS(CONV_2D); |
| 75 | COMPARE_ENUMS(DEPTHWISE_CONV_2D); |
| 76 | COMPARE_ENUMS(DEPTH_TO_SPACE); |
| 77 | COMPARE_ENUMS(DEQUANTIZE); |
| 78 | COMPARE_ENUMS(EMBEDDING_LOOKUP); |
| 79 | COMPARE_ENUMS(FLOOR); |
| 80 | COMPARE_ENUMS(FULLY_CONNECTED); |
| 81 | COMPARE_ENUMS(HASHTABLE_LOOKUP); |
| 82 | COMPARE_ENUMS(L2_NORMALIZATION); |
| 83 | COMPARE_ENUMS(L2_POOL_2D); |
| 84 | COMPARE_ENUMS(LOCAL_RESPONSE_NORMALIZATION); |
| 85 | COMPARE_ENUMS(LOGISTIC); |
| 86 | COMPARE_ENUMS(LSH_PROJECTION); |
| 87 | COMPARE_ENUMS(LSTM); |
| 88 | COMPARE_ENUMS(MAX_POOL_2D); |
| 89 | COMPARE_ENUMS(MUL); |
| 90 | COMPARE_ENUMS(RELU); |
| 91 | COMPARE_ENUMS(RELU1); |
| 92 | COMPARE_ENUMS(RELU6); |
| 93 | COMPARE_ENUMS(RESHAPE); |
| 94 | COMPARE_ENUMS(RESIZE_BILINEAR); |
| 95 | COMPARE_ENUMS(RNN); |
| 96 | COMPARE_ENUMS(SOFTMAX); |
| 97 | COMPARE_ENUMS(SPACE_TO_DEPTH); |
| 98 | COMPARE_ENUMS(SVDF); |
| 99 | COMPARE_ENUMS(TANH); |
| 100 | COMPARE_ENUMS(BATCH_TO_SPACE_ND); |
| 101 | COMPARE_ENUMS(DIV); |
| 102 | COMPARE_ENUMS(MEAN); |
| 103 | COMPARE_ENUMS(PAD); |
| 104 | COMPARE_ENUMS(SPACE_TO_BATCH_ND); |
| 105 | COMPARE_ENUMS(SQUEEZE); |
| 106 | COMPARE_ENUMS(STRIDED_SLICE); |
| 107 | COMPARE_ENUMS(SUB); |
| 108 | COMPARE_ENUMS(TRANSPOSE); |
| 109 | COMPARE_ENUMS(ABS); |
| 110 | COMPARE_ENUMS(ARGMAX); |
| 111 | COMPARE_ENUMS(ARGMIN); |
| 112 | COMPARE_ENUMS(AXIS_ALIGNED_BBOX_TRANSFORM); |
| 113 | COMPARE_ENUMS(BIDIRECTIONAL_SEQUENCE_LSTM); |
| 114 | COMPARE_ENUMS(BIDIRECTIONAL_SEQUENCE_RNN); |
| 115 | COMPARE_ENUMS(BOX_WITH_NMS_LIMIT); |
| 116 | COMPARE_ENUMS(CAST); |
| 117 | COMPARE_ENUMS(CHANNEL_SHUFFLE); |
| 118 | COMPARE_ENUMS(DETECTION_POSTPROCESSING); |
| 119 | COMPARE_ENUMS(EQUAL); |
| 120 | COMPARE_ENUMS(EXP); |
| 121 | COMPARE_ENUMS(EXPAND_DIMS); |
| 122 | COMPARE_ENUMS(GATHER); |
| 123 | COMPARE_ENUMS(GENERATE_PROPOSALS); |
| 124 | COMPARE_ENUMS(GREATER); |
| 125 | COMPARE_ENUMS(GREATER_EQUAL); |
| 126 | COMPARE_ENUMS(GROUPED_CONV_2D); |
| 127 | COMPARE_ENUMS(HEATMAP_MAX_KEYPOINT); |
| 128 | COMPARE_ENUMS(INSTANCE_NORMALIZATION); |
| 129 | COMPARE_ENUMS(LESS); |
| 130 | COMPARE_ENUMS(LESS_EQUAL); |
| 131 | COMPARE_ENUMS(LOG); |
| 132 | COMPARE_ENUMS(LOGICAL_AND); |
| 133 | COMPARE_ENUMS(LOGICAL_NOT); |
| 134 | COMPARE_ENUMS(LOGICAL_OR); |
| 135 | COMPARE_ENUMS(LOG_SOFTMAX); |
| 136 | COMPARE_ENUMS(MAXIMUM); |
| 137 | COMPARE_ENUMS(MINIMUM); |
| 138 | COMPARE_ENUMS(NEG); |
| 139 | COMPARE_ENUMS(NOT_EQUAL); |
| 140 | COMPARE_ENUMS(PAD_V2); |
| 141 | COMPARE_ENUMS(POW); |
| 142 | COMPARE_ENUMS(PRELU); |
| 143 | COMPARE_ENUMS(QUANTIZE); |
| 144 | COMPARE_ENUMS(QUANTIZED_16BIT_LSTM); |
| 145 | COMPARE_ENUMS(RANDOM_MULTINOMIAL); |
| 146 | COMPARE_ENUMS(REDUCE_ALL); |
| 147 | COMPARE_ENUMS(REDUCE_ANY); |
| 148 | COMPARE_ENUMS(REDUCE_MAX); |
| 149 | COMPARE_ENUMS(REDUCE_MIN); |
| 150 | COMPARE_ENUMS(REDUCE_PROD); |
| 151 | COMPARE_ENUMS(REDUCE_SUM); |
| 152 | COMPARE_ENUMS(ROI_ALIGN); |
| 153 | COMPARE_ENUMS(ROI_POOLING); |
| 154 | COMPARE_ENUMS(RSQRT); |
| 155 | COMPARE_ENUMS(SELECT); |
| 156 | COMPARE_ENUMS(SIN); |
| 157 | COMPARE_ENUMS(SLICE); |
| 158 | COMPARE_ENUMS(SPLIT); |
| 159 | COMPARE_ENUMS(SQRT); |
| 160 | COMPARE_ENUMS(TILE); |
| 161 | COMPARE_ENUMS(TOPK_V2); |
| 162 | COMPARE_ENUMS(TRANSPOSE_CONV_2D); |
| 163 | COMPARE_ENUMS(UNIDIRECTIONAL_SEQUENCE_LSTM); |
| 164 | COMPARE_ENUMS(UNIDIRECTIONAL_SEQUENCE_RNN); |
| 165 | COMPARE_ENUMS(RESIZE_NEAREST_NEIGHBOR); |
| 166 | COMPARE_ENUMS(OEM_OPERATION); |
| 167 | |
| 168 | #undef COMPARE_ENUMS |
| 169 | |
| 170 | #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, DeviceType) |
| 171 | |
| 172 | COMPARE_ENUMS(OTHER); |
| 173 | COMPARE_ENUMS(CPU); |
| 174 | COMPARE_ENUMS(GPU); |
| 175 | COMPARE_ENUMS(ACCELERATOR); |
| 176 | |
| 177 | #undef COMPARE_ENUMS |
| 178 | |
| 179 | #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, MeasureTiming) |
| 180 | |
| 181 | COMPARE_ENUMS(NO); |
| 182 | COMPARE_ENUMS(YES); |
| 183 | |
| 184 | #undef COMPARE_ENUMS |
| 185 | |
| 186 | #undef COMPARE_ENUMS_FULL |
| 187 | |
| 188 | } // anonymous namespace |