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 19 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  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 <map>
  21. #include <vector>
  22. #include <string>
  23. #include "pybind11/pybind11.h"
  24. #include "ir/meta_func_graph.h"
  25. #include "ir/param_value_py.h"
  26. #include "ir/primitive.h"
  27. #include "utils/graph_utils.h"
  28. #include "utils/utils.h"
  29. #include "operator/composite/composite.h"
  30. #include "ir/tensor.h"
  31. namespace py = pybind11;
  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 : SuccIncoming(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 = SuccIncoming(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(filename_with_suffix, func_graph, false);
  171. }
  172. void DrawUserFuncGraph(const std::string &filename, const FuncGraphPtr &func_graph) {
  173. DrawByOpt(filename, 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 param_value = std::dynamic_pointer_cast<ParamValuePy>(param->default_param());
  276. auto py_p = param_value->value();
  277. if (py::hasattr(py_p, "default_input")) {
  278. py_p = py_p.attr("default_input");
  279. std::vector<int> shape;
  280. if (py::hasattr(py_p, PYTHON_TENSOR_FLAG)) {
  281. auto m_tensor = py_p.cast<std::shared_ptr<tensor::Tensor>>();
  282. shape = m_tensor->shape();
  283. } else if (py::hasattr(py_p, PYTHON_META_TENSOR_FLAG)) {
  284. auto m_tensor = py_p.cast<std::shared_ptr<tensor::MetaTensor>>();
  285. shape = m_tensor->shape();
  286. }
  287. std::ostringstream shape_str;
  288. std::copy(shape.begin(), shape.end(), std::ostream_iterator<int>(shape_str, ","));
  289. buffer_ << "[" << shape_str.str() << "]";
  290. }
  291. }
  292. buffer_ << "</td></tr>";
  293. count++;
  294. // wrap the text.
  295. if (count % 10 == 0) {
  296. buffer_ << "\n";
  297. }
  298. }
  299. buffer_ << "</table>>,];";
  300. }
  301. void BaseDigraph::SubGraph(const FuncGraphPtr &key, const std::shared_ptr<BaseDigraph> &gsub) {
  302. if (key == nullptr || gsub == nullptr) {
  303. return;
  304. }
  305. std::string label = key->debug_info()->get_full_name();
  306. if (label.empty()) {
  307. label = gsub->name();
  308. }
  309. std::string label_managed = "[managed]";
  310. if (key->manager() == nullptr) {
  311. label_managed = "[not managed]";
  312. }
  313. label += label_managed;
  314. gsub->FuncGraphParameters(key);
  315. buffer_ << "subgraph cluster_" << key << "{" << std::endl;
  316. buffer_ << "id=cluster_" << key << std::endl;
  317. buffer_ << "label=\"" << label << "\"" << std::endl;
  318. buffer_ << "fontname=\"Courier New\"" << std::endl;
  319. buffer_ << gsub->buffer().str();
  320. buffer_ << "}" << std::endl;
  321. }
  322. Digraph::~Digraph() {
  323. try {
  324. if (fout_.is_open()) {
  325. fout_.close();
  326. }
  327. } catch (const std::exception &e) {
  328. MS_LOG(ERROR) << "Exception when closing file " << filename_;
  329. }
  330. }
  331. static std::string ReplaceAll(std::string str, const std::string &from, const std::string &to) {
  332. size_t start_pos = 0;
  333. while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
  334. (void)str.replace(start_pos, from.length(), to);
  335. start_pos += to.length(); // Handles case where 'to' is a substring of 'from'
  336. }
  337. return str;
  338. }
  339. static void DrawValueNode(Graphviz *const graph_obj, const ValueNodePtr &node) {
  340. MS_EXCEPTION_IF_NULL(graph_obj);
  341. graph_obj->buffer() << "label=<<table port='core' cellborder='0' cellspacing='2' bgcolor='" << graph_obj->Color(node)
  342. << "'>";
  343. graph_obj->buffer() << "<tr><td bgcolor='white'>";
  344. graph_obj->buffer() << ValueType(node);
  345. graph_obj->buffer() << "</td></tr>";
  346. graph_obj->buffer() << "<tr><td>";
  347. if (IsValueNode<MetaFuncGraph>(node)) {
  348. graph_obj->buffer() << node->value()->cast<MetaFuncGraphPtr>()->name();
  349. } else if (IsValueNode<parse::NameSpace>(node)) {
  350. graph_obj->buffer() << node->value()->cast<parse::NameSpacePtr>()->name();
  351. } else if (IsValueNode<parse::Symbol>(node)) {
  352. graph_obj->buffer() << ReplaceSpecialChar(node->value()->cast<parse::SymbolPtr>()->name());
  353. } else {
  354. std::ostringstream ss;
  355. ss << node->value()->ToString();
  356. std::string s = ReplaceAll(ss.str(), ", ", "<br/>");
  357. graph_obj->buffer() << s;
  358. ValuePtr value = node->value();
  359. if (value->isa<Primitive>()) {
  360. PrimitivePtr primitive = value->cast<PrimitivePtr>();
  361. graph_obj->buffer() << "</td></tr>";
  362. graph_obj->buffer() << "<tr><td align='left'>";
  363. if (!primitive->instance_name().empty()) {
  364. graph_obj->buffer() << "instance name:"
  365. << " ";
  366. graph_obj->buffer() << primitive->instance_name();
  367. graph_obj->buffer() << "<br/>";
  368. }
  369. auto attrs = primitive->attrs();
  370. if (attrs.size() > 0) {
  371. graph_obj->buffer() << "</td></tr>";
  372. graph_obj->buffer() << "<tr><td align='left'>";
  373. int i = 0;
  374. for (const auto &attr : attrs) {
  375. if (i != 0) {
  376. graph_obj->buffer() << "<br/>";
  377. }
  378. graph_obj->buffer() << attr.first << " ";
  379. graph_obj->buffer() << attr.second->ToString();
  380. i++;
  381. }
  382. }
  383. }
  384. }
  385. graph_obj->buffer() << "</td></tr>";
  386. graph_obj->buffer() << "</table>>,";
  387. }
  388. static void DrawParallelInfo(Graphviz *const graph_obj, const CNodePtr &node) {
  389. if (graph_obj == nullptr || node == nullptr) {
  390. return;
  391. }
  392. auto distributed_operation_info = node->operator_info();
  393. if (distributed_operation_info != nullptr) {
  394. auto strategyPtr = distributed_operation_info->strategy();
  395. if (strategyPtr != nullptr) {
  396. auto num = node->inputs().size();
  397. graph_obj->buffer() << "<tr><td colspan='" << num << "' ";
  398. graph_obj->buffer() << "bgcolor='" << graph_obj->Color(node) << "'>";
  399. std::vector<ValuePtr> temp = {MakeValue(strategyPtr->GetInputStage()), MakeValue(strategyPtr->GetInputDim())};
  400. ValueTuplePtr strategy_tuple = std::make_shared<ValueTuple>(temp);
  401. graph_obj->buffer() << "Strategy " << strategy_tuple->ToString();
  402. graph_obj->buffer() << "</td></tr>" << std::endl;
  403. }
  404. }
  405. }
  406. static void DrawCNode(Graphviz *const graph_obj, const CNodePtr &node) {
  407. if (graph_obj == nullptr || node == nullptr || node->size() == 0) {
  408. return;
  409. }
  410. auto num = node->size();
  411. bool is_modelgraph = false;
  412. if (typeid(*graph_obj) == typeid(ModelDigraph)) {
  413. is_modelgraph = true;
  414. num -= 1;
  415. }
  416. graph_obj->buffer() << "label=<<table port='core'>" << std::endl;
  417. // Draw ports for CNode
  418. if (num > 0) {
  419. graph_obj->buffer() << "<tr>";
  420. for (size_t i = 0; i < num; i++) {
  421. graph_obj->buffer() << "<td port='" << i << "'>" << i << "</td>";
  422. }
  423. graph_obj->buffer() << "</tr>" << std::endl;
  424. }
  425. // Draw op name
  426. graph_obj->buffer() << "<tr><td";
  427. if (num > 0) {
  428. graph_obj->buffer() << " colspan='" << num << "'";
  429. }
  430. graph_obj->buffer() << " bgcolor='" << graph_obj->Color(node) << "'>";
  431. if (IsValueNode<Primitive>(node->input(0)) && is_modelgraph) {
  432. auto primitive = GetValueNode<PrimitivePtr>(node->input(0));
  433. graph_obj->buffer() << ReplaceAll(primitive->ToString(), ", ", "<br/>");
  434. auto attrs = primitive->attrs();
  435. if (attrs.size() > 0) {
  436. graph_obj->buffer() << "</td></tr>" << std::endl << "<tr><td";
  437. // Draw attrs
  438. if (num > 0) {
  439. graph_obj->buffer() << " colspan='" << num << "'";
  440. }
  441. graph_obj->buffer() << ">";
  442. int i = 0;
  443. for (auto &attr : attrs) {
  444. if (i != 0) {
  445. graph_obj->buffer() << "<br/>";
  446. }
  447. graph_obj->buffer() << attr.first << " " << attr.second->ToString();
  448. i++;
  449. }
  450. }
  451. graph_obj->buffer() << "CNode";
  452. } else {
  453. graph_obj->buffer() << "CNode(" << node->ToString() << ")";
  454. }
  455. graph_obj->buffer() << "</td></tr>" << std::endl;
  456. DrawParallelInfo(graph_obj, node);
  457. graph_obj->buffer() << "</table>>,";
  458. }
  459. void Digraph::Node(AnfNodePtr node, int id) {
  460. if (node == nullptr) {
  461. return;
  462. }
  463. buffer_ << "node" << node << "_" << id;
  464. buffer_ << "[";
  465. // set fontname
  466. buffer_ << "fontname=\"Courier New\",";
  467. // set label and shape
  468. buffer_ << "shape=" << Shape(node) << ",";
  469. if (node->isa<CNode>()) {
  470. DrawCNode(this, node->cast<CNodePtr>());
  471. } else if (node->isa<ValueNode>() && !IsValueNode<FuncGraph>(node)) {
  472. DrawValueNode(this, node->cast<ValueNodePtr>());
  473. } else {
  474. buffer_ << "label=\"" << node->ToString();
  475. if (IsValueNode<FuncGraph>(node)) {
  476. FuncGraphPtr nextNet = GetValueNode<FuncGraphPtr>(node);
  477. std::string nextNetName = nextNet->debug_info()->get_full_name();
  478. if (!nextNetName.empty()) {
  479. buffer_ << "[" << nextNet->debug_info()->get_full_name().c_str() << "]";
  480. }
  481. }
  482. buffer_ << "\","
  483. << "style=filled,fillcolor=" << Color(node) << ",";
  484. }
  485. // Set URL for func graph
  486. if (IsValueNode<FuncGraph>(node)) {
  487. buffer_ << "URL=\"#cluster_" << GetValueNode(node) << "\",";
  488. }
  489. buffer_ << "]" << std::endl;
  490. }
  491. void Digraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) {
  492. if (start == nullptr || end == nullptr) {
  493. return;
  494. }
  495. Head(start, id_start);
  496. buffer_ << "->";
  497. Tail(end, idx);
  498. buffer_ << "[arrowhead=vee,";
  499. // check how many inputs for end
  500. if (end->isa<CNode>()) {
  501. auto cnode = end->cast<CNodePtr>();
  502. MS_EXCEPTION_IF_NULL(cnode);
  503. auto num = cnode->inputs().size();
  504. if (idx == 0 && num > 1) {
  505. buffer_ << "style=dashed";
  506. }
  507. }
  508. buffer_ << "]" << std::endl;
  509. }
  510. ModelDigraph::~ModelDigraph() {
  511. try {
  512. if (fout_.is_open()) {
  513. fout_.close();
  514. }
  515. } catch (const std::exception &e) {
  516. MS_LOG(ERROR) << "exception when closing file " << filename_;
  517. }
  518. }
  519. std::string ModelDigraph::Shape(AnfNodePtr node) {
  520. if (node == nullptr) {
  521. return "";
  522. }
  523. if (node->isa<CNode>()) {
  524. return "plaintext";
  525. }
  526. if (node->isa<Parameter>()) {
  527. return "ellipse";
  528. }
  529. if (IsValueNode<FuncGraph>(node)) {
  530. return "oval";
  531. }
  532. return "plaintext";
  533. }
  534. void ModelDigraph::Node(AnfNodePtr node, int id) {
  535. if (node == nullptr) {
  536. return;
  537. }
  538. if (IsValueNode<Primitive>(node)) {
  539. return;
  540. }
  541. buffer_ << "node" << node << "_" << id;
  542. buffer_ << "[";
  543. // set fontname
  544. buffer_ << "fontname=\"Courier New\",";
  545. // set label and shape
  546. buffer_ << "shape=" << Shape(node) << ",";
  547. if (node->isa<CNode>()) {
  548. DrawCNode(this, node->cast<CNodePtr>());
  549. } else if (node->isa<ValueNode>() && !IsValueNode<FuncGraph>(node)) {
  550. DrawValueNode(this, node->cast<ValueNodePtr>());
  551. } else {
  552. buffer_ << "label=\"" << node->ToString() << "\",";
  553. buffer_ << "style=filled,fillcolor=" << Color(node) << ",";
  554. }
  555. // Set URL for func graph
  556. if (IsValueNode<FuncGraph>(node)) {
  557. buffer_ << "URL=\"#cluster_" << GetValueNode(node) << "\",";
  558. }
  559. buffer_ << "]" << std::endl;
  560. }
  561. void ModelDigraph::Edge(AnfNodePtr start, AnfNodePtr end, int idx, int id_start) {
  562. if (start == nullptr || end == nullptr) {
  563. return;
  564. }
  565. Head(start, id_start);
  566. buffer_ << "->";
  567. Tail(end, idx);
  568. buffer_ << "[arrowhead=vee,";
  569. buffer_ << "]" << std::endl;
  570. }
  571. } // namespace draw
  572. } // namespace mindspore