1 | /* Copyright 2021 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_OP_ATTRS_H_ |
16 | #define TENSORFLOW_C_EAGER_ABSTRACT_OP_ATTRS_H_ |
17 | |
18 | #include "absl/container/inlined_vector.h" |
19 | #include "tensorflow/core/framework/attr_value.pb.h" |
20 | #include "tensorflow/core/framework/types.pb.h" |
21 | #include "tensorflow/core/platform/status.h" |
22 | |
23 | namespace tensorflow { |
24 | |
25 | // Attributes of an op. |
26 | class AbstractOpAttrs { |
27 | protected: |
28 | enum AbstractOpAttrsKind { kEager, kTfrt }; |
29 | explicit AbstractOpAttrs(AbstractOpAttrsKind kind) : kind_(kind) {} |
30 | |
31 | public: |
32 | // Returns which subclass is this instance of. |
33 | AbstractOpAttrsKind getKind() const { return kind_; } |
34 | virtual ~AbstractOpAttrs() = default; |
35 | |
36 | // Returns the AbstractFunction as a FunctionDef. |
37 | virtual void GetNameAttrList( |
38 | tensorflow::NameAttrList* name_and_attrs) const = 0; |
39 | |
40 | virtual bool GetInt(absl::string_view, int64_t* result) const = 0; |
41 | virtual bool GetFloat(absl::string_view attr_name, float* result) const = 0; |
42 | virtual bool GetBool(absl::string_view attr_name, bool* result) const = 0; |
43 | virtual bool GetType(absl::string_view attr_name, DataType* result) const = 0; |
44 | virtual Status GetTypeList( |
45 | absl::string_view attr_name, |
46 | absl::InlinedVector<DataType, 4>* type_list) const = 0; |
47 | |
48 | private: |
49 | const AbstractOpAttrsKind kind_; |
50 | }; |
51 | |
52 | } // namespace tensorflow |
53 | |
54 | #endif // TENSORFLOW_C_EAGER_ABSTRACT_OP_ATTRS_H_ |
55 | |