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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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_CONTEXT_H__
  17. #define __CCE_RUNTIME_CONTEXT_H__
  18. #include "base.h"
  19. #ifdef __cplusplus
  20. extern "C" {
  21. #endif
  22. /**
  23. * @ingroup rt_context
  24. * @brief runtime context handle.
  25. */
  26. typedef void *rtContext_t;
  27. typedef enum tagDryRunFlag {
  28. RT_DRYRUN_FLAG_FALSE = 0,
  29. RT_DRYRUN_FLAG_TRUE = 1,
  30. } rtDryRunFlag_t;
  31. typedef enum tagCtxMode {
  32. RT_CTX_NORMAL_MODE = 0,
  33. RT_CTX_GEN_MODE = 1,
  34. } rtCtxMode_t;
  35. /**
  36. * @ingroup rt_context
  37. * @brief create context and associates it with the calling thread
  38. * @param [out] ctx created context
  39. * @param [in] flags context creation flag. set to 0.
  40. * @param [in] device device to create context on
  41. * @return RT_ERROR_NONE for ok
  42. */
  43. RTS_API rtError_t rtCtxCreate(rtContext_t *ctx, uint32_t flags, int32_t device);
  44. /**
  45. * @ingroup rt_context
  46. * @brief create context and associates it with the calling thread
  47. * @param [out] ctx created context
  48. * @param [in] flags context creation flag. set to 0.
  49. * @param [in] device device to create context on
  50. * @return RT_ERROR_NONE for ok
  51. */
  52. RTS_API rtError_t rtCtxCreateEx(rtContext_t *ctx, uint32_t flags, int32_t device);
  53. /**
  54. * @ingroup rt_context
  55. * @brief destroy context instance
  56. * @param [in] ctx context to destroy
  57. * @return RT_ERROR_NONE for ok
  58. */
  59. RTS_API rtError_t rtCtxDestroy(rtContext_t ctx);
  60. /**
  61. * @ingroup rt_context
  62. * @brief destroy context instance
  63. * @param [in] ctx context to destroy
  64. * @return RT_ERROR_NONE for ok
  65. */
  66. RTS_API rtError_t rtCtxDestroyEx(rtContext_t ctx);
  67. /**
  68. * @ingroup rt_context
  69. * @brief binds context to the calling CPU thread.
  70. * @param [in] ctx context to bind. if NULL, unbind current context.
  71. * @return RT_ERROR_NONE for ok
  72. */
  73. RTS_API rtError_t rtCtxSetCurrent(rtContext_t ctx);
  74. /**
  75. * @ingroup rt_context
  76. * @brief block for a context's tasks to complete
  77. * @return RT_ERROR_NONE for ok
  78. */
  79. RTS_API rtError_t rtCtxSynchronize(void);
  80. /**
  81. * @ingroup rt_context
  82. * @brief returns the context bound to the calling CPU thread.
  83. * @param [out] ctx returned context
  84. * @return RT_ERROR_NONE for ok
  85. */
  86. RTS_API rtError_t rtCtxGetCurrent(rtContext_t *ctx);
  87. /**
  88. * @ingroup rt_context
  89. * @brief returns the primary context of device.
  90. * @param [out] ctx returned context
  91. * @return RT_ERROR_NONE for ok
  92. */
  93. RTS_API rtError_t rtGetPriCtxByDeviceId(int32_t device, rtContext_t *ctx);
  94. /**
  95. * @ingroup rt_context
  96. * @brief returns the device ID for the current context
  97. * @param [out] device returned device id
  98. * @return RT_ERROR_NONE for ok
  99. */
  100. RTS_API rtError_t rtCtxGetDevice(int32_t *device);
  101. /**
  102. * @ingroup rt_context
  103. * @brief set ctx run mode: normal or dryrun
  104. * @param [in] ctx: context
  105. * @param [in] enable: set true means enable dryrun mode
  106. * @param [in] flag: reserved
  107. * @return RT_ERROR_NONE for ok
  108. */
  109. RTS_API rtError_t rtCtxSetDryRun(rtContext_t ctx, rtDryRunFlag_t enable, uint32_t flag);
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. #endif // __CCE_RUNTIME_CONTEXT_H__

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