1/* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6
7    http://www.apache.org/licenses/LICENSE-2.0
8
9Unless required by applicable law or agreed to in writing, software
10distributed under the License is distributed on an "AS IS" BASIS,
11WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12See the License for the specific language governing permissions and
13limitations under the License.
14==============================================================================*/
15#ifndef TENSORFLOW_CONTRIB_LITE_KERNELS_REGISTER_H_
16#define TENSORFLOW_CONTRIB_LITE_KERNELS_REGISTER_H_
17
18#include <unordered_map>
19#include "tensorflow/contrib/lite/context.h"
20#include "tensorflow/contrib/lite/model.h"
21
22namespace tflite {
23namespace ops {
24namespace builtin {
25
26class BuiltinOpResolver : public OpResolver {
27 public:
28  BuiltinOpResolver();
29  TfLiteRegistration* FindOp(tflite::BuiltinOperator op) const override;
30  TfLiteRegistration* FindOp(const char* op) const override;
31  void AddBuiltin(tflite::BuiltinOperator op, TfLiteRegistration* registration);
32  void AddCustom(const char* name, TfLiteRegistration* registration);
33
34 private:
35  struct BuiltinOperatorHasher {
36    size_t operator()(const tflite::BuiltinOperator& x) const {
37      return std::hash<size_t>()(static_cast<size_t>(x));
38    }
39  };
40  std::unordered_map<tflite::BuiltinOperator, TfLiteRegistration*,
41                     BuiltinOperatorHasher>
42      builtins_;
43  std::unordered_map<std::string, TfLiteRegistration*> custom_ops_;
44};
45
46}  // namespace builtin
47}  // namespace ops
48}  // namespace tflite
49
50#endif  // TENSORFLOW_CONTRIB_LITE_KERNELS_BUILTIN_KERNELS_H
51