• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2017 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_TOCO_TFLITE_SIMPLE_OPERATOR_H_
16 #define TENSORFLOW_LITE_TOCO_TFLITE_SIMPLE_OPERATOR_H_
17 
18 #include "tensorflow/lite/toco/tflite/operator.h"
19 
20 namespace toco {
21 
22 namespace tflite {
23 
24 // Simple operators don't have any configuration options and can be trivially
25 // serialized and deserialized. Note that most of toco's operators will
26 // likely be supported as builtin operators in TF Lite.  Simple (and custom)
27 // operators are mostly a convenience for the times when tf.mini supports more
28 // operators than TF Lite.
29 //
30 // Template argument T must derive from ::toco::Operator.
31 template <typename T>
32 class SimpleOperator : public BaseOperator {
33  public:
34   using BaseOperator::BaseOperator;
35 
SimpleOperator(::tflite::BuiltinOperator op,OperatorType type)36   SimpleOperator(::tflite::BuiltinOperator op, OperatorType type)
37       : BaseOperator(::tflite::EnumNameBuiltinOperator(op), type),
38         builtin_op_(op) {}
39 
Serialize(const Operator & op,flatbuffers::FlatBufferBuilder * builder)40   Options Serialize(const Operator& op,
41                     flatbuffers::FlatBufferBuilder* builder) const override {
42     return Options();
43   }
Deserialize(const BuiltinOptions * builtin_options,const CustomOptions * custom_options)44   std::unique_ptr<Operator> Deserialize(
45       const BuiltinOptions* builtin_options,
46       const CustomOptions* custom_options) const override {
47     return std::unique_ptr<Operator>(new T);
48   }
49 
GetVersion(const OperatorSignature & op_signature)50   int GetVersion(const OperatorSignature& op_signature) const override {
51     return ::tflite::GetBuiltinOperatorVersion(
52         GetVersioningOpSig(builtin_op_, op_signature));
53   }
54 
builtin_op()55   ::tflite::BuiltinOperator builtin_op() const { return builtin_op_; }
56 
57  private:
58   const ::tflite::BuiltinOperator builtin_op_;
59 };
60 
61 }  // namespace tflite
62 
63 }  // namespace toco
64 
65 #endif  // TENSORFLOW_LITE_TOCO_TFLITE_SIMPLE_OPERATOR_H_
66