MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / operator()

Method operator()

tensorflow/compiler/jit/extract_outside_compilation_pass.cc:2026–2128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2024} // namespace
2025
2026Status RewriteOutsideCompilationSubgraphFn::operator()(
2027 const std::vector<OutputTensor>& arg_source_tensors,
2028 std::unique_ptr<Graph>* graph, std::vector<int>* input_permutation,
2029 std::vector<int>* output_permutation, NodeDef* node_def) {
2030 string old_name = node_def->op();
2031 string new_name =
2032 absl::StrCat(xla_cluster_name_, "_", new_function_name_, "_", old_name);
2033 node_def->set_op(new_name);
2034 node_def->set_name(new_name);
2035
2036 // Later we will run PruneForReverseReachability(), so make sure all original
2037 // nodes are reachable from sink node and won't be removed.
2038 FixupSourceAndSinkEdges(graph->get());
2039
2040 // Step 1: create a key placeholder node.
2041 TF_ASSIGN_OR_RETURN(
2042 Node * key_placeholder,
2043 AddHostComputeKeyPlaceholder(xla_cluster_name_, graph->get()));
2044
2045 // Step 2: build RecvAtHost node, and replace all _Arg nodes with it.
2046 std::vector<DataType> recv_at_host_dtypes;
2047 TF_ASSIGN_OR_RETURN(
2048 Node * recv_at_host_node,
2049 ReplaceArgNodesWithRecvAtHostNode(graph->get(), new_name,
2050 &recv_at_host_dtypes, key_placeholder));
2051
2052 // Step 3: build SendFromHost node, and replace all _Retval nodes with it.
2053 std::vector<DataType> send_from_host_dtypes;
2054 TF_ASSIGN_OR_RETURN(
2055 Node * send_from_host_node,
2056 ReplaceRetNodesWithSendFromHostNode(
2057 graph->get(), new_name, &send_from_host_dtypes, key_placeholder));
2058
2059 // Step 4: add XLA cluster and outside compilation attr.
2060 for (Node* n : (*graph)->nodes()) {
2061 if (IsKeyPlaceholderNode(*n)) {
2062 continue;
2063 }
2064
2065 n->AddAttr(xla_cluster_attr_name_, xla_cluster_name_);
2066 n->AddAttr(outside_compilation_attr_name_, old_name);
2067 }
2068
2069 // Check whether we have all input shapes for XlaSendFromHost. If we do, we
2070 // will set `shapes` attr for the call node; otherwise we will save the
2071 // shape inference graph and set `shape_inference_graph` for the call node.
2072 absl::optional<std::vector<PartialTensorShape>> shapes =
2073 GetInferredInputShapes(send_from_host_dtypes.size(), send_from_host_node);
2074 for (Node* n : (*graph)->nodes()) {
2075 n->ClearAttr(kXlaInferredShapesAttrName);
2076 }
2077
2078 // Step 5: add control edges for originally XLA <-> outside compilation
2079 // control edges.
2080 for (Node* n : (*graph)->nodes()) {
2081 if (HasNodeAttr(n->def(), kXlaConnectedToXlaComputationAttrName)) {
2082 (*graph)->AddControlEdge(n, send_from_host_node);
2083 n->ClearAttr(kXlaConnectedToXlaComputationAttrName);

Callers

nothing calls this directly

Calls 15

FixupSourceAndSinkEdgesFunction · 0.85
IsKeyPlaceholderNodeFunction · 0.85
GetInferredInputShapesFunction · 0.85
set_opMethod · 0.80
AddAttrMethod · 0.80
ClearAttrMethod · 0.80
StrCatFunction · 0.50
TF_ASSIGN_OR_RETURNFunction · 0.50

Tested by

no test coverage detected