• 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_SIDE_EFFECT_UTIL_H_
17 #define TENSORFLOW_COMPILER_TF2XLA_SIDE_EFFECT_UTIL_H_
18 
19 #include <vector>
20 
21 #include "tensorflow/core/graph/graph.h"
22 
23 namespace tensorflow {
24 
25 // Side-effecting nodes will have this attribute set. Its value is the list of
26 // node names which this node has side-effect dependencies on.
27 //
28 // Nodes like HostCompute, SendToHost, RecvFromHost always have this attribute,
29 // because they always have side-effect.
30 // If and While nodes may or may not have this attribute, depending on whether
31 // their bodies have side-effecting nodes.
32 extern const char kXlaTokenInputNodesAttrName[];
33 
34 // This node name is used in kXlaTokenInputNodesAttrName attr to signal that a
35 // node has side-effect dependency on current graph's token input.
36 extern const char kXlaTokenArgNodeName[];
37 
38 // This node have XlaRecvAtHost/XlaSendFromHost in its associated functions.
39 extern const char kXlaHasHostTransferAttrName[];
40 
41 // This attribute is the replica id for an outside compilation node node.
42 extern const char kXlaReplicaIdAttrName[];
43 
44 // This node is a Placeholder node added for tail outside compilation.
45 extern const char kXlaIsPlaceholderForTailOcAttrName[];
46 
47 // This attribute is the original node name for this node.
48 extern const char kXlaOriginalOutsideCompilationNodeName[];
49 
50 // Sets device ordinal attribute for nodes with attribute
51 // `kXlaHasHostTransferAttrName`.
52 Status SetDeviceOrdinalAttributeForNode(Node* node, int device_ordinal);
53 
54 // Calculates side-effect dependencies for the graph's token output.
55 // Returns a set of node names representing these dependencies.
56 std::set<std::string> CalculateTokenInputsForOutputToken(const Graph& g);
57 
58 // Returns whether a graph contains side-effecting nodes.
59 bool HasSideEffectingNodes(const Graph& g);
60 
61 // Parse the mapping from outside_compilation_subgraph name to core number,
62 // which is specified in an attr as a list of strings
63 // <subgraph_name>:<core_index>.
64 Status ParseHostComputeCoreList(absl::Span<const string> list_from_attr,
65                                 std::map<string, int>* host_compute_core);
66 
67 }  // namespace tensorflow
68 
69 #endif  // TENSORFLOW_COMPILER_TF2XLA_SIDE_EFFECT_UTIL_H_
70