• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef TENSORFLOW_COMPILER_TF2XLA_RESOURCE_OPERATION_TABLE_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_RESOURCE_OPERATION_TABLE_H_
18 
19 #include <string>
20 #include <vector>
21 
22 #include "absl/strings/string_view.h"
23 #include "tensorflow/core/platform/logging.h"
24 
25 // Exposes information about the resource operations supported by tf2xla in a
26 // structured form.
27 
28 namespace tensorflow {
29 enum class XlaResourceOpKind {
30   kRead,      // Only reads from resources.
31   kWrite,     // Only writes to resources.
32   kReadWrite  // Reads from and writes to resources.
33 };
34 
35 enum class XlaResourceKind {
36   kVariable,    // Operates on resource variables.
37   kStack,       // Operates on stacks.
38   kTensorArray  // Operates on tensor arrays.
39 };
40 
41 class XlaResourceOpInfo {
42  public:
XlaResourceOpInfo(XlaResourceOpKind op_kind,XlaResourceKind resource_kind)43   explicit XlaResourceOpInfo(XlaResourceOpKind op_kind,
44                              XlaResourceKind resource_kind)
45       : op_kind_(op_kind), resource_kind_(resource_kind) {}
46 
kind()47   XlaResourceOpKind kind() const { return op_kind_; }
resource_kind()48   XlaResourceKind resource_kind() const { return resource_kind_; }
49 
50   static absl::string_view XlaResourceOpKindToString(XlaResourceOpKind op_kind);
51 
52  private:
53   XlaResourceOpKind op_kind_;
54   XlaResourceKind resource_kind_;
55 };
56 
57 // Returns a XlaResourceOpInfo describing `op` if it is a resource operation
58 // supported by tf2xla, otherwise returns null (i.e. if this returns null then
59 // `op` is either not a resource operation or is unsupported by XLA).
60 const XlaResourceOpInfo* GetResourceOpInfoForOp(absl::string_view op);
61 
62 namespace resource_op_table_internal {
63 // NB! Implementation detail exposed for unit testing, do not use.
64 //
65 // Returns the set of resource operations known by this module.
66 std::vector<absl::string_view> GetKnownResourceOps();
67 }  // namespace resource_op_table_internal
68 
69 }  // namespace tensorflow
70 
71 #endif  // TENSORFLOW_COMPILER_TF2XLA_RESOURCE_OPERATION_TABLE_H_
72