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

Method AddSubgraph

tensorflow/core/grappler/mutable_graph_view.cc:448–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

446}
447
448Status MutableGraphView::AddSubgraph(GraphDef&& subgraph) {
449 // 1. Add all new functions and check that functions with the same name
450 // have identical definition.
451 const int function_size = subgraph.library().function_size();
452 if (function_size > 0) {
453 absl::flat_hash_map<absl::string_view, const FunctionDef*> graph_fdefs;
454 for (const FunctionDef& fdef : graph()->library().function()) {
455 graph_fdefs.emplace(fdef.signature().name(), &fdef);
456 }
457
458 for (FunctionDef& fdef : *subgraph.mutable_library()->mutable_function()) {
459 const auto graph_fdef = graph_fdefs.find(fdef.signature().name());
460
461 if (graph_fdef == graph_fdefs.end()) {
462 VLOG(3) << "Add new function definition: " << fdef.signature().name();
463 graph()->mutable_library()->add_function()->Swap(&fdef);
464 } else {
465 if (!FunctionDefsEqual(fdef, *graph_fdef->second)) {
466 return MutationError(
467 "AddSubgraph",
468 absl::Substitute("function_size=$0", function_size),
469 absl::StrCat(
470 "Found different function definition with the same name: ",
471 fdef.signature().name()));
472 }
473 }
474 }
475 }
476
477 // 2. Add all nodes to the underlying graph.
478 int node_size_before = graph()->node_size();
479
480 for (NodeDef& node : *subgraph.mutable_node()) {
481 auto* node_in_graph = graph()->add_node();
482 node_in_graph->Swap(&node);
483 TF_RETURN_IF_ERROR(AddUniqueNode(node_in_graph));
484 }
485
486 // TODO(ezhulenev, lyandy): Right now AddAndDedupFanouts do not check that
487 // fanins actually exists in the graph, and there is already TODO for that.
488
489 for (int i = node_size_before; i < graph()->node_size(); ++i) {
490 NodeDef* node = graph()->mutable_node(i);
491 AddAndDedupFanouts(node);
492 }
493
494 return Status::OK();
495}
496
497Status MutableGraphView::UpdateNode(
498 absl::string_view node_name, absl::string_view op, absl::string_view device,

Callers 1

TESTFunction · 0.80

Calls 13

graphFunction · 0.85
FunctionDefsEqualFunction · 0.85
MutationErrorFunction · 0.85
signatureMethod · 0.80
nameMethod · 0.65
StrCatFunction · 0.50
libraryMethod · 0.45
functionMethod · 0.45
emplaceMethod · 0.45
findMethod · 0.45
endMethod · 0.45
SwapMethod · 0.45

Tested by 1

TESTFunction · 0.64