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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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 Node::Vistor<InDataAnchorPtr> Node::GetAllInDataAnchors() const {
  365. return Vistor<InDataAnchorPtr>(shared_from_this(), in_data_anchors_);
  366. }
  367. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<OutDataAnchorPtr> Node::GetAllOutDataAnchors() const {
  368. return Vistor<OutDataAnchorPtr>(shared_from_this(), out_data_anchors_);
  369. }
  370. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY uint32_t Node::GetAllInDataAnchorsSize() const {
  371. return in_data_anchors_.size();
  372. }
  373. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY uint32_t Node::GetAllOutDataAnchorsSize() const {
  374. return out_data_anchors_.size();
  375. }
  376. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<AnchorPtr> Node::GetAllInAnchors() const {
  377. std::vector<AnchorPtr> vec;
  378. // Push back in_data_anchors_
  379. for (const auto &in_anchor_iter : Vistor<InDataAnchorPtr>(shared_from_this(), in_data_anchors_)) {
  380. auto in_anchor = Anchor::DynamicAnchorCast<Anchor>(in_anchor_iter);
  381. if (in_anchor != nullptr) {
  382. vec.push_back(in_anchor);
  383. }
  384. }
  385. // Push back in_control_anchor_
  386. if ((in_control_anchor_->GetPeerOutControlAnchors().size() > 0) ||
  387. (in_control_anchor_->GetPeerOutDataAnchors().size() > 0)) {
  388. auto in_anchor = Anchor::DynamicAnchorCast<Anchor>(in_control_anchor_);
  389. if (in_anchor != nullptr) {
  390. vec.push_back(in_anchor);
  391. }
  392. }
  393. return Node::Vistor<AnchorPtr>(shared_from_this(), vec);
  394. }
  395. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<AnchorPtr> Node::GetAllOutAnchors() const {
  396. std::vector<AnchorPtr> vec;
  397. // Push back out_data_anchors_
  398. for (const auto &out_anchor_iter : Vistor<OutDataAnchorPtr>(shared_from_this(), out_data_anchors_)) {
  399. auto out_anchor = Anchor::DynamicAnchorCast<Anchor>(out_anchor_iter);
  400. if (out_anchor != nullptr) {
  401. vec.push_back(out_anchor);
  402. }
  403. }
  404. // Push back out_control_anchor_
  405. if (out_control_anchor_->GetPeerInControlAnchors().size() > 0 ||
  406. out_control_anchor_->GetPeerInDataAnchors().size() > 0) {
  407. auto out_anchor = Anchor::DynamicAnchorCast<Anchor>(out_control_anchor_);
  408. if (out_anchor != nullptr) {
  409. vec.push_back(out_anchor);
  410. }
  411. }
  412. return Node::Vistor<AnchorPtr>(shared_from_this(), vec);
  413. }
  414. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InDataAnchorPtr Node::GetInDataAnchor(int idx) const {
  415. if (idx < 0 || idx >= static_cast<int>(in_data_anchors_.size())) {
  416. ErrorManager::GetInstance().ATCReportErrMessage(
  417. "E19019", {"opname", "index", "anchorname", "optype"},
  418. {GetName().c_str(), std::to_string(idx), "in_data_anchor", GetType().c_str()});
  419. GELOGE(GRAPH_FAILED, "Op[%s] doesn't have index[%d]'s in_data_anchor which optype is %s.", GetName().c_str(), idx,
  420. GetType().c_str());
  421. return nullptr;
  422. } else {
  423. return in_data_anchors_[idx];
  424. }
  425. }
  426. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AnchorPtr Node::GetInAnchor(int idx) const {
  427. // Idx can't be less than -1 or >= in_data_anchors_.size(), -1 means index of control anchor_
  428. if (idx < -1 || idx >= static_cast<int>(in_data_anchors_.size())) {
  429. GELOGW("Op[%s] doesn't have index[%d]'s in_anchor which optype is %s.", GetName().c_str(), idx, GetType().c_str());
  430. return nullptr;
  431. } else {
  432. // Return control anchor
  433. if (idx == -1) {
  434. auto in_anchor = Anchor::DynamicAnchorCast<Anchor>(in_control_anchor_);
  435. return in_anchor;
  436. }
  437. // Return data anchor
  438. return in_data_anchors_[idx];
  439. }
  440. }
  441. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY AnchorPtr Node::GetOutAnchor(int idx) const {
  442. // Idx can't be less than -1 or >= out_data_anchors_.size(), -1 means index of control anchor_
  443. if (idx < -1 || idx >= static_cast<int>(out_data_anchors_.size())) {
  444. ErrorManager::GetInstance().ATCReportErrMessage("E19019", {"opname", "index", "anchorname", "optype"},
  445. {
  446. GetName().c_str(),
  447. std::to_string(idx),
  448. "out_anchor",
  449. GetType().c_str(),
  450. });
  451. GELOGE(GRAPH_FAILED, "Op[%s] doesn't have index[%d]'s out_anchor which optype is %s.", GetName().c_str(), idx,
  452. GetType().c_str());
  453. return nullptr;
  454. } else {
  455. // Return control anchor
  456. if (idx == -1) {
  457. auto out_anchor = Anchor::DynamicAnchorCast<Anchor>(out_control_anchor_);
  458. return out_anchor;
  459. }
  460. // Return data anchor
  461. return out_data_anchors_[idx];
  462. }
  463. }
  464. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OutDataAnchorPtr Node::GetOutDataAnchor(int idx) const {
  465. if (idx < 0 || idx >= static_cast<int>(out_data_anchors_.size())) {
  466. ErrorManager::GetInstance().ATCReportErrMessage(
  467. "E19019", {"opname", "index", "anchorname", "optype"},
  468. {GetName().c_str(), std::to_string(idx), "out_data_anchor", GetType().c_str()});
  469. GELOGE(GRAPH_FAILED, "Op[%s] doesn't have index[%d]'s out_data_anchor which optype is %s.", GetName().c_str(), idx,
  470. GetType().c_str());
  471. return nullptr;
  472. } else {
  473. return out_data_anchors_[idx];
  474. }
  475. }
  476. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY InControlAnchorPtr Node::GetInControlAnchor() const {
  477. return in_control_anchor_;
  478. }
  479. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OutControlAnchorPtr Node::GetOutControlAnchor() const {
  480. return out_control_anchor_;
  481. }
  482. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInNodes() const {
  483. std::vector<NodePtr> vec;
  484. for (const auto &in_anchor : in_data_anchors_) {
  485. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "in_data_anchor is nullptr");
  486. auto out_anchor = in_anchor->GetPeerOutAnchor();
  487. if (out_anchor == nullptr) {
  488. continue;
  489. }
  490. auto node = out_anchor->GetOwnerNode();
  491. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  492. vec.push_back(node);
  493. }
  494. if (in_control_anchor_ != nullptr) {
  495. if (in_control_anchor_->IsPeerOutAnchorsEmpty()) {
  496. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  497. }
  498. auto peer_out_anchors = in_control_anchor_->GetPeerOutDataAnchors();
  499. for (const auto &out_anchor : peer_out_anchors) {
  500. GE_CHK_BOOL_EXEC(out_anchor != nullptr, continue, "in_control_anchor_ peer out data anchors is nullptr");
  501. auto node = out_anchor->GetOwnerNode();
  502. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  503. vec.push_back(node);
  504. }
  505. auto peer_out_control_anchors = in_control_anchor_->GetPeerOutControlAnchors();
  506. for (const auto &out_control_anchor : peer_out_control_anchors) {
  507. GE_CHK_BOOL_EXEC(out_control_anchor != nullptr, continue,
  508. "in_control_anchor_ peer out control anchors is nullptr");
  509. auto node = out_control_anchor->GetOwnerNode();
  510. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  511. vec.push_back(node);
  512. }
  513. }
  514. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  515. }
  516. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY bool Node::IsAllInNodesSeen(
  517. std::unordered_set<Node *> &nodes_seen) const {
  518. for (const auto &in_anchor : in_data_anchors_) {
  519. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "in_data_anchor is nullptr");
  520. auto out_anchor = in_anchor->GetPeerOutAnchor();
  521. if (out_anchor == nullptr) {
  522. continue;
  523. }
  524. auto node = out_anchor->GetOwnerNode();
  525. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  526. if ((node->GetType() == NEXTITERATION) || (node->GetType() == REFNEXTITERATION)) {
  527. continue;
  528. }
  529. if (nodes_seen.count(node.get()) == 0) {
  530. return false;
  531. }
  532. }
  533. if (in_control_anchor_ != nullptr) {
  534. if (in_control_anchor_->IsPeerOutAnchorsEmpty()) {
  535. return true;
  536. }
  537. auto peer_out_control_anchors = in_control_anchor_->GetPeerOutControlAnchors();
  538. for (const auto &out_control_anchor : peer_out_control_anchors) {
  539. GE_CHK_BOOL_EXEC(out_control_anchor != nullptr, continue, "out_control_anchor is nullptr");
  540. auto node = out_control_anchor->GetOwnerNode();
  541. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  542. if ((node->GetType() == NEXTITERATION) || (node->GetType() == REFNEXTITERATION)) {
  543. continue;
  544. }
  545. if (nodes_seen.count(node.get()) == 0) {
  546. return false;
  547. }
  548. }
  549. }
  550. return true;
  551. }
  552. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInDataNodes() const {
  553. std::vector<NodePtr> vec;
  554. for (const auto &in_anchor : in_data_anchors_) {
  555. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "in_data_anchor is nullptr");
  556. auto anchor_ptr = in_anchor->GetPeerOutAnchor();
  557. if (anchor_ptr == nullptr) {
  558. continue;
  559. }
  560. auto node = anchor_ptr->GetOwnerNode();
  561. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  562. vec.push_back(node);
  563. }
  564. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  565. }
  566. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInControlNodes() const {
  567. std::vector<NodePtr> vec;
  568. if (in_control_anchor_ != nullptr) {
  569. for (const auto &in_anchor : in_control_anchor_->GetPeerOutControlAnchors()) {
  570. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerOutControlAnchors is nullptr");
  571. auto node = in_anchor->GetOwnerNode();
  572. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  573. vec.push_back(node);
  574. }
  575. }
  576. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  577. }
  578. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutNodes() const {
  579. std::vector<NodePtr> vec;
  580. for (const auto &out_anchor : out_data_anchors_) {
  581. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  582. for (const auto &peer_in_anchor : out_anchor->GetPeerInDataAnchors()) {
  583. GE_CHK_BOOL_EXEC((peer_in_anchor != nullptr), continue, "GetPeerInDataAnchors is nullptr");
  584. auto node = peer_in_anchor->GetOwnerNode();
  585. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  586. vec.push_back(node);
  587. }
  588. }
  589. if (out_control_anchor_ != nullptr) {
  590. auto peer_in_control_anchors = out_control_anchor_->GetPeerInControlAnchors();
  591. for (const auto &in_control_anchor : peer_in_control_anchors) {
  592. GE_CHK_BOOL_EXEC(in_control_anchor != nullptr, continue,
  593. "out_control_anchor_ peer in control anchors is nullptr");
  594. auto node = in_control_anchor->GetOwnerNode();
  595. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  596. vec.push_back(node);
  597. }
  598. }
  599. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  600. }
  601. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetInAllNodes() const {
  602. std::vector<NodePtr> vec;
  603. for (const auto &in_node : GetInDataNodes()) {
  604. vec.push_back(in_node);
  605. }
  606. for (const auto &in_control_node : GetInControlNodes()) {
  607. vec.push_back(in_control_node);
  608. }
  609. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  610. }
  611. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutDataNodes() const {
  612. std::vector<NodePtr> vec;
  613. for (const auto &out_anchor : out_data_anchors_) {
  614. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  615. for (const auto &in_anchor : out_anchor->GetPeerInDataAnchors()) {
  616. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "GetPeerInDataAnchors is nullptr");
  617. auto node = in_anchor->GetOwnerNode();
  618. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  619. vec.push_back(node);
  620. }
  621. }
  622. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  623. }
  624. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY uint32_t Node::GetOutDataNodesSize() const {
  625. uint32_t out_nums = 0;
  626. for (const auto &out_anchor : out_data_anchors_) {
  627. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  628. out_nums += out_anchor->GetPeerInDataNodesSize();
  629. }
  630. return out_nums;
  631. }
  632. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutControlNodes() const {
  633. std::vector<NodePtr> vec;
  634. for (const auto &out_anchor : out_data_anchors_) {
  635. GE_CHK_BOOL_EXEC((out_anchor != nullptr), continue, "out_data_anchors_ is nullptr");
  636. for (const auto &in_anchor : out_anchor->GetPeerInControlAnchors()) {
  637. GE_CHK_BOOL_EXEC((in_anchor != nullptr), continue, "GetPeerInControlAnchors is nullptr");
  638. auto node = in_anchor->GetOwnerNode();
  639. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  640. vec.push_back(node);
  641. }
  642. }
  643. if (out_control_anchor_ != nullptr) {
  644. for (const auto &in_anchor : out_control_anchor_->GetPeerAnchors()) {
  645. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerInControlAnchors is nullptr");
  646. auto node = in_anchor->GetOwnerNode();
  647. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  648. vec.push_back(node);
  649. }
  650. }
  651. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  652. }
  653. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<NodePtr> Node::GetOutAllNodes() const {
  654. std::vector<NodePtr> vec;
  655. for (const auto &out_anchor : out_data_anchors_) {
  656. GE_CHK_BOOL_EXEC((out_anchor != nullptr), { continue; }, "out_data_anchors_ is nullptr");
  657. for (const auto &in_anchor : out_anchor->GetPeerInDataAnchors()) {
  658. GE_CHK_BOOL_EXEC((in_anchor != nullptr), { continue; }, "GetPeerInDataAnchors is nullptr");
  659. auto node = in_anchor->GetOwnerNode();
  660. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  661. vec.push_back(node);
  662. }
  663. for (const auto &in_anchor : out_anchor->GetPeerInControlAnchors()) {
  664. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerInControlAnchors is nullptr");
  665. auto node = in_anchor->GetOwnerNode();
  666. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  667. vec.push_back(node);
  668. }
  669. }
  670. if (out_control_anchor_ != nullptr) {
  671. for (const auto &in_anchor : out_control_anchor_->GetPeerAnchors()) {
  672. GE_CHK_BOOL_EXEC(in_anchor != nullptr, continue, "GetPeerInControlAnchors is nullptr");
  673. auto node = in_anchor->GetOwnerNode();
  674. GE_CHK_BOOL_EXEC(node != nullptr, continue, "GetOwnerNode is nullptr");
  675. vec.push_back(node);
  676. }
  677. }
  678. return Node::Vistor<NodePtr>(shared_from_this(), vec);
  679. }
  680. graphStatus Node::InferShapeAndType() const {
  681. Operator op = ge::OpDescUtils::CreateOperatorFromNode(shared_from_this());
  682. graphStatus ret = ShapeRefiner::InferShapeAndType(shared_from_this(), op);
  683. return ret;
  684. }
  685. graphStatus Node::InferOriginFormat() const {
  686. Operator op = ge::OpDescUtils::CreateOperatorFromNode(shared_from_this());
  687. // Get infer func and execute
  688. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  689. return op_->CallInferFormatFunc(op);
  690. }
  691. graphStatus Node::Verify() const {
  692. const string data_type = "Data";
  693. const string aipp_data_type = "AippData";
  694. const string const_type = "Const";
  695. const string variable_type = "Variable";
  696. bool is_unknown_graph = GetOwnerComputeGraph()->GetGraphUnknownFlag();
  697. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  698. if (!is_unknown_graph) {
  699. for (const auto &in_anchor_ptr : GetAllInDataAnchors()) {
  700. GE_IF_BOOL_EXEC(in_anchor_ptr == nullptr, GELOGW("in anchor ptr is null"); continue);
  701. bool valid_anchor = op_->GetType() == data_type || op_->GetType() == aipp_data_type ||
  702. op_->GetType() == const_type || op_->GetType() == variable_type ||
  703. op_->IsOptionalInput(in_anchor_ptr->GetIdx()) || in_anchor_ptr->GetPeerAnchors().size() > 0;
  704. if (!valid_anchor) {
  705. ErrorManager::GetInstance().ATCReportErrMessage("E11019", {"opname", "index"},
  706. {GetName(), std::to_string(in_anchor_ptr->GetIdx())});
  707. GELOGE(GRAPH_FAILED, "operator %s's input %d is not linked.", GetName().c_str(), in_anchor_ptr->GetIdx());
  708. return GRAPH_FAILED;
  709. }
  710. }
  711. }
  712. string frameworkop_type = "FrameworkOp";
  713. bool need_update_name = op_->GetType() != frameworkop_type && !is_unknown_graph;
  714. if (need_update_name) {
  715. auto node_op = ge::OperatorFactoryImpl::CreateOperator("node_op", op_->GetType());
  716. if (node_op.IsEmpty()) {
  717. GELOGW("get op from OperatorFactory fail. opType: %s", op_->GetType().c_str());
  718. } else {
  719. GELOGD("get op from OperatorFactory success. opType: %s", op_->GetType().c_str());
  720. auto temp_op_desc = ge::OpDescUtils::GetOpDescFromOperator(node_op);
  721. if (temp_op_desc == nullptr) {
  722. GELOGE(GRAPH_FAILED, "temp op desc is null");
  723. return GRAPH_FAILED;
  724. }
  725. if (!op_->UpdateInputName(temp_op_desc->GetAllInputName())) {
  726. GELOGW("Verify UpdateInputName failed");
  727. }
  728. if (!op_->UpdateOutputName(temp_op_desc->GetAllOutputName())) {
  729. GELOGW("Verify UpdateOutputName failed");
  730. }
  731. }
  732. node_op.BreakConnect();
  733. }
  734. GE_IF_BOOL_EXEC(is_unknown_graph, return GRAPH_SUCCESS;);
  735. if (op_->CommonVerify() == GRAPH_SUCCESS) {
  736. Operator op_proxy = ge::OpDescUtils::CreateOperatorFromNode(shared_from_this());
  737. auto verify_func = op_->GetVerifyFunc();
  738. if (verify_func == nullptr) {
  739. verify_func = OperatorFactoryImpl::GetVerifyFunc(GetType());
  740. }
  741. if (verify_func != nullptr) {
  742. return (graphStatus)verify_func(op_proxy);
  743. }
  744. return GRAPH_SUCCESS;
  745. } else {
  746. GELOGE(GRAPH_FAILED, "%s Verify failed.", op_->GetType().c_str());
  747. return GRAPH_FAILED;
  748. }
  749. }
  750. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY OpDescPtr Node::GetOpDesc() const { return op_; }
  751. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY graphStatus Node::UpdateOpDesc(const OpDescPtr &op_desc) {
  752. GE_CHK_BOOL_EXEC(op_ != nullptr, return GRAPH_FAILED, "original OpDesc is nullptr");
  753. GE_CHK_BOOL_EXEC(op_desc != nullptr, return GRAPH_PARAM_INVALID, "Param OpDesc is nullptr");
  754. GE_CHK_BOOL_EXEC(op_->GetInputsSize() == op_desc->GetInputsSize(), return GRAPH_PARAM_INVALID,
  755. "Inputs count expected to be same, orginial OpDesc %zu, Param OpDesc %zu", op_->GetInputsSize(),
  756. op_desc->GetInputsSize());
  757. GE_CHK_BOOL_EXEC(op_->GetOutputsSize() == op_desc->GetOutputsSize(), return GRAPH_PARAM_INVALID,
  758. "Outputs count expected to be same, orginial OpDesc %zu, Param OpDesc %zu", op_->GetOutputsSize(),
  759. op_desc->GetOutputsSize());
  760. op_ = op_desc;
  761. return GRAPH_SUCCESS;
  762. }
  763. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<std::pair<NodePtr, OutDataAnchorPtr>>
  764. Node::GetInDataNodesAndAnchors() const {
  765. std::vector<std::pair<NodePtr, OutDataAnchorPtr>> vec;
  766. for (const auto &p : in_data_anchors_) {
  767. if (p == nullptr) {
  768. GELOGW("indata anchor is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  769. continue;
  770. }
  771. auto anchor_ptr = p->GetPeerOutAnchor();
  772. if (anchor_ptr == nullptr) {
  773. continue;
  774. }
  775. auto node = anchor_ptr->GetOwnerNode();
  776. if (node == nullptr) {
  777. GELOGW("src node is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  778. continue;
  779. }
  780. vec.push_back(std::make_pair(node, anchor_ptr));
  781. }
  782. return Node::Vistor<std::pair<NodePtr, OutDataAnchorPtr>>(shared_from_this(), vec);
  783. }
  784. GE_FUNC_DEV_VISIBILITY GE_FUNC_HOST_VISIBILITY Node::Vistor<std::pair<NodePtr, InDataAnchorPtr>>
  785. Node::GetOutDataNodesAndAnchors() const {
  786. std::vector<std::pair<NodePtr, InDataAnchorPtr>> vec;
  787. for (const auto &p : out_data_anchors_) {
  788. if (p == nullptr) {
  789. GELOGW("out data anchor is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  790. continue;
  791. }
  792. for (const auto &in_anchor : p->GetPeerInDataAnchors()) {
  793. if (in_anchor == nullptr) {
  794. GELOGW("dst in data anchor is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  795. continue;
  796. }
  797. auto node = in_anchor->GetOwnerNode();
  798. if (node == nullptr) {
  799. GELOGW("dst node is nullptr, node %s:%s", GetType().c_str(), GetName().c_str());
  800. continue;
  801. }
  802. vec.push_back(std::make_pair(node, in_anchor));
  803. }
  804. }
  805. return Node::Vistor<std::pair<NodePtr, InDataAnchorPtr>>(shared_from_this(), vec);
  806. }
  807. } // namespace ge

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