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

Function DescribeCycle

tensorflow/compiler/jit/cuda_graph_mode_cluster_util.cc:43–79  ·  view source on GitHub ↗

Returns a string describing how an edge from src to dst would create a cycle.

Source from the content-addressed store, hash-verified

41// Returns a string describing how an edge from src to dst would
42// create a cycle.
43string DescribeCycle(const GraphCycles* cycles, const Graph& graph, int src,
44 int dst) {
45 int32 max_path_size = graph.num_node_ids() + 1;
46 std::vector<int32> path(max_path_size);
47 int32 path_size = cycles->FindPath(dst, src, max_path_size, path.data());
48 if (path_size == 0) {
49 return "";
50 }
51
52 auto node_name = [&graph](int node_id) {
53 if (!FastBoundsCheck(node_id, graph.num_node_ids())) {
54 return string("(null)");
55 }
56 auto* node = graph.FindNodeId(node_id);
57 if (node == nullptr) {
58 return string("(null)");
59 }
60 return node->name();
61 };
62
63 string description;
64 absl::StrAppend(&description, "Edge from ", node_name(src), " to ",
65 node_name(dst), " would create a cycle.\n");
66 path.resize(path_size);
67 for (int32 node_id : path) {
68 string ascii_art;
69 if (node_id == dst) {
70 ascii_art = "+-> ";
71 } else if (node_id != src) {
72 ascii_art = "| ";
73 } else {
74 ascii_art = "+-- ";
75 }
76 absl::StrAppend(&description, ascii_art, node_name(node_id), "\n");
77 }
78 return description;
79}
80
81bool AlwaysForwardsRefInput(const Node& node) { return node.IsIdentity(); }
82

Callers

nothing calls this directly

Calls 8

FastBoundsCheckFunction · 0.85
FindPathMethod · 0.80
nameMethod · 0.65
StrAppendFunction · 0.50
num_node_idsMethod · 0.45
dataMethod · 0.45
FindNodeIdMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected