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

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