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.3 kB

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

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