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_TOOLS_OPTIMIZE_LOGGING_OP_RESOLVER_H_ 16 #define TENSORFLOW_LITE_TOOLS_OPTIMIZE_LOGGING_OP_RESOLVER_H_ 17 18 #include <set> 19 #include <unordered_map> 20 21 #include "tensorflow/lite/core/api/op_resolver.h" 22 #include "tensorflow/lite/mutable_op_resolver.h" 23 #include "tensorflow/lite/op_resolver.h" 24 #include "tensorflow/lite/tools/optimize/calibration/calibration_common.h" 25 26 namespace tflite { 27 namespace optimize { 28 namespace calibration { 29 // A resolver that replaces the kernel invocations with a wrapper 30 // eval function. 31 class LoggingOpResolver : public OpResolver { 32 public: 33 // Creates an instance of |LoggingOpResolver|. 34 // All |TfLiteRegistration.invoke| functions are replaced by 35 // |logging_eval_fn|. 36 // TODO(shashishekhar): This interface needs to change for custom ops and 37 // BuiltinOps that need special logging implementations. 38 LoggingOpResolver(const BuiltinOpsSet& ops_to_replace, 39 const OpResolver& base_resolver, 40 KernelEvalFuncPtr logging_eval_fn); 41 42 const TfLiteRegistration* FindOp(BuiltinOperator op, 43 int version) const override; 44 45 KernelEvalFuncPtr GetWrappedKernelInvoke(BuiltinOperator op, 46 int version) const; 47 const TfLiteRegistration* FindOp(const char* op, int version) const override; 48 49 private: 50 BuiltinOpsMap<std::unique_ptr<TfLiteRegistration>> 51 builtin_op_registration_map_; 52 BuiltinOpsMap<KernelEvalFuncPtr> builtin_op_evalfn_map_; 53 }; 54 55 } // namespace calibration 56 } // namespace optimize 57 } // namespace tflite 58 59 #endif // TENSORFLOW_LITE_TOOLS_OPTIMIZE_LOGGING_OP_RESOLVER_H_ 60