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_state.h 3.4 kB

4 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. #ifndef GE_HYBRID_EXECUTOR_NODE_STATE_H_
  17. #define GE_HYBRID_EXECUTOR_NODE_STATE_H_
  18. #include <condition_variable>
  19. #include <future>
  20. #include <mutex>
  21. #include "external/ge/ge_api_error_codes.h"
  22. #include "hybrid/model/node_item.h"
  23. #include "node_done_manager.h"
  24. namespace ge {
  25. namespace hybrid {
  26. class NodeTask;
  27. struct GraphExecutionContext;
  28. class SubgraphContext;
  29. class TaskContext;
  30. class ShapeFuture {
  31. public:
  32. ShapeFuture(NodePtr src_node, uint32_t src_index, SubgraphContext *subgraph_context);
  33. ~ShapeFuture() = default;
  34. Status Get(GeShape &ori_shape, GeShape &shape);
  35. Status GetTensorDesc(GeTensorDescPtr &tensor_desc);
  36. private:
  37. NodePtr src_node_;
  38. uint32_t src_index_;
  39. SubgraphContext *subgraph_context_;
  40. };
  41. struct ShapeInferenceState {
  42. explicit ShapeInferenceState(const NodeItem &node_item);
  43. Status UpdateInputShape(int idx, const GeTensorDesc &tensor_desc);
  44. void UpdateInputShapeFuture(int idx, ShapeFuture &&future);
  45. Status AwaitShapesReady(const GraphExecutionContext &context);
  46. const NodeItem &node_item;
  47. private:
  48. std::vector<std::pair<int, ShapeFuture>> shape_futures;
  49. int num_pending_shapes_ = 0;
  50. std::condition_variable ready_cv_;
  51. std::mutex mu_;
  52. };
  53. // saving sth. dynamic during execution
  54. struct NodeState {
  55. public:
  56. NodeState(const NodeItem &node_item, SubgraphContext *subgraph_context);
  57. ~NodeState() = default;
  58. OpDesc *GetOpDesc() const {
  59. return op_desc_.get();
  60. }
  61. inline const NodeItem *GetNodeItem() const {
  62. return node_item_;
  63. }
  64. inline const string &GetName() const {
  65. return node_item_->NodeName();
  66. }
  67. inline const string &GetType() const {
  68. return node_item_->NodeType();
  69. }
  70. ShapeInferenceState &GetShapeInferenceState() {
  71. return shape_inference_state_;
  72. }
  73. const shared_ptr<NodeTask> &GetKernelTask() const {
  74. return kernel_task_;
  75. }
  76. void SetKernelTask(const shared_ptr<NodeTask> &kernel_task) {
  77. kernel_task_ = kernel_task;
  78. }
  79. Status WaitForPrepareDone();
  80. void SetPrepareFuture(std::future<Status> &&prepare_future) {
  81. this->prepare_future_ = std::move(prepare_future);
  82. }
  83. Status AwaitInputTensors(GraphExecutionContext &context) const;
  84. void SetTaskContext(std::shared_ptr<TaskContext> &task_context);
  85. std::shared_ptr<TaskContext> GetTaskContext();
  86. private:
  87. const NodeItem *node_item_ = nullptr;
  88. std::shared_ptr<NodeTask> kernel_task_ = nullptr;
  89. std::future<Status> prepare_future_;
  90. OpDescPtr op_desc_;
  91. ShapeInferenceState shape_inference_state_;
  92. SubgraphContext *subgraph_context_;
  93. std::shared_ptr<TaskContext> task_context_ = nullptr;
  94. std::mutex mu_;
  95. };
  96. using NodeStatePtr = std::shared_ptr<NodeState>;
  97. } // namespace hybrid
  98. } // namespace ge
  99. #endif // GE_HYBRID_EXECUTOR_NODE_STATE_H_

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