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.

model_utils.h 3.8 kB

5 years ago
5 years ago
5 years ago
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
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
4 years ago
4 years ago
4 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Copyright 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_GRAPH_LOAD_NEW_MODEL_MANAGER_MODEL_UTILS_H_
  17. #define GE_GRAPH_LOAD_NEW_MODEL_MANAGER_MODEL_UTILS_H_
  18. #include <vector>
  19. #include "common/ge_inner_error_codes.h"
  20. #include "common/types.h"
  21. #include "graph/load/model_manager/task_info/task_info.h"
  22. #include "graph/op_desc.h"
  23. #include "graph/utils/tensor_adapter.h"
  24. #include "model/ge_model.h"
  25. using std::vector;
  26. namespace ge {
  27. class ModelUtils {
  28. public:
  29. ModelUtils() = default;
  30. ~ModelUtils() = default;
  31. ///
  32. /// @ingroup ge
  33. /// @brief Get input size.
  34. /// @return vector<uint32_t>
  35. ///
  36. static vector<int64_t> GetInputSize(ConstOpDescPtr op_desc);
  37. ///
  38. /// @ingroup ge
  39. /// @brief Get output size.
  40. /// @return vector<uint32_t>
  41. ///
  42. static vector<int64_t> GetOutputSize(ConstOpDescPtr op_desc);
  43. ///
  44. /// @ingroup ge
  45. /// @brief Get workspace size.
  46. /// @return vector<uint32_t>
  47. ///
  48. static vector<int64_t> GetWorkspaceSize(ConstOpDescPtr op_desc);
  49. ///
  50. /// @ingroup ge
  51. /// @brief Get weight size.
  52. /// @return vector<uint32_t>
  53. ///
  54. static vector<int64_t> GetWeightSize(ConstOpDescPtr op_desc);
  55. ///
  56. /// @ingroup ge
  57. /// @brief Get weights.
  58. /// @return vector<ConstGeTensorPtr>
  59. ///
  60. static vector<ConstGeTensorPtr> GetWeights(ConstOpDescPtr op_desc);
  61. ///
  62. /// @ingroup ge
  63. /// @brief Get AiCpuOp Input descriptor.
  64. /// @return vector<::tagCcAICPUTensor>
  65. ///
  66. static vector<::tagCcAICPUTensor> GetInputDescs(ConstOpDescPtr op_desc);
  67. ///
  68. /// @ingroup ge
  69. /// @brief Get AiCpuOp Output descriptor.
  70. /// @return vector<::tagCcAICPUTensor>
  71. ///
  72. static vector<::tagCcAICPUTensor> GetOutputDescs(ConstOpDescPtr op_desc);
  73. ///
  74. /// @ingroup ge
  75. /// @brief Get input data address.
  76. /// @return vector<void*>
  77. ///
  78. static vector<void *> GetInputDataAddrs(const RuntimeParam &model_param, ConstOpDescPtr op_desc);
  79. ///
  80. /// @ingroup ge
  81. /// @brief Get output data address.
  82. /// @return vector<void*>
  83. ///
  84. static vector<void *> GetOutputDataAddrs(const RuntimeParam &model_param, ConstOpDescPtr op_desc);
  85. ///
  86. /// @ingroup ge
  87. /// @brief Get workspace data address.
  88. /// @return vector<void*>
  89. ///
  90. static vector<void *> GetWorkspaceDataAddrs(const RuntimeParam &model_param, ConstOpDescPtr op_desc);
  91. ///
  92. /// @ingroup ge
  93. /// @brief Get memory runtime base.
  94. /// @return Status
  95. ///
  96. static Status GetRtAddress(const RuntimeParam &model_param, uintptr_t logic_addr, uint8_t *&mem_addr);
  97. ///
  98. /// @ingroup ge
  99. /// @brief Calculate hccl follw stream
  100. /// @return Status
  101. ///
  102. static Status CalculateFollowStream(const GeModelPtr &ge_model, int64_t &hccl_fellow_stream_num);
  103. ///
  104. /// @ingroup ge
  105. /// @brief Calculate the sum of follow stream
  106. /// @return int64_t
  107. ///
  108. static int64_t CalFollowStramSum(const std::multimap<int64_t, int64_t> &hccl_stream_map);
  109. private:
  110. ///
  111. /// @ingroup ge
  112. /// @brief Get variable address.
  113. /// @return Status
  114. ///
  115. static Status GetVarAddr(const RuntimeParam &model_param, const ConstOpDescPtr &op_desc, int64_t offset,
  116. int64_t tensor_size, uint8_t *&var_addr);
  117. };
  118. } // namespace ge
  119. #endif // GE_GRAPH_LOAD_NEW_MODEL_MANAGER_MODEL_UTILS_H_

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