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.

multi_batch_options.h 4.3 kB

4 years ago
4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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_PREPROCESS_MULTI_BATCH_OPTIONS_H_
  17. #define GE_GRAPH_PREPROCESS_MULTI_BATCH_OPTIONS_H_
  18. #include <vector>
  19. #include "external/ge/ge_api_error_codes.h"
  20. #include "graph/ge_tensor.h"
  21. #include "graph/op_desc.h"
  22. #include "graph/node.h"
  23. namespace ge {
  24. namespace multibatch {
  25. ///
  26. /// @ingroup ge
  27. /// @brief Update Dynamic Param from Options.
  28. /// @param [in] ComputeGraphPtr &graph: the train graph
  29. /// @return SUCCESS: valid / PARAM_INVALID: invalid.
  30. ///
  31. Status CheckSequenceOfOptions(ComputeGraphPtr &graph, std::vector<NodePtr> &data_nodes,
  32. std::vector<NodePtr> &getnext_nosink_nodes, std::vector<NodePtr> &getnext_sink_nodes);
  33. Status UpdateNameOfInputShape(ComputeGraphPtr &graph, const vector<NodePtr> &data_nodes,
  34. const vector<NodePtr> &getnext_nosink_nodes, const vector<NodePtr> &getnext_sink_nodes);
  35. Status DeleteIdentityInsertByAdapter(ComputeGraphPtr &graph);
  36. Status CheckNegativeCountOfOptions(const std::vector<std::vector<int64_t>> &shapes);
  37. ///
  38. /// @ingroup ge
  39. /// @brief Init Dynamic Param from Options.
  40. /// @param [out] std::vector<std::vector<int64_t>> &shapes: Result for Params.
  41. /// @return true: Configed for Multi batch / false: Not configed for Multi batch.
  42. ///
  43. bool InitDynamicParams(std::vector<std::vector<int64_t>> &shapes);
  44. ///
  45. /// @ingroup ge
  46. /// @brief Check Dynamic Param is invalid.
  47. /// @param [in] const vector<vector<int64_t>> &shapes: Params for check.
  48. /// @return SUCCESS: valid / PARAM_INVALID: invalid.
  49. ///
  50. Status CheckDynamicParams(const std::vector<std::vector<int64_t>> &shapes);
  51. ///
  52. /// @ingroup ge
  53. /// @brief Get GeShape from configed shape.
  54. /// @param [in] const std::vector<int64_t> &batch_shape: Configed shape.
  55. /// @param [out] GeShape &data_shape: GeShape for configed shape.
  56. /// @return SUCCESS / PARAM_INVALID
  57. ///
  58. Status CalcShape(const std::vector<int64_t> &batch_shape, GeShape &data_shape);
  59. ///
  60. /// @ingroup ge
  61. /// @brief parse each data's own dynamic dims.
  62. /// @param [in] vector<vector<int64_t>> &shapes: dynamic batch gears info.
  63. /// @param [in] vector<pair<string, vector<int64_t>>> data_name_and_shape: eg:{{data:{1,1,-1,2}}}.
  64. /// @param [out] map<string, vector<vector<int64_t>>> &data_to_dynamic_info: key:data_name. value:dynamic dims.
  65. /// @return SUCCESS / PARAM_INVALID
  66. ///
  67. Status ParserDataToDynmaicInfo(const vector<vector<int64_t>> &shapes,
  68. vector<pair<string, vector<int64_t>>> &data_name_and_shape,
  69. map<string, vector<vector<int64_t>>> &data_to_dynamic_info);
  70. ///
  71. /// @ingroup ge
  72. /// @brief Set mbatch_dynamic_type on node.
  73. /// @param [in] const OpDescPtr &op_desc: Node for set attribute.
  74. /// @return 0: SUCCESS / others: INTERNAL_ERROR
  75. ///
  76. Status StampDynamicType(const OpDescPtr &op_desc);
  77. ///
  78. /// @ingroup ge
  79. /// @brief Check dynamic batch Shape.
  80. /// @param [in] const vector<int64_t> &shape: data_shape to be checked.
  81. /// @param [in] const string &data_name: cur data name.
  82. /// @return 0: true/false
  83. ///
  84. bool CheckDynamicBatchShape(const vector<int64_t> &shape, const string &data_name);
  85. ///
  86. /// @ingroup ge
  87. /// @brief Check Dynamic image size shape.
  88. /// @param [in] unordered_map<string, vector<int64_t>> &shape_map: map of data_name and data_shape.
  89. /// @param [in] const string &data_name: cur data name.
  90. /// @param [in] const std::string &input_format: cur data format.
  91. /// @param [in] const std::string &input_format: format of input.
  92. /// @return 0: true/false
  93. ///
  94. bool CheckDynamicImageSizeShape(const vector<int64_t> &shape, const string &data_name,
  95. const std::string &input_format);
  96. } // namespace multibatch
  97. } // namespace ge
  98. #endif // GE_GRAPH_PREPROCESS_MULTI_BATCH_OPTIONS_H_

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