blob: 0f0095196dd0ac8349f6ca547645658ecf143357 [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.0/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_0::lhsType>, \
29 std::underlying_type_t<::android::nn::rhsType>>, \
30 "::android::hardware::neuralnetworks::V1_0::" #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(ErrorStatus, ErrorStatus);
36COMPARE_ENUMS_TYPES(OperandLifeTime, Operand::LifeTime);
37
38#undef COMPARE_ENUMS_TYPES
39
40#define COMPARE_ENUMS_FULL(lhsSymbol, rhsSymbol, lhsType, rhsType) \
41 static_assert( \
42 static_cast< \
43 std::underlying_type_t<::android::hardware::neuralnetworks::V1_0::lhsType>>( \
44 ::android::hardware::neuralnetworks::V1_0::lhsType::lhsSymbol) == \
45 static_cast<std::underlying_type_t<::android::nn::rhsType>>( \
46 ::android::nn::rhsType::rhsSymbol), \
47 "::android::hardware::neuralnetworks::V1_0::" #lhsType "::" #lhsSymbol \
48 " does not match ::android::nn::" #rhsType "::" #rhsSymbol)
49
50#define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, symbol, OperandType, OperandType)
51
52COMPARE_ENUMS(FLOAT32);
53COMPARE_ENUMS(INT32);
54COMPARE_ENUMS(UINT32);
55COMPARE_ENUMS(TENSOR_FLOAT32);
56COMPARE_ENUMS(TENSOR_INT32);
57COMPARE_ENUMS(TENSOR_QUANT8_ASYMM);
58COMPARE_ENUMS(OEM);
59COMPARE_ENUMS(TENSOR_OEM_BYTE);
60
61#undef COMPARE_ENUMS
62
63#define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, symbol, OperationType, OperationType)
64
65COMPARE_ENUMS(ADD);
66COMPARE_ENUMS(AVERAGE_POOL_2D);
67COMPARE_ENUMS(CONCATENATION);
68COMPARE_ENUMS(CONV_2D);
69COMPARE_ENUMS(DEPTHWISE_CONV_2D);
70COMPARE_ENUMS(DEPTH_TO_SPACE);
71COMPARE_ENUMS(DEQUANTIZE);
72COMPARE_ENUMS(EMBEDDING_LOOKUP);
73COMPARE_ENUMS(FLOOR);
74COMPARE_ENUMS(FULLY_CONNECTED);
75COMPARE_ENUMS(HASHTABLE_LOOKUP);
76COMPARE_ENUMS(L2_NORMALIZATION);
77COMPARE_ENUMS(L2_POOL_2D);
78COMPARE_ENUMS(LOCAL_RESPONSE_NORMALIZATION);
79COMPARE_ENUMS(LOGISTIC);
80COMPARE_ENUMS(LSH_PROJECTION);
81COMPARE_ENUMS(LSTM);
82COMPARE_ENUMS(MAX_POOL_2D);
83COMPARE_ENUMS(MUL);
84COMPARE_ENUMS(RELU);
85COMPARE_ENUMS(RELU1);
86COMPARE_ENUMS(RELU6);
87COMPARE_ENUMS(RESHAPE);
88COMPARE_ENUMS(RESIZE_BILINEAR);
89COMPARE_ENUMS(RNN);
90COMPARE_ENUMS(SOFTMAX);
91COMPARE_ENUMS(SPACE_TO_DEPTH);
92COMPARE_ENUMS(SVDF);
93COMPARE_ENUMS(TANH);
94COMPARE_ENUMS(OEM_OPERATION);
95
96#undef COMPARE_ENUMS
97
98#define COMPARE_ENUMS(symbol) COMPARE_ENUMS_FULL(symbol, symbol, ErrorStatus, ErrorStatus)
99
100COMPARE_ENUMS(NONE);
101COMPARE_ENUMS(DEVICE_UNAVAILABLE);
102COMPARE_ENUMS(GENERAL_FAILURE);
103COMPARE_ENUMS(OUTPUT_INSUFFICIENT_SIZE);
104COMPARE_ENUMS(INVALID_ARGUMENT);
105
106#undef COMPARE_ENUMS
107
108#define COMPARE_ENUMS(lhsSymbol, rhsSymbol) \
109 COMPARE_ENUMS_FULL(lhsSymbol, rhsSymbol, OperandLifeTime, Operand::LifeTime)
110
111COMPARE_ENUMS(TEMPORARY_VARIABLE, TEMPORARY_VARIABLE);
112COMPARE_ENUMS(MODEL_INPUT, SUBGRAPH_INPUT);
113COMPARE_ENUMS(MODEL_OUTPUT, SUBGRAPH_OUTPUT);
114COMPARE_ENUMS(CONSTANT_COPY, CONSTANT_COPY);
115COMPARE_ENUMS(CONSTANT_REFERENCE, CONSTANT_REFERENCE);
116COMPARE_ENUMS(NO_VALUE, NO_VALUE);
117
118#undef COMPARE_ENUMS
119
120#undef COMPARE_ENUMS_FULL
121
122} // anonymous namespace