1 /* 2 * Copyright (C) 2022 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 #ifndef ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_OPERATION_CONVERTERS_OPERATION_CONVERTER_RESOLVER_H 18 #define ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_OPERATION_CONVERTERS_OPERATION_CONVERTER_RESOLVER_H 19 20 #include "OperationConverter.h" 21 #include "SubGraphContext.h" 22 23 namespace android { 24 namespace nn { 25 26 // OperationConverterResolver is used to register all operation converters that implement 27 // IOperationConverter. This retrieves the correct converter to use based on OperationType 28 class OperationConverterResolver { 29 public: get()30 static const OperationConverterResolver* get() { 31 static OperationConverterResolver instance; 32 return &instance; 33 } 34 const IOperationConverter* findOperationConverter(OperationType operationType) const; 35 36 private: 37 OperationConverterResolver(); 38 39 void registerOperationConverter(const IOperationConverter* operationConverter, 40 OperationType operationType); 41 42 const IOperationConverter* mConverters[kNumberOfOperationTypes] = {}; 43 }; 44 45 // Use to register operation converter into OperationConverterResolver 46 #define NN_REGISTER_OPERATION_CONVERTER(identifier, OperationConverterClass) \ 47 const IOperationConverter* registerConverter_##identifier() { \ 48 static OperationConverterClass converter; \ 49 return &converter; \ 50 } 51 52 // Use to indicate which operations are not supported 53 #define NN_OPERATION_CONVERTER_NOT_IMPLEMENTED(identifier) \ 54 const IOperationConverter* registerConverter_##identifier() { \ 55 return nullptr; \ 56 } 57 58 } // namespace nn 59 } // namespace android 60 61 #endif // ANDROID_PACKAGES_MODULES_NEURALNETWORKS_RUNTIME_OPERATION_CONVERTERS_OPERATION_CONVERTER_RESOLVER_H