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.

node.cc 37 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883
  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 "graph/node.h"
  17. #include <utility>
  18. #include "debug/ge_op_types.h"
  19. #include "debug/ge_util.h"
  20. #include "external/graph/operator_factory.h"
  21. #include "framework/common/debug/ge_log.h"
  22. #include "graph/ge_tensor.h"
  23. #include "graph/operator_factory_impl.h"
  24. #include "graph/shape_refiner.h"
  25. #include "utils/ge_ir_utils.h"
  26. #include "utils/node_utils.h"
  27. #include "utils/op_desc_utils.h"
  28. #include "common/util/error_manager/error_manager.h"
  29. using std::string;
  30. using std::vector;
  31. namespace ge {
  32. Node::Node(const OpDescPtr &op, const ComputeGraphPtr &owner_graph)
  33. : op_(op),
  34. owner_graph_(owner_graph),
  35. in_data_anchors_(),
  36. out_data_anchors_(),
  37. in_control_anchor_(nullptr),
  38. out_control_anchor_(nullptr),
  39. attrs_(),
  40. has_init_(false) {
  41. anchor_status_updated_ = false;
  42. }
  43. Node::~Node() {
  44. for (const auto &in_data_anchor : in_data_anchors_) {
  45. if (in_data_anchor != nullptr) {
  46. in_data_anchor->UnlinkAll();
  47. }
  48. }
  49. for (const auto &out_data_anchor : out_data_anchors_) {
  50. if (out_data_anchor != nullptr) {
  51. out_data_anchor->UnlinkAll();
  52. }
  53. }
  54. if (in_control_anchor_ != nullptr) {
  55. in_control_anchor_->UnlinkAll();
  56. }
  57. if (out_control_anchor_ != nullptr) {
  58. out_control_anchor_->UnlinkAll();
  59. }
  60. }
  61. graphStatus Node::Init() {
  62. if (has_init_) {
  63. return GRAPH_SUCCESS;
  64. }
  65. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  66. size_t size = op_->GetAllInputsSize();
  67. for (size_t i = 0; i < size; i++) {
  68. std::shared_ptr<InDataAnchor> anchor = ComGraphMakeShared<InDataAnchor>(shared_from_this(), i);
  69. if (anchor == nullptr) {
  70. GELOGE(GRAPH_FAILED, "Current in_data_anchor is null, malloc shared_ptr failed.");
  71. return GRAPH_FAILED;
  72. }
  73. in_data_anchors_.push_back(anchor);
  74. }
  75. size = op_->GetOutputsSize();
  76. for (size_t i = 0; i < size; i++) {
  77. std::shared_ptr<OutDataAnchor> anchor = ComGraphMakeShared<OutDataAnchor>(shared_from_this(), i);
  78. if (anchor == nullptr) {
  79. GELOGE(GRAPH_FAILED, "Current out_data_anchor is null, malloc shared_ptr failed.");
  80. return GRAPH_FAILED;
  81. }
  82. out_data_anchors_.push_back(anchor);
  83. }
  84. in_control_anchor_ = ComGraphMakeShared<InControlAnchor>(shared_from_this(), -1);
  85. out_control_anchor_ = ComGraphMakeShared<OutControlAnchor>(shared_from_this(), -1);
  86. if (in_control_anchor_ == nullptr || out_control_anchor_ == nullptr) {
  87. GELOGE(GRAPH_FAILED, "Current in_control_anchor or out_control_anchor is null, malloc shared_ptr failed.");
  88. return GRAPH_FAILED;
  89. }
  90. has_init_ = true;
  91. return GRAPH_SUCCESS;
  92. }
  93. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY std::string Node::GetName() const {
  94. GE_CHK_BOOL_EXEC(op_ != nullptr, return string(), "original OpDesc is nullptr");
  95. return op_->GetName();
  96. }
  97. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY std::string Node::GetType() const {
  98. GE_CHK_BOOL_EXEC(op_ != nullptr, return string(), "original OpDesc is nullptr");
  99. return op_->GetType();
  100. }
  101. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::NodeAttrsAreEqual(const Node &r_node) const {
  102. const auto &attr_map = this->attrs_;
  103. const auto &r_attr_map = r_node.attrs_;
  104. // 1.Verify node's map<string, AttrValue> size
  105. if (attr_map.size() != r_attr_map.size()) {
  106. GELOGE(GRAPH_FAILED, "Size of node's attr map verify failed, node name: %s.", this->GetName().c_str());
  107. return false;
  108. }
  109. // 2.Verify node's map<string, AttrValue> key, verify values is temporarily not implemented
  110. for (const auto &it : attr_map) {
  111. if (r_attr_map.count(it.first) == 0) {
  112. GELOGE(GRAPH_FAILED, "Key of node's attr map verify failed, node name: %s key name: %s.", this->GetName().c_str(),
  113. it.first.c_str());
  114. return false;
  115. }
  116. }
  117. return true;
  118. }
  119. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::NodeMembersAreEqual(const Node &r_node) const {
  120. return ((((this->op_ != nullptr) && (r_node.op_ != nullptr) && (IsEqual(*(this->op_), *(r_node.op_), "node.op_"))) ||
  121. ((this->op_ == nullptr) && (r_node.op_ == nullptr))) &&
  122. IsEqual(this->has_init_, r_node.has_init_, "node.has_init_") &&
  123. IsEqual(this->anchor_status_updated_, r_node.anchor_status_updated_, "node.anchor_status_updated_") &&
  124. IsEqual(this->send_event_id_list_, r_node.send_event_id_list_, "node.send_event_id_list_") &&
  125. IsEqual(this->recv_event_id_list_, r_node.recv_event_id_list_, "node.recv_event_id_list_"));
  126. }
  127. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::NodeAnchorIsEqual(const AnchorPtr &left_anchor,
  128. const AnchorPtr &right_anchor,
  129. size_t i) const {
  130. GE_IF_BOOL_EXEC(left_anchor == nullptr, GELOGE(GRAPH_FAILED, "left_anchor is null."); return false);
  131. GE_IF_BOOL_EXEC(right_anchor == nullptr, GELOGE(GRAPH_FAILED, "right_anchor is null."); return false);
  132. const auto anchor_peer_size = left_anchor->GetPeerAnchors().size();
  133. const auto right_anchor_peer_size = right_anchor->GetPeerAnchors().size();
  134. // Firstly, verify anchor's peer anchors size equal or not
  135. if (anchor_peer_size != right_anchor_peer_size) {
  136. GELOGE(GRAPH_FAILED,
  137. "Size of anchor's peer anchors verify failed, node name: %s "
  138. "anchor_peer_size [%zu] is different form [%zu] at index [%zu].",
  139. this->GetName().c_str(), anchor_peer_size, right_anchor_peer_size, i);
  140. return false;
  141. }
  142. // Secondly, verify anchor's peer anchor owner node equal or not
  143. for (size_t j = 0; j < anchor_peer_size; j++) {
  144. const auto &peer_node = left_anchor->GetPeerAnchors().at(j)->GetOwnerNode();
  145. const auto &r_peer_node = right_anchor->GetPeerAnchors().at(j)->GetOwnerNode();
  146. if (peer_node == nullptr || r_peer_node == nullptr) {
  147. GELOGE(GRAPH_FAILED, "anchor's peer node is null, node name: %s index[%zu] peer node index[%zu]. ",
  148. this->GetName().c_str(), i, j);
  149. return false;
  150. }
  151. // Determine the connection relationship by linking the node's name
  152. if (peer_node->GetName() != r_peer_node->GetName()) {
  153. GELOGE(GRAPH_FAILED,
  154. "anchor's peer node name verify failed, node name: %s index[%zu]"
  155. "peer node name %s is different from %s at index [%zu].",
  156. this->GetName().c_str(), i, peer_node->GetName().c_str(), r_peer_node->GetName().c_str(), j);
  157. return false;
  158. }
  159. }
  160. return true;
  161. }
  162. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::NodeInConnectsAreEqual(const Node &r_node) const {
  163. // 1.Verify all in data and control anchors size
  164. const auto in_data_anchor_size = this->GetAllInDataAnchors().size();
  165. const auto r_in_data_anchor_size = r_node.GetAllInDataAnchors().size();
  166. if (in_data_anchor_size != r_in_data_anchor_size) {
  167. GELOGE(GRAPH_FAILED, "Size of node's in data anchors verify failed, node name: %s.", this->GetName().c_str());
  168. return false;
  169. }
  170. const auto l_in_anchors = this->GetAllInAnchors();
  171. const auto r_in_anchors = r_node.GetAllInAnchors();
  172. // Data anchors size equal, all anchors size not equal, means control anchor size not equal
  173. const auto in_control_anchor_size = l_in_anchors.size() - in_data_anchor_size;
  174. const auto r_in_control_anchor_size = r_in_anchors.size() - r_in_data_anchor_size;
  175. if (in_control_anchor_size != r_in_control_anchor_size) {
  176. GELOGE(GRAPH_FAILED, "Size of node's in control anchors verify failed, node name: %s.", this->GetName().c_str());
  177. return false;
  178. }
  179. // 2.Verify all in data and control anchors connect info
  180. for (size_t i = 0; i < this->GetAllInAnchors().size(); i++) {
  181. // Verify data anchors
  182. if (i < in_data_anchor_size) {
  183. const auto &in_anchor = l_in_anchors.at(i);
  184. const auto &r_in_anchor = r_in_anchors.at(i);
  185. if (!(NodeAnchorIsEqual(in_anchor, r_in_anchor, i))) {
  186. GELOGE(GRAPH_FAILED, "Node's in data control anchor verify failed, node name: %s.", this->GetName().c_str());
  187. return false;
  188. }
  189. } else {
  190. // Verify control anchors
  191. const auto &in_control_anchor = l_in_anchors.at(i);
  192. const auto &r_in_control_anchor = r_in_anchors.at(i);
  193. if (!(NodeAnchorIsEqual(in_control_anchor, r_in_control_anchor, i - in_data_anchor_size))) {
  194. GELOGE(GRAPH_FAILED, "Node's in control anchor verify failed, node name: %s.", this->GetName().c_str());
  195. return false;
  196. }
  197. }
  198. }
  199. return true;
  200. }
  201. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::NodeOutConnectsAreEqual(const Node &r_node) const {
  202. // 1.Verify all out data and control anchors size
  203. const auto l_out_data_anchors = this->GetAllOutDataAnchors();
  204. const auto r_out_data_anchors = r_node.GetAllOutDataAnchors();
  205. const auto out_data_anchor_size = l_out_data_anchors.size();
  206. const auto r_out_data_anchor_size = r_out_data_anchors.size();
  207. if (out_data_anchor_size != r_out_data_anchor_size) {
  208. GELOGE(GRAPH_FAILED, "Size of node's out data anchors verify failed, node name: %s.", this->GetName().c_str());
  209. return false;
  210. }
  211. const auto l_out_anchors = this->GetAllOutAnchors();
  212. const auto r_out_anchors = r_node.GetAllOutAnchors();
  213. // Data anchors size equal, all anchors size not equal, means control anchor size not equal
  214. const auto out_control_anchor_size = l_out_anchors.size() - out_data_anchor_size;
  215. const auto r_out_control_anchor_size = r_out_anchors.size() - r_out_data_anchor_size;
  216. if (out_control_anchor_size != r_out_control_anchor_size) {
  217. GELOGE(GRAPH_FAILED, "Size of node's out control anchors verify failed, node name: %s.", this->GetName().c_str());
  218. return false;
  219. }
  220. // 2.Verify all out data and control anchors connect info
  221. for (size_t i = 0; i < this->GetAllOutAnchors().size(); i++) {
  222. // Verify data anchors
  223. if (i < out_data_anchor_size) {
  224. const auto &out_anchor = l_out_data_anchors.at(i);
  225. const auto &r_out_anchor = r_out_data_anchors.at(i);
  226. if (!(NodeAnchorIsEqual(out_anchor, r_out_anchor, i))) {
  227. GELOGE(GRAPH_FAILED, "Node's out data control anchor verify failed, node name: %s.", this->GetName().c_str());
  228. return false;
  229. }
  230. } else {
  231. // Verify control anchors
  232. const auto &out_control_anchor = l_out_anchors.at(i);
  233. const auto &r_out_control_anchor = r_out_anchors.at(i);
  234. if (!(NodeAnchorIsEqual(out_control_anchor, r_out_control_anchor, i - out_data_anchor_size))) {
  235. GELOGE(GRAPH_FAILED, "Node's out control anchor verify failed, node name: %s.", this->GetName().c_str());
  236. return false;
  237. }
  238. }
  239. }
  240. return true;
  241. }
  242. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::operator==(const Node &r_node) const {
  243. return (NodeMembersAreEqual(r_node) && NodeAttrsAreEqual(r_node) && NodeInConnectsAreEqual(r_node) &&
  244. NodeOutConnectsAreEqual(r_node));
  245. }
  246. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::AddLinkFrom(const NodePtr &input_node) {
  247. // This function is deprecated, please use other two overloaded functions
  248. GE_CHECK_NOTNULL(input_node);
  249. // Input_node ---> this
  250. auto out_anchors = input_node->GetAllOutDataAnchors();
  251. if (out_anchors.size() != 1) {
  252. GELOGE(GRAPH_FAILED, "out_anchor size is:%zu, only support 1", out_anchors.size());
  253. return GRAPH_PARAM_INVALID;
  254. }
  255. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  256. auto op_desc = input_node->GetOpDesc();
  257. GE_CHECK_NOTNULL(op_desc);
  258. if (op_->AddInputDesc(op_desc->GetOutputDesc(0)) != GRAPH_SUCCESS) {
  259. GELOGE(GRAPH_FAILED, "add input desc failed.");
  260. return GRAPH_FAILED;
  261. }
  262. std::shared_ptr<InDataAnchor> anchor = ComGraphMakeShared<InDataAnchor>(shared_from_this(), in_data_anchors_.size());
  263. if (anchor == nullptr) {
  264. GELOGE(GRAPH_FAILED, "out_anchor size is:%zu, malloc shared_ptr failed.", out_anchors.size());
  265. return GRAPH_FAILED;
  266. }
  267. in_data_anchors_.push_back(anchor);
  268. (void)out_anchors.at(0)->LinkTo(in_data_anchors_.back());
  269. return GRAPH_SUCCESS;
  270. }
  271. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::AddLinkFrom(const uint32_t &index,
  272. NodePtr input_node) {
  273. GE_CHECK_NOTNULL(input_node);
  274. // Input_node ---> this
  275. auto out_anchors = input_node->GetAllOutDataAnchors();
  276. if (out_anchors.size() != 1) {
  277. GELOGE(GRAPH_FAILED, "out_anchor size is:%zu, only support 1", out_anchors.size());
  278. return GRAPH_PARAM_INVALID;
  279. }
  280. GE_CHECK_NOTNULL(op_);
  281. auto op_desc = input_node->GetOpDesc();
  282. GE_CHECK_NOTNULL(op_desc);
  283. if (op_->AddInputDesc(index, op_desc->GetOutputDesc(0)) != GRAPH_SUCCESS) {
  284. GELOGE(GRAPH_FAILED, "add input desc failed.");
  285. return GRAPH_FAILED;
  286. }
  287. if (index < GetAllInDataAnchors().size()) {
  288. (void)out_anchors.at(0)->LinkTo(in_data_anchors_[index]);
  289. } else {
  290. std::shared_ptr<InDataAnchor> anchor =
  291. ComGraphMakeShared<InDataAnchor>(shared_from_this(), in_data_anchors_.size());
  292. if (anchor == nullptr) {
  293. GELOGE(GRAPH_FAILED, "out_anchor size is:%zu, malloc shared_ptr failed.", out_anchors.size());
  294. return GRAPH_FAILED;
  295. }
  296. in_data_anchors_.push_back(anchor);
  297. (void)out_anchors.at(0)->LinkTo(in_data_anchors_.back());
  298. }
  299. return GRAPH_SUCCESS;
  300. }
  301. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::AddLinkFromForParse(const NodePtr &input_node) {
  302. // This function is used for ParseWeights.
  303. GE_CHECK_NOTNULL(input_node);
  304. // Input_node ---> this
  305. auto out_anchors = input_node->GetAllOutDataAnchors();
  306. if (out_anchors.size() != 1) {
  307. GELOGE(GRAPH_PARAM_INVALID, "out_anchor size is:%zu, only support 1", out_anchors.size());
  308. return GRAPH_PARAM_INVALID;
  309. }
  310. std::shared_ptr<InDataAnchor> anchor = ComGraphMakeShared<InDataAnchor>(shared_from_this(), in_data_anchors_.size());
  311. if (anchor == nullptr) {
  312. GELOGE(GRAPH_FAILED, "out_anchor size is:%zu, make anchor failed", out_anchors.size());
  313. return GRAPH_FAILED;
  314. }
  315. in_data_anchors_.push_back(anchor);
  316. (void)out_anchors.at(0)->LinkTo(in_data_anchors_.back());
  317. return GRAPH_SUCCESS;
  318. }
  319. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::AddLinkFrom(const string &name, NodePtr input_node) {
  320. GE_CHECK_NOTNULL(input_node);
  321. // Input_node ---> this
  322. auto out_anchors = input_node->GetAllOutDataAnchors();
  323. if (out_anchors.size() != 1) {
  324. GELOGE(GRAPH_PARAM_INVALID, "out_anchor size is:%zu, only support 1", out_anchors.size());
  325. return GRAPH_PARAM_INVALID;
  326. }
  327. GE_CHECK_NOTNULL(op_);
  328. auto input_op_desc = input_node->GetOpDesc();
  329. GE_CHECK_NOTNULL(input_op_desc);
  330. auto index = op_->GetInputIndexByName(name);
  331. if (index != -1) {
  332. if (index >= static_cast<int>(in_data_anchors_.size())) {
  333. GELOGE(GRAPH_FAILED, "op %s get input name %s 's index %d is illegal.", op_->GetName().c_str(), name.c_str(),
  334. index);
  335. return GRAPH_FAILED;
  336. }
  337. (void)out_anchors.at(0)->LinkTo(in_data_anchors_[index]);
  338. } else {
  339. std::shared_ptr<InDataAnchor> anchor =
  340. ComGraphMakeShared<InDataAnchor>(shared_from_this(), in_data_anchors_.size());
  341. if (anchor == nullptr) {
  342. GELOGE(GRAPH_FAILED, "in_data_anchors_size is:%zu, malloc shared_ptr failed.", in_data_anchors_.size());
  343. return GRAPH_FAILED;
  344. }
  345. in_data_anchors_.push_back(anchor);
  346. (void)out_anchors.at(0)->LinkTo(in_data_anchors_.back());
  347. }
  348. if (op_->AddInputDesc(name, input_op_desc->GetOutputDesc(0)) != GRAPH_SUCCESS) {
  349. GELOGE(GRAPH_FAILED, "add input desc failed.");
  350. return GRAPH_FAILED;
  351. }
  352. return GRAPH_SUCCESS;
  353. }
  354. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY ComputeGraphPtr Node::GetOwnerComputeGraph() const {
  355. return owner_graph_.lock();
  356. }
  357. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::SetOwnerComputeGraph(const ComputeGraphPtr &graph) {
  358. if (graph == nullptr) {
  359. return GRAPH_PARAM_INVALID;
  360. }
  361. owner_graph_ = graph;
  362. return GRAPH_SUCCESS;
  363. }
  364. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::SetAnyOwnerComputeGraph(const ComputeGraphPtr &graph) {
  365. owner_graph_ = graph;
  366. return GRAPH_SUCCESS;
  367. }
  368. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<InDataAnchorPtr> Node::GetAllInDataAnchors() const {
  369. return Vistor<InDataAnchorPtr>(shared_from_this(), in_data_anchors_);
  370. }
  371. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<OutDataAnchorPtr> Node::GetAllOutDataAnchors() const {
  372. return Vistor<OutDataAnchorPtr>(shared_from_this(), out_data_anchors_);
  373. }
  374. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY uint32_t Node::GetAllInDataAnchorsSize() const {
  375. return in_data_anchors_.size();
  376. }
  377. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY uint32_t Node::GetAllOutDataAnchorsSize() const {
  378. return out_data_anchors_.size();
  379. }
  380. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<AnchorPtr> Node::GetAllInAnchors() const {
  381. std::vector<AnchorPtr> vec;
  382. // Push back in_data_anchors_
  383. for (const auto &in_anchor_iter : Vistor<InDataAnchorPtr>(shared_from_this(), in_data_anchors_)) {
  384. auto in_anchor = Anchor::DynamicAnchorCast<Anchor>(in_anchor_iter);
  385. if (in_anchor != nullptr) {
  386. vec.push_back(in_anchor);
  387. }
  388. }
  389. // Push back in_control_anchor_
  390. if ((in_control_anchor_->GetPeerOutControlAnchors().size() > 0) ||
  391. (in_control_anchor_->GetPeerOutDataAnchors().size() > 0)) {
  392. auto in_anchor = Anchor::DynamicAnchorCast<Anchor>(in_control_anchor_);
  393. if (in_anchor != nullptr) {
  394. vec.push_back(in_anchor);
  395. }
  396. }
  397. return Node::Vistor<AnchorPtr>(shared_from_this(), vec);
  398. }
  399. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<AnchorPtr> Node::GetAllOutAnchors() const {
  400. std::vector<AnchorPtr> vec;
  401. // Push back out_data_anchors_
  402. for (const auto &out_anchor_iter : Vistor<OutDataAnchorPtr>(shared_from_this(), out_data_anchors_)) {
  403. auto out_anchor = Anchor::DynamicAnchorCast<Anchor>(out_anchor_iter);
  404. if (out_anchor != nullptr) {
  405. vec.push_back(out_anchor);
  406. }
  407. }
  408. // Push back out_control_anchor_
  409. if (out_control_anchor_->GetPeerInControlAnchors().size() > 0 ||
  410. out_control_anchor_->GetPeerInDataAnchors().size() > 0) {
  411. auto out_anchor = Anchor::DynamicAnchorCast<Anchor>(out_control_anchor_);
  412. if (out_anchor != nullptr) {
  413. vec.push_back(out_anchor);
  414. }
  415. }
  416. return Node::Vistor<AnchorPtr>(shared_from_this(), vec);
  417. }
  418. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InDataAnchorPtr Node::GetInDataAnchor(int idx) const {
  419. if (idx < 0 || idx >= static_cast<int>(in_data_anchors_.size())) {
  420. ErrorManager::GetInstance().ATCReportErrMessage(
  421. "E19019", {"opname", "index", "anchorname", "optype"},
  422. {GetName().c_str(), std::to_string(idx), "in_data_anchor", GetType().c_str()});
  423. GELOGE(GRAPH_FAILED, "Op[%s] doesn't have index[%d]'s in_data_anchor which optype is %s.", GetName().c_str(), idx,
  424. GetType().c_str());
  425. return nullptr;
  426. } else {
  427. return in_data_anchors_[idx];
  428. }
  429. }
  430. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AnchorPtr Node::GetInAnchor(int idx) const {
  431. // Idx can't be less than -1 or >= in_data_anchors_.size(), -1 means index of control anchor_
  432. if (idx < -1 || idx >= static_cast<int>(in_data_anchors_.size())) {
  433. GELOGW("Op[%s] doesn't have index[%d]'s in_anchor which optype is %s.", GetName().c_str(), idx, GetType().c_str());
  434. return nullptr;
  435. } else {
  436. // Return control anchor
  437. if (idx == -1) {
  438. auto in_anchor = Anchor::DynamicAnchorCast<Anchor>(in_control_anchor_);
  439. return in_anchor;
  440. }
  441. // Return data anchor
  442. return in_data_anchors_[idx];
  443. }
  444. }
  445. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AnchorPtr Node::GetOutAnchor(int idx) const {
  446. // Idx can't be less than -1 or >= out_data_anchors_.size(), -1 means index of control anchor_
  447. if (idx < -1 || idx >= static_cast<int>(out_data_anchors_.size())) {
  448. ErrorManager::GetInstance().ATCReportErrMessage("E19019", {"opname", "index", "anchorname", "optype"},
  449. {
  450. GetName().c_str(),
  451. std::to_string(idx),
  452. "out_anchor",
  453. GetType().c_str(),
  454. });
  455. GELOGE(GRAPH_FAILED, "Op[%s] doesn't have index[%d]'s out_anchor which optype is %s.", GetName().c_str(), idx,
  456. GetType().c_str());
  457. return nullptr;
  458. } else {
  459. // Return control anchor
  460. if (idx == -1) {
  461. auto out_anchor = Anchor::DynamicAnchorCast<Anchor>(out_control_anchor_);
  462. return out_anchor;
  463. }
  464. // Return data anchor
  465. return out_data_anchors_[idx];
  466. }
  467. }
  468. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OutDataAnchorPtr Node::GetOutDataAnchor(int idx) const {
  469. if (idx < 0 || idx >= static_cast<int>(out_data_anchors_.size())) {
  470. ErrorManager::GetInstance().ATCReportErrMessage(
  471. "E19019", {"opname", "index", "anchorname", "optype"},
  472. {GetName().c_str(), std::to_string(idx), "out_data_anchor", GetType().c_str()});
  473. GELOGE(GRAPH_FAILED, "Op[%s] doesn't have index[%d]'s out_data_anchor which optype is %s.", GetName().c_str(), idx,
  474. GetType().c_str());
  475. return nullptr;
  476. } else {
  477. return out_data_anchors_[idx];
  478. }
  479. }
  480. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InControlAnchorPtr Node::GetInControlAnchor() const {
  481. return in_control_anchor_;
  482. }
  483. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OutControlAnchorPtr Node::GetOutControlAnchor() const {
  484. return out_control_anchor_;
  485. }
  486. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInNodes() const {
  487. std::vector<NodePtr> vec;
  488. for (const auto &in_anchor : in_data_anchors_) {
  489. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "in_data_anchor is nullptr");
  490. auto out_anchor = in_anchor->GetPeerOutAnchor();
  491. if (out_anchor == nullptr) {
  492. continue;
  493. }
  494. auto node = out_anchor->GetOwnerNode();
  495. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  496. vec.push_back(node);
  497. }
  498. if (in_control_anchor_ != nullptr) {
  499. if (in_control_anchor_->IsPeerOutAnchorsEmpty()) {
  500. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  501. }
  502. auto peer_out_anchors = in_control_anchor_->GetPeerOutDataAnchors();
  503. for (const auto &out_anchor : peer_out_anchors) {
  504. GE_CHK_BOOL_EXEC(out_anchor != nullptr, continue, "in_control_anchor_ peer out data anchors is nullptr");
  505. auto node = out_anchor->GetOwnerNode();
  506. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  507. vec.push_back(node);
  508. }
  509. auto peer_out_control_anchors = in_control_anchor_->GetPeerOutControlAnchors();
  510. for (const auto &out_control_anchor : peer_out_control_anchors) {
  511. GE_CHK_BOOL_EXEC(out_control_anchor != nullptr, continue,
  512. "in_control_anchor_ peer out control anchors is nullptr");
  513. auto node = out_control_anchor->GetOwnerNode();
  514. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  515. vec.push_back(node);
  516. }
  517. }
  518. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  519. }
  520. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::IsAllInNodesSeen(
  521. std::unordered_set<Node *> &nodes_seen) const {
  522. for (const auto &in_anchor : in_data_anchors_) {
  523. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "in_data_anchor is nullptr");
  524. auto out_anchor = in_anchor->GetPeerOutAnchor();
  525. if (out_anchor == nullptr) {
  526. continue;
  527. }
  528. auto node = out_anchor->GetOwnerNode();
  529. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  530. if ((node->GetType() == NEXTITERATION) || (node->GetType() == REFNEXTITERATION)) {
  531. continue;
  532. }
  533. if (nodes_seen.count(node.get()) == 0) {
  534. return false;
  535. }
  536. }
  537. if (in_control_anchor_ != nullptr) {
  538. if (in_control_anchor_->IsPeerOutAnchorsEmpty()) {
  539. return true;
  540. }
  541. auto peer_out_control_anchors = in_control_anchor_->GetPeerOutControlAnchors();
  542. for (const auto &out_control_anchor : peer_out_control_anchors) {
  543. GE_CHK_BOOL_EXEC(out_control_anchor != nullptr, continue, "out_control_anchor is nullptr");
  544. auto node = out_control_anchor->GetOwnerNode();
  545. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  546. if ((node->GetType() == NEXTITERATION) || (node->GetType() == REFNEXTITERATION)) {
  547. continue;
  548. }
  549. if (nodes_seen.count(node.get()) == 0) {
  550. return false;
  551. }
  552. }
  553. }
  554. return true;
  555. }
  556. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInDataNodes() const {
  557. std::vector<NodePtr> vec;
  558. for (const auto &in_anchor : in_data_anchors_) {
  559. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "in_data_anchor is nullptr");
  560. auto anchor_ptr = in_anchor->GetPeerOutAnchor();
  561. if (anchor_ptr == nullptr) {
  562. continue;
  563. }
  564. auto node = anchor_ptr->GetOwnerNode();
  565. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  566. vec.push_back(node);
  567. }
  568. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  569. }
  570. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInControlNodes() const {
  571. std::vector<NodePtr> vec;
  572. if (in_control_anchor_ != nullptr) {
  573. for (const auto &in_anchor : in_control_anchor_->GetPeerOutControlAnchors()) {
  574. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerOutControlAnchors is nullptr");
  575. auto node = in_anchor->GetOwnerNode();
  576. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  577. vec.push_back(node);
  578. }
  579. }
  580. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  581. }
  582. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutNodes() const {
  583. std::vector<NodePtr> vec;
  584. for (const auto &out_anchor : out_data_anchors_) {
  585. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  586. for (const auto &peer_in_anchor : out_anchor->GetPeerInDataAnchors()) {
  587. GE_CHK_BOOL_EXEC((peer_in_anchor != nullptr), continue, "GetPeerInDataAnchors is nullptr");
  588. auto node = peer_in_anchor->GetOwnerNode();
  589. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  590. vec.push_back(node);
  591. }
  592. }
  593. if (out_control_anchor_ != nullptr) {
  594. auto peer_in_control_anchors = out_control_anchor_->GetPeerInControlAnchors();
  595. for (const auto &in_control_anchor : peer_in_control_anchors) {
  596. GE_CHK_BOOL_EXEC(in_control_anchor != nullptr, continue,
  597. "out_control_anchor_ peer in control anchors is nullptr");
  598. auto node = in_control_anchor->GetOwnerNode();
  599. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  600. vec.push_back(node);
  601. }
  602. }
  603. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  604. }
  605. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInAllNodes() const {
  606. std::vector<NodePtr> vec;
  607. for (const auto &in_node : GetInDataNodes()) {
  608. vec.push_back(in_node);
  609. }
  610. for (const auto &in_control_node : GetInControlNodes()) {
  611. vec.push_back(in_control_node);
  612. }
  613. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  614. }
  615. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutDataNodes() const {
  616. std::vector<NodePtr> vec;
  617. for (const auto &out_anchor : out_data_anchors_) {
  618. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  619. for (const auto &in_anchor : out_anchor->GetPeerInDataAnchors()) {
  620. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "GetPeerInDataAnchors is nullptr");
  621. auto node = in_anchor->GetOwnerNode();
  622. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  623. vec.push_back(node);
  624. }
  625. }
  626. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  627. }
  628. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY uint32_t Node::GetOutDataNodesSize() const {
  629. uint32_t out_nums = 0;
  630. for (const auto &out_anchor : out_data_anchors_) {
  631. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  632. out_nums += out_anchor->GetPeerInDataNodesSize();
  633. }
  634. return out_nums;
  635. }
  636. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutControlNodes() const {
  637. std::vector<NodePtr> vec;
  638. for (const auto &out_anchor : out_data_anchors_) {
  639. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  640. for (const auto &in_anchor : out_anchor->GetPeerInControlAnchors()) {
  641. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "GetPeerInControlAnchors is nullptr");
  642. auto node = in_anchor->GetOwnerNode();
  643. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  644. vec.push_back(node);
  645. }
  646. }
  647. if (out_control_anchor_ != nullptr) {
  648. for (const auto &in_anchor : out_control_anchor_->GetPeerAnchors()) {
  649. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerInControlAnchors is nullptr");
  650. auto node = in_anchor->GetOwnerNode();
  651. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  652. vec.push_back(node);
  653. }
  654. }
  655. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  656. }
  657. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutAllNodes() const {
  658. std::vector<NodePtr> vec;
  659. for (const auto &out_anchor : out_data_anchors_) {
  660. GE_CHK_BOOL_EXEC((out_anchor != nullptr), { continue; }, "out_data_anchors_ is nullptr");
  661. for (const auto &in_anchor : out_anchor->GetPeerInDataAnchors()) {
  662. GE_CHK_BOOL_EXEC((in_anchor != nullptr), { continue; }, "GetPeerInDataAnchors is nullptr");
  663. auto node = in_anchor->GetOwnerNode();
  664. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  665. vec.push_back(node);
  666. }
  667. for (const auto &in_anchor : out_anchor->GetPeerInControlAnchors()) {
  668. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerInControlAnchors is nullptr");
  669. auto node = in_anchor->GetOwnerNode();
  670. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  671. vec.push_back(node);
  672. }
  673. }
  674. if (out_control_anchor_ != nullptr) {
  675. for (const auto &in_anchor : out_control_anchor_->GetPeerAnchors()) {
  676. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerInControlAnchors is nullptr");
  677. auto node = in_anchor->GetOwnerNode();
  678. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  679. vec.push_back(node);
  680. }
  681. }
  682. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  683. }
  684. graphStatus Node::InferShapeAndType() const {
  685. Operator op = ge::OpDescUtils::CreateOperatorFromNode(shared_from_this());
  686. graphStatus ret = ShapeRefiner::InferShapeAndType(shared_from_this(), op);
  687. return ret;
  688. }
  689. graphStatus Node::InferOriginFormat() const {
  690. Operator op = ge::OpDescUtils::CreateOperatorFromNode(shared_from_this());
  691. // Get infer func and execute
  692. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  693. return op_->CallInferFormatFunc(op);
  694. }
  695. graphStatus Node::Verify() const {
  696. const string data_type = "Data";
  697. const string aipp_data_type = "AippData";
  698. const string const_type = "Const";
  699. const string variable_type = "Variable";
  700. bool is_unknown_graph = GetOwnerComputeGraph()->GetGraphUnknownFlag();
  701. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  702. if (!is_unknown_graph) {
  703. for (const auto &in_anchor_ptr : GetAllInDataAnchors()) {
  704. GE_IF_BOOL_EXEC(in_anchor_ptr == nullptr, GELOGW("in anchor ptr is null"); continue);
  705. bool valid_anchor =
  706. op_->GetType() == data_type || op_->GetType() == aipp_data_type || op_->GetType() == const_type ||
  707. op_->GetType() == variable_type || op_->IsOptionalInput(in_anchor_ptr->GetIdx()) ||
  708. op_->MutableInputDesc(in_anchor_ptr->GetIdx()) == nullptr || in_anchor_ptr->GetPeerAnchors().size() > 0;
  709. if (!valid_anchor) {
  710. ErrorManager::GetInstance().ATCReportErrMessage("E11019", {"opname", "index"},
  711. {GetName(), std::to_string(in_anchor_ptr->GetIdx())});
  712. GELOGE(GRAPH_FAILED, "operator %s's input %d is not linked.", GetName().c_str(), in_anchor_ptr->GetIdx());
  713. return GRAPH_FAILED;
  714. }
  715. }
  716. }
  717. string frameworkop_type = "FrameworkOp";
  718. bool need_update_name = op_->GetType() != frameworkop_type && !is_unknown_graph;
  719. if (need_update_name) {
  720. auto node_op = ge::OperatorFactoryImpl::CreateOperator("node_op", op_->GetType());
  721. if (node_op.IsEmpty()) {
  722. GELOGW("get op from OperatorFactory fail. opType: %s", op_->GetType().c_str());
  723. } else {
  724. GELOGD("get op from OperatorFactory success. opType: %s", op_->GetType().c_str());
  725. auto temp_op_desc = ge::OpDescUtils::GetOpDescFromOperator(node_op);
  726. if (temp_op_desc == nullptr) {
  727. GELOGE(GRAPH_FAILED, "temp op desc is null");
  728. return GRAPH_FAILED;
  729. }
  730. if (!op_->UpdateInputName(temp_op_desc->GetAllInputName())) {
  731. GELOGW("Verify UpdateInputName failed");
  732. }
  733. if (!op_->UpdateOutputName(temp_op_desc->GetAllOutputName())) {
  734. GELOGW("Verify UpdateOutputName failed");
  735. }
  736. }
  737. node_op.BreakConnect();
  738. }
  739. GE_IF_BOOL_EXEC(is_unknown_graph, return GRAPH_SUCCESS;);
  740. if (op_->CommonVerify() == GRAPH_SUCCESS) {
  741. Operator op_proxy = ge::OpDescUtils::CreateOperatorFromNode(shared_from_this());
  742. auto verify_func = op_->GetVerifyFunc();
  743. if (verify_func == nullptr) {
  744. verify_func = OperatorFactoryImpl::GetVerifyFunc(GetType());
  745. }
  746. if (verify_func != nullptr) {
  747. return (graphStatus)verify_func(op_proxy);
  748. }
  749. return GRAPH_SUCCESS;
  750. } else {
  751. GELOGE(GRAPH_FAILED, "%s Verify failed.", op_->GetType().c_str());
  752. return GRAPH_FAILED;
  753. }
  754. }
  755. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OpDescPtr Node::GetOpDesc() const { return op_; }
  756. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::UpdateOpDesc(const OpDescPtr &op_desc) {
  757. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  758. GE_CHK_BOOL_EXEC(op_desc != nullptr, return GRAPH_PARAM_INVALID, "Param OpDesc is nullptr");
  759. GE_CHK_BOOL_EXEC(op_->GetInputsSize() == op_desc->GetInputsSize(), return GRAPH_PARAM_INVALID,
  760. "Inputs count expected to be same, orginial OpDesc %zu, Param OpDesc %zu", op_->GetInputsSize(),
  761. op_desc->GetInputsSize());
  762. GE_CHK_BOOL_EXEC(op_->GetOutputsSize() == op_desc->GetOutputsSize(), return GRAPH_PARAM_INVALID,
  763. "Outputs count expected to be same, orginial OpDesc %zu, Param OpDesc %zu", op_->GetOutputsSize(),
  764. op_desc->GetOutputsSize());
  765. op_ = op_desc;
  766. return GRAPH_SUCCESS;
  767. }
  768. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<std::pair<NodePtr, OutDataAnchorPtr>>
  769. Node::GetInDataNodesAndAnchors() const {
  770. std::vector<std::pair<NodePtr, OutDataAnchorPtr>> vec;
  771. for (const auto &p : in_data_anchors_) {
  772. if (p == nullptr) {
  773. GELOGW("indata anchor is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  774. continue;
  775. }
  776. auto anchor_ptr = p->GetPeerOutAnchor();
  777. if (anchor_ptr == nullptr) {
  778. continue;
  779. }
  780. auto node = anchor_ptr->GetOwnerNode();
  781. if (node == nullptr) {
  782. GELOGW("src node is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  783. continue;
  784. }
  785. vec.push_back(std::make_pair(node, anchor_ptr));
  786. }
  787. return Node::Vistor<std::pair<NodePtr, OutDataAnchorPtr>>(shared_from_this(), vec);
  788. }
  789. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<std::pair<NodePtr, InDataAnchorPtr>>
  790. Node::GetOutDataNodesAndAnchors() const {
  791. std::vector<std::pair<NodePtr, InDataAnchorPtr>> vec;
  792. for (const auto &p : out_data_anchors_) {
  793. if (p == nullptr) {
  794. GELOGW("out data anchor is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  795. continue;
  796. }
  797. for (const auto &in_anchor : p->GetPeerInDataAnchors()) {
  798. if (in_anchor == nullptr) {
  799. GELOGW("dst in data anchor is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  800. continue;
  801. }
  802. auto node = in_anchor->GetOwnerNode();
  803. if (node == nullptr) {
  804. GELOGW("dst node is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  805. continue;
  806. }
  807. vec.push_back(std::make_pair(node, in_anchor));
  808. }
  809. }
  810. return Node::Vistor<std::pair<NodePtr, InDataAnchorPtr>>(shared_from_this(), vec);
  811. }
  812. } // namespace ge

图引擎模块(GE)是MindSpore的一个子模块,其代码由C++实现,位于前端模块ME和底层硬件之间,起到承接作用。图引擎模块以ME下发的图作为输入,然后进行一系列的深度图优化操作,最后输出一张可以在底层硬件上高效运行的图。GE针对昇腾AI处理器的硬件结构特点,做了特定的优化工作,以此来充分发挥出昇腾AI处理器的强大算力。在进行模型训练/推理时,GE会被自动调用而用户并不感知.