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.

batch_ops.h 6.0 kB

5 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
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. /*!
  17. * \file batch_ops.h
  18. * \brief
  19. */
  20. #ifndef GE_OP_BATCH_OPS_H_
  21. #define GE_OP_BATCH_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. *@brief Creates batches of tensors in "x_tensors".
  26. *@par Inputs:
  27. *Input "x_tensors" is a list or a dictionary of tensors. \n
  28. *x_tensors: The list or dictionary of tensors to enqueue.
  29. *@par Attributes:
  30. *@li num_batch_threads: The number of threads enqueuing "x_tensors". \n
  31. The batching will be nondeterministic if "num_batch_threads" > 1.
  32. *@li max_batch_size: The maximum batch size pulled from the queue.
  33. *@li max_enqueued_batches: The maximum number of batches pulled from the queue.
  34. *@li batch_timeout_micros: The batch processing timeout, in microseconds.
  35. *@li allowed_batch_sizes: The allowed batch size pulled from the queue.
  36. *@li grad_timeout_micros: The gradient batch processing timeout, \n
  37. in microseconds.
  38. *@li container: If non-empty, this queue is placed in the given container. \n
  39. Otherwise, a default container is used.
  40. *@li shared_name: If set, this queue will be shared under the given name \n
  41. across multiple sessions.
  42. *@li batching_queue: The queue resource container.
  43. *@par Outputs:
  44. *@li y_index: A Tensor. The index of a BatchTensor. Must be in row-major order.
  45. *@li y_id: A Tensor. The ID of a BatchTensor. Must be in row-major order.
  46. *@li y_tensors: A list or dictionary of tensors with \n
  47. the same types as "x_tensors".
  48. *@attention Constraints: \n
  49. *Batch runs on the Ascend AI CPU, which delivers poor performance. \n
  50. *@par Third-party framework compatibility
  51. *Compatible with the TensorFlow operator Batch.
  52. */
  53. REG_OP(Batch)
  54. .DYNAMIC_INPUT(x_tensors, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, \
  55. DT_INT16, DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_BOOL, DT_DOUBLE}))
  56. .OUTPUT(y_index, TensorType({ DT_INT64 }))
  57. .OUTPUT(y_id, TensorType({ DT_INT64 }))
  58. .DYNAMIC_OUTPUT(y_tensors, TensorType({DT_INT8, DT_UINT8, DT_INT16, \
  59. DT_UINT16, DT_INT32, DT_INT64, DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_BOOL}))
  60. .REQUIRED_ATTR(num_batch_threads, Int)
  61. .REQUIRED_ATTR(max_batch_size, Int)
  62. .ATTR(max_enqueued_batches, Int, 10)
  63. .REQUIRED_ATTR(batch_timeout_micros, Int)
  64. .ATTR(allowed_batch_sizes, ListInt, {})
  65. .REQUIRED_ATTR(grad_timeout_micros, Int)
  66. .ATTR(container, String, "")
  67. .ATTR(shared_name, String, "")
  68. .ATTR(batching_queue, String, "")
  69. .OP_END_FACTORY_REG(Batch)
  70. /**
  71. *@brief Reverses the operation of Batch for a single output Tensor.
  72. *@par Inputs:
  73. *Input "x_tensors" is a list or a dictionary of tensors. \n
  74. * @li x_tensors: The list or dictionary of tensors to enqueue.
  75. * @li index: The matching "batch_index" obtained from Batch.
  76. * @li id: The "id" scalar emitted by Batch.
  77. *@par Attributes:
  78. *@li timeout_micros: The unbatch processing timeout, in microseconds.
  79. *@li container: If non-empty, this queue is placed in the given container. \n
  80. Otherwise, a default container is used.
  81. *@li shared_name: If set, this queue will be shared under the given name \n
  82. across multiple sessions.
  83. *@par Outputs:
  84. *y_tensor: A list or dictionary of tensors with the same types as "x_tensors".
  85. *@attention Constraints: \n
  86. *Unbatch runs on the Ascend AI CPU, which delivers poor performance. \n
  87. *@par Third-party framework compatibility
  88. *Compatible with the TensorFlow operator Unbatch.
  89. */
  90. REG_OP(Unbatch)
  91. .INPUT(x_tensor, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  92. DT_INT32, DT_INT64, DT_BOOL, DT_FLOAT, DT_DOUBLE}))
  93. .INPUT(index, TensorType({DT_INT64}))
  94. .INPUT(id, TensorType({DT_INT64}))
  95. .OUTPUT(y_tensor, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  96. DT_INT32, DT_INT64, DT_BOOL, DT_FLOAT, DT_DOUBLE}))
  97. .REQUIRED_ATTR(timeout_micros, Int)
  98. .ATTR(container, String, "")
  99. .ATTR(shared_name, String, "")
  100. .OP_END_FACTORY_REG(Unbatch)
  101. /**
  102. *@brief Acts like Batch but using the given "batch_index" index of batching \n
  103. things as they become available.
  104. *@par Inputs:
  105. *Input "x_input" is a list or a dictionary of tensors. \n
  106. * @li x_input: The input to the Unbatch operation.
  107. * @li index: The batch_index given to the Unbatch operation.
  108. * @li id: The "id" scalar emitted by Batch.
  109. * @li grad: The downstream gradient.
  110. *@par Attributes:
  111. *@li container: If non-empty, this queue is placed in the given container. \n
  112. Otherwise, a default container is used.
  113. *@li shared_name: If set, this queue will be shared under the given name \n
  114. across multiple sessions.
  115. *@par Outputs:
  116. *y_grad: The return value, either an empty tensor or the batched gradient.
  117. *@attention Constraints: \n
  118. *UnbatchGrad runs on the Ascend AI CPU, which delivers poor performance. \n
  119. *@par Third-party framework compatibility
  120. *Compatible with the TensorFlow operator UnbatchGrad.
  121. */
  122. REG_OP(UnbatchGrad)
  123. .INPUT(x_input, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  124. DT_INT32, DT_INT64, DT_BOOL, DT_FLOAT, DT_DOUBLE}))
  125. .INPUT(index, TensorType({DT_INT64}))
  126. .INPUT(grad, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  127. DT_INT32, DT_INT64, DT_BOOL, DT_FLOAT, DT_DOUBLE}))
  128. .INPUT(id, TensorType({DT_INT64}))
  129. .OUTPUT(y_grad, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, \
  130. DT_INT32, DT_INT64, DT_BOOL, DT_FLOAT, DT_DOUBLE}))
  131. .ATTR(container, String, "")
  132. .ATTR(shared_name, String, "")
  133. .OP_END_FACTORY_REG(UnbatchGrad)
  134. } // namespace ge
  135. #endif // GE_OP_BATCH_OPS_H_

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