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.

math_ops.h 13 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
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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 GE_OP_MATH_OPS_H_
  17. #define GE_OP_MATH_OPS_H_
  18. #include "graph/operator_reg.h"
  19. #include "graph/operator.h"
  20. namespace ge {
  21. /**
  22. *@brief Compute the lower regularized incomplete Gamma function P(a, x).
  23. *@par Inputs:
  24. *The input a and x must have the same type. Inputs include: \n
  25. *@li a:A Tensor. Must be one of the following types: float, double.
  26. *@li x:A Tensor. Must have the same type as a.
  27. *@par Outputs:
  28. *z:A Tensor. Has the same type as a.
  29. */
  30. REG_OP(Igamma)
  31. .INPUT(a, TensorType({DT_FLOAT, DT_DOUBLE}))
  32. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
  33. .OUTPUT(z, TensorType({DT_FLOAT, DT_DOUBLE}))
  34. .OP_END_FACTORY_REG(Igamma)
  35. /**
  36. *@brief Compute the upper regularized incomplete Gamma function Q(a, x).
  37. *@par Inputs:
  38. *The input a and x must have the same type. Inputs include: \n
  39. *@li a:A Tensor. Must be one of the following types: float, float64.
  40. *@li x:A Tensor. Must have the same type as a.
  41. *@par Outputs:
  42. *z:A Tensor. Has the same type as a.
  43. */
  44. REG_OP(Igammac)
  45. .INPUT(a, TensorType({DT_FLOAT, DT_DOUBLE}))
  46. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
  47. .OUTPUT(z, TensorType({DT_FLOAT, DT_DOUBLE}))
  48. .OP_END_FACTORY_REG(Igammac)
  49. /**
  50. *@brief Compare values of input to threshold and pack resulting bits into \n
  51. a uint8.
  52. *@par Inputs:
  53. *The input size must be a non-negative int32 scalar Tensor. Inputs include: \n
  54. *@li input:Values to compare against threshold and bitpack.
  55. *@li threshold:Threshold to compare against.
  56. *@par Outputs:
  57. *y:The bitpacked comparisons.
  58. *@attention Constraints: \n
  59. *Currently, the innermost dimension of the tensor must be divisible by 8. \n
  60. */
  61. REG_OP(CompareAndBitpack)
  62. .INPUT(x, TensorType({ DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_INT8, \
  63. DT_INT16, DT_INT32, DT_INT64, DT_BOOL }))
  64. .INPUT(threshold, TensorType({ DT_FLOAT, DT_FLOAT16, DT_DOUBLE, \
  65. DT_INT8, DT_INT16, DT_INT32, DT_INT64, DT_BOOL }))
  66. .OUTPUT(y, TensorType(DT_UINT8))
  67. .OP_END_FACTORY_REG(CompareAndBitpack)
  68. /**
  69. *@brief Counts the number of occurrences of each value in an integer array. \n
  70. Outputs a vector with length size and the same dtype as weights. If weights \n
  71. are empty, then index i stores the number of times the value i is counted in \n
  72. arr. If weights are non-empty, then index i stores the sum of the value in \n
  73. weights at each index.
  74. *@par Inputs:
  75. *The input size must be a non-negative int32 scalar Tensor. Inputs include: \n
  76. *@li array:int32 Tensor.
  77. *@li size:non-negative int32 scalar Tensor.
  78. *@li weights: is an int32, int64, float32, or double Tensor with the same \n
  79. shape as arr, or a length-0 Tensor, in which case it acts as all weights \n
  80. equal to 1.
  81. *@par Outputs:
  82. *bins:1D Tensor with length equal to size. The counts or summed weights for \n
  83. each value in the range [0, size).
  84. */
  85. REG_OP(Bincount)
  86. .INPUT(array, TensorType(DT_INT32))
  87. .INPUT(size, TensorType(DT_INT32))
  88. .INPUT(weights, TensorType({ DT_FLOAT, DT_INT32, DT_INT64, DT_DOUBLE }))
  89. .OUTPUT(bins, TensorType({ DT_FLOAT, DT_INT32, DT_INT64, DT_DOUBLE }))
  90. .OP_END_FACTORY_REG(Bincount)
  91. /**
  92. *@brief Compute the regularized incomplete beta integral.
  93. *@par Inputs:
  94. *The input b and x must have the same types as a. Inputs include: \n
  95. *@li a:A Tensor. Must be one of the following types: float32, double.
  96. *@li b:A Tensor. Must have the same type as a.
  97. *@li x:A Tensor. Must have the same type as a.
  98. *@par Outputs:
  99. *z:A Tensor. Has the same type as a.
  100. */
  101. REG_OP(Betainc)
  102. .INPUT(a, TensorType({DT_DOUBLE, DT_FLOAT}))
  103. .INPUT(b, TensorType({DT_DOUBLE, DT_FLOAT}))
  104. .INPUT(x, TensorType({DT_DOUBLE, DT_FLOAT}))
  105. .OUTPUT(z, TensorType({DT_DOUBLE, DT_FLOAT}))
  106. .OP_END_FACTORY_REG(Betainc)
  107. /**
  108. *@brief Compute the Hurwitz zeta function
  109. *@par Inputs:
  110. *The input q must be the same type as x. Inputs include: \n
  111. *@li x:A Tensor. Must be one of the following types: float32, double.
  112. *@li q:A Tensor. Must have the same type as x.
  113. *@par Outputs:
  114. *z:A Tensor. Has the same type as x.
  115. *@attention Constraints: \n
  116. *The implementation for Zeta on Ascend uses ai cpu, with bad performance. \n
  117. */
  118. REG_OP(Zeta)
  119. .INPUT(x, TensorType({DT_DOUBLE, DT_FLOAT}))
  120. .INPUT(q, TensorType({DT_DOUBLE, DT_FLOAT}))
  121. .OUTPUT(z, TensorType({DT_DOUBLE, DT_FLOAT}))
  122. .OP_END_FACTORY_REG(Zeta)
  123. /**
  124. *@brief Bucketizes 'input' based on 'boundaries'. For example, if the inputs \n
  125. are boundaries = [0, 10, 100] input = [[-5, 10000] [150, 10] [5, 100]] then \n
  126. the output will be output = [[0, 3] [3, 2] [1, 3]]
  127. *@par Inputs:
  128. *The dtype of input x must be int or float. Inputs include: \n
  129. *x:Any shape of Tensor contains with int or float type.
  130. *@par Attributes:
  131. *boundaries:A sorted list of floats gives the boundary of the buckets.
  132. *@par Outputs:
  133. *y:Same shape with 'input', each value of input replaced with bucket index.
  134. */
  135. REG_OP(Bucketize)
  136. .INPUT(x, TensorType({DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT}))
  137. .OUTPUT(y, TensorType({DT_INT32}))
  138. .REQUIRED_ATTR(boundaries, ListFloat)
  139. .OP_END_FACTORY_REG(Bucketize)
  140. /**
  141. *@brief Computes the sum along sparse segments of a tensor.
  142. *@par Inputs:
  143. *The input indices and segment_ids must have same rank. Inputs include: \n
  144. *@li x:A Tensor. Must be one of the following types: float, double, int32, \n
  145. uint8, int16, int8, int64, uint16, uint32, uint64.
  146. *@li indices: A Tensor. Must be one of the following types: int32, int64. \n
  147. A 1-D tensor. Has same rank as segment_ids.
  148. *@li segment_ids: A Tensor of type int32. A 1-D tensor. Values should be \n
  149. sorted and can be repeated.
  150. *@par Outputs:
  151. *y:A Tensor. Has the same type as x.
  152. */
  153. REG_OP(SparseSegmentSum)
  154. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  155. DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16}))
  156. .INPUT(indices, TensorType({DT_INT32}))
  157. .INPUT(segment_ids, TensorType({DT_INT32}))
  158. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16,
  159. DT_INT32, DT_INT64, DT_DOUBLE, DT_FLOAT, DT_FLOAT16}))
  160. .OP_END_FACTORY_REG(SparseSegmentSum)
  161. /**
  162. *@brief Computes the mean along sparse segments of a tensor.
  163. *@par Inputs:
  164. *The input indices and segment_ids must have same rank. Inputs include: \n
  165. *@li x: A Tensor. Must be one of the following types: float, double.
  166. *@li indices: A Tensor. Must be one of the following types: int32, int64. \n
  167. A 1-D tensor. Has same rank as segment_ids.
  168. *@li segment_ids: A Tensor of type int32. A 1-D tensor. Values should be \n
  169. sorted and can be repeated.
  170. *@par Outputs:
  171. *y:A Tensor. Has the same type as x.
  172. */
  173. REG_OP(SparseSegmentMean)
  174. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
  175. .INPUT(indices, TensorType({DT_INT32}))
  176. .INPUT(segment_ids, TensorType({DT_INT32}))
  177. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
  178. .OP_END_FACTORY_REG(SparseSegmentMean)
  179. /**
  180. *@brief Computes gradients for SparseSegmentMean.
  181. *@par Inputs:
  182. *The input grad must have be type float or double. Inputs include: \n
  183. *@li grad: A Tensor. Must be one of the following types: float, double. \n
  184. gradient propagated to the SparseSegmentMean op.
  185. *@li indices: A Tensor. Must be one of the following types: int32, int64. \n
  186. indices passed to the corresponding SparseSegmentMean op.
  187. *@li segment_ids: A Tensor of type int32. segment_ids passed to the \n
  188. corresponding SparseSegmentMean op.
  189. *@li output_dim0: A Tensor of type int32. dimension 0 of "x" passed to \n
  190. SparseSegmentMean op.
  191. *@par Outputs:
  192. *y:A Tensor. Has the same type as grad.
  193. */
  194. REG_OP(SparseSegmentMeanGrad)
  195. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
  196. .INPUT(indices, TensorType({DT_INT32}))
  197. .INPUT(segment_ids, TensorType({DT_INT32}))
  198. .INPUT(output_dim0, TensorType({DT_INT32}))
  199. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE}))
  200. .OP_END_FACTORY_REG(SparseSegmentMeanGrad)
  201. /**
  202. *@brief Computes the gradient of igamma(a, x) wrt a
  203. *@par Inputs:
  204. *The input a and x must have the same type. Inputs include: \n
  205. *@li a:A Tensor. Must be one of the following types: float32, double.
  206. *@li x:A Tensor. Must have the same type as a.
  207. *@par Outputs:
  208. *y:A Tensor. Has the same type as a.
  209. */
  210. REG_OP(IgammaGradA)
  211. .INPUT(a, TensorType({DT_FLOAT, DT_DOUBLE}))
  212. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE}))
  213. .OUTPUT(z, TensorType({DT_FLOAT, DT_DOUBLE}))
  214. .OP_END_FACTORY_REG(IgammaGradA)
  215. /**
  216. *@brief Initialize data process channel.
  217. *@par Attributes:
  218. *channel_name: A string. Default "".
  219. */
  220. REG_OP(InitData)
  221. .ATTR(channel_name, String, "")
  222. .OP_END_FACTORY_REG(InitData)
  223. /**
  224. *@brief Get the next batch of data in data processing.
  225. *@par Attributes:
  226. *@li output_types: A nested structure of DType objects corresponding to each \n
  227. component of an element of this dataset.
  228. *@li output_shapes: A nested structure of TensorShape objects corresponding \n
  229. to each component of an element of this dataset.
  230. *@li channel_name: A string. Default "".
  231. *@par Outputs:
  232. *y:A nested structure of Tensor objects.
  233. */
  234. REG_OP(GetNext)
  235. .DYNAMIC_OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_UINT16, DT_INT32, DT_INT64, DT_UINT32, DT_UINT64,
  236. DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_BOOL}))
  237. .ATTR(output_types, ListInt, {})
  238. .ATTR(output_shapes, ListListInt, {})
  239. .ATTR(output_num, Int, 1)
  240. .ATTR(channel_name, String, "")
  241. .OP_END_FACTORY_REG(GetNext)
  242. /**
  243. *@brief: Computes the Gauss error function of `x` element-wise.
  244. *@par Inputs:\n
  245. *x: A Tensor of type float16 or float32.
  246. *@par Outputs:
  247. *y: A Tensor. Has the same type as "x".
  248. */
  249. REG_OP(Erf)
  250. .INPUT(x, TensorType::FloatingDataType())
  251. .OUTPUT(y, TensorType::FloatingDataType())
  252. .OP_END_FACTORY_REG(Erf)
  253. /**
  254. *@brief: Computes the Gauss complementary error function of "x" element-wise.
  255. *@par Inputs:\n
  256. *x: A Tensor of type float16 or float32.
  257. *@par Outputs:
  258. *y: A Tensor. Has the same type as "x".
  259. */
  260. REG_OP(Erfc)
  261. .INPUT(x, TensorType::FloatingDataType())
  262. .OUTPUT(y, TensorType::FloatingDataType())
  263. .OP_END_FACTORY_REG(Erfc)
  264. /**
  265. *@brief This operation returns a rank 1 histogram counting the number of entries in `values` \n
  266. * that fell into every bin.The bins are equal width and determined by the arguments \n
  267. * 'value_range' and 'nbins'. \n
  268. *@par Inputs:
  269. *Three inputs, including: \n
  270. *@li x: A Tensor of type float32,float16,int32.
  271. *@li range: A Tensor of type float32,float16,int32.
  272. *@li nbins: A Tensor of type int32.
  273. *@par Attributes:
  274. * dtype: An optional attribute. Defaults to "int32".
  275. *@par Outputs:
  276. *y: A Tensor. A Tensor of type int32.
  277. */
  278. REG_OP(HistogramFixedWidth)
  279. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  280. .INPUT(range, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  281. .INPUT(nbins, TensorType({DT_INT32}))
  282. .OUTPUT(y, TensorType({DT_INT32}))
  283. .ATTR(dtype, String, "int32")
  284. .OP_END_FACTORY_REG(HistogramFixedWidth)
  285. /**
  286. *@brief This operation returns a rank 1 histogram counting the number of entries in `values` \n
  287. * that fell into every bin.The bins are equal width and determined by the arguments \n
  288. * 'value_range' and 'nbins'. \n
  289. *@par Inputs:
  290. *Two inputs, including: \n
  291. *@li x: A Tensor of type float32,float16,int32.
  292. *@li range: A Tensor of type float32,float16,int32.
  293. *@par Attributes:
  294. *@li dtype: An optional attribute. Defaults to "int32".
  295. *@li nbins: A required attribute,the type is int32.
  296. *@par Outputs:
  297. *y: A Tensor. A Tensor of type int32.
  298. */
  299. REG_OP(HistogramFixedWidthD)
  300. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  301. .INPUT(range, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  302. .OUTPUT(y, TensorType({DT_INT32}))
  303. .REQUIRED_ATTR(nbins, Int)
  304. .ATTR(dtype, String, "int32")
  305. .OP_END_FACTORY_REG(HistogramFixedWidthD)
  306. /**
  307. *@brief Returns the next representable value of x1 in the direction of x2, element-wise.
  308. *@par Inputs:
  309. *The input X1 and x2 must have the same type. Inputs include: \n
  310. *@li x1:A Tensor. Must be one of the following types: float32, double.
  311. *@li x2:A Tensor. Must have the same type as x1.
  312. *@par Outputs:
  313. *output:A Tensor. Has the same type as x1.
  314. */
  315. REG_OP(NextAfter)
  316. .INPUT(x1, TensorType({DT_FLOAT, DT_DOUBLE}))
  317. .INPUT(x2, TensorType({DT_FLOAT, DT_DOUBLE}))
  318. .OUTPUT(output, TensorType({DT_FLOAT, DT_DOUBLE}))
  319. .OP_END_FACTORY_REG(NextAfter)
  320. /**
  321. * *@brief Compute element-wise finiteness, return a boolean tensor.
  322. *
  323. * *@par Inputs:
  324. * *x:A Tensor.
  325. *
  326. * *@par Outputs:
  327. * *y:A Tensor. Has the same shape as x.
  328. *
  329. * */
  330. REG_OP(IsFinite)
  331. .INPUT(x, TensorType({DT_INT8, DT_INT16, DT_INT32, DT_INT64,
  332. DT_UINT8, DT_UINT16, DT_UINT32, DT_UINT64,
  333. DT_FLOAT, DT_FLOAT16, DT_DOUBLE, DT_BOOL}))
  334. .OUTPUT(y, TensorType({DT_BOOL}))
  335. .OP_END_FACTORY_REG(IsFinite)
  336. } // namespace ge
  337. #endif // GE_OP_MATH_OPS_H_

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