1 /* Copyright 2017 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_TF2XLA_UTIL_H_ 17 #define TENSORFLOW_COMPILER_TF2XLA_TF2XLA_UTIL_H_ 18 19 #include <unordered_map> 20 21 #include "tensorflow/compiler/tf2xla/tf2xla.pb.h" 22 #include "tensorflow/core/framework/graph.pb.h" 23 #include "tensorflow/core/framework/op.h" 24 #include "tensorflow/core/graph/graph.h" 25 #include "tensorflow/core/lib/core/status.h" 26 27 namespace tensorflow { 28 29 // ValidateConfig returns OK iff config is valid. 30 Status ValidateConfig(const tf2xla::Config& config); 31 32 // Modifies <graph_def> to include placeholders for each fed tensor, and 33 // update references to the fed tensors to refer to the placeholders. 34 // The existing nodes referenced by the feeds are not removed or modified 35 // (except where their input edges are modified by the replacement of other 36 // feeds). 37 Status AddPlaceholdersForFeeds( 38 const tf2xla::Config& config, const OpRegistryInterface* op_registry, 39 std::unordered_map<string, string>* feed_remapping, GraphDef* graph_def); 40 41 // Returns in <out> a copy of <in>, pruned to only include fetches from 42 // <config>. 43 Status PruneGraphDefInto(const tf2xla::Config& config, const GraphDef& in, 44 GraphDef* out); 45 46 // Returns node:port for the given <id>. 47 string TensorIdToString(const tf2xla::TensorId& id); 48 49 // Updates the sharding of <n> based on the sharding of its neighbors. 50 // If <out_edges> is true, outgoing edges from <n> are considered; else incoming 51 // edges are considered. 52 Status SetNodeShardingFromNeighbors(Node* n, bool out_edges); 53 54 } // namespace tensorflow 55 56 #endif // TENSORFLOW_COMPILER_TF2XLA_TF2XLA_UTIL_H_ 57