1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ 16 #define TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ 17 18 #include "tensorflow/lite/c/c_api_internal.h" 19 #include "tensorflow/lite/core/api/error_reporter.h" 20 #include "tensorflow/lite/schema/schema_generated.h" 21 22 namespace tflite { 23 24 // Abstract interface that returns TfLiteRegistrations given op codes or custom 25 // op names. This is the mechanism that ops being referenced in the flatbuffer 26 // model are mapped to executable function pointers (TfLiteRegistrations). 27 class OpResolver { 28 public: 29 // Finds the op registration for a builtin operator by enum code. 30 virtual const TfLiteRegistration* FindOp(tflite::BuiltinOperator op, 31 int version) const = 0; 32 // Finds the op registration of a custom operator by op name. 33 virtual const TfLiteRegistration* FindOp(const char* op, 34 int version) const = 0; ~OpResolver()35 virtual ~OpResolver() {} 36 }; 37 38 // Handles the logic for converting between an OperatorCode structure extracted 39 // from a flatbuffer and information about a registered operator implementation. 40 TfLiteStatus GetRegistrationFromOpCode(const OperatorCode* opcode, 41 const OpResolver& op_resolver, 42 ErrorReporter* error_reporter, 43 const TfLiteRegistration** registration); 44 45 } // namespace tflite 46 47 #endif // TENSORFLOW_LITE_CORE_API_OP_RESOLVER_H_ 48