• 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_XLA_SERVICE_HLO_DOMAIN_METADATA_H_
17 #define TENSORFLOW_COMPILER_XLA_SERVICE_HLO_DOMAIN_METADATA_H_
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 
23 #include "absl/container/flat_hash_set.h"
24 #include "absl/strings/string_view.h"
25 #include "tensorflow/compiler/xla/statusor.h"
26 #include "tensorflow/compiler/xla/types.h"
27 #include "tensorflow/core/lib/core/status.h"
28 
29 namespace xla {
30 
31 // Cannot include hlo_instruction.h as this file is included from there.
32 class HloInstruction;
33 
34 // The DomainMetadata represents the base class for metadata which can be
35 // attached to kDomain HLO instructions.
36 class DomainMetadata {
37  public:
38   // A Domain data structure captures all the information about a kDomain
39   // bounded instruction set.
40   struct Domain {
41     // The set of instructions which are reachable from each other via
42     // operand/user pathways, without crossing a kDomain instruction of a given
43     // kind. The reach_set can contain kDomain instructions of other kinds, if
44     // two domains of different kind intersect each other.
45     absl::flat_hash_set<HloInstruction*> reach_set;
46 
47     // The same instructions in reach_set, but purged from kDomain instructions
48     // and ordered according to their computation graph post-order, i.e.
49     // if instructions[pos_a] depends on instructions[pos_b], then pos_a >
50     // pos_b.
51     std::vector<HloInstruction*> instructions;
52 
53     // If we consider a graph edge as an arrow oriented from the operand to the
54     // user, the enter_domains will contain the set of kDomain instructions
55     // whose dataflow enters the reach set (domain), while the exit_domains
56     // contains the set of kDomain instructions whose dataflow exit the reach
57     // set.
58     absl::flat_hash_set<HloInstruction*> enter_domains;
59     absl::flat_hash_set<HloInstruction*> exit_domains;
60   };
61 
62   virtual ~DomainMetadata() = default;
63 
64   // Clones the metadata object.
65   virtual std::unique_ptr<DomainMetadata> Clone() const = 0;
66 
67   // Returns the metadata type. A unique identifier which describes the real
68   // metadata type.
69   virtual absl::string_view Kind() const = 0;
70 
71   // Compares the metadata object with another one and returns true if the
72   // two matches.
73   virtual bool Matches(const DomainMetadata& other) const = 0;
74 
75   // Returns the hash value of the metadata.
76   virtual size_t Hash() const = 0;
77 
78   // Returns a string representation of the metadata.
79   virtual string ToString() const = 0;
80 };
81 
82 }  // namespace xla
83 
84 #endif  // TENSORFLOW_COMPILER_XLA_SERVICE_HLO_DOMAIN_METADATA_H_
85