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 20 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. namespace ge {
  20. /**
  21. *@brief Performs pooling on the input.
  22. *@par Inputs:
  23. *@li x: An NCHW tensor of type float16.
  24. *@par Attributes:
  25. *@li mode: An optional int32, specifying the pooling algorithm, either "1" (max pooling) or "0" (avg pooling). Defaults to "0".
  26. *@li global_pooling: An optional bool. Defaults to "false".
  27. *@li window: Optional, including: \n
  28. *window[0]: An optional int32, specifying the window size along in the H dimension. The value range is [1, 32768]. Defaults to "1". \n
  29. *window[1]: An optional int32, specifying the window size along in the W dimension. The value range is [1, 32768]. Defaults to "1". \n
  30. *@li stride: Optional, including: \n
  31. *stride[0]: An optional int32, specifying the stride along in the H dimension. The value range is [1, 63]. Defaults to "1". \n
  32. *stride[1]: An optional int32, specifying the stride along in the W dimension. The value range is [1, 63]. Defaults to "1". \n
  33. *@li pad: Optional, including: \n
  34. *pad[0]: An optional int32, specifying the up padding. Defaults to "0". \n
  35. *pad[1]: An optional int32, specifying the bottom padding. Defaults to "0". \n
  36. *pad[2]: An optional int32, specifying the left padding. Defaults to "0". \n
  37. *pad[3]: An optional int32, specifying the right padding. Defaults to "0". \n
  38. *@li dilation: Optional, including: \n
  39. *dilation[0]: An optional int32, specifying the up dilation. Defaults to "1". \n
  40. *dilation[1]: An optional int32, specifying the bottom dilation. Defaults to "1". \n
  41. *dilation[2]: An optional int32, specifying the left dilation. Defaults to "1". \n
  42. *dilation[3]: An optional int32, specifying the right dilation. Defaults to "1". \n
  43. *@li ceil_mode: An optional int32, either "0" (ceil mode) or "1" (floor mode). Defaults to "0".
  44. *@par Outputs:
  45. *y: An NCHW tensor of type float16.
  46. *@attention Constraints:\n
  47. *@li window[0] * window[1] < 256;
  48. *@li 1<=input_h<=4096,1<=input_w<=4096
  49. */
  50. REG_OP(Pooling)
  51. .INPUT(x, TensorType({DT_FLOAT16}))
  52. .OUTPUT(y, TensorType({DT_FLOAT16}))
  53. .ATTR(mode, Int, 0) // 0:max pooling or 1:avg pooling
  54. .ATTR(global_pooling, Bool, false)
  55. .ATTR(window, ListInt, {1,1}) // kernel size
  56. .ATTR(stride, ListInt, {1,1}) // stride size
  57. .ATTR(pad, ListInt, {0,0,0,0}) // pad size
  58. .ATTR(dilation, ListInt, {1,1,1,1})
  59. .ATTR(ceil_mode, Int, 0)
  60. .OP_END_FACTORY_REG(Pooling)
  61. /**
  62. *@brief Performs average pooling on the input.
  63. *@par Inputs:
  64. *x: A tensor of type float16.
  65. *@par Attributes:
  66. *@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].
  67. *@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].
  68. *@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.
  69. *@li data_format: An optional string, specifying the data format of "ksize" and "strides", either "NCHW", "NC1HWC0", or "NHWC" (default).
  70. *@par Outputs:
  71. *y: The average pooled output tensor.
  72. *@attention Constraints:\n
  73. *@li Only single input and single output are supported.
  74. *@li Global pooling is supported.
  75. *@li "ksize_H" and "ksize_W" are positive integers within the range [1, 32768]. ksize_H * ksize_W < 256
  76. *@li Due to instruction restrictions, the values of "strides_h" and "strides_w" are positive integers within the range [1, 63].
  77. */
  78. REG_OP(AvgPool)
  79. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  80. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  81. .REQUIRED_ATTR(ksize, ListInt)
  82. .REQUIRED_ATTR(strides, ListInt)
  83. .REQUIRED_ATTR(padding, String)
  84. .ATTR(data_format, String, "NHWC")
  85. .OP_END_FACTORY_REG(AvgPool)
  86. /**
  87. *@brief Performs max_pool_ext2 on the input.
  88. *@par Inputs:
  89. * One input:
  90. *x: An NC1HWC0 Tensor of type float16.
  91. *@par Attributes:
  92. *@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.
  93. *@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.
  94. *@li padding: A required string. No default value.
  95. *@li data_format: An optional string. Defaults to "NC1HWC0".
  96. *@par Outputs:
  97. *y: A Tensor. Has the same type and format as input "x".
  98. *@attention Constraints:
  99. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  100. *@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.
  101. *@li "padding" is either "SAME" or "VALID".
  102. */
  103. REG_OP(MaxPoolExt2)
  104. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  105. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  106. DT_UINT16, DT_QINT8}))
  107. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  108. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  109. DT_UINT16, DT_QINT8}))
  110. .REQUIRED_ATTR(ksize, ListInt)
  111. .REQUIRED_ATTR(strides, ListInt)
  112. .REQUIRED_ATTR(padding, String)
  113. .ATTR(data_format, String, "NHWC")
  114. .OP_END_FACTORY_REG(MaxPoolExt2)
  115. /**
  116. *@brief Performs max pooling on the input.
  117. *@par Inputs:
  118. * One input:
  119. *x: An NC1HWC0 Tensor of type float16.
  120. *@par Attributes:
  121. *@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.
  122. *@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.
  123. *@li padding: A required string. No default value.
  124. *@li data_format: An optional string. Defaults to "NC1HWC0".
  125. *@par Outputs:
  126. *y: A Tensor. Has the same type and format as input "x".
  127. *@attention Constraints:
  128. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  129. *@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.
  130. *@li "padding" is either "SAME" or "VALID".
  131. */
  132. REG_OP(MaxPool)
  133. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  134. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  135. DT_UINT16, DT_QINT8}))
  136. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  137. DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  138. .REQUIRED_ATTR(ksize, ListInt)
  139. .REQUIRED_ATTR(strides, ListInt)
  140. .REQUIRED_ATTR(padding, String)
  141. .ATTR(data_format, String, "NHWC")
  142. .OP_END_FACTORY_REG(MaxPool)
  143. REG_OP(MaxPool3D)
  144. .INPUT(x, TensorType({DT_FLOAT16}))
  145. .OUTPUT(y, TensorType({DT_FLOAT16}))
  146. .REQUIRED_ATTR(ksize, ListInt)
  147. .REQUIRED_ATTR(strides, ListInt)
  148. .REQUIRED_ATTR(padding, String)
  149. .ATTR(data_format, String, "NDHWC")
  150. .OP_END_FACTORY_REG(MaxPool3D)
  151. /**
  152. * @brief Computes gradients of the maxpooling function.
  153. * @par Inputs:
  154. * @li x1: A mutable NC1HWC0 tensor of type RealNumberType.
  155. * @li x2: A mutable NC1HWC0 tensor of type RealNumberTypex.
  156. * @li grad: A mutable NC1HWC0 tensor of type RealNumberType.
  157. * @par Attributes:
  158. * @li ksize: A required tuple or list, specifying the size of the window for
  159. * each dimension of the input tensor.
  160. * @li strides: A required tuple or list, specifying the stride of the sliding
  161. * window for each dimension of the input tensor.
  162. * @li padding: A required string, specifying the type of padding algorithm
  163. * to use.
  164. * @li data_format: An optional string, Specify the data format of the input and
  165. * output data. With the default format "NHWC".
  166. * @par Outputs:
  167. * y: A mutable tensor. Has the same shape and type as "x1".
  168. * @attention Constraints:
  169. * @li Computing gradients of global pooling is not supported, which means
  170. * "ksize < x1".
  171. * @li "ksiez" is in the range [1, 255]. "strides" is in the range [1, 63]
  172. */
  173. REG_OP(MaxPoolGrad)
  174. .INPUT(x1, TensorType::RealNumberType())
  175. .INPUT(x2, TensorType::RealNumberType())
  176. .INPUT(grad, TensorType::RealNumberType())
  177. .OUTPUT(y, TensorType::RealNumberType())
  178. .REQUIRED_ATTR(ksize, ListInt)
  179. .REQUIRED_ATTR(strides, ListInt)
  180. .REQUIRED_ATTR(padding, String)
  181. .ATTR(data_format, String, "NHWC")
  182. .OP_END_FACTORY_REG(MaxPoolGrad)
  183. /**
  184. * @brief Computes second-order gradients of the maxpooling function.
  185. * @par Inputs:
  186. * @li x1: Original forward input tensor of type float16
  187. * @li x2: Original forward output tensor of type float16
  188. * @li grad: Gradient tensor of type float16
  189. * @par Attributes:
  190. * @li ksize: A required list or tuple,
  191. * specifying the size of the sliding window.
  192. * @li strides: A required list or tuple,
  193. * specifying the stride of the sliding window.
  194. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  195. * @li data_format: An optional string.
  196. * Format of the original input, either NCHW or NHWC. Defaults to NHWC.
  197. * @attention Constraints:
  198. * @li Only the Ascend 910 platform is supported.
  199. * @li "x1" and "grads" must have the same shape.
  200. * @li "x2" and "y" must have the same shape. Otherwise, an error is reported.
  201. * @li "x1", "x2", "grads", and "y" must be 5D tensors.
  202. * @par Outputs:
  203. * @li y: Result tensor of type float16
  204. */
  205. REG_OP(MaxPoolGradGrad)
  206. .INPUT(x1, TensorType::RealNumberType())
  207. .INPUT(x2, TensorType::RealNumberType())
  208. .INPUT(grad, TensorType::RealNumberType())
  209. .OUTPUT(y, TensorType::RealNumberType())
  210. .REQUIRED_ATTR(ksize, ListInt)
  211. .REQUIRED_ATTR(strides, ListInt)
  212. .REQUIRED_ATTR(padding, String)
  213. .ATTR(data_format, String, "NHWC")
  214. .OP_END_FACTORY_REG(MaxPoolGradGrad)
  215. /**
  216. *@brief Performs max_pool_ext2 on the input.
  217. *@par Inputs:
  218. * Two inputs:
  219. *@li x: An NC1HWC0 Tensor of type float16.
  220. *@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.
  221. *@li ksize: A required type of int32 values, specifying the size of the window for each dimension of the input tensor. No default value.
  222. *@par Attributes:
  223. *@li padding: A required string. No default value.
  224. *@li data_format: An optional string. Defaults to "NC1HWC0".
  225. *@par Outputs:
  226. *y: A Tensor. Has the same type and format as input "x".
  227. *@attention Constraints:
  228. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  229. *@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.
  230. *@li "padding" is either "SAME" or "VALID".
  231. */
  232. REG_OP(MaxPoolV2)
  233. .INPUT(x, TensorType({DT_FLOAT16}))
  234. .INPUT(ksize, TensorType({DT_INT32}))
  235. .INPUT(strides, TensorType({DT_INT32}))
  236. .OUTPUT(y, TensorType({DT_FLOAT16}))
  237. .REQUIRED_ATTR(padding, String)
  238. .ATTR(data_format, String, "NHWC")
  239. .OP_END_FACTORY_REG(MaxPoolV2)
  240. /**
  241. *@brief Performs max pooling on the input and outputs both max values and indices.
  242. *@par Inputs:
  243. * One input:
  244. *x: An NC1HWC0 Tensor of type float16.
  245. *@par Attributes:
  246. *@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.
  247. *@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.
  248. *@li padding: A required string. No default value.
  249. *@par Outputs:
  250. *y: A Tensor. Has the same type and format as input "x".
  251. *@attention Constraints:
  252. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  253. *@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.
  254. *@li "padding" is either "SAME" or "VALID".
  255. */
  256. REG_OP(MaxPoolWithArgmax)
  257. .INPUT(x, TensorType::RealNumberType())
  258. .OUTPUT(y, TensorType::RealNumberType())
  259. .OUTPUT(argmax, TensorType::IndexNumberType())
  260. .REQUIRED_ATTR(ksize, ListInt)
  261. .REQUIRED_ATTR(strides, ListInt)
  262. .REQUIRED_ATTR(padding, String)
  263. .ATTR(Targmax, Int, 7)
  264. .OP_END_FACTORY_REG(MaxPoolWithArgmax)
  265. /**
  266. *@brief Performs the backpropagation of MaxPoolWithArgmax.
  267. *@par Inputs:
  268. * Three inputs, including:
  269. *@li x: An NC1HWC0 tensor of type float16.
  270. *@li grad: An NC1HWC0 tensor of type float16.
  271. *@li argmx: An NC1HWC0 tensor of type uint16 or int64.
  272. *@par Attributes:
  273. *@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.
  274. *@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.
  275. *@li padding: A required string. No default value.
  276. *@par Outputs:
  277. *y: A Tensor. Has the same type and format as input "x".
  278. *@attention Constraints:
  279. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  280. *@li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  281. *@li "padding" is either "SAME" or "VALID".
  282. *@see max_pool_with_argmax
  283. */
  284. REG_OP(MaxPoolGradWithArgmax)
  285. .INPUT(x, TensorType::RealNumberType())
  286. .INPUT(grad, TensorType::RealNumberType())
  287. .INPUT(argmax, TensorType::IndexNumberType())
  288. .OUTPUT(y, TensorType::RealNumberType())
  289. .REQUIRED_ATTR(ksize, ListInt)
  290. .REQUIRED_ATTR(strides, ListInt)
  291. .REQUIRED_ATTR(padding, String)
  292. .OP_END_FACTORY_REG(MaxPoolGradWithArgmax)
  293. /**
  294. * @brief Computes second-order gradients of the maxpooling function.
  295. * @par Inputs:
  296. * @li x: Original forward input tensor of type float16
  297. * @li grad: Gradient tensor of type float16
  298. * @li argmax: An tensor of type uint16
  299. * @par Attributes:
  300. * @li ksize: A required list, specifying the size of the sliding window.
  301. * @li strides: A required list, specifying the stride of the sliding window.
  302. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  303. * @par Outputs:
  304. * @li y:Result tensor of type float16
  305. * @attention Constraints:
  306. * @li Only the cloud platform is supported.
  307. * @li "x1" and "grads" must have the same shape.
  308. * @li length of the shape of x, grads, argmax, y must be 5.
  309. * @li shape of argmax must be (fmap_n, fmap_c1, kernel_h * kernel_w,
  310. * (shape_max_pool[2] * shape_max_pool[3] + 15) // 16 * 16, 1),
  311. * or (fmap_n, fmap_c1, kernel_h * kernel_w,
  312. * (shape_max_pool[2] * shape_max_pool[3] + 31) // 16, 16), else failed.
  313. */
  314. REG_OP(MaxPoolGradGradWithArgmax)
  315. .INPUT(x, TensorType::RealNumberType())
  316. .INPUT(grad, TensorType::RealNumberType())
  317. .INPUT(argmax, TensorType::IndexNumberType())
  318. .OUTPUT(y, TensorType::RealNumberType())
  319. .REQUIRED_ATTR(ksize, ListInt)
  320. .REQUIRED_ATTR(strides, ListInt)
  321. .REQUIRED_ATTR(padding, String)
  322. .OP_END_FACTORY_REG(MaxPoolGradGradWithArgmax)
  323. /**
  324. * @brief Computes avgpoograd function.
  325. * @par Inputs:
  326. * @li orig_input_shape: An NHWC tensor of type int32.
  327. * @li input_grad: An NHWC tensor of type float16, float32, or double.
  328. * @par Attributes:
  329. * @li ksize: A required tuple or list, specifying the size of the window for
  330. * each dimension of the input tensor.
  331. * @li strides: A required tuple or list, specifying the stride of the sliding
  332. * window for each dimension of the input tensor.
  333. * @li padding: A required string, specifying the type of
  334. * the padding algorithm to use.
  335. * @li data_format: An optional string. Defaults to "NHWC".
  336. * @par Outputs:
  337. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  338. */
  339. REG_OP(AvgPoolGrad)
  340. .INPUT(orig_input_shape, TensorType({DT_INT32}))
  341. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  342. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  343. .REQUIRED_ATTR(ksize, ListInt)
  344. .REQUIRED_ATTR(strides, ListInt)
  345. .REQUIRED_ATTR(padding, String)
  346. .ATTR(data_format, String, "NHWC")
  347. .OP_END_FACTORY_REG(AvgPoolGrad)
  348. /**
  349. * @brief Computes gradients of average pooling function.
  350. * @par Inputs:
  351. * @input_grad: An NHWC tensor of type float16, float32, or double.
  352. * @par Attributes:
  353. * @li orig_input_shape: A required Original input dimensions.
  354. * @li ksize: A required tuple or list, specifying the size of the window
  355. * for each dimension of the input tensor.
  356. * @li strides: A required tuple or list, specifying the stride of
  357. * the sliding window for each dimension of the input tensor.
  358. * @li padding: A required string, specifying the type of the padding algorithm
  359. * to use.
  360. * @li data_format: An optional string. Defaults to "NHWC".
  361. * @par Outputs:
  362. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  363. */
  364. REG_OP(AvgPoolGradD)
  365. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  366. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  367. .REQUIRED_ATTR(orig_input_shape, ListInt)
  368. .REQUIRED_ATTR(ksize, ListInt)
  369. .REQUIRED_ATTR(strides, ListInt)
  370. .REQUIRED_ATTR(padding, String)
  371. .ATTR(data_format, String, "NHWC")
  372. .OP_END_FACTORY_REG(AvgPoolGradD)
  373. REG_OP(MaxPoolWithArgmaxCCE)
  374. .INPUT(x, TensorType::ALL())
  375. .OUTPUT(y, TensorType::ALL())
  376. .OUTPUT(argmax, TensorType::ALL())
  377. .ATTR(mode, Int, 0)
  378. .ATTR(pad_mode, Int, 0)
  379. .ATTR(window, ListInt, {1,1})
  380. .ATTR(stride, ListInt, {1,1})
  381. .ATTR(pad, ListInt, {0,0,0,0})
  382. .ATTR(ceil_mode, Int, 0)
  383. .ATTR(data_mode, Int, 1)
  384. .ATTR(nan_opt, Int, 0)
  385. .OP_END_FACTORY_REG(MaxPoolWithArgmaxCCE)
  386. REG_OP(MaxPoolGradWithArgmaxCCE)
  387. .INPUT(x, TensorType::ALL())
  388. .INPUT(grad,TensorType::ALL())
  389. .INPUT(arg,TensorType::ALL())
  390. .OUTPUT(output,TensorType::ALL())
  391. .ATTR(mode, Int, 0)
  392. .ATTR(max_pool_grad_output_shape, ListInt, {0,0,0,0})
  393. .ATTR(pad_mode, Int, 0)
  394. .ATTR(window, ListInt, {1,1})
  395. .ATTR(stride, ListInt, {1,1})
  396. .ATTR(pad, ListInt, {0,0,0,0})
  397. .ATTR(ceil_mode, Int, 0)
  398. .ATTR(data_mode, Int, 1)
  399. .ATTR(nan_opt, Int, 0)
  400. .OP_END_FACTORY_REG(MaxPoolGradWithArgmaxCCE)
  401. /**
  402. *@brief :upsample the layer
  403. *@par Inputs:
  404. * one input, including:
  405. *@li x: A tensor of type float16 or float32.
  406. *@par Attributes:
  407. *@li scale:scale factor of x
  408. *@li stride_h:broadcast the axis of h
  409. *@li stride_w:broadcast the axis of w
  410. *@par Outputs:
  411. *y: A tensor of type float16 or float32.
  412. */
  413. REG_OP(Upsample)
  414. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  415. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  416. .ATTR(scale, Float, 1)
  417. .ATTR(stride_h, Int, 2)
  418. .ATTR(stride_w, Int, 2)
  419. .OP_END_FACTORY_REG(Upsample)
  420. /**
  421. *@brief Spatial Pyramid Pooling, multi-level pooling.
  422. * Pooling out(n, sigma(c*2^i*2^i)) tensor, i in range[0,pyramid_height).
  423. *@par Inputs:
  424. *x: An NCHW tensor, support float16 or float32 type.
  425. *@par Attributes:
  426. * @li pyramid_height: An required int32.
  427. * Multi-level pooling out from 2^0 to 2^(pyramid_height-1).
  428. * @li pool_method: An optional int32, pooling method: 0-MAX, 1-AVE.
  429. * Defaults to "0".
  430. *@par Outputs:
  431. *y: A NCHW tensor, support float16 or float32 type.
  432. *@attention Constraints:
  433. * @li pyramid_height: pyramid_heigjt should be in range [0,7).
  434. * @li feature_size:input feture map h and w should be [1, 510].
  435. */
  436. REG_OP(SPP)
  437. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  438. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  439. .REQUIRED_ATTR(pyramid_height, Int)
  440. .ATTR(pool_method, Int, 0)
  441. .OP_END_FACTORY_REG(SPP)
  442. } // namespace ge
  443. #endif // GE_OP_NN_POOLING_OPS_H

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