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