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 // Sets device ordinal attribute for nodes with attribute 42 // `kXlaHasHostTransferAttrName`. 43 Status SetDeviceOrdinalAttributeForNode(Node* node, int device_ordinal); 44 45 // Calculates side-effect dependencies for the graph's token output. 46 // Returns a set of node names representing these dependencies. 47 std::set<std::string> CalculateTokenInputsForOutputToken(const Graph& g); 48 49 // Returns whether a graph contains side-effecting nodes. 50 bool HasSideEffectingNodes(const Graph& g); 51 52 // Parse the mapping from outside_compilation_subgraph name to core number, 53 // which is specified in an attr as a list of strings 54 // <subgraph_name>:<core_index>. 55 Status ParseHostComputeCoreList(absl::Span<const string> list_from_attr, 56 std::map<string, int>* host_compute_core); 57 58 } // namespace tensorflow 59 60 #endif // TENSORFLOW_COMPILER_TF2XLA_SIDE_EFFECT_UTIL_H_ 61