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.

nn_pooling_ops.h 27 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
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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  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_NN_POOLING_OPS_H
  17. #define GE_OP_NN_POOLING_OPS_H
  18. #include "graph/operator_reg.h"
  19. #include "graph/operator.h"
  20. namespace ge {
  21. /**
  22. *@brief Performs pooling on the input.
  23. *@par Inputs:
  24. *@li x: An NCHW tensor of type float16, float32.
  25. *@par Attributes:
  26. *@li mode: An optional int32, specifying the pooling algorithm, either "1" (max pooling) or "0" (avg pooling). Defaults to "0".
  27. *@li global_pooling: An optional bool. Defaults to "false".
  28. *@li window: Optional, including: \n
  29. *window[0]: An optional int32, specifying the window size along in the H dimension. The value range is [1, 32768]. Defaults to "1". \n
  30. *window[1]: An optional int32, specifying the window size along in the W dimension. The value range is [1, 32768]. Defaults to "1". \n
  31. *@li stride: Optional, including: \n
  32. *stride[0]: An optional int32, specifying the stride along in the H dimension. The value range is [1, 63]. Defaults to "1". \n
  33. *stride[1]: An optional int32, specifying the stride along in the W dimension. The value range is [1, 63]. Defaults to "1". \n
  34. *@li pad: Optional, including: \n
  35. *pad[0]: An optional int32, specifying the up padding. Defaults to "0". \n
  36. *pad[1]: An optional int32, specifying the bottom padding. Defaults to "0". \n
  37. *pad[2]: An optional int32, specifying the left padding. Defaults to "0". \n
  38. *pad[3]: An optional int32, specifying the right padding. Defaults to "0". \n
  39. *@li dilation: Optional, including: \n
  40. *dilation[0]: An optional int32, specifying the up dilation. Defaults to "1". \n
  41. *dilation[1]: An optional int32, specifying the bottom dilation. Defaults to "1". \n
  42. *dilation[2]: An optional int32, specifying the left dilation. Defaults to "1". \n
  43. *dilation[3]: An optional int32, specifying the right dilation. Defaults to "1". \n
  44. *@li ceil_mode: An optional int32, either "0" (ceil mode) or "1" (floor mode). Defaults to "0".
  45. *@par Outputs:
  46. *y: An NCHW tensor of type float16, float32.
  47. *@attention Constraints:\n
  48. *@li window[0] * window[1] < 256;
  49. *@li 1<=input_h<=4096,1<=input_w<=4096
  50. *@li If input tensor N is a prime number, it should be less than 65535.
  51. */
  52. REG_OP(Pooling)
  53. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT8}))
  54. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT32}))
  55. .ATTR(mode, Int, 0) // 0:max pooling or 1:avg pooling
  56. .ATTR(global_pooling, Bool, false)
  57. .ATTR(window, ListInt, {1,1}) // kernel size
  58. .ATTR(stride, ListInt, {1,1}) // stride size
  59. .ATTR(pad, ListInt, {0,0,0,0}) // pad size
  60. .ATTR(dilation, ListInt, {1,1,1,1})
  61. .ATTR(ceil_mode, Int, 0)
  62. .OP_END_FACTORY_REG(Pooling)
  63. /**
  64. *@brief Performs average pooling on the input.
  65. *@par Inputs:
  66. *x: A tensor of type float16.
  67. *@par Attributes:
  68. *@li ksize: A required list of 4 ints, specifying the size (N, C, H, and W) of the sliding window, where N = C = 1, and H and W are positive integers within the range [1, 32768].
  69. *@li strides: A required list of 4 ints, specifying the stride of the sliding window. The strides of the N and C dimensions are 1. The strides of the H and W dimensions are positive integers within the range [1, 63].
  70. *@li padding: A required string, specifying the padding algorithm, either "VALID" or "SAME". With "SAME" means that the outputs will have the same spatial dimensions as its inputs. With "VALID" means no padding.
  71. *@li data_format: An optional string, specifying the data format of "ksize" and "strides", either "NCHW", "NC1HWC0", or "NHWC" (default).
  72. *@par Outputs:
  73. *y: The average pooled output tensor.
  74. *@attention Constraints:\n
  75. *@li Only single input and single output are supported.
  76. *@li Global pooling is supported.
  77. *@li "ksize_H" and "ksize_W" are positive integers within the range [1, 32768]. ksize_H * ksize_W < 256
  78. *@li Due to instruction restrictions, the values of "strides_h" and "strides_w" are positive integers within the range [1, 63].
  79. */
  80. REG_OP(AvgPool)
  81. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  82. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  83. .REQUIRED_ATTR(ksize, ListInt)
  84. .REQUIRED_ATTR(strides, ListInt)
  85. .REQUIRED_ATTR(padding, String)
  86. .ATTR(data_format, String, "NHWC")
  87. .OP_END_FACTORY_REG(AvgPool)
  88. /**
  89. *@brief Performs max_pool_ext2 on the input.
  90. *@par Inputs:
  91. * One input:
  92. *x: An NC1HWC0 Tensor of type float16.
  93. *@par Attributes:
  94. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for each dimension of the input tensor. No default value.
  95. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for each dimension of the input tensor. No default value.
  96. *@li padding: A required string. No default value.
  97. *@li data_format: An optional string. Defaults to "NC1HWC0".
  98. *@par Outputs:
  99. *y: A Tensor. Has the same type and format as input "x".
  100. *@attention Constraints:
  101. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  102. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  103. *@li "padding" is either "SAME" or "VALID".
  104. */
  105. REG_OP(MaxPoolExt2)
  106. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  107. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  108. DT_UINT16, DT_QINT8}))
  109. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  110. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  111. DT_UINT16, DT_QINT8}))
  112. .REQUIRED_ATTR(ksize, ListInt)
  113. .REQUIRED_ATTR(strides, ListInt)
  114. .REQUIRED_ATTR(padding, String)
  115. .ATTR(data_format, String, "NHWC")
  116. .OP_END_FACTORY_REG(MaxPoolExt2)
  117. /**
  118. *@brief Performs max pooling on the input.
  119. *@par Inputs:
  120. * One input:
  121. *x: An NC1HWC0 Tensor of type float16.
  122. *@par Attributes:
  123. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for each dimension of the input tensor. No default value.
  124. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for each dimension of the input tensor. No default value.
  125. *@li padding: A required string. No default value.
  126. *@li data_format: An optional string. Defaults to "NC1HWC0".
  127. *@par Outputs:
  128. *y: A Tensor. Has the same type and format as input "x".
  129. *@attention Constraints:
  130. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  131. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  132. *@li "padding" is either "SAME" or "VALID".
  133. */
  134. REG_OP(MaxPool)
  135. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  136. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  137. DT_UINT16, DT_QINT8}))
  138. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  139. DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  140. .REQUIRED_ATTR(ksize, ListInt)
  141. .REQUIRED_ATTR(strides, ListInt)
  142. .REQUIRED_ATTR(padding, String)
  143. .ATTR(data_format, String, "NHWC")
  144. .OP_END_FACTORY_REG(MaxPool)
  145. REG_OP(MaxPool3D)
  146. .INPUT(x, TensorType({DT_FLOAT16}))
  147. .OUTPUT(y, TensorType({DT_FLOAT16}))
  148. .REQUIRED_ATTR(ksize, ListInt)
  149. .REQUIRED_ATTR(strides, ListInt)
  150. .REQUIRED_ATTR(padding, String)
  151. .ATTR(pads, ListInt, {0,0,0})
  152. .ATTR(dilation, ListInt, {0,0,0})
  153. .ATTR(ceil_mode, Int, 0)
  154. .ATTR(data_format, String, "NDHWC")
  155. .OP_END_FACTORY_REG(MaxPool3D)
  156. /**
  157. * @brief Computes gradients of the maxpooling function.
  158. * @par Inputs:
  159. * @li x1: A mutable NC1HWC0 tensor of type RealNumberType.
  160. * @li x2: A mutable NC1HWC0 tensor of type RealNumberTypex.
  161. * @li grad: A mutable NC1HWC0 tensor of type RealNumberType.
  162. * @par Attributes:
  163. * @li ksize: A required tuple or list, specifying the size of the window for
  164. * each dimension of the input tensor.
  165. * @li strides: A required tuple or list, specifying the stride of the sliding
  166. * window for each dimension of the input tensor.
  167. * @li padding: A required string, specifying the type of padding algorithm
  168. * to use.
  169. * @li data_format: An optional string, Specify the data format of the input and
  170. * output data. With the default format "NHWC".
  171. * @par Outputs:
  172. * y: A mutable tensor. Has the same shape and type as "x1".
  173. * @attention Constraints:
  174. * @li Computing gradients of global pooling is not supported, which means
  175. * "ksize < x1".
  176. * @li "ksiez" is in the range [1, 255]. "strides" is in the range [1, 63]
  177. */
  178. REG_OP(MaxPoolGrad)
  179. .INPUT(x1, TensorType::RealNumberType())
  180. .INPUT(x2, TensorType::RealNumberType())
  181. .INPUT(grad, TensorType::RealNumberType())
  182. .OUTPUT(y, TensorType::RealNumberType())
  183. .REQUIRED_ATTR(ksize, ListInt)
  184. .REQUIRED_ATTR(strides, ListInt)
  185. .REQUIRED_ATTR(padding, String)
  186. .ATTR(data_format, String, "NHWC")
  187. .OP_END_FACTORY_REG(MaxPoolGrad)
  188. /**
  189. * @brief Computes second-order gradients of the maxpooling function.
  190. * @par Inputs:
  191. * @li x1: Original forward input tensor of type float16
  192. * @li x2: Original forward output tensor of type float16
  193. * @li grad: Gradient tensor of type float16
  194. * @par Attributes:
  195. * @li ksize: A required list or tuple,
  196. * specifying the size of the sliding window.
  197. * @li strides: A required list or tuple,
  198. * specifying the stride of the sliding window.
  199. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  200. * @li data_format: An optional string.
  201. * Format of the original input, either NCHW or NHWC. Defaults to NHWC.
  202. * @attention Constraints:
  203. * @li Only the Ascend 910 platform is supported.
  204. * @li "x1" and "grads" must have the same shape.
  205. * @li "x2" and "y" must have the same shape. Otherwise, an error is reported.
  206. * @li "x1", "x2", "grads", and "y" must be 5D tensors.
  207. * @par Outputs:
  208. * @li y: Result tensor of type float16
  209. */
  210. REG_OP(MaxPoolGradGrad)
  211. .INPUT(x1, TensorType::RealNumberType())
  212. .INPUT(x2, TensorType::RealNumberType())
  213. .INPUT(grad, TensorType::RealNumberType())
  214. .OUTPUT(y, TensorType::RealNumberType())
  215. .REQUIRED_ATTR(ksize, ListInt)
  216. .REQUIRED_ATTR(strides, ListInt)
  217. .REQUIRED_ATTR(padding, String)
  218. .ATTR(data_format, String, "NHWC")
  219. .OP_END_FACTORY_REG(MaxPoolGradGrad)
  220. /**
  221. *@brief Performs max_pool_ext2 on the input.
  222. *@par Inputs:
  223. * Two inputs:
  224. *@li x: An NC1HWC0 Tensor of type float16.
  225. *@li strides: A required type of int32 values, specifying the stride of the sliding window for each dimension of the input tensor. No default value.
  226. *@li ksize: A required type of int32 values, specifying the size of the window for each dimension of the input tensor. No default value.
  227. *@par Attributes:
  228. *@li padding: A required string. No default value.
  229. *@li data_format: An optional string. Defaults to "NC1HWC0".
  230. *@par Outputs:
  231. *y: A Tensor. Has the same type and format as input "x".
  232. *@attention Constraints:
  233. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  234. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  235. *@li "padding" is either "SAME" or "VALID".
  236. */
  237. REG_OP(MaxPoolV2)
  238. .INPUT(x, TensorType({DT_FLOAT16}))
  239. .INPUT(ksize, TensorType({DT_INT32}))
  240. .INPUT(strides, TensorType({DT_INT32}))
  241. .OUTPUT(y, TensorType({DT_FLOAT16}))
  242. .REQUIRED_ATTR(padding, String)
  243. .ATTR(data_format, String, "NHWC")
  244. .OP_END_FACTORY_REG(MaxPoolV2)
  245. /**
  246. *@brief Performs max pooling on the input and outputs both max values and indices.
  247. *@par Inputs:
  248. * One input:
  249. *x: An NC1HWC0 Tensor of type float16.
  250. *@par Attributes:
  251. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for each dimension of the input tensor. No default value.
  252. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for each dimension of the input tensor. No default value.
  253. *@li padding: A required string. No default value.
  254. *@par Outputs:
  255. *y: A Tensor. Has the same type and format as input "x".
  256. *@attention Constraints:
  257. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  258. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  259. *@li "padding" is either "SAME" or "VALID".
  260. */
  261. REG_OP(MaxPoolWithArgmax)
  262. .INPUT(x, TensorType::RealNumberType())
  263. .OUTPUT(y, TensorType::RealNumberType())
  264. .OUTPUT(argmax, TensorType::IndexNumberType())
  265. .REQUIRED_ATTR(ksize, ListInt)
  266. .REQUIRED_ATTR(strides, ListInt)
  267. .REQUIRED_ATTR(padding, String)
  268. .ATTR(Targmax, Int, 7)
  269. .OP_END_FACTORY_REG(MaxPoolWithArgmax)
  270. /**
  271. *@brief Performs the backpropagation of MaxPoolWithArgmax.
  272. *@par Inputs:
  273. * Three inputs, including:
  274. *@li x: An NC1HWC0 tensor of type float16.
  275. *@li grad: An NC1HWC0 tensor of type float16.
  276. *@li argmx: An NC1HWC0 tensor of type uint16 or int64.
  277. *@par Attributes:
  278. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for each dimension of the input tensor. No default value.
  279. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for each dimension of the input tensor. No default value.
  280. *@li padding: A required string. No default value.
  281. *@par Outputs:
  282. *y: A Tensor. Has the same type and format as input "x".
  283. *@attention Constraints:
  284. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  285. *@li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  286. *@li "padding" is either "SAME" or "VALID".
  287. *@see max_pool_with_argmax
  288. */
  289. REG_OP(MaxPoolGradWithArgmax)
  290. .INPUT(x, TensorType::RealNumberType())
  291. .INPUT(grad, TensorType::RealNumberType())
  292. .INPUT(argmax, TensorType::IndexNumberType())
  293. .OUTPUT(y, TensorType::RealNumberType())
  294. .REQUIRED_ATTR(ksize, ListInt)
  295. .REQUIRED_ATTR(strides, ListInt)
  296. .REQUIRED_ATTR(padding, String)
  297. .OP_END_FACTORY_REG(MaxPoolGradWithArgmax)
  298. /**
  299. * @brief Computes second-order gradients of the maxpooling function.
  300. * @par Inputs:
  301. * @li x: Original forward input tensor of type float16
  302. * @li grad: Gradient tensor of type float16
  303. * @li argmax: An tensor of type uint16
  304. * @par Attributes:
  305. * @li ksize: A required list, specifying the size of the sliding window.
  306. * @li strides: A required list, specifying the stride of the sliding window.
  307. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  308. * @par Outputs:
  309. * @li y:Result tensor of type float16
  310. * @attention Constraints:
  311. * @li Only the cloud platform is supported.
  312. * @li "x1" and "grads" must have the same shape.
  313. * @li length of the shape of x, grads, argmax, y must be 5.
  314. * @li shape of argmax must be (fmap_n, fmap_c1, kernel_h * kernel_w,
  315. * (shape_max_pool[2] * shape_max_pool[3] + 15) // 16 * 16, 1),
  316. * or (fmap_n, fmap_c1, kernel_h * kernel_w,
  317. * (shape_max_pool[2] * shape_max_pool[3] + 31) // 16, 16), else failed.
  318. */
  319. REG_OP(MaxPoolGradGradWithArgmax)
  320. .INPUT(x, TensorType::RealNumberType())
  321. .INPUT(grad, TensorType::RealNumberType())
  322. .INPUT(argmax, TensorType::IndexNumberType())
  323. .OUTPUT(y, TensorType::RealNumberType())
  324. .REQUIRED_ATTR(ksize, ListInt)
  325. .REQUIRED_ATTR(strides, ListInt)
  326. .REQUIRED_ATTR(padding, String)
  327. .OP_END_FACTORY_REG(MaxPoolGradGradWithArgmax)
  328. /**
  329. * @brief Computes avgpoograd function.
  330. * @par Inputs:
  331. * @li orig_input_shape: An NHWC tensor of type int32.
  332. * @li input_grad: An NHWC tensor of type float16, float32, or double.
  333. * @par Attributes:
  334. * @li ksize: A required tuple or list, specifying the size of the window for
  335. * each dimension of the input tensor.
  336. * @li strides: A required tuple or list, specifying the stride of the sliding
  337. * window for each dimension of the input tensor.
  338. * @li padding: A required string, specifying the type of
  339. * the padding algorithm to use.
  340. * @li data_format: An optional string. Defaults to "NHWC".
  341. * @par Outputs:
  342. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  343. */
  344. REG_OP(AvgPoolGrad)
  345. .INPUT(orig_input_shape, TensorType({DT_INT32}))
  346. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  347. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  348. .REQUIRED_ATTR(ksize, ListInt)
  349. .REQUIRED_ATTR(strides, ListInt)
  350. .REQUIRED_ATTR(padding, String)
  351. .ATTR(data_format, String, "NHWC")
  352. .OP_END_FACTORY_REG(AvgPoolGrad)
  353. /**
  354. * @brief Computes gradients of average pooling function.
  355. * @par Inputs:
  356. * @input_grad: An NHWC tensor of type float16, float32, or double.
  357. * @par Attributes:
  358. * @li orig_input_shape: A required Original input dimensions.
  359. * @li ksize: A required tuple or list, specifying the size of the window
  360. * for each dimension of the input tensor.
  361. * @li strides: A required tuple or list, specifying the stride of
  362. * the sliding window for each dimension of the input tensor.
  363. * @li padding: A required string, specifying the type of the padding algorithm
  364. * to use.
  365. * @li data_format: An optional string. Defaults to "NHWC".
  366. * @par Outputs:
  367. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  368. */
  369. REG_OP(AvgPoolGradD)
  370. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  371. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  372. .REQUIRED_ATTR(orig_input_shape, ListInt)
  373. .REQUIRED_ATTR(ksize, ListInt)
  374. .REQUIRED_ATTR(strides, ListInt)
  375. .REQUIRED_ATTR(padding, String)
  376. .ATTR(data_format, String, "NHWC")
  377. .OP_END_FACTORY_REG(AvgPoolGradD)
  378. REG_OP(MaxPoolWithArgmaxCCE)
  379. .INPUT(x, TensorType::ALL())
  380. .OUTPUT(y, TensorType::ALL())
  381. .OUTPUT(argmax, TensorType::ALL())
  382. .ATTR(mode, Int, 0)
  383. .ATTR(pad_mode, Int, 0)
  384. .ATTR(window, ListInt, {1,1})
  385. .ATTR(stride, ListInt, {1,1})
  386. .ATTR(pad, ListInt, {0,0,0,0})
  387. .ATTR(ceil_mode, Int, 0)
  388. .ATTR(data_mode, Int, 1)
  389. .ATTR(nan_opt, Int, 0)
  390. .OP_END_FACTORY_REG(MaxPoolWithArgmaxCCE)
  391. REG_OP(MaxPoolGradWithArgmaxCCE)
  392. .INPUT(x, TensorType::ALL())
  393. .INPUT(grad,TensorType::ALL())
  394. .INPUT(arg,TensorType::ALL())
  395. .OUTPUT(output,TensorType::ALL())
  396. .ATTR(mode, Int, 0)
  397. .ATTR(max_pool_grad_output_shape, ListInt, {0,0,0,0})
  398. .ATTR(pad_mode, Int, 0)
  399. .ATTR(window, ListInt, {1,1})
  400. .ATTR(stride, ListInt, {1,1})
  401. .ATTR(pad, ListInt, {0,0,0,0})
  402. .ATTR(ceil_mode, Int, 0)
  403. .ATTR(data_mode, Int, 1)
  404. .ATTR(nan_opt, Int, 0)
  405. .OP_END_FACTORY_REG(MaxPoolGradWithArgmaxCCE)
  406. /**
  407. *@brief :upsample the layer
  408. *@par Inputs:
  409. * one input, including:
  410. *@li x: A tensor of type float16 or float32.
  411. *@par Attributes:
  412. *@li scale:scale factor of x
  413. *@li stride_h:broadcast the axis of h
  414. *@li stride_w:broadcast the axis of w
  415. *@par Outputs:
  416. *y: A tensor of type float16 or float32.
  417. */
  418. REG_OP(Upsample)
  419. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  420. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  421. .ATTR(scale, Float, 1)
  422. .ATTR(stride_h, Int, 2)
  423. .ATTR(stride_w, Int, 2)
  424. .OP_END_FACTORY_REG(Upsample)
  425. /**
  426. *@brief Computes gradient of the FractionalMaxPool function.
  427. *@par Inputs:
  428. *Inputs include: \n
  429. * @li orig_input: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  430. * @li orig_output: A Tensor. Must have the same type as orig_input.
  431. * @li out_backprop: A Tensor. Must have the same type as orig_input. \n
  432. 4-D with shape [batch, height, width, channels].
  433. * @li row_pooling_sequence: A Tensor of type int64.
  434. * @li col_pooling_sequence: A Tensor of type int64.
  435. *@par Attributes:
  436. *overlapping: An optional bool. Defaults to False.
  437. *@par Outputs:
  438. *y: A Tensor. Has the same type as orig_input.
  439. *@attention Constraints:\n
  440. *-The implementation for FractionalMaxPoolGrad on Ascend uses AICPU, with bad performance.\n
  441. */
  442. REG_OP(FractionalMaxPoolGrad)
  443. .INPUT(orig_input, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  444. .INPUT(orig_output, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  445. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  446. .INPUT(row_pooling_sequence, TensorType({ DT_INT64 }))
  447. .INPUT(col_pooling_sequence, TensorType({ DT_INT64 }))
  448. .OUTPUT(y, TensorType({ DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64 }))
  449. .ATTR(overlapping, Bool, false)
  450. .OP_END_FACTORY_REG(FractionalMaxPoolGrad)
  451. /**
  452. *@brief Performs fractional average pooling on the input.
  453. *@par Inputs:
  454. *Inputs include: \n
  455. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64. \n
  456. 4-D with shape [batch, height, width, channels].
  457. *@par Attributes:
  458. *@li pooling_ratio: A list of floats that has length >= 4.
  459. *@li pseudo_random: An optional bool. Defaults to False.
  460. *@li overlapping: An optional bool. Defaults to False. When set to True, it means when pooling.
  461. *@li deterministic: An optional bool. Defaults to False.
  462. *@li seed: An optional int. Defaults to 0.
  463. *@li seed2: An optional int. Defaults to 0.
  464. *@par Outputs:
  465. *@li y: A Tensor. Has the same type as x.
  466. *@li row_pooling_sequence: A Tensor of type int64.
  467. *@li col_pooling_sequence: A Tensor of type int64.
  468. *@attention Constraints:\n
  469. *-The implementation for FractionalAvgPool on Ascend uses AICPU, with bad performance.\n
  470. */
  471. REG_OP(FractionalAvgPool)
  472. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  473. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  474. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  475. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  476. .ATTR(pooling_ratio, ListFloat, {})
  477. .ATTR(pseudo_random, Bool, false)
  478. .ATTR(overlapping, Bool, false)
  479. .ATTR(deterministic, Bool, false)
  480. .ATTR(seed, Int, 0)
  481. .ATTR(seed2, Int, 0)
  482. .OP_END_FACTORY_REG(FractionalAvgPool)
  483. /**
  484. *@brief Performs fractional max pooling on the input.
  485. *@par Inputs:
  486. *Inputs include: \n
  487. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64. \n
  488. 4-D with shape [batch, height, width, channels].
  489. *@par Attributes:
  490. *@li pooling_ratio: A list of floats that has length >= 4. Pooling ratio for each dimension of value.
  491. *@li pseudo_random: An optional bool. Defaults to False.
  492. *@li overlapping: An optional bool. Defaults to False.
  493. *@li deterministic: An optional bool. Defaults to False.
  494. *@li seed: An optional int. Defaults to 0.
  495. *@li seed2: An optional int. Defaults to 0.
  496. *@par Outputs:
  497. *@li y: A Tensor. Has the same type as x.
  498. *@li row_pooling_sequence: A Tensor of type int64.
  499. *@li col_pooling_sequence: A Tensor of type int64.
  500. *@attention Constraints:\n
  501. *-The implementation for FractionalMaxPool on Ascend uses AICPU, with bad performance.\n
  502. */
  503. REG_OP(FractionalMaxPool)
  504. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  505. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  506. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  507. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  508. .ATTR(pooling_ratio, ListFloat, {})
  509. .ATTR(pseudo_random, Bool, false)
  510. .ATTR(overlapping, Bool, false)
  511. .ATTR(deterministic, Bool, false)
  512. .ATTR(seed, Int, 0)
  513. .ATTR(seed2, Int, 0)
  514. .OP_END_FACTORY_REG(FractionalMaxPool)
  515. /**
  516. *@brief Finds values of the n-th order statistic for the last dimension.
  517. *@par Inputs:
  518. *Inputs include: \n
  519. * @li x: A Tensor. Must be one of the following types: float32, float64, int32, uint8, \n
  520. int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
  521. * @li n: A Tensor of type int32. 0-D.
  522. *@par Attributes:
  523. *reverse: An optional bool. Defaults to False.
  524. *@par Outputs:
  525. *y: A Tensor. Has the same type as x.
  526. *@attention Constraints:\n
  527. *-The implementation for NthElement on Ascend uses AICPU, with bad performance.\n
  528. */
  529. REG_OP(NthElement)
  530. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  531. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  532. .INPUT(n, TensorType({DT_INT32}))
  533. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  534. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  535. .ATTR(reverse, Bool, false)
  536. .OP_END_FACTORY_REG(NthElement)
  537. /**
  538. *@brief Computes gradient of the FractionalAvgPool function.
  539. *@par Inputs:
  540. *Inputs include: \n
  541. * @li orig_input_tensor_shape: A Tensor of type int64.
  542. * @li out_backprop: A Tensor. Must be one of the following types: float32, float64, \n
  543. int32, int64. 4-D with shape [batch, height, width, channels].
  544. * @li row_pooling_sequence: A Tensor of type int64.
  545. * @li col_pooling_sequence: A Tensor of type int64.
  546. *@par Attributes:
  547. *overlapping: An optional bool. Defaults to False.
  548. *@par Outputs:
  549. *y: A Tensor. Has the same type as out_backprop.
  550. *@attention Constraints:\n
  551. *-The implementation for FractionalAvgPoolGrad on Ascend uses AICPU, with bad performance.\n
  552. */
  553. REG_OP(FractionalAvgPoolGrad)
  554. .INPUT(orig_input_tensor_shape, TensorType({DT_INT64}))
  555. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  556. .INPUT(row_pooling_sequence, TensorType({DT_INT64}))
  557. .INPUT(col_pooling_sequence, TensorType({DT_INT64}))
  558. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  559. .ATTR(overlapping, Bool, false)
  560. .OP_END_FACTORY_REG(FractionalAvgPoolGrad)
  561. /**
  562. *@brief Returns the permuted vector/tensor in the destination data format given the.
  563. *@par Inputs:
  564. *Inputs include: \n
  565. *x: A Tensor. Must be one of the following types: int32, int64. Vector of size 4 \n
  566. or Tensor of shape (4, 2) in source data format.
  567. *@par Attributes:
  568. *@li src_format: An optional string. Defaults to "NHWC". source data format.
  569. *@li dst_format: An optional string. Defaults to "NCHW". destination data format.
  570. *@par Outputs:
  571. *y: A Tensor. Has the same type as x.
  572. *@attention Constraints:\n
  573. *-The implementation for DataFormatVecPermute on Ascend uses AICPU, with bad performance.\n
  574. */
  575. REG_OP(DataFormatVecPermute)
  576. .INPUT(x, TensorType({ DT_INT32, DT_INT64 }))
  577. .OUTPUT(y, TensorType({ DT_INT32, DT_INT64 }))
  578. .ATTR(src_format, String, "NHWC")
  579. .ATTR(dst_format, String, "NCHW")
  580. .OP_END_FACTORY_REG(DataFormatVecPermute)
  581. } // namespace ge
  582. #endif // GE_OP_NN_POOLING_OPS_H

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