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.

ge_op_utils.h 5.0 kB

5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /**
  2. * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
  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 INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_
  17. #define INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_
  18. #include <memory>
  19. #include <vector>
  20. #include "framework/common/op/attr_value_util.h"
  21. #include "register/register_types.h"
  22. #include "register/register_error_codes.h"
  23. #include "framework/common/util.h"
  24. #include "graph/attr_value.h"
  25. #include "graph/ge_tensor.h"
  26. #include "graph/node.h"
  27. #include "graph/op_desc.h"
  28. #include "proto/insert_op.pb.h"
  29. namespace ge {
  30. // Add Sub Mul
  31. GE_FUNC_VISIBILITY extern const uint32_t ADD_INPUT_NUM;
  32. GE_FUNC_VISIBILITY extern const uint32_t SUB_INPUT_NUM;
  33. GE_FUNC_VISIBILITY extern const uint32_t MUL_INPUT_NUM;
  34. // Permute
  35. GE_FUNC_VISIBILITY extern const int32_t PERMUTE_ORDER_NUM;
  36. // Ssd PriroBox
  37. GE_FUNC_VISIBILITY extern const double SSD_PRIORBOX_ASPECT_RATIO_VALUE;
  38. GE_FUNC_VISIBILITY extern const uint32_t STRIDEDSLICE_INPUT_NUM;
  39. // Switch
  40. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_INPUT_NUM;
  41. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_OUTPUT_NUM;
  42. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_FALSE_OUTPUT;
  43. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_TRUE_OUTPUT;
  44. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_DATA_INPUT;
  45. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_PRED_INPUT;
  46. // Merge
  47. GE_FUNC_VISIBILITY extern const int32_t MERGE_DATA_OUTPUT;
  48. GE_FUNC_VISIBILITY extern const int32_t MERGE_INDEX_OUTPUT;
  49. // FunctionOp
  50. GE_FUNC_VISIBILITY extern const uint32_t IF_COND_INPUT;
  51. GE_FUNC_VISIBILITY extern const uint32_t FOR_START_INPUT;
  52. GE_FUNC_VISIBILITY extern const uint32_t FOR_LIMIT_INPUT;
  53. GE_FUNC_VISIBILITY extern const uint32_t FOR_DELTA_INPUT;
  54. GE_FUNC_VISIBILITY extern const uint32_t FOR_DATA_INPUT;
  55. GE_FUNC_VISIBILITY extern const int32_t NORMAL_TENSOR_SIZE;
  56. /*lint -e148*/
  57. class GE_FUNC_VISIBILITY OpUtils {
  58. public:
  59. ///
  60. /// @ingroup domi_ome
  61. /// @brief Check whether check_value is in [min_enum_value, max_enum_value]
  62. /// @return true Within
  63. /// @return false out of range
  64. //
  65. static inline bool CheckEnumValid(int32_t check_value, int32_t min_enum_value, int32_t max_enum_value) {
  66. return check_value < min_enum_value ? false : (check_value >= max_enum_value ? false : true);
  67. }
  68. ///
  69. /// @ingroup domi_omg
  70. /// @brief Determine whether to manually calculate the tensor size based on the values of format and dim
  71. /// @param [in] format, Format information of the tensor
  72. /// @param [in] real_dim_cnt, Tensor dim
  73. /// @return true Manually calculate the size based on dim and datatype
  74. /// @return false skip
  75. ///
  76. static bool IsComputDimsSize(const int32_t format, const uint32_t real_dim_cnt);
  77. ///
  78. /// @brief Extract AIPP parameters from AttrDefMap and splice them
  79. /// @param [in] aipp_attr attr of operator
  80. /// @param [out] aipp_params aipp parameters
  81. /// @return enum of tagCCAippInputFormat
  82. ///
  83. static Status ConvertAippParams(const NamedAttrs &aipp_attr, domi::AippOpParams &aipp_params);
  84. template <typename T>
  85. static void SliceData(const std::vector<char *> &input, int64_t chunk_size, std::vector<char *> &output,
  86. int64_t begin, int64_t out_dim, int64_t stride);
  87. template <typename T>
  88. static Status SetDataByDataType(size_t out_size, const std::vector<char *> &chunk_input,
  89. const std::vector<char *> &chunk_output, GeTensor *output);
  90. template <typename T>
  91. static Status SetOutputSliceDataByDataType(void *data, int64_t data_size, const std::vector<int64_t> &input_dims,
  92. const std::vector<int64_t> &begin, const std::vector<int64_t> &output_dims,
  93. ge::GeTensor *output, const std::vector<int64_t> &stride);
  94. static Status SetOutputSliceData(void *const data, const int64_t data_size, const int32_t data_type,
  95. const std::vector<int64_t> &input_dims, const std::vector<int64_t> &begin,
  96. const std::vector<int64_t> &output_dims, GeTensor *const output,
  97. const std::vector<int64_t> &stride);
  98. static Status GetShapeDataFromConstTensor(const ConstGeTensorPtr &tensor, const DataType type,
  99. std::vector<int64_t> &dims);
  100. };
  101. /*lint +e148*/
  102. } // namespace ge
  103. #endif // INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_

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