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.

stream.h 7.2 kB

5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. * Copyright 2019-2020 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 __CCE_RUNTIME_STREAM_H__
  17. #define __CCE_RUNTIME_STREAM_H__
  18. #include "base.h"
  19. #include "event.h"
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /**
  24. * @ingroup stream_flags
  25. * @brief stream op bit flags
  26. */
  27. #define RT_STREAM_DEFAULT (0x00)
  28. #define RT_STREAM_PERSISTENT (0x01)
  29. #define RT_STREAM_FORCE_COPY (0x02)
  30. #define RT_STREAM_HUGE (0x04)
  31. #define RT_STREAM_AICPU (0x08)
  32. #define RT_STREAM_FORBIDDEN_DEFAULT (0x10)
  33. #define RT_STREAM_HEAD (0x20)
  34. /**
  35. * priority level default value when create a stream
  36. */
  37. #define RT_STREAM_PRIORITY_DEFAULT (0)
  38. /**
  39. * @ingroup dvrt_stream
  40. * @brief create stream instance
  41. * @param [in|out] stream created stream
  42. * @param [in] priority stream priority
  43. * @return RT_ERROR_NONE for ok
  44. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream handle
  45. * @return RT_ERROR_INVALID_VALUE for error input priority
  46. */
  47. RTS_API rtError_t rtStreamCreate(rtStream_t *stream, int32_t priority);
  48. /**
  49. * @ingroup dvrt_stream
  50. * @brief create stream instance
  51. * @param [in|out] stream created stream
  52. * @param [in] priority stream priority
  53. * @param [in] flags stream op flags
  54. * @return RT_ERROR_NONE for ok
  55. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream handle
  56. * @return RT_ERROR_INVALID_VALUE for error input priority
  57. */
  58. RTS_API rtError_t rtStreamCreateWithFlags(rtStream_t *stream, int32_t priority, uint32_t flags);
  59. /**
  60. * @ingroup dvrt_stream
  61. * @brief destroy stream instance.
  62. * @param [in] stream the stream to destroy
  63. * @return RT_ERROR_NONE for ok
  64. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream handle
  65. */
  66. RTS_API rtError_t rtStreamDestroy(rtStream_t stream);
  67. /**
  68. * @ingroup dvrt_stream
  69. * @brief wait an recorded event for stream
  70. * @param [in] stream the wait stream
  71. * @param [in] event the event to wait
  72. * @return RT_ERROR_NONE for ok
  73. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream or event handle
  74. */
  75. RTS_API rtError_t rtStreamWaitEvent(rtStream_t stream, rtEvent_t event);
  76. /**
  77. * @ingroup dvrt_stream
  78. * @brief wait stream to be complete
  79. * @param [in] stream stream to wait
  80. * @return RT_ERROR_NONE for ok
  81. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream or event handle
  82. */
  83. RTS_API rtError_t rtStreamSynchronize(rtStream_t stream);
  84. /**
  85. * @ingroup dvrt_stream
  86. * @brief queries an asynchronous stream for completion status
  87. * @param [in] stream stream to query
  88. * @return RT_ERROR_NONE for complete
  89. * @return RT_ERROR_NOT_READY for not complete
  90. */
  91. RTS_API rtError_t rtStreamQuery(rtStream_t stream);
  92. /**
  93. * @ingroup dvrt_stream
  94. * @brief get stream id from a stream handle
  95. * @param [in] stream stream hadle
  96. * @param [in] streamId stream id
  97. * @return RT_ERROR_NONE for complete
  98. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream handle
  99. */
  100. RTS_API rtError_t rtGetStreamId(rtStream_t stream, int32_t *streamId);
  101. /**
  102. * @ingroup dvrt_stream
  103. * @brief inquire max stream count and max task count per stream
  104. * @param [in] MaxStrCount Max stream count
  105. * @param [in] MaxTaskCount max task count per stream
  106. * @return RT_ERROR_NONE for complete
  107. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for error input stream handle
  108. */
  109. RTS_API rtError_t rtGetMaxStreamAndTask(uint32_t *MaxStrCount, uint32_t *MaxTaskCount);
  110. /**
  111. * @ingroup dvrt_stream
  112. * @brief Name a stream
  113. * @param [in] stream_ stream to be named
  114. * @param [in] name identification name
  115. * @return RT_ERROR_NONE for complete
  116. * @return RT_ERROR_INVALID_VALUE for error input
  117. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for invalid resource handle
  118. */
  119. RTS_API rtError_t rtNameStream(rtStream_t stream_, const char *name);
  120. /**
  121. * @ingroup dvrt_stream
  122. * @brief switch to the corresponding stream according to the contents of the ptr
  123. * @param [in] ptr Determine the address where the value of the true and false branches is located
  124. * @param [in] condition switch condition
  125. * @param [in] value switch value
  126. * @param [in] true_stream Stream that needs to be activated when the value is non-zero
  127. * @param [in] stream input stream to init task
  128. * @return RT_ERROR_NONE for complete
  129. * @return RT_ERROR_INVALID_VALUE for error input
  130. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for invalid resource handle
  131. * @return RT_ERROR_INVALID_DEVICE for invalid device handle
  132. * @return ERROR_RECYCLE for switching task init failed or submit failed
  133. */
  134. RTS_API rtError_t rtStreamSwitch(void *ptr, rtCondition_t condition, int64_t value, rtStream_t true_stream,
  135. rtStream_t stream);
  136. /**
  137. * @brief execute extensible stream switch task
  138. * @param [in] ptr pointer of value
  139. * @param [in] condition judge condition
  140. * @param [in] value_ptr pointer of target value
  141. * @param [in] true_stream stream to be activated when value is not zero
  142. * @param [in] stream stream id
  143. * @param [in] dataType data type of target value
  144. * @return RT_ERROR_NONE for complete
  145. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for not complete
  146. */
  147. RTS_API rtError_t rtStreamSwitchEx(void *ptr, rtCondition_t condition, void *value_ptr, rtStream_t true_stream,
  148. rtStream_t stream, rtSwitchDataType_t dataType);
  149. /**
  150. * @ingroup dvrt_stream
  151. * @brief Active a stream
  152. * @param [in] active_stream stream to be activated
  153. * @param [in] stream input stream to init task
  154. * @return RT_ERROR_NONE for complete
  155. * @return RT_ERROR_INVALID_VALUE for error input
  156. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for invalid resource handle
  157. * @return RT_ERROR_INVALID_DEVICE for invalid device handle
  158. * @return ERROR_RECYCLE for switching task init failed or submit failed
  159. */
  160. RTS_API rtError_t rtStreamActive(rtStream_t active_stream, rtStream_t stream);
  161. /**
  162. * @brief execute extensible stream case switch task
  163. * @param [in] ptr pointer of value
  164. * @param [in] size pointer num of value
  165. * @param [in] valuePtr pointer of target value, length = size * elementSize
  166. * @param [in] trueStreamPtr streams to be activated
  167. * @param [in] elementSize size of to be activated true streams
  168. * @param [in] stream input stream to init task
  169. * @param [in] dataType data type of target value
  170. * @return RT_ERROR_NONE for complete
  171. * @return RT_ERROR_INVALID_RESOURCE_HANDLE for not complete
  172. */
  173. RTS_API rtError_t rtStreamSwitchN(void *ptr, uint32_t size, void *valuePtr, rtStream_t *trueStreamPtr,
  174. uint32_t elementSize, rtStream_t stream, rtSwitchDataType_t dataType);
  175. #ifdef __cplusplus
  176. }
  177. #endif
  178. #endif // __CCE_RUNTIME_STREAM_H__

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