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 4.1 kB

5 years ago
5 years ago
5 years ago
4 years ago
5 years ago
4 years ago
5 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 "graph/debug/ge_attr_define.h"
  21. #include "framework/common/util.h"
  22. #include "graph/attr_value.h"
  23. #include "graph/ge_tensor.h"
  24. #include "graph/node.h"
  25. #include "graph/op_desc.h"
  26. #include "proto/insert_op.pb.h"
  27. namespace ge {
  28. // Add Sub Mul
  29. GE_FUNC_VISIBILITY extern const uint32_t ADD_INPUT_NUM;
  30. GE_FUNC_VISIBILITY extern const uint32_t MUL_INPUT_NUM;
  31. // Permute
  32. GE_FUNC_VISIBILITY extern const int32_t PERMUTE_ORDER_NUM;
  33. // Ssd PriroBox
  34. GE_FUNC_VISIBILITY extern const float64_t SSD_PRIORBOX_ASPECT_RATIO_VALUE;
  35. GE_FUNC_VISIBILITY extern const uint32_t STRIDEDSLICE_INPUT_NUM;
  36. // Switch
  37. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_INPUT_NUM;
  38. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_OUTPUT_NUM;
  39. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_FALSE_OUTPUT;
  40. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_TRUE_OUTPUT;
  41. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_DATA_INPUT;
  42. GE_FUNC_VISIBILITY extern const uint32_t SWITCH_PRED_INPUT;
  43. // Merge
  44. GE_FUNC_VISIBILITY extern const int32_t MERGE_DATA_OUTPUT;
  45. GE_FUNC_VISIBILITY extern const int32_t MERGE_INDEX_OUTPUT;
  46. // FunctionOp
  47. GE_FUNC_VISIBILITY extern const uint32_t IF_COND_INPUT;
  48. GE_FUNC_VISIBILITY extern const uint32_t FOR_START_INPUT;
  49. GE_FUNC_VISIBILITY extern const uint32_t FOR_LIMIT_INPUT;
  50. GE_FUNC_VISIBILITY extern const uint32_t FOR_DELTA_INPUT;
  51. GE_FUNC_VISIBILITY extern const uint32_t FOR_DATA_INPUT;
  52. GE_FUNC_VISIBILITY extern const int32_t NORMAL_TENSOR_SIZE;
  53. /*lint -e148*/
  54. class GE_FUNC_VISIBILITY OpUtils {
  55. public:
  56. ///
  57. /// @brief Extract AIPP parameters from AttrDefMap and splice them
  58. /// @param [in] aipp_attr attr of operator
  59. /// @param [out] aipp_params aipp parameters
  60. /// @return enum of tagCCAippInputFormat
  61. ///
  62. static Status ConvertAippParams(const GeAttrValue::NamedAttrs &aipp_attr, domi::AippOpParams &aipp_params);
  63. template <typename T>
  64. static void SliceData(const std::vector<char_t *> &input, const int64_t chunk_size, std::vector<char_t *> &output,
  65. const int64_t begin, const int64_t out_dim, const int64_t stride);
  66. template <typename T>
  67. static Status SetDataByDataType(const size_t out_size, const std::vector<char_t *> &chunk_input,
  68. const std::vector<char_t *> &chunk_output, GeTensor *const output);
  69. template <typename T>
  70. static Status SetOutputSliceDataByDataType(void *const data, const int64_t data_size,
  71. const std::vector<int64_t> &input_dims, const std::vector<int64_t> &begin,
  72. const std::vector<int64_t> &output_dims, ge::GeTensor *const output,
  73. const std::vector<int64_t> &stride);
  74. static Status SetOutputSliceData(void *const data, const int64_t data_size, const int32_t data_type,
  75. const std::vector<int64_t> &input_dims, const std::vector<int64_t> &begin,
  76. const std::vector<int64_t> &output_dims, GeTensor *const output,
  77. const std::vector<int64_t> &stride);
  78. static Status GetShapeDataFromConstTensor(const ConstGeTensorPtr &tensor, const DataType type,
  79. std::vector<int64_t> &dims);
  80. };
  81. /*lint +e148*/
  82. } // namespace ge
  83. #endif // INC_FRAMEWORK_COMMON_OP_GE_OP_UTILS_H_

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