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

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