You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

draw.cc 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /**
  2. * Copyright 2019 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "debug/draw.h"
  17. #include <iostream>
  18. #include <map>
  19. #include <vector>
  20. #include <string>
  21. #include "ir/meta_func_graph.h"
  22. #include "utils/graph_utils.h"
  23. #include "utils/utils.h"
  24. #include "operator/composite/composite.h"
  25. #include "ir/meta_tensor.h"
  26. namespace mindspore {
  27. // namespace to support debug utils
  28. namespace draw {
  29. namespace {
  30. // Only for ValueNode
  31. std::string ValueType(const ValueNodePtr &node) {
  32. if (node == nullptr) {
  33. return "";
  34. }
  35. auto v = node->value();
  36. return v->type_name();
  37. }
  38. std::string ReplaceSpecialChar(const std::string &str) {
  39. std::ostringstream oss;
  40. for (size_t i = 0; i < str.size(); i++) {
  41. if (str[i] == '<') {
  42. oss << "「";
  43. } else if (str[i] == '>') {
  44. oss << "」";
  45. } else {
  46. oss << str[i];
  47. }
  48. }
  49. return oss.str();
  50. }
  51. } // namespace
  52. // API of debug utils
  53. void DrawNodes(const std::vector<AnfNodePtr> &nodes, OrderedMap<FuncGraphPtr, std::shared_ptr<BaseDigraph>> *sub_graphs,
  54. bool is_user) {
  55. if (sub_graphs == nullptr) {
  56. return;
  57. }
  58. for (auto &nd : nodes) {
  59. MS_EXCEPTION_IF_NULL(nd);
  60. auto sub_graph = nd->func_graph();
  61. if (sub_graph != nullptr) {
  62. auto gsub = (*sub_graphs)[sub_graph];
  63. if (gsub == nullptr) {
  64. if (is_user) {
  65. gsub = std::make_shared<ModelDigraph>(sub_graph->ToString());
  66. } else {
  67. gsub = std::make_shared<Digraph>(sub_graph->ToString());
  68. }
  69. (*sub_graphs)[sub_graph] = gsub;
  70. }
  71. if (!nd->isa<Parameter>()) {
  72. gsub->Node(nd);
  73. }
  74. }
  75. }
  76. }
  77. void DrawValueNodes(const std::vector<AnfNodePtr> &nodes,
  78. OrderedMap<FuncGraphPtr, std::shared_ptr<BaseDigraph>> *sub_graphs) {
  79. if (sub_graphs == nullptr) {
  80. return;
  81. }
  82. int dup_idx = 0;
  83. for (auto &nd : nodes) {
  84. for (auto &t : SuccIncoming(nd)) {
  85. MS_EXCEPTION_IF_NULL(t);
  86. MS_EXCEPTION_IF_NULL(nd);
  87. if (t->isa<ValueNode>() && (*sub_graphs).find(nd->func_graph()) != (*sub_graphs).end()) {
  88. (*sub_graphs)[nd->func_graph()]->Node(t, dup_idx);
  89. dup_idx++;
  90. } else if (t->isa<Parameter>() && (*sub_graphs).find(t->func_graph()) != (*sub_graphs).end()) {
  91. (*sub_graphs)[t->func_graph()]->Node(t, dup_idx);
  92. dup_idx++;
  93. }
  94. }
  95. }
  96. }
  97. void DrawEdges(const std::vector<AnfNodePtr> &nodes, const std::shared_ptr<BaseDigraph> &digraph, bool is_user) {
  98. if (digraph == nullptr) {
  99. return;
  100. }
  101. int dup_idx = 0;
  102. int offset = 0;
  103. if (is_user) {
  104. offset = 1;
  105. }
  106. // Draw edge
  107. for (auto &nd : nodes) {
  108. auto succs = SuccIncoming(nd);
  109. auto num = succs.size();
  110. for (size_t i = 0; i < num; i++) {
  111. auto &t = succs.at(i);
  112. MS_EXCEPTION_IF_NULL(t);
  113. if (t->isa<ValueNode>() || t->isa<Parameter>()) {
  114. if ((!is_user) || (i != 0)) {
  115. // `SizeToInt(i) - offset` is just for printing as text
  116. digraph->Edge(t, nd, SizeToInt(i) - offset, dup_idx);
  117. }
  118. if (IsValueNode<FuncGraph>(t)) {
  119. auto const_graph = GetValueNode<FuncGraphPtr>(t);
  120. digraph->Edge(t, const_graph, dup_idx);
  121. }
  122. dup_idx++;
  123. } else {
  124. digraph->Edge(t, nd, SizeToInt(i) - offset);
  125. }
  126. }
  127. }
  128. }
  129. void DrawByOpt(std::string filename, const FuncGraphPtr &func_graph, bool is_user) {
  130. if (func_graph == nullptr) {
  131. return;
  132. }
  133. auto ret = func_graph->get_return();
  134. auto nodes = DeepScopedGraphSearch(ret);
  135. std::shared_ptr<BaseDigraph> digraph;
  136. OrderedMap<FuncGraphPtr, std::shared_ptr<BaseDigraph>> sub_graphs;
  137. ChangeFileMode(filename, S_IRWXU);
  138. if (is_user) {
  139. digraph = std::make_shared<ModelDigraph>("mindspore", filename);
  140. } else {
  141. digraph = std::make_shared<Digraph>("mindspore", filename);
  142. }
  143. MS_EXCEPTION_IF_NULL(digraph);
  144. digraph->Start();
  145. // Draw nodes
  146. DrawNodes(nodes, &sub_graphs, is_user);
  147. // Draw ValueNodes on CNodes
  148. DrawValueNodes(nodes, &sub_graphs);
  149. // Draw subgraph
  150. for (const auto &gsub : sub_graphs) {
  151. digraph->SubGraph(gsub.first, gsub.second);
  152. }
  153. // Draw edge
  154. DrawEdges(nodes, digraph, is_user);
  155. digraph->End();
  156. // set file mode to read only by user
  157. ChangeFileMode(filename, S_IRUSR);
  158. }
  159. #ifdef ENABLE_DUMP_IR
  160. void Draw(const std::string &filename, const FuncGraphPtr &func_graph) {
  161. const std::string dot_suffix = ".dot";
  162. std::string filename_with_suffix =
  163. (filename.rfind(dot_suffix) != (filename.size() - dot_suffix.size())) ? (filename + dot_suffix) : filename;
  164. DrawByOpt(filename_with_suffix, func_graph, false);
  165. }
  166. void DrawUserFuncGraph(const std::string &filename, const FuncGraphPtr &func_graph) {
  167. DrawByOpt(filename, func_graph, true);
  168. }
  169. #else
  170. void Draw(const std::string &, const FuncGraphPtr &) {
  171. static bool already_printed = false;
  172. if (already_printed) {
  173. return;
  174. }
  175. already_printed = true;
  176. MS_LOG(WARNING) << "The functionality of dumping function graph IR in graphviz dot format is disabled, "
  177. << "please recompile source to enable it. See help of building script.";
  178. }
  179. void DrawUserFuncGraph(const std::string &, const FuncGraphPtr &) {
  180. static bool already_printed = false;
  181. if (already_printed) {
  182. return;
  183. }
  184. already_printed = true;
  185. MS_LOG(WARNING) << "The functionality of dumping function graph IR in graphviz dot format is disabled, "
  186. << "please recompile source to enable it. See help of building script.";
  187. }
  188. #endif
  189. std::string Graphviz::Shape(AnfNodePtr node) {
  190. if (node == nullptr) {
  191. return "";
  192. }
  193. if (node->isa<CNode>()) {
  194. return "plaintext";
  195. }
  196. if (node->isa<Parameter>()) {
  197. return "octagon";
  198. }
  199. if (IsValueNode<FuncGraph>(node)) {
  200. return "oval";
  201. }
  202. return "plaintext";
  203. }
  204. std::string Graphviz::Color(const AnfNodePtr &node) {
  205. if (node == nullptr) {
  206. return "";
  207. }
  208. if (node->isa<CNode>()) {
  209. return "cornsilk";
  210. }
  211. if (node->isa<Parameter>()) {
  212. return "paleturquoise";
  213. }
  214. if (IsValueNode<FuncGraph>(node)) {
  215. return "palegreen";
  216. }
  217. return "lavender";
  218. }
  219. void BaseDigraph::Start() {
  220. buffer_ << "digraph " << name_ << " {" << std::endl;
  221. buffer_ << "compound=true" << std::endl;
  222. }
  223. void BaseDigraph::Head(const AnfNodePtr &node, int id) {
  224. if (node == nullptr) {
  225. return;
  226. }
  227. buffer_ << "node" << node << "_" << id;
  228. if (node->isa<CNode>() || (node->isa<ValueNode>() && !IsValueNode<FuncGraph>(node))) {
  229. buffer_ << ":core";
  230. }
  231. }
  232. void BaseDigraph::Tail(const AnfNodePtr &node, int idx, int id) {
  233. if (node == nullptr) {
  234. return;
  235. }
  236. buffer_ << "node" << node << "_" << id;
  237. buffer_ << ":" << idx;
  238. }
  239. void BaseDigraph::Tail(const FuncGraphPtr &func_graph) {
  240. if (func_graph == nullptr) {
  241. return;
  242. }
  243. buffer_ << "node" << func_graph->get_return() << "_" << 0;
  244. }
  245. void BaseDigraph::Edge(AnfNodePtr start, FuncGraphPtr end, int id_start) {
  246. Head(start, id_start);
  247. buffer_ << "->";
  248. Tail(end);
  249. buffer_ << "[lhead=cluster_" << end;
  250. buffer_ << ",dir=both,arrowhead=dot,style=filled,color=blue]";
  251. buffer_ << std::endl;
  252. }
  253. void BaseDigraph::End() {
  254. buffer_ << "}" << std::endl;
  255. if (fout_.is_open()) {
  256. fout_ << buffer_.str();
  257. }
  258. }
  259. void BaseDigraph::FuncGraphParameters(const FuncGraphPtr &key) {
  260. buffer_ << "parameters_" << key << "[shape=plaintext ";
  261. buffer_ << "label=<<table bgcolor='paleturquoise' cellspacing='0' cellborder='1' border='0'>";
  262. buffer_ << "<tr><td>parameters</td></tr>";
  263. int count = 0;
  264. for (auto &parameter : key->parameters()) {
  265. buffer_ << "<tr><td>";
  266. buffer_ << parameter->ToString();
  267. auto py_p = dyn_cast<Parameter>(parameter)->default_param();
  268. if (py::hasattr(py_p, "default_input")) {
  269. py_p = py_p.attr("default_input");
  270. if (py::hasattr(py_p, PYTHON_TENSOR_FLAG)) {
  271. std::shared_ptr<tensor::Tensor> m_tensor = py_p.cast<std::shared_ptr<tensor::Tensor>>();
  272. py::tuple shape = m_tensor->GetPyTupleShape();
  273. buffer_ << "[" << std::string(py::str(shape)) << "]";
  274. }
  275. }
  276. buffer_ << "</td></tr>";
  277. count++;
  278. // wrap the text.
  279. if (count % 10 == 0) {
  280. buffer_ << "\n";
  281. }
  282. }
  283. buffer_ << "</table>>,];";
  284. }
  285. void BaseDigraph::SubGraph(const FuncGraphPtr &key, const std::shared_ptr<BaseDigraph> &gsub) {
  286. if (key == nullptr || gsub == nullptr) {
  287. return;
  288. }
  289. std::string label = key->debug_info()->get_full_name();
  290. if (label.empty()) {
  291. label = gsub->name();
  292. }
  293. std::string label_managed = "[managed]";
  294. if (key->manager() == nullptr) {
  295. label_managed = "[not managed]";
  296. }
  297. label += label_managed;
  298. gsub->FuncGraphParameters(key);
  299. buffer_ << "subgraph cluster_" << key << "{" << std::endl;
  300. buffer_ << "id=cluster_" << key << std::endl;
  301. buffer_ << "label=\"" << label << "\"" << std::endl;
  302. buffer_ << "fontname=\"Courier New\"" << std::endl;
  303. buffer_ << gsub->buffer().str();
  304. buffer_ << "}" << std::endl;
  305. }
  306. Digraph::~Digraph() {
  307. try {
  308. if (fout_.is_open()) {
  309. fout_.close();
  310. }
  311. } catch (const std::exception &e) {
  312. MS_LOG(ERROR) << "Exception when closing file " << filename_;
  313. }
  314. }
  315. static std::string ReplaceAll(std::string str, const std::string &from, const std::string &to) {
  316. size_t start_pos = 0;
  317. while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
  318. (void)str.replace(start_pos, from.length(), to);
  319. start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
  320. }
  321. return str;
  322. }
  323. static void DrawValueNode(Graphviz *const graph_obj, const ValueNodePtr &node) {
  324. MS_EXCEPTION_IF_NULL(graph_obj);
  325. graph_obj->buffer() << "label=<<table port='core' cellborder='0' cellspacing='2' bgcolor='" << graph_obj->Color(node)
  326. << "'>";
  327. graph_obj->buffer() << "<tr><td bgcolor='white'>";
  328. graph_obj->buffer() << ValueType(node);
  329. graph_obj->buffer() << "</td></tr>";
  330. graph_obj->buffer() << "<tr><td>";
  331. if (IsValueNode<MetaFuncGraph>(node)) {
  332. graph_obj->buffer() << node->value()->cast<MetaFuncGraphPtr>()->name();
  333. } else if (IsValueNode<parse::NameSpace>(node)) {
  334. graph_obj->buffer() << node->value()->cast<parse::NameSpacePtr>()->name();
  335. } else if (IsValueNode<parse::Symbol>(node)) {
  336. graph_obj->buffer() << ReplaceSpecialChar(node->value()->cast<parse::SymbolPtr>()->name());
  337. } else {
  338. std::ostringstream ss;
  339. ss << node->value()->ToString();
  340. std::string s = ReplaceAll(ss.str(), ", ", "<br/>");
  341. graph_obj->buffer() << s;
  342. ValuePtr value = node->value();
  343. if (value->isa<Primitive>()) {
  344. PrimitivePtr primitive = value->cast<PrimitivePtr>();
  345. graph_obj->buffer() << "</td></tr>";
  346. graph_obj->buffer() << "<tr><td align='left'>";
  347. if (!primitive->instance_name().empty()) {
  348. graph_obj->buffer() << "instance name:"
  349. << " ";
  350. graph_obj->buffer() << primitive->instance_name();
  351. graph_obj->buffer() << "<br/>";
  352. }
  353. auto attrs = primitive->attrs();
  354. if (attrs.size() > 0) {
  355. graph_obj->buffer() << "</td></tr>";
  356. graph_obj->buffer() << "<tr><td align='left'>";
  357. int i = 0;
  358. for (const auto &attr : attrs) {
  359. if (i != 0) {
  360. graph_obj->buffer() << "<br/>";
  361. }
  362. graph_obj->buffer() << attr.first << " ";
  363. graph_obj->buffer() << attr.second->ToString();
  364. i++;
  365. }
  366. }
  367. }
  368. }
  369. graph_obj->buffer() << "</td></tr>";
  370. graph_obj->buffer() << "</table>>,";
  371. }
  372. static void DrawParallelInfo(Graphviz *const graph_obj, const CNodePtr &node) {
  373. if (graph_obj == nullptr || node == nullptr) {
  374. return;
  375. }
  376. auto distributed_operation_info = node->operator_info();
  377. if (distributed_operation_info != nullptr) {
  378. auto strategyPtr = distributed_operation_info->strategy();
  379. if (strategyPtr != nullptr) {
  380. auto num = node->inputs().size();
  381. graph_obj->buffer() << "<tr><td colspan='" << num << "' ";
  382. graph_obj->buffer() << "bgcolor='" << graph_obj->Color(node) << "'>";
  383. std::vector<ValuePtr> temp = {MakeValue(strategyPtr->GetInputStage()), MakeValue(strategyPtr->GetInputDim())};
  384. ValueTuplePtr strategy_tuple = std::make_shared<ValueTuple>(temp);
  385. graph_obj->buffer() << "Strategy " << strategy_tuple->ToString();
  386. graph_obj->buffer() << "</td></tr>" << std::endl;
  387. }
  388. }
  389. }
  390. static void DrawCNode(Graphviz *const graph_obj, const CNodePtr &node) {
  391. if (graph_obj == nullptr || node == nullptr || node->size() == 0) {
  392. return;
  393. }
  394. auto num = node->size();
  395. bool is_modelgraph = false;
  396. if (typeid(*graph_obj) == typeid(ModelDigraph)) {
  397. is_modelgraph = true;
  398. num -= 1;
  399. }
  400. graph_obj->buffer() << "label=<<table port='core'>" << std::endl;
  401. // Draw ports for CNode
  402. if (num > 0) {
  403. graph_obj->buffer() << "<tr>";
  404. for (size_t i = 0; i < num; i++) {
  405. graph_obj->buffer() << "<td port='" << i << "'>" << i << "</td>";
  406. }
  407. graph_obj->buffer() << "</tr>" << std::endl;
  408. }
  409. // Draw op name
  410. graph_obj->buffer() << "<tr><td";
  411. if (num > 0) {
  412. graph_obj->buffer() << " colspan='" << num << "'";
  413. }
  414. graph_obj->buffer() << " bgcolor='" << graph_obj->Color(node) << "'>";
  415. if (IsValueNode<Primitive>(node->input(0)) && is_modelgraph) {
  416. auto primitive = GetValueNode<PrimitivePtr>(node->input(0));
  417. graph_obj->buffer() << ReplaceAll(primitive->ToString(), ", ", "<br/>");
  418. auto attrs = primitive->attrs();
  419. if (attrs.size() > 0) {
  420. graph_obj->buffer() << "</td></tr>" << std::endl << "<tr><td";
  421. // Draw attrs
  422. if (num > 0) {
  423. graph_obj->buffer() << " colspan='" << num << "'";
  424. }
  425. graph_obj->buffer() << ">";
  426. int i = 0;
  427. for (auto &attr : attrs) {
  428. if (i != 0) {
  429. graph_obj->buffer() << "<br/>";
  430. }
  431. graph_obj->buffer() << attr.first << " " << attr.second->ToString();
  432. i++;
  433. }
  434. }
  435. graph_obj->buffer() << "CNode";
  436. } else {
  437. graph_obj->buffer() << "CNode(" << node->ToString() << ")";
  438. }
  439. graph_obj->buffer() << "</td></tr>" << std::endl;
  440. DrawParallelInfo(graph_obj, node);
  441. graph_obj->buffer() << "</table>>,";
  442. }
  443. void Digraph::Node(AnfNodePtr node, int id) {
  444. if (node == nullptr) {
  445. return;
  446. }
  447. buffer_ << "node" << node << "_" << id;
  448. buffer_ << "[";
  449. // set fontname
  450. buffer_ << "fontname=\"Courier New\",";
  451. // set label and shape
  452. buffer_ << "shape=" << Shape(node) << ",";
  453. if (node->isa<CNode>()) {
  454. DrawCNode(this, node->cast<CNodePtr>());
  455. } else if (node->isa<ValueNode>() && !IsValueNode<FuncGraph>(node)) {
  456. DrawValueNode(this, node->cast<ValueNodePtr>());
  457. } else {
  458. buffer_ << "label=\"" << node->ToString();
  459. if (IsValueNode<FuncGraph>(node)) {
  460. FuncGraphPtr nextNet = GetValueNode<FuncGraphPtr>(node);
  461. std::string nextNetName = nextNet->debug_info()->get_full_name();
  462. if (!nextNetName.empty()) {
  463. buffer_ << "[" << nextNet->debug_info()->get_full_name().c_str() << "]";
  464. }
  465. }
  466. buffer_ << "\","
  467. << "style=filled,fillcolor=" << Color(node) << ",";
  468. }
  469. // Set URL for func graph
  470. if (IsValueNode<FuncGraph>(node)) {
  471. buffer_ << "URL=\"#cluster_" << GetValueNode(node) << "\",";
  472. }
  473. buffer_ << "]" << std::endl;
  474. }
  475. void Digraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) {
  476. if (start == nullptr || end == nullptr) {
  477. return;
  478. }
  479. Head(start, id_start);
  480. buffer_ << "->";
  481. Tail(end, idx);
  482. buffer_ << "[arrowhead=vee,";
  483. // check how many inputs for end
  484. if (end->isa<CNode>()) {
  485. auto cnode = end->cast<CNodePtr>();
  486. MS_EXCEPTION_IF_NULL(cnode);
  487. auto num = cnode->inputs().size();
  488. if (idx == 0 && num > 1) {
  489. buffer_ << "style=dashed";
  490. }
  491. }
  492. buffer_ << "]" << std::endl;
  493. }
  494. ModelDigraph::~ModelDigraph() {
  495. try {
  496. if (fout_.is_open()) {
  497. fout_.close();
  498. }
  499. } catch (const std::exception &e) {
  500. MS_LOG(ERROR) << "exception when closing file " << filename_;
  501. }
  502. }
  503. std::string ModelDigraph::Shape(AnfNodePtr node) {
  504. if (node == nullptr) {
  505. return "";
  506. }
  507. if (node->isa<CNode>()) {
  508. return "plaintext";
  509. }
  510. if (node->isa<Parameter>()) {
  511. return "ellipse";
  512. }
  513. if (IsValueNode<FuncGraph>(node)) {
  514. return "oval";
  515. }
  516. return "plaintext";
  517. }
  518. void ModelDigraph::Node(AnfNodePtr node, int id) {
  519. if (node == nullptr) {
  520. return;
  521. }
  522. if (IsValueNode<Primitive>(node)) {
  523. return;
  524. }
  525. buffer_ << "node" << node << "_" << id;
  526. buffer_ << "[";
  527. // set fontname
  528. buffer_ << "fontname=\"Courier New\",";
  529. // set label and shape
  530. buffer_ << "shape=" << Shape(node) << ",";
  531. if (node->isa<CNode>()) {
  532. DrawCNode(this, node->cast<CNodePtr>());
  533. } else if (node->isa<ValueNode>() && !IsValueNode<FuncGraph>(node)) {
  534. DrawValueNode(this, node->cast<ValueNodePtr>());
  535. } else {
  536. buffer_ << "label=\"" << node->ToString() << "\",";
  537. buffer_ << "style=filled,fillcolor=" << Color(node) << ",";
  538. }
  539. // Set URL for func graph
  540. if (IsValueNode<FuncGraph>(node)) {
  541. buffer_ << "URL=\"#cluster_" << GetValueNode(node) << "\",";
  542. }
  543. buffer_ << "]" << std::endl;
  544. }
  545. void ModelDigraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) {
  546. if (start == nullptr || end == nullptr) {
  547. return;
  548. }
  549. Head(start, id_start);
  550. buffer_ << "->";
  551. Tail(end, idx);
  552. buffer_ << "[arrowhead=vee,";
  553. buffer_ << "]" << std::endl;
  554. }
  555. } // namespace draw
  556. } // namespace mindspore