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.

acl_op_compiler.h 8.0 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /**
  2. * Copyright 2019-2022 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 INC_EXTERNAL_ACL_ACL_OP_COMPILER_H_
  17. #define INC_EXTERNAL_ACL_ACL_OP_COMPILER_H_
  18. #include "acl_base.h"
  19. #include "acl_op.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef enum aclCompileType { ACL_COMPILE_SYS, ACL_COMPILE_UNREGISTERED } aclopCompileType;
  24. typedef enum {
  25. ACL_PRECISION_MODE,
  26. ACL_AICORE_NUM,
  27. ACL_AUTO_TUNE_MODE,
  28. ACL_OP_SELECT_IMPL_MODE,
  29. ACL_OPTYPELIST_FOR_IMPLMODE,
  30. ACL_OP_DEBUG_LEVEL,
  31. ACL_DEBUG_DIR,
  32. ACL_OP_COMPILER_CACHE_MODE,
  33. ACL_OP_COMPILER_CACHE_DIR,
  34. ACL_OP_PERFORMANCE_MODE,
  35. ACL_OP_JIT_COMPILE
  36. } aclCompileOpt;
  37. typedef enum aclCompileFlag { ACL_OP_COMPILE_DEFAULT, ACL_OP_COMPILE_FUZZ } aclOpCompileFlag;
  38. typedef struct aclGraphDumpOption aclGraphDumpOption;
  39. /**
  40. * @ingroup AscendCL
  41. * @brief compile op
  42. *
  43. * @param opType [IN] op type
  44. * @param numInputs [IN] number of inputs
  45. * @param inputDesc [IN] pointer to array of input tensor descriptions
  46. * @param numOutputs [IN] number of outputs
  47. * @param outputDesc [IN] pointer to array of output tensor descriptions
  48. * @param attr [IN] pointer to instance of aclopAttr.
  49. * may pass nullptr if the op has no attribute
  50. * @param engineType [IN] engine type
  51. * @param compileFlag [IN] compile flag
  52. * @param opPath [IN] path of op
  53. *
  54. * @retval ACL_SUCCESS The function is successfully executed.
  55. * @retval OtherValues Failure
  56. */
  57. ACL_FUNC_VISIBILITY aclError aclopCompile(const char *opType, int numInputs, const aclTensorDesc *const inputDesc[],
  58. int numOutputs, const aclTensorDesc *const outputDesc[],
  59. const aclopAttr *attr, aclopEngineType engineType,
  60. aclopCompileType compileFlag, const char *opPath);
  61. /**
  62. * @ingroup AscendCL
  63. * @brief compile and execute op
  64. *
  65. * @param opType [IN] op type
  66. * @param numInputs [IN] number of inputs
  67. * @param inputDesc [IN] pointer to array of input tensor descriptions
  68. * @param inputs [IN] pointer to array of input buffers
  69. * @param numOutputs [IN] number of outputs
  70. * @param outputDesc [IN] pointer to array of output tensor descriptions
  71. * @param outputs [IN] pointer to array of outputs buffers
  72. * @param attr [IN] pointer to instance of aclopAttr.
  73. * may pass nullptr if the op has no attribute
  74. * @param engineType [IN] engine type
  75. * @param compileFlag [IN] compile flag
  76. * @param opPath [IN] path of op
  77. * @param stream [IN] stream handle
  78. *
  79. * @retval ACL_SUCCESS The function is successfully executed.
  80. * @retval OtherValues Failure
  81. */
  82. ACL_FUNC_VISIBILITY aclError aclopCompileAndExecute(
  83. const char *opType, int numInputs, const aclTensorDesc *const inputDesc[], const aclDataBuffer *const inputs[],
  84. int numOutputs, const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[], const aclopAttr *attr,
  85. aclopEngineType engineType, aclopCompileType compileFlag, const char *opPath, aclrtStream stream);
  86. /**
  87. * @ingroup AscendCL
  88. * @brief compile and execute op
  89. *
  90. * @param opType [IN] op type
  91. * @param numInputs [IN] number of inputs
  92. * @param inputDesc [IN] pointer to array of input tensor descriptions
  93. * @param inputs [IN] pointer to array of input buffers
  94. * @param numOutputs [IN] number of outputs
  95. * @param outputDesc [IN|OUT] pointer to array of output tensor descriptions
  96. * @param outputs [IN] pointer to array of outputs buffers
  97. * @param attr [IN] pointer to instance of aclopAttr.
  98. * may pass nullptr if the op has no attribute
  99. * @param engineType [IN] engine type
  100. * @param compileFlag [IN] compile flag
  101. * @param opPath [IN] path of op
  102. * @param stream [IN] stream handle
  103. *
  104. * @retval ACL_SUCCESS The function is successfully executed.
  105. * @retval OtherValues Failure
  106. */
  107. ACL_FUNC_VISIBILITY aclError aclopCompileAndExecuteV2(const char *opType, int numInputs, aclTensorDesc *inputDesc[],
  108. aclDataBuffer *inputs[], int numOutputs,
  109. aclTensorDesc *outputDesc[], aclDataBuffer *outputs[],
  110. aclopAttr *attr, aclopEngineType engineType,
  111. aclopCompileType compileFlag, const char *opPath,
  112. aclrtStream stream);
  113. /**
  114. * @ingroup AscendCL
  115. * @brief set compile option
  116. *
  117. * @param aclCompileOpt [IN] compile option
  118. * @param value [IN] pointer for the option value
  119. *
  120. * @retval ACL_SUCCESS The function is successfully executed.
  121. * @retval OtherValues Failure
  122. */
  123. ACL_FUNC_VISIBILITY aclError aclSetCompileopt(aclCompileOpt opt, const char *value);
  124. /**
  125. * @ingroup AscendCL
  126. * @brief set compile flag
  127. *
  128. * @param flag [IN] compile flag, ACL_OP_COMPILE_DEFAULT means compile with default mode
  129. * ACL_OP_COMPILE_FUZZ means compile with fuzz mode
  130. *
  131. * @retval ACL_SUCCESS The function is successfully executed.
  132. * @retval OtherValues Failure
  133. */
  134. ACL_FUNC_VISIBILITY aclError aclopSetCompileFlag(aclOpCompileFlag flag);
  135. /**
  136. * @ingroup AscendCL
  137. * @brief generate graph and dump
  138. *
  139. * @param opType [IN] op type
  140. * @param numInputs [IN] number of inputs
  141. * @param inputDesc [IN] pointer to array of input tensor descriptions
  142. * @param inputs [IN] pointer to array of input buffers
  143. * @param numOutputs [IN] number of outputs
  144. * @param outputDesc [IN] pointer to array of output tensor descriptions
  145. * @param outputs [IN] pointer to array of outputs buffers
  146. * @param attr [IN] pointer to instance of aclopAttr.
  147. * may pass nullptr if the op has no attribute
  148. * @param engineType [IN] engine type
  149. * @param graphDumpPath [IN] dump path, if the suffix is ".txt", it means file path, else it means directory path
  150. * @param graphDumpOpt [IN] dump option, nullptr is supported
  151. *
  152. * @retval ACL_SUCCESS The function is successfully executed.
  153. * @retval OtherValues Failure
  154. */
  155. ACL_FUNC_VISIBILITY aclError aclGenGraphAndDumpForOp(
  156. const char *opType, int numInputs, const aclTensorDesc *const inputDesc[], const aclDataBuffer *const inputs[],
  157. int numOutputs, const aclTensorDesc *const outputDesc[], aclDataBuffer *const outputs[], const aclopAttr *attr,
  158. aclopEngineType engineType, const char *graphDumpPath, const aclGraphDumpOption *graphDumpOpt);
  159. /**
  160. * @ingroup AscendCL
  161. * @brief Create the graph dump option
  162. *
  163. * @retval null for failed
  164. * @retval OtherValues success
  165. *
  166. * @see aclDestroyGraphDumpOpt
  167. */
  168. ACL_FUNC_VISIBILITY aclGraphDumpOption *aclCreateGraphDumpOpt();
  169. /**
  170. * @ingroup AscendCL
  171. * @brief Destroy graph dump option
  172. *
  173. * @param graphDumpOpt [IN] pointer to the graph dump option
  174. *
  175. * @retval ACL_SUCCESS The function is successfully executed.
  176. * @retval OtherValues Failure
  177. *
  178. * @see aclCreateGraphDumpOpt
  179. */
  180. ACL_FUNC_VISIBILITY aclError aclDestroyGraphDumpOpt(const aclGraphDumpOption *graphDumpOpt);
  181. #ifdef __cplusplus
  182. }
  183. #endif
  184. #endif // INC_EXTERNAL_ACL_ACL_OP_COMPILER_H_

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