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.

stateful_random_ops.h 8.3 kB

4 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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 stateful_random_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_STATEFUL_RANDOM_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_STATEFUL_RANDOM_OPS_H_
  22. #include "graph/operator.h"
  23. #include "graph/operator_reg.h"
  24. namespace ge {
  25. /**
  26. *@brief Non-deterministically generates some integers . \n
  27. *@par Inputs:
  28. *This op may use some OS-provided source of non-determinism (e.g. an RNG),
  29. *so each execution will give different results. Inputs included:
  30. *@li shape: The shape of the output tensor . \n
  31. *@par Outputs:
  32. *y:A Returns Non-deterministic integer values with specified shape . \n
  33. *@par Third-party framework compatibility
  34. *Compatible with tensorflow NonDeterministicInts operator.
  35. */
  36. REG_OP(NonDeterministicInts)
  37. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  38. .OUTPUT(y, TensorType({DT_INT32,DT_INT64}))
  39. .REQUIRED_ATTR(dtype, Type)
  40. .OP_END_FACTORY_REG(NonDeterministicInts)
  41. /**
  42. *@brief Advance the counter of a counter-based RNG. The state of the RNG after
  43. *`rng_skip(n)` will be the same as that after `stateful_uniform([n])`
  44. *(or any other distribution). The actual increment added to the
  45. *counter is an unspecified implementation detail . \n
  46. *@par Inputs:
  47. *@li resource: The handle of the resource variable that stores the state of the RNG.
  48. *@li algorithm: The RNG algorithm.
  49. *@li delta: The amount of advancement . \n
  50. *@par Outputs:
  51. *y:A Returns the created operation . \n
  52. *@par Third-party framework compatibility
  53. * Compatible with tensorflow RngSkip operator.
  54. */
  55. REG_OP(RngSkip)
  56. .INPUT(x, TensorType({DT_RESOURCE}))
  57. .INPUT(algorithm, TensorType({DT_INT64}))
  58. .INPUT(delta, TensorType({DT_INT64}))
  59. .OP_END_FACTORY_REG(RngSkip)
  60. /**
  61. *@brief Outputs random integers from a uniform distribution.
  62. The generated values are uniform integers in the range `[minval, maxval)`.
  63. The lower bound `minval` is included in the range, while the upper bound
  64. `maxval` is excluded.
  65. The random integers are slightly biased unless `maxval - minval` is an exact
  66. power of two. The bias is small for values of `maxval - minval` significantly
  67. smaller than the range of the output (either `2^32` or `2^64`) . \n
  68. *@par Inputs:
  69. *@li resource: The handle of the resource variable that stores the state of the RNG.
  70. *@li algorithm: The RNG algorithm.
  71. *@li shape: The shape of the output tensor.
  72. *@li minval: Minimum value (inclusive, scalar).
  73. *@li maxval: Maximum value (exclusive, scalar) . \n
  74. *@par Outputs:
  75. *y:A Returns Random values with specified shape . \n
  76. *@par Third-party framework compatibility
  77. * Compatible with tensorflow StatefulRandomBinomial operator.
  78. */
  79. REG_OP(StatefulRandomBinomial)
  80. .INPUT(x, TensorType({DT_RESOURCE}))
  81. .INPUT(algorithm, TensorType({DT_INT64}))
  82. .INPUT(shape, TensorType({DT_INT32}))
  83. .INPUT(counts, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  84. .INPUT(probs, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  85. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  86. .REQUIRED_ATTR(dtype, Type)
  87. .OP_END_FACTORY_REG(StatefulRandomBinomial)
  88. /**
  89. *@brief Outputs random values from a normal distribution.
  90. *The generated values will have mean 0 and standard deviation 1 . \n
  91. *@par Inputs:
  92. *@li resource: The handle of the resource variable that stores the state of the RNG.
  93. *@li algorithm: The RNG algorithm.
  94. *@li shape: The shape of the output tensor . \n
  95. *@par Outputs:
  96. *y:A Returns A tensor of the specified shape filled with random normal values . \n
  97. *@par Third-party framework compatibility
  98. * Compatible with tensorflow StatefulStandardNormalV2 operator.
  99. */
  100. REG_OP(StatefulStandardNormalV2)
  101. .INPUT(x, TensorType({DT_RESOURCE}))
  102. .INPUT(algorithm, TensorType({DT_INT64}))
  103. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  104. .OUTPUT(y, TensorType({DT_FLOAT}))
  105. .OP_END_FACTORY_REG(StatefulStandardNormalV2)
  106. /**
  107. *@brief Outputs random values from a truncated normal distribution.
  108. *The generated values follow a normal distribution with mean 0 and standard
  109. *deviation 1, except that values whose magnitude is more than 2 standard
  110. *deviations from the mean are dropped and re-picked . \n
  111. *@par Inputs:
  112. *@li resource: The handle of the resource variable that stores the state of the RNG.
  113. *@li algorithm: The RNG algorithm.
  114. *@li shape: The shape of the output tensor . \n
  115. *@par Outputs:
  116. *y:A Returns Random values with specified shape . \n
  117. *@par Third-party framework compatibility
  118. * Compatible with tensorflow StatefulTruncatedNormal operator.
  119. */
  120. REG_OP(StatefulTruncatedNormal)
  121. .INPUT(x, TensorType({DT_RESOURCE}))
  122. .INPUT(algorithm, TensorType({DT_INT64}))
  123. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  124. .OUTPUT(y, TensorType({DT_FLOAT}))
  125. .OP_END_FACTORY_REG(StatefulTruncatedNormal)
  126. /**
  127. *@brief Outputs random values from a uniform distribution.
  128. The generated values follow a uniform distribution in the range `[0, 1)`. The
  129. lower bound 0 is included in the range, while the upper bound 1 is excluded.
  130. *@par Inputs:
  131. *@li resource: The handle of the resource variable that stores the state of the RNG.
  132. *@li algorithm: The RNG algorithm.
  133. *@li shape: The shape of the output tensor . \n
  134. *@par Outputs:
  135. *y:A Returns Random values with specified shape . \n
  136. *@par Third-party framework compatibility
  137. * Compatible with tensorflow StatefulUniform operator.
  138. */
  139. REG_OP(StatefulUniform)
  140. .INPUT(x, TensorType({DT_RESOURCE}))
  141. .INPUT(algorithm, TensorType({DT_INT64}))
  142. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  143. .OUTPUT(y, TensorType({DT_FLOAT}))
  144. .OP_END_FACTORY_REG(StatefulUniform)
  145. /**
  146. *@brief Outputs random integers from a uniform distribution.
  147. The generated values are uniform integers covering the whole range of `dtype` . \n
  148. *@par Inputs:
  149. *@li resource: The handle of the resource variable that stores the state of the RNG.
  150. *@li algorithm: The RNG algorithm.
  151. *@li shape: The shape of the output tensor . \n
  152. *@par Outputs:
  153. *y:A Returns Random values with specified shape . \n
  154. *@par Third-party framework compatibility
  155. * Compatible with tensorflow StatefulUniformFullInt operator.
  156. */
  157. REG_OP(StatefulUniformFullInt)
  158. .INPUT(x, TensorType({DT_RESOURCE}))
  159. .INPUT(algorithm, TensorType({DT_INT64}))
  160. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  161. .OUTPUT(y, TensorType({DT_UINT64}))
  162. .OP_END_FACTORY_REG(StatefulUniformFullInt)
  163. /**
  164. *@brief Outputs random integers from a uniform distribution.
  165. The generated values are uniform integers in the range `[minval, maxval)`.
  166. The lower bound `minval` is included in the range, while the upper bound
  167. `maxval` is excluded.
  168. The random integers are slightly biased unless `maxval - minval` is an exact
  169. power of two. The bias is small for values of `maxval - minval` significantly
  170. smaller than the range of the output (either `2^32` or `2^64`) . \n
  171. *@par Inputs:
  172. *@li resource: The handle of the resource variable that stores the state of the RNG.
  173. *@li algorithm: The RNG algorithm.
  174. *@li shape: The shape of the output tensor.
  175. *@li minval: Minimum value (inclusive, scalar).
  176. *@li maxval: Maximum value (exclusive, scalar) . \n
  177. *@par Outputs:
  178. *y:A Returns Random values with specified shape . \n
  179. *@par Third-party framework compatibility
  180. * Compatible with tensorflow StatefulUniformInt operator.
  181. */
  182. REG_OP(StatefulUniformInt)
  183. .INPUT(x, TensorType({DT_RESOURCE}))
  184. .INPUT(algorithm, TensorType({DT_INT64}))
  185. .INPUT(shape, TensorType({DT_INT32,DT_INT64}))
  186. .INPUT(minval, TensorType({DT_INT64}))
  187. .INPUT(maxval, TensorType({DT_INT64}))
  188. .OUTPUT(y, TensorType({DT_INT64}))
  189. .OP_END_FACTORY_REG(StatefulUniformInt)
  190. } // namespace ge
  191. #endif // OPS_BUILT_IN_OP_PROTO_INC_STATEFUL_RANDOM_OPS_H_

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