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.1/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_1::type>, \ 28 std::underlying_type_t<::android::nn::type>>, \ 29 "::android::hardware::neuralnetworks::V1_1::" #type \ 30 " does not have the same underlying type as ::android::nn::" #type) 31 32 COMPARE_ENUMS_TYPES(OperationType); 33 COMPARE_ENUMS_TYPES(ExecutionPreference); 34 35 #undef COMPARE_ENUMS_TYPES 36 37 #define COMPARE_ENUMS_FULL(symbol, type) \ 38 static_assert( \ 39 static_cast<std::underlying_type_t<::android::hardware::neuralnetworks::V1_1::type>>( \ 40 ::android::hardware::neuralnetworks::V1_1::type::symbol) == \ 41 static_cast<std::underlying_type_t<::android::nn::type>>( \ 42 ::android::nn::type::symbol), \ 43 "::android::hardware::neuralnetworks::V1_1::" #type "::" #symbol \ 44 " does not match ::android::nn::" #type "::" #symbol) 45 46 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, OperationType) 47 48 COMPARE_ENUMS(ADD); 49 COMPARE_ENUMS(AVERAGE_POOL_2D); 50 COMPARE_ENUMS(CONCATENATION); 51 COMPARE_ENUMS(CONV_2D); 52 COMPARE_ENUMS(DEPTHWISE_CONV_2D); 53 COMPARE_ENUMS(DEPTH_TO_SPACE); 54 COMPARE_ENUMS(DEQUANTIZE); 55 COMPARE_ENUMS(EMBEDDING_LOOKUP); 56 COMPARE_ENUMS(FLOOR); 57 COMPARE_ENUMS(FULLY_CONNECTED); 58 COMPARE_ENUMS(HASHTABLE_LOOKUP); 59 COMPARE_ENUMS(L2_NORMALIZATION); 60 COMPARE_ENUMS(L2_POOL_2D); 61 COMPARE_ENUMS(LOCAL_RESPONSE_NORMALIZATION); 62 COMPARE_ENUMS(LOGISTIC); 63 COMPARE_ENUMS(LSH_PROJECTION); 64 COMPARE_ENUMS(LSTM); 65 COMPARE_ENUMS(MAX_POOL_2D); 66 COMPARE_ENUMS(MUL); 67 COMPARE_ENUMS(RELU); 68 COMPARE_ENUMS(RELU1); 69 COMPARE_ENUMS(RELU6); 70 COMPARE_ENUMS(RESHAPE); 71 COMPARE_ENUMS(RESIZE_BILINEAR); 72 COMPARE_ENUMS(RNN); 73 COMPARE_ENUMS(SOFTMAX); 74 COMPARE_ENUMS(SPACE_TO_DEPTH); 75 COMPARE_ENUMS(SVDF); 76 COMPARE_ENUMS(TANH); 77 COMPARE_ENUMS(BATCH_TO_SPACE_ND); 78 COMPARE_ENUMS(DIV); 79 COMPARE_ENUMS(MEAN); 80 COMPARE_ENUMS(PAD); 81 COMPARE_ENUMS(SPACE_TO_BATCH_ND); 82 COMPARE_ENUMS(SQUEEZE); 83 COMPARE_ENUMS(STRIDED_SLICE); 84 COMPARE_ENUMS(SUB); 85 COMPARE_ENUMS(TRANSPOSE); 86 COMPARE_ENUMS(OEM_OPERATION); 87 88 #undef COMPARE_ENUMS 89 90 #define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, ExecutionPreference) 91 92 COMPARE_ENUMS(LOW_POWER); 93 COMPARE_ENUMS(FAST_SINGLE_ANSWER); 94 COMPARE_ENUMS(SUSTAINED_SPEED); 95 96 #undef COMPARE_ENUMS 97 98 #undef COMPARE_ENUMS_FULL 99 100 } // anonymous namespace 101