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.

context.h 4.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /**
  2. * Copyright 2020 Huawei Technologies Co., Ltd
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. * http://www.apache.org/licenses/LICENSE-2.0
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. #ifndef CCE_RUNTIME_CONTEXT_H
  14. #define CCE_RUNTIME_CONTEXT_H
  15. #include "base.h"
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif
  19. /**
  20. * @ingroup rt_context
  21. * @brief runtime context handle.
  22. */
  23. typedef void *rtContext_t;
  24. typedef enum tagDryRunFlag {
  25. RT_DRYRUN_FLAG_FALSE = 0,
  26. RT_DRYRUN_FLAG_TRUE = 1,
  27. } rtDryRunFlag_t;
  28. typedef enum tagCtxMode {
  29. RT_CTX_NORMAL_MODE = 0,
  30. RT_CTX_GEN_MODE = 1,
  31. } rtCtxMode_t;
  32. typedef struct tagRtGroupInfo {
  33. int32_t groupId;
  34. uint32_t flag;
  35. uint32_t aicoreNum;
  36. uint32_t aicpuNum;
  37. uint32_t aivectorNum;
  38. uint32_t sdmaNum;
  39. uint32_t activeStreamNum;
  40. void *extrPtr;
  41. } rtGroupInfo_t;
  42. /**
  43. * @ingroup rt_context
  44. * @brief create context and associates it with the calling thread
  45. * @param [out] ctx created context
  46. * @param [in] flags context creation flag. set to 0.
  47. * @param [in] device device to create context on
  48. * @return RT_ERROR_NONE for ok
  49. */
  50. RTS_API rtError_t rtCtxCreate(rtContext_t *ctx, uint32_t flags, int32_t device);
  51. /**
  52. * @ingroup rt_context
  53. * @brief create context and associates it with the calling thread
  54. * @param [out] ctx created context
  55. * @param [in] flags context creation flag. set to 0.
  56. * @param [in] device device to create context on
  57. * @param [in] deviceMode the device mode
  58. * @return RT_ERROR_NONE for ok
  59. */
  60. RTS_API rtError_t rtCtxCreateV2(rtContext_t *ctx, uint32_t flags, int32_t device, rtDeviceMode deviceMode);
  61. /**
  62. * @ingroup rt_context
  63. * @brief create context and associates it with the calling thread
  64. * @param [out] ctx created context
  65. * @param [in] flags context creation flag. set to 0.
  66. * @param [in] device device to create context on
  67. * @return RT_ERROR_NONE for ok
  68. */
  69. RTS_API rtError_t rtCtxCreateEx(rtContext_t *ctx, uint32_t flags, int32_t device);
  70. /**
  71. * @ingroup rt_context
  72. * @brief destroy context instance
  73. * @param [in] ctx context to destroy
  74. * @return RT_ERROR_NONE for ok
  75. */
  76. RTS_API rtError_t rtCtxDestroy(rtContext_t ctx);
  77. /**
  78. * @ingroup rt_context
  79. * @brief destroy context instance
  80. * @param [in] ctx context to destroy
  81. * @return RT_ERROR_NONE for ok
  82. */
  83. RTS_API rtError_t rtCtxDestroyEx(rtContext_t ctx);
  84. /**
  85. * @ingroup rt_context
  86. * @brief binds context to the calling CPU thread.
  87. * @param [in] ctx context to bind. if NULL, unbind current context.
  88. * @return RT_ERROR_NONE for ok
  89. */
  90. RTS_API rtError_t rtCtxSetCurrent(rtContext_t ctx);
  91. /**
  92. * @ingroup rt_context
  93. * @brief block for a context's tasks to complete
  94. * @return RT_ERROR_NONE for ok
  95. */
  96. RTS_API rtError_t rtCtxSynchronize(void);
  97. /**
  98. * @ingroup rt_context
  99. * @brief returns the context bound to the calling CPU thread.
  100. * @param [out] ctx returned context
  101. * @return RT_ERROR_NONE for ok
  102. */
  103. RTS_API rtError_t rtCtxGetCurrent(rtContext_t *ctx);
  104. /**
  105. * @ingroup rt_context
  106. * @brief returns the primary context of device.
  107. * @param [out] ctx returned context
  108. * @return RT_ERROR_NONE for ok
  109. */
  110. RTS_API rtError_t rtGetPriCtxByDeviceId(int32_t device, rtContext_t *ctx);
  111. /**
  112. * @ingroup rt_context
  113. * @brief returns the device ID for the current context
  114. * @param [out] device returned device id
  115. * @return RT_ERROR_NONE for ok
  116. */
  117. RTS_API rtError_t rtCtxGetDevice(int32_t *device);
  118. /**
  119. * @ingroup
  120. * @brief set group id
  121. * @param [in] groupid
  122. * @return RT_ERROR_NONE for ok, errno for failed
  123. */
  124. RTS_API rtError_t rtSetGroup(int32_t groupId);
  125. /**
  126. * @ingroup
  127. * @brief get group info
  128. * @param [in] groupid count
  129. * @return RT_ERROR_NONE for ok, errno for failed
  130. */
  131. RTS_API rtError_t rtGetGroupInfo(int32_t groupId, rtGroupInfo_t *groupInfo, uint32_t count);
  132. /**
  133. * @ingroup
  134. * @brief get group count
  135. * @param [in] groupid count
  136. * @return RT_ERROR_NONE for ok, errno for failed
  137. */
  138. RTS_API rtError_t rtGetGroupCount(uint32_t *count);
  139. /**
  140. * @ingroup rt_context
  141. * @brief set context INF mode
  142. * @param [in] mode
  143. * @return RT_ERROR_NONE for ok
  144. */
  145. RTS_API rtError_t rtSetCtxINFMode(bool mode);
  146. #if defined(__cplusplus)
  147. }
  148. #endif
  149. #endif // CCE_RUNTIME_CONTEXT_H

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