xref: /aosp_15_r20/external/tensorflow/tensorflow/c/eager/abstract_function.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2020 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_C_EAGER_ABSTRACT_FUNCTION_H_
16 #define TENSORFLOW_C_EAGER_ABSTRACT_FUNCTION_H_
17 
18 #include "tensorflow/core/framework/function.pb.h"
19 #include "tensorflow/core/platform/intrusive_ptr.h"
20 #include "tensorflow/core/platform/refcount.h"
21 #include "tensorflow/core/platform/status.h"
22 
23 namespace tensorflow {
24 
25 // A traced function: this hides the complexity of converting the serialized
26 // representation between various supported formats e.g. FunctionDef and Mlir
27 // function.
28 class AbstractFunction : public core::RefCounted {
29  protected:
30   enum AbstractFunctionKind { kGraph, kMlir };
AbstractFunction(AbstractFunctionKind kind)31   explicit AbstractFunction(AbstractFunctionKind kind) : kind_(kind) {}
32 
33  public:
34   // Returns which subclass is this instance of.
getKind()35   AbstractFunctionKind getKind() const { return kind_; }
36 
37   // Returns the AbstractFunction as a FunctionDef.
38   virtual Status GetFunctionDef(FunctionDef**) = 0;
39 
40  private:
41   const AbstractFunctionKind kind_;
42 };
43 
44 using AbstractFunctionPtr =
45     tensorflow::core::IntrusivePtr<tensorflow::AbstractFunction>;
46 
47 }  // namespace tensorflow
48 
49 #endif  // TENSORFLOW_C_EAGER_ABSTRACT_FUNCTION_H_
50