MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / CopySubgraphEdges

Method CopySubgraphEdges

tensorflow/compiler/jit/encapsulate_subgraphs_pass.cc:706–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

704}
705
706Status Encapsulator::CopySubgraphEdges(
707 const std::unordered_map<const Node*, Node*>& node_images,
708 std::vector<std::pair<const Node*, Node*>>* src_arg_pairs) {
709 for (const Edge* edge : graph_in_->edges()) {
710 string src_func_id;
711 TF_RETURN_IF_ERROR(GetFunctionNameAttr(edge->src(), &src_func_id));
712 string dst_func_id;
713 TF_RETURN_IF_ERROR(GetFunctionNameAttr(edge->dst(), &dst_func_id));
714 Node* src_image = gtl::FindWithDefault(node_images, edge->src(), nullptr);
715 Node* dst_image = gtl::FindWithDefault(node_images, edge->dst(), nullptr);
716
717 // Copy edges that are local to a subgraph.
718 if (IsInSubgraph(src_func_id) && IsInSubgraph(dst_func_id) &&
719 src_func_id == dst_func_id) {
720 Graph* g = subgraphs_[src_func_id].GetGraph();
721 if (edge->IsControlEdge()) {
722 g->AddControlEdge(src_image, dst_image,
723 /* allow_duplicates= */ true);
724 } else {
725 g->AddEdge(src_image, edge->src_output(), dst_image, edge->dst_input());
726 }
727 continue;
728 }
729
730 // Record 'src' as an output of its subgraph, if applicable.
731 if (IsInSubgraph(src_func_id)) {
732 if (!edge->IsControlEdge()) {
733 DataType dtype = edge->src()->output_type(edge->src_output());
734 if (IsRefType(dtype)) {
735 return errors::InvalidArgument(
736 "Ref Tensors (e.g., Variables) are not supported as results: "
737 "tensor ",
738 edge->src()->name(), ":", edge->src_output());
739 }
740 }
741
742 Subgraph& src_subgraph = subgraphs_[src_func_id];
743 if (edge->IsControlEdge()) {
744 TF_RETURN_IF_ERROR(src_subgraph.RecordControlResult(edge, node_images));
745 } else {
746 TF_RETURN_IF_ERROR(src_subgraph.RecordResult(edge, node_images));
747 }
748 }
749
750 // Record 'dst' as an input of its subgraph, if applicable.
751 if (IsInSubgraph(dst_func_id)) {
752 // Look at the type of the destination not the source, since Ref output
753 // Tensors can be automatically cast to non-Ref Tensors at the
754 // destination.
755 if (!edge->IsControlEdge()) {
756 DataType dtype = edge->dst()->input_type(edge->dst_input());
757 if (IsRefType(dtype)) {
758 return errors::InvalidArgument(
759 "Ref Tensors (e.g., Variables) are not supported as args: "
760 "tensor ",
761 edge->src()->name(), ":", edge->src_output());
762 }
763 }

Callers

nothing calls this directly

Calls 15

IsRefTypeFunction · 0.85
InvalidArgumentFunction · 0.85
edgesMethod · 0.80
IsInSubgraphFunction · 0.70
nameMethod · 0.65
srcMethod · 0.45
dstMethod · 0.45
GetGraphMethod · 0.45
IsControlEdgeMethod · 0.45
AddControlEdgeMethod · 0.45
AddEdgeMethod · 0.45
src_outputMethod · 0.45

Tested by

no test coverage detected