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 43 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
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
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  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. /*!
  17. * \file nn_pooling_ops.h
  18. * \brief
  19. */
  20. #ifndef GE_OP_NN_POOLING_OPS_H
  21. #define GE_OP_NN_POOLING_OPS_H
  22. #include "graph/operator_reg.h"
  23. #include "graph/operator.h"
  24. namespace ge {
  25. /**
  26. *@brief Performs pooling on the input.
  27. *@par Inputs:
  28. *@li x: An NCHW tensor of type float16, float32, int8.
  29. *@par Attributes:
  30. *@li mode: An optional int32, specifying the pooling algorithm, either "1" (max pooling) or "0" (avg pooling). Defaults to "0".
  31. *@li global_pooling: An optional bool. Defaults to "false".
  32. *@li window: Optional, including:
  33. *window[0]: An optional int32, specifying the window size along in the H dimension. The value range is [1, 32768]. Defaults to "1".
  34. *window[1]: An optional int32, specifying the window size along in the W dimension. The value range is [1, 32768]. Defaults to "1".
  35. *@li stride: Optional, including:
  36. *stride[0]: An optional int32, specifying the stride along in the H dimension. The value range is [1, 63]. Defaults to "1".
  37. *stride[1]: An optional int32, specifying the stride along in the W dimension. The value range is [1, 63]. Defaults to "1".
  38. *@li pad: Optional, including:
  39. *pad[0]: An optional int32, specifying the up padding. Defaults to "0".
  40. *pad[1]: An optional int32, specifying the bottom padding. Defaults to "0".
  41. *pad[2]: An optional int32, specifying the left padding. Defaults to "0".
  42. *pad[3]: An optional int32, specifying the right padding. Defaults to "0".
  43. *@li dilation: Optional, including:
  44. *dilation[0]: An optional int32, specifying the up dilation. Defaults to "1".
  45. *dilation[1]: An optional int32, specifying the bottom dilation. Defaults to "1".
  46. *dilation[2]: An optional int32, specifying the left dilation. Defaults to "1".
  47. *dilation[3]: An optional int32, specifying the right dilation. Defaults to "1".
  48. *@li ceil_mode: An optional int32, either "0" (ceil mode) or "1" (floor mode). Defaults to "0".
  49. *@par Outputs:
  50. *y: An NCHW tensor of type float16, float32, int32.
  51. *@attention Constraints:
  52. *@li window[0] * window[1] < 256;
  53. *@li 1<=input_h<=4096,1<=input_w<=4096
  54. *@li If input tensor N is a prime number, it should be less than 65535.
  55. *@par Third-party framework compatibility
  56. *@li Compatible with the Caffe operator Pooling.
  57. *@li Compatible with the TensorFlow operator Pooling.
  58. */
  59. REG_OP(Pooling)
  60. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT8}))
  61. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_INT32}))
  62. .ATTR(mode, Int, 0) // 0:max pooling or 1:avg pooling
  63. .ATTR(global_pooling, Bool, false)
  64. .ATTR(window, ListInt, {1,1}) // kernel size
  65. .ATTR(stride, ListInt, {1,1}) // stride size
  66. .ATTR(pad, ListInt, {0,0,0,0}) // pad size
  67. .ATTR(dilation, ListInt, {1,1,1,1})
  68. .ATTR(ceil_mode, Int, 0)
  69. .OP_END_FACTORY_REG(Pooling)
  70. /**
  71. *@brief Performs average pooling on the input . \n
  72. *@par Inputs:
  73. *x: A tensor of type float16, float32, double . \n
  74. *@par Attributes:
  75. *@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].
  76. *@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].
  77. *@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.
  78. *@li data_format: An optional string, specifying the data format of "ksize" and "strides", either "NCHW", "NC1HWC0", or "NHWC" (default) . \n
  79. *@par Outputs:
  80. *y: The average pooled output tensor. Has the same type and format as input "x" . \n
  81. *@attention Constraints:
  82. *@li This operator applies only to a TensorFlow network.
  83. *@li Only single input and single output are supported.
  84. *@li Global pooling is supported.
  85. *@li "ksize_H" and "ksize_W" are positive integers within the range [1, 32768]. ksize_H * ksize_W < 256
  86. *@li Due to instruction restrictions, the values of "strides_h" and "strides_w" are positive integers within the range [1, 63].
  87. *@par Third-party framework compatibility
  88. * Compatible with the TensorFlow operator AvgPool.
  89. */
  90. REG_OP(AvgPool)
  91. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  92. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  93. .REQUIRED_ATTR(ksize, ListInt)
  94. .REQUIRED_ATTR(strides, ListInt)
  95. .REQUIRED_ATTR(padding, String)
  96. .ATTR(data_format, String, "NHWC")
  97. .OP_END_FACTORY_REG(AvgPool)
  98. /**
  99. *@brief Performs average pooling on the input . \n
  100. *@par Inputs:
  101. *x: A 5-D Tensor of shape [batch, depth, height, width, channels] and type float16, float32, double . \n
  102. *@par Attributes:
  103. *@li ksize: List of ints that has length 1, 3 or 5. The size of the window for each dimension of the input tensor.
  104. *@li strides:List of ints that has length 1, 3 or 5. The stride of the sliding window for each dimension of the input tensor.
  105. *@li pads: List of ints, implicit zero paddings on both sides of the input.
  106. *@li ceil_mode: When true, will use ceil instead of floor in the formula to compute the output shape.
  107. *@li count_include_pad: When true, will include the zero-padding in the averaging calculation.
  108. *@li divisor_override: if specified, it will be used as divisor, otherwise size of the pooling region will be used.
  109. *@li data_format: A string, format of input data . \n
  110. *@par Outputs:
  111. *y: The average pooled output tensor . \n
  112. *@attention Constraints:
  113. *@li "ksize" is in the range [1, 255]. "strides" is in the range [1, 63]
  114. *@par Third-party framework compatibility
  115. * Compatible with the TensorFlow operator AvgPool3D.
  116. */
  117. REG_OP(AvgPool3D)
  118. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  119. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  120. .REQUIRED_ATTR(ksize, ListInt)
  121. .REQUIRED_ATTR(strides, ListInt)
  122. .REQUIRED_ATTR(pads, ListInt)
  123. .ATTR(ceil_mode, Bool, false)
  124. .ATTR(count_include_pad, Bool, true)
  125. .ATTR(divisor_override, Int, 0)
  126. .ATTR(data_format, String, "NDHWC")
  127. .OP_END_FACTORY_REG(AvgPool3D)
  128. /**
  129. *@brief Performs max_pool_ext2 on the input . \n
  130. *@par Inputs:
  131. * One input:
  132. *x: An NC1HWC0 Tensor of type float16.
  133. *@par Attributes:
  134. *@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.
  135. *@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.
  136. *@li padding: A required string. No default value.
  137. *@li data_format: An optional string. Defaults to "NC1HWC0" . \n
  138. *@par Outputs:
  139. *y: A Tensor. Has the same type and format as input "x" . \n
  140. *@attention Constraints:
  141. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  142. *@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.
  143. *@li "padding" is either "SAME" or "VALID" . \n
  144. *@par Third-party framework compatibility
  145. * Compatible with the TensorFlow operator MaxPoolV2.
  146. */
  147. REG_OP(MaxPoolExt2)
  148. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  149. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  150. DT_UINT16, DT_QINT8}))
  151. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  152. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  153. DT_UINT16, DT_QINT8}))
  154. .REQUIRED_ATTR(ksize, ListInt)
  155. .REQUIRED_ATTR(strides, ListInt)
  156. .REQUIRED_ATTR(padding, String)
  157. .ATTR(data_format, String, "NHWC")
  158. .OP_END_FACTORY_REG(MaxPoolExt2)
  159. /**
  160. *@brief Performs max pooling on the input . \n
  161. *@par Inputs:
  162. * One input:
  163. *x: An NC1HWC0 Tensor. Supported type:float16, float32, double, int8, int16,
  164. * int32, int64, uint8, uint16, qint8
  165. *@par Attributes:
  166. *@li ksize: A required list of int8, int16, int32, or int64 values,
  167. * specifying the size of the window for each dimension of the input tensor.
  168. * No default value.
  169. *@li strides: A required list of int8, int16, int32, or int64 values,
  170. * specifying the stride of the sliding window for each dimension of
  171. * the input tensor. No default value.
  172. *@li padding: A required string. No default value.
  173. *@li data_format: An optional string. Defaults to "NHWC" . \n
  174. *@par Outputs:
  175. *y: A Tensor. Has the same type and format as input "x" . \n
  176. *@attention Constraints:
  177. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  178. * ksize[1] * ksize[2] <= 255.
  179. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  180. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  181. *@li "padding" is either "SAME" or "VALID".
  182. *@par Third-party framework compatibility
  183. * Compatible with the TensorFlow operator MaxPool.
  184. */
  185. REG_OP(MaxPool)
  186. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  187. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  188. DT_UINT16, DT_QINT8}))
  189. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  190. DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  191. .REQUIRED_ATTR(ksize, ListInt)
  192. .REQUIRED_ATTR(strides, ListInt)
  193. .REQUIRED_ATTR(padding, String)
  194. .ATTR(data_format, String, "NHWC")
  195. .OP_END_FACTORY_REG(MaxPool)
  196. /**
  197. *@brief Performs max 3d pooling on the input . \n
  198. *@par Inputs:
  199. *x: An NC1HWC0 Tensor. Supported type float16, float32, double . \n
  200. *@par Attributes:
  201. *@li ksize: A required list of int8, int16, int32, or int64 values,
  202. specifying the size of the window for each dimension of the input tensor.
  203. No default value.
  204. *@li strides: A required list of int8, int16, int32, or int64 values,
  205. specifying the stride of the sliding window for each dimension of
  206. the input tensor. No default value.
  207. *@li padding: A required string type of float16.
  208. *@li pads: A list type of int32. Default value {0, 0, 0}.
  209. *@li dilation: A list type of int32. Default value {1, 1, 1}.
  210. *@li ceil_mode: A ceil mode number of int32 . Default value 0.
  211. *@li data_format: An optional string. Defaults to "NDHWC" . \n
  212. *@par Outputs:
  213. *y: A Tensor. Has the same type and format as input "x" . \n
  214. *@attention Constraints:
  215. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  216. * ksize[1] * ksize[2] <= 255.
  217. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  218. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  219. *@li "padding" is either "SAME" or "VALID" . \n
  220. *@par Third-party framework compatibility
  221. * Compatible with the TensorFlow operator MaxPool3D.
  222. */
  223. REG_OP(MaxPool3D)
  224. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  225. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  226. .REQUIRED_ATTR(ksize, ListInt)
  227. .REQUIRED_ATTR(strides, ListInt)
  228. .REQUIRED_ATTR(padding, String)
  229. .ATTR(pads, ListInt, {0,0,0})
  230. .ATTR(dilation, ListInt, {1,1,1})
  231. .ATTR(ceil_mode, Int, 0)
  232. .ATTR(data_format, String, "NDHWC")
  233. .OP_END_FACTORY_REG(MaxPool3D)
  234. /**
  235. * @brief Computes second-order gradients of the maxpooling3d function . \n
  236. * @par Inputs:
  237. * @li orig_x: Original forward input tensor(NDC1HWC0) of type float16
  238. * @li orig_y: Original forward output tensor(NDC1HWC0) of type float16
  239. * @li grads: Gradient tensor(NDC1HWC0) of type float16
  240. * @li assist: Assist tensor(NDC1HWC0) of type float16
  241. * @par Attributes:
  242. * @li ksize: A required list or tuple,
  243. * specifying the size of the sliding window.
  244. * @li strides: A required list or tuple,
  245. * specifying the stride of the sliding window.
  246. * @li pads: A required list or tuple
  247. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  248. * @li data_format: An optional string.
  249. * Format of the original input, either NCDHW or NDHWC. Defaults to NDHWC . \n
  250. * @attention Constraints:
  251. * @li Only the Ascend 910 platform is supported.
  252. * @li "orig_x" and "grads" must have the same shape.
  253. * @li "orig_y" and "y" must have the same shape. Otherwise, an error is reported.
  254. * @li "orig_x", "orig_y", "grads", and "y" must be NDC1HWC0 tensors . \n
  255. * @par Outputs:
  256. * @li y: Result tensor of type float16
  257. * @par Third-party framework compatibility
  258. * @li Compatible with the TensorFlow operator MaxPool3DGradGrad.
  259. */
  260. REG_OP(MaxPool3DGradGrad)
  261. .INPUT(orig_x, TensorType::RealNumberType())
  262. .INPUT(orig_y, TensorType::RealNumberType())
  263. .INPUT(grads, TensorType::RealNumberType())
  264. .OUTPUT(y, TensorType::RealNumberType())
  265. .REQUIRED_ATTR(ksize, ListInt)
  266. .REQUIRED_ATTR(strides, ListInt)
  267. .REQUIRED_ATTR(pads, ListInt)
  268. .ATTR(data_format, String, "NDHWC")
  269. .OP_END_FACTORY_REG(MaxPool3DGradGrad)
  270. /**
  271. * @brief Computes gradients of the maxpooling function . \n
  272. * @par Inputs:
  273. * @li x1: A mutable NC1HWC0 tensor of type RealNumberType.
  274. * @li x2: A mutable NC1HWC0 tensor of type RealNumberTypex.
  275. * @li grad: A mutable NC1HWC0 tensor of type RealNumberType . \n
  276. * @par Attributes:
  277. * @li ksize: A required tuple or list, specifying the size of the window for
  278. * each dimension of the input tensor.
  279. * @li strides: A required tuple or list, specifying the stride of the sliding
  280. * window for each dimension of the input tensor.
  281. * @li padding: A required string, specifying the type of padding algorithm
  282. * to use.
  283. * @li data_format: An optional string, Specify the data format of the input and
  284. * output data. With the default format "NHWC" . \n
  285. * @par Outputs:
  286. * y: A mutable tensor. Has the same shape and type as "x1" . \n
  287. * @attention Constraints:
  288. * @li Computing gradients of global pooling is not supported, which means
  289. * "ksize < x1".
  290. * @li "ksize" is in the range [1, 255]. "strides" is in the range [1, 63]
  291. * @par Third-party framework compatibility
  292. * Compatible with the TensorFlow operator MaxPoolGrad.
  293. */
  294. REG_OP(MaxPoolGrad)
  295. .INPUT(x1, TensorType::RealNumberType())
  296. .INPUT(x2, TensorType::RealNumberType())
  297. .INPUT(grad, TensorType::RealNumberType())
  298. .OUTPUT(y, TensorType::RealNumberType())
  299. .REQUIRED_ATTR(ksize, ListInt)
  300. .REQUIRED_ATTR(strides, ListInt)
  301. .REQUIRED_ATTR(padding, String)
  302. .ATTR(data_format, String, "NHWC")
  303. .OP_END_FACTORY_REG(MaxPoolGrad)
  304. /**
  305. * @brief Computes second-order gradients of the maxpooling function . \n
  306. * @par Inputs:
  307. * @li x1: Original forward input tensor. Supported type:float, double, int32,
  308. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  309. * @li x2: Has the same type and format as input "x1".
  310. * @li grad:Has the same type and format as input "x1" . \n
  311. * @par Attributes:
  312. * @li ksize: A required list or tuple,
  313. * specifying the size of the sliding window.
  314. * @li strides: A required list or tuple,
  315. * specifying the stride of the sliding window.
  316. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  317. * @li data_format: An optional string.
  318. * Format of the original input, either NCHW or NHWC. Defaults to NHWC . \n
  319. * @attention Constraints:
  320. * @li Only the Ascend 910 platform is supported.
  321. * @li "x1" and "grads" must have the same shape.
  322. * @li "x2" and "y" must have the same shape. Otherwise, an error is reported.
  323. * @li "x1", "x2", "grads", and "y" must be 5D tensors.
  324. * @li ksize[H] and ksize[W] is in the range [1, 255].
  325. * @li strides[H] and strides[W] is in the range [1, 63].
  326. * @li Other dimensions of ksize and strides is 1 . \n
  327. * @par Outputs:
  328. * @li y: Has the same type and format as input "x1" . \n
  329. * @par Third-party framework compatibility
  330. * @li Compatible with the TensorFlow operator MaxPoolGradGrad.
  331. */
  332. REG_OP(MaxPoolGradGrad)
  333. .INPUT(x1, TensorType::RealNumberType())
  334. .INPUT(x2, TensorType::RealNumberType())
  335. .INPUT(grad, TensorType::RealNumberType())
  336. .OUTPUT(y, TensorType::RealNumberType())
  337. .REQUIRED_ATTR(ksize, ListInt)
  338. .REQUIRED_ATTR(strides, ListInt)
  339. .REQUIRED_ATTR(padding, String)
  340. .ATTR(data_format, String, "NHWC")
  341. .OP_END_FACTORY_REG(MaxPoolGradGrad)
  342. /**
  343. *@brief Performs max_pool_ext2 on the input . \n
  344. *@par Inputs:
  345. * Two inputs:
  346. *@li x: An NC1HWC0 Tensor of type float16.
  347. *@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.
  348. *@li ksize: A required type of int32 values, specifying the size of the window for each dimension of the input tensor. No default value.
  349. *@par Attributes:
  350. *@li padding: A required string. No default value.
  351. *@li data_format: An optional string. Defaults to "NC1HWC0" . \n
  352. *@par Outputs:
  353. *y: A Tensor. Has the same type and format as input "x" . \n
  354. *@attention Constraints:
  355. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  356. *@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.
  357. *@li "padding" is either "SAME" or "VALID" . \n
  358. *@par Third-party framework compatibility
  359. * Compatible with the TensorFlow operator MaxPoolV2.
  360. */
  361. REG_OP(MaxPoolV2)
  362. .INPUT(x, TensorType({DT_FLOAT16}))
  363. .INPUT(ksize, TensorType({DT_INT32}))
  364. .INPUT(strides, TensorType({DT_INT32}))
  365. .OUTPUT(y, TensorType({DT_FLOAT16}))
  366. .REQUIRED_ATTR(padding, String)
  367. .ATTR(data_format, String, "NHWC")
  368. .OP_END_FACTORY_REG(MaxPoolV2)
  369. /**
  370. *@brief Performs max pooling on the input and outputs both max values and
  371. * indices . \n
  372. *@par Inputs:
  373. * One input:
  374. *x: An NC1HWC0 Tensor. Supported type: float, double, int32,
  375. * uint8, int16, int8, int64, uint16, half, uint32, uint64 . \n
  376. *@par Attributes:
  377. *@li ksize: A required list of int8, int16, int32, or int64 values,
  378. * specifying the size of the window for each dimension of the input tensor.
  379. * No default value.
  380. *@li strides: A required list of int8, int16, int32, or int64 values,
  381. * specifying the stride of the sliding window for each dimension of
  382. * the input tensor. No default value.
  383. *@li padding: A required string. No default value . \n
  384. *@par Outputs:
  385. *y: A Tensor. Has the same type and format as input "x".
  386. *argmax: A Tensor. Has the same type and format as input "x".
  387. *@attention Constraints:
  388. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  389. * ksize[1] * ksize[2] <= 255.
  390. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  391. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  392. *@li "padding" is either "SAME" or "VALID" . \n
  393. *@par Third-party framework compatibility
  394. * Compatible with the TensorFlow operator MaxPoolWithArgmax.
  395. */
  396. REG_OP(MaxPoolWithArgmax)
  397. .INPUT(x, TensorType::RealNumberType())
  398. .OUTPUT(y, TensorType::RealNumberType())
  399. .OUTPUT(argmax, TensorType::IndexNumberType())
  400. .REQUIRED_ATTR(ksize, ListInt)
  401. .REQUIRED_ATTR(strides, ListInt)
  402. .REQUIRED_ATTR(padding, String)
  403. .ATTR(Targmax, Int, 7)
  404. .OP_END_FACTORY_REG(MaxPoolWithArgmax)
  405. /**
  406. *@brief Performs the backpropagation of MaxPoolWithArgmax . \n
  407. *@par Inputs:
  408. * Three inputs, including:
  409. *@li x: An NC1HWC0 tensor. Supported type: float, double, int32,
  410. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  411. *@li grad: An NC1HWC0 tensor. Supported type: float, double, int32,
  412. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  413. *@li argmx: An NC1HWC0 tensor of type int32 or int64 . \n
  414. *@par Attributes:
  415. *@li ksize: A required list of int8, int16, int32, or int64 values,
  416. * specifying the size of the window for each dimension of the input tensor.
  417. * No default value.
  418. *@li strides: A required list of int8, int16, int32, or int64 values,
  419. * specifying the stride of the sliding window for each dimension of
  420. * the input tensor. No default value.
  421. *@li padding: A required string. No default value . \n
  422. *@par Outputs:
  423. *y: A Tensor. Has the same type and format as input "x" . \n
  424. *@attention Constraints:
  425. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  426. * ksize[1] * ksize[2] <= 255.
  427. *@li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  428. *@li "padding" is either "SAME" or "VALID".
  429. *@see max_pool_with_argmax
  430. *@par Third-party framework compatibility
  431. * Compatible with the TensorFlow operator MaxPoolGradWithArgmax.
  432. */
  433. REG_OP(MaxPoolGradWithArgmax)
  434. .INPUT(x, TensorType::RealNumberType())
  435. .INPUT(grad, TensorType::RealNumberType())
  436. .INPUT(argmax, TensorType::IndexNumberType())
  437. .OUTPUT(y, TensorType::RealNumberType())
  438. .REQUIRED_ATTR(ksize, ListInt)
  439. .REQUIRED_ATTR(strides, ListInt)
  440. .REQUIRED_ATTR(padding, String)
  441. .OP_END_FACTORY_REG(MaxPoolGradWithArgmax)
  442. /**
  443. *@brief Performs transform mask to argmax . \n
  444. *@par Inputs:
  445. * Two input:
  446. *x: An NC1HWC0 Tensor of type float16.
  447. *mask: An NC1HWC0 Tensor of type uint16 . \n
  448. *@par Attributes:
  449. *@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.
  450. *@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.
  451. *@li padding: A required string. No default value . \n
  452. *@par Outputs:
  453. *argmax: An NC1HWC0 Tensor of type int32 . \n
  454. *@attention Constraints:
  455. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  456. *@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.
  457. *@li "padding" is either "SAME" or "VALID" . \n
  458. *@par Third-party framework compatibility
  459. * Compatible with the TensorFlow operator Mask2Argmax.
  460. */
  461. REG_OP(Mask2Argmax)
  462. .INPUT(x, TensorType::RealNumberType())
  463. .INPUT(mask, TensorType::IndexNumberType())
  464. .OUTPUT(argmax, TensorType::IndexNumberType())
  465. .REQUIRED_ATTR(ksize, ListInt)
  466. .REQUIRED_ATTR(strides, ListInt)
  467. .REQUIRED_ATTR(padding, String)
  468. .REQUIRED_ATTR(originshape, ListInt)
  469. .OP_END_FACTORY_REG(Mask2Argmax)
  470. /**
  471. * @brief Computes second-order gradients of the maxpooling function . \n
  472. * @par Inputs:
  473. * @li x: Original forward input tensor. Supported type: float, double, int32,
  474. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  475. * @li grad: Gradient tensor. Supported type: float, double, int32,
  476. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  477. * @li argmax: An tensor of type int32 or int64.
  478. * @par Attributes:
  479. * @li ksize: A required list, specifying the size of the sliding window.
  480. * @li strides: A required list, specifying the stride of the sliding window.
  481. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  482. * @par Outputs:
  483. * @li y:Result tensor. Supported type: float, double, int32,
  484. * uint8, int16, int8, int64, uint16, half, uint32, uint64
  485. * @attention Constraints:
  486. * @li Only the cloud platform is supported.
  487. * @li "x1" and "grads" must have the same shape.
  488. * @li length of the shape of x, grads, argmax, y must be 5.
  489. * @li shape of argmax must be (fmap_n, fmap_c1, kernel_h * kernel_w,
  490. * (shape_max_pool[2] * shape_max_pool[3] + 15) // 16 * 16, 1),
  491. * or (fmap_n, fmap_c1, kernel_h * kernel_w,
  492. * (shape_max_pool[2] * shape_max_pool[3] + 31) // 16, 16), else failed . \n
  493. * @par Third-party framework compatibility
  494. * @li Compatible with the TensorFlow operator MaxPoolGradGradWithArgmax.
  495. */
  496. REG_OP(MaxPoolGradGradWithArgmax)
  497. .INPUT(x, TensorType::RealNumberType())
  498. .INPUT(grad, TensorType::RealNumberType())
  499. .INPUT(argmax, TensorType::IndexNumberType())
  500. .OUTPUT(y, TensorType::RealNumberType())
  501. .REQUIRED_ATTR(ksize, ListInt)
  502. .REQUIRED_ATTR(strides, ListInt)
  503. .REQUIRED_ATTR(padding, String)
  504. .OP_END_FACTORY_REG(MaxPoolGradGradWithArgmax)
  505. /**
  506. * @brief Computes avgpoograd function . \n
  507. * @par Inputs:
  508. * @li orig_input_shape: An NHWC tensor of type int32.
  509. * @li input_grad: An NHWC tensor of type float16, float32, or double . \n
  510. * @par Attributes:
  511. * @li ksize: A required tuple or list, specifying the size of the window for
  512. * each dimension of the input tensor.
  513. * @li strides: A required tuple or list, specifying the stride of the sliding
  514. * window for each dimension of the input tensor.
  515. * @li padding: A required string, specifying the type of
  516. * the padding algorithm to use.
  517. * @li data_format: An optional string. Defaults to "NHWC" . \n
  518. * @par Outputs:
  519. * @out_grad: A mutable tensor with the same shape and type as "orig_input" . \n
  520. * @par Third-party framework compatibility
  521. * @li Compatible with the TensorFlow operator AvgPoolGrad.
  522. */
  523. REG_OP(AvgPoolGrad)
  524. .INPUT(orig_input_shape, TensorType({DT_INT32}))
  525. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  526. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  527. .REQUIRED_ATTR(ksize, ListInt)
  528. .REQUIRED_ATTR(strides, ListInt)
  529. .REQUIRED_ATTR(padding, String)
  530. .ATTR(data_format, String, "NHWC")
  531. .OP_END_FACTORY_REG(AvgPoolGrad)
  532. /**
  533. * @brief Computes gradients of average pooling function . \n
  534. * @par Inputs:
  535. * @input_grad: An NHWC tensor of type float16.
  536. * @mean_matrix: Assist matrix, an NHWC tensor of type float16.
  537. * @kernel_matrix: Assist matrix, an NHWC tensor of type float16. \n
  538. * @par Attributes:
  539. * @li orig_input_shape: A required Original input dimensions.
  540. * @li ksize: A required tuple or list, specifying the size of the window
  541. * for each dimension of the input tensor.
  542. * @li strides: A required tuple or list, specifying the stride of
  543. * the sliding window for each dimension of the input tensor.
  544. * @li padding: A required string, specifying the type of the padding algorithm
  545. * to use.
  546. * @li data_format: An optional string. Defaults to "NHWC" . \n
  547. * @par Outputs:
  548. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  549. *
  550. * @par Restrictions:
  551. * Warning: THIS FUNCTION IS DEPRECATED. Please use AvgPoolGrad instead.
  552. */
  553. REG_OP(AvgPoolGradD)
  554. .INPUT(input_grad, TensorType({DT_FLOAT16}))
  555. .INPUT(mean_matrix, TensorType({DT_FLOAT16}))
  556. .INPUT(kernel_matrix, TensorType({DT_FLOAT16}))
  557. .OUTPUT(out_grad, TensorType({DT_FLOAT16}))
  558. .REQUIRED_ATTR(orig_input_shape, ListInt)
  559. .REQUIRED_ATTR(ksize, ListInt)
  560. .REQUIRED_ATTR(strides, ListInt)
  561. .REQUIRED_ATTR(padding, String)
  562. .ATTR(data_format, String, "NHWC")
  563. .OP_END_FACTORY_REG(AvgPoolGradD)
  564. /**
  565. *@brief :upsample the layer
  566. *@par Inputs:
  567. * one input, including:
  568. *@li x: A tensor of type float16 or float32.
  569. *@par Attributes:
  570. *@li scale: A optional float32, scale factor of x. Defaults to "1.0".
  571. *@li stride_h: An optional int32, broadcast the axis of h. Defaults to "2".
  572. *@li stride_w: An optional int32, broadcast the axis of w. Defaults to "2".
  573. *@par Outputs:
  574. *y: A tensor of type float16 or float32.
  575. */
  576. REG_OP(Upsample)
  577. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  578. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  579. .ATTR(scale, Float, 1)
  580. .ATTR(stride_h, Int, 2)
  581. .ATTR(stride_w, Int, 2)
  582. .OP_END_FACTORY_REG(Upsample)
  583. /**
  584. *@brief Computes gradient of the FractionalMaxPool function . \n
  585. *@par Inputs:
  586. *Inputs include:
  587. * @li orig_input: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  588. * @li orig_output: A Tensor. Must have the same type as orig_input.
  589. * @li out_backprop: A Tensor. Must have the same type as orig_input.
  590. 4-D with shape [batch, height, width, channels].
  591. * @li row_pooling_sequence: A Tensor of type int64.
  592. * @li col_pooling_sequence: A Tensor of type int64 . \n
  593. *@par Attributes:
  594. *overlapping: An optional bool. Defaults to False . \n
  595. *@par Outputs:
  596. *y: A Tensor. Has the same type as orig_input . \n
  597. *@attention Constraints:
  598. *The implementation for FractionalMaxPoolGrad on Ascend uses AICPU, with bad performance.
  599. *@par Third-party framework compatibility
  600. *@li compatible with tensorflow FractionalMaxPoolGrad operator.
  601. */
  602. REG_OP(FractionalMaxPoolGrad)
  603. .INPUT(orig_input, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  604. .INPUT(orig_output, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  605. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  606. .INPUT(row_pooling_sequence, TensorType({ DT_INT64 }))
  607. .INPUT(col_pooling_sequence, TensorType({ DT_INT64 }))
  608. .OUTPUT(y, TensorType({ DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64 }))
  609. .ATTR(overlapping, Bool, false)
  610. .OP_END_FACTORY_REG(FractionalMaxPoolGrad)
  611. /**
  612. *@brief Performs fractional average pooling on the input . \n
  613. *@par Inputs:
  614. *Inputs include:
  615. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  616. 4-D with shape [batch, height, width, channels] . \n
  617. *@par Attributes:
  618. *@li pooling_ratio: A list of floats that has length >= 4.
  619. *@li pseudo_random: An optional bool. Defaults to False.
  620. *@li overlapping: An optional bool. Defaults to False. When set to True, it means when pooling.
  621. *@li deterministic: An optional bool. Defaults to False.
  622. *@li seed: An optional int. Defaults to 0.
  623. *@li seed2: An optional int. Defaults to 0 . \n
  624. *@par Outputs:
  625. *@li y: A Tensor. Has the same type as x.
  626. *@li row_pooling_sequence: A Tensor of type int64.
  627. *@li col_pooling_sequence: A Tensor of type int64 . \n
  628. *@attention Constraints:
  629. *The implementation for FractionalAvgPool on Ascend uses AICPU, with bad performance.
  630. *@par Third-party framework compatibility
  631. *@li compatible with tensorflow FractionalAvgPool operator.
  632. */
  633. REG_OP(FractionalAvgPool)
  634. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  635. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  636. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  637. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  638. .ATTR(pooling_ratio, ListFloat, {})
  639. .ATTR(pseudo_random, Bool, false)
  640. .ATTR(overlapping, Bool, false)
  641. .ATTR(deterministic, Bool, false)
  642. .ATTR(seed, Int, 0)
  643. .ATTR(seed2, Int, 0)
  644. .OP_END_FACTORY_REG(FractionalAvgPool)
  645. /**
  646. *@brief Performs fractional max pooling on the input . \n
  647. *@par Inputs:
  648. *Inputs include:
  649. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  650. 4-D with shape [batch, height, width, channels] . \n
  651. *@par Attributes:
  652. *@li pooling_ratio: A list of floats that has length >= 4. Pooling ratio for each dimension of value.
  653. *@li pseudo_random: An optional bool. Defaults to False.
  654. *@li overlapping: An optional bool. Defaults to False.
  655. *@li deterministic: An optional bool. Defaults to False.
  656. *@li seed: An optional int. Defaults to 0.
  657. *@li seed2: An optional int. Defaults to 0 . \n
  658. *@par Outputs:
  659. *@li y: A Tensor. Has the same type as x.
  660. *@li row_pooling_sequence: A Tensor of type int64.
  661. *@li col_pooling_sequence: A Tensor of type int64 . \n
  662. *@attention Constraints:
  663. *The implementation for FractionalMaxPool on Ascend uses AICPU, with bad performance.
  664. *@par Third-party framework compatibility
  665. *@li compatible with tensorflow FractionalMaxPool operator.
  666. */
  667. REG_OP(FractionalMaxPool)
  668. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  669. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  670. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  671. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  672. .ATTR(pooling_ratio, ListFloat, {})
  673. .ATTR(pseudo_random, Bool, false)
  674. .ATTR(overlapping, Bool, false)
  675. .ATTR(deterministic, Bool, false)
  676. .ATTR(seed, Int, 0)
  677. .ATTR(seed2, Int, 0)
  678. .OP_END_FACTORY_REG(FractionalMaxPool)
  679. /**
  680. *@brief Finds values of the n-th order statistic for the last dimension . \n
  681. *@par Inputs:
  682. *Inputs include:
  683. * @li x: A Tensor. Must be one of the following types: float32, float64, int32, uint8,
  684. int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
  685. * @li n: A Tensor of type int32. 0-D . \n
  686. *@par Attributes:
  687. *reverse: An optional bool. Defaults to False . \n
  688. *@par Outputs:
  689. *y: A Tensor. Has the same type as x . \n
  690. *@attention Constraints:
  691. *The implementation for NthElement on Ascend uses AICPU, with bad performance.
  692. *@par Third-party framework compatibility
  693. *@li compatible with tensorflow NthElement operator.
  694. */
  695. REG_OP(NthElement)
  696. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  697. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  698. .INPUT(n, TensorType({DT_INT32}))
  699. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  700. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  701. .ATTR(reverse, Bool, false)
  702. .OP_END_FACTORY_REG(NthElement)
  703. /**
  704. *@brief Computes gradient of the FractionalAvgPool function . \n
  705. *@par Inputs:
  706. *Inputs include:
  707. * @li orig_input_tensor_shape: A Tensor of type int64.
  708. * @li out_backprop: A Tensor. Must be one of the following types: float32, float64,
  709. int32, int64. 4-D with shape [batch, height, width, channels].
  710. * @li row_pooling_sequence: A Tensor of type int64.
  711. * @li col_pooling_sequence: A Tensor of type int64 . \n
  712. *@par Attributes:
  713. *overlapping: An optional bool. Defaults to False . \n
  714. *@par Outputs:
  715. *y: A Tensor. Has the same type as out_backprop . \n
  716. *@attention Constraints:
  717. *The implementation for FractionalAvgPoolGrad on Ascend uses AICPU, with bad performance.
  718. *@par Third-party framework compatibility
  719. *@li compatible with tensorflow FractionalAvgPoolGrad operator.
  720. */
  721. REG_OP(FractionalAvgPoolGrad)
  722. .INPUT(orig_input_tensor_shape, TensorType({DT_INT64}))
  723. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  724. .INPUT(row_pooling_sequence, TensorType({DT_INT64}))
  725. .INPUT(col_pooling_sequence, TensorType({DT_INT64}))
  726. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  727. .ATTR(overlapping, Bool, false)
  728. .OP_END_FACTORY_REG(FractionalAvgPoolGrad)
  729. /**
  730. *@brief Returns the permuted vector/tensor in the destination data format given the . \n
  731. *@par Inputs:
  732. *Inputs include:
  733. *x: A Tensor. Must be one of the following types: int32, int64. Vector of size 4
  734. or Tensor of shape (4, 2) in source data format . \n
  735. *@par Attributes:
  736. *@li src_format: An optional string. Defaults to "NHWC". source data format.
  737. *@li dst_format: An optional string. Defaults to "NCHW". destination data format . \n
  738. *@par Outputs:
  739. *y: A Tensor. Has the same type as x . \n
  740. *@attention Constraints:
  741. *The implementation for DataFormatVecPermute on Ascend uses AICPU, with bad performance.
  742. *@par Third-party framework compatibility
  743. *@li compatible with tensorflow DataFormatVecPermute operator.
  744. */
  745. REG_OP(DataFormatVecPermute)
  746. .INPUT(x, TensorType({ DT_INT32, DT_INT64 }))
  747. .OUTPUT(y, TensorType({ DT_INT32, DT_INT64 }))
  748. .ATTR(src_format, String, "NHWC")
  749. .ATTR(dst_format, String, "NCHW")
  750. .OP_END_FACTORY_REG(DataFormatVecPermute)
  751. /**
  752. * @brief Computes gradients of the MaxPool3D function . \n
  753. * @par Inputs:
  754. * @li orig_x: A mutable NDC1HWC0 tensor of type float16.
  755. * @li orig_y: A mutable NDC1HWC0 tensor of type float16.
  756. * @li grads: A mutable NDC1HWC0 tensor of type float16 . \n
  757. * @par Attributes:
  758. * @li ksize: A required tuple or list, specifying the size of the window for
  759. * each dimension of the input tensor.
  760. * @li strides: A required tuple or list, specifying the stride of the sliding
  761. * window for each dimension of the input tensor.
  762. * @li pads: A list of 6 ints. Supports only padding along the D,
  763. * H and W dimensions in sequence of head, tail, top, bottom, left and right.
  764. * to use.
  765. * @li data_format: An optional string, Specify the data format of the input and
  766. * output data. With the default format "NDHWC" . \n
  767. * @par Outputs:
  768. * y: A mutable tensor. Has the same shape as "orig_x", but type is float32 . \n
  769. * @par Third-party framework compatibility
  770. * Compatible with the TensorFlow operator MaxPool3DGrad.
  771. */
  772. REG_OP(MaxPool3DGrad)
  773. .INPUT(orig_x, TensorType::RealNumberType())
  774. .INPUT(orig_y, TensorType::RealNumberType())
  775. .INPUT(grads, TensorType::RealNumberType())
  776. .OUTPUT(y, TensorType::RealNumberType())
  777. .REQUIRED_ATTR(ksize, ListInt)
  778. .REQUIRED_ATTR(strides, ListInt)
  779. .REQUIRED_ATTR(pads, ListInt)
  780. .ATTR(data_format, String, "NDHWC")
  781. .OP_END_FACTORY_REG(MaxPool3DGrad)
  782. /**
  783. *@brief Performs AvgPool1D on the input . \n
  784. *@par Inputs:
  785. *x: A Tensor. Must be one of the following types: int8, uint8, int16, int32, int64, float16, float32, float64 . \n
  786. *@par Attributes:
  787. *@li ksize: An required int, specifying the size of the window.
  788. *@li strides: An required int.
  789. *@li pads: A required tuple or list.
  790. *@li ceil_mode: An optional bool. Defaults to False.
  791. *@li count_include_pad: An optional bool. Defaults to False . \n
  792. *@par Outputs:
  793. *y: A Tensor. Has the same type as x . \n
  794. *@par Third-party framework compatibility
  795. *@li compatible with pytorch AvgPool1D operator.
  796. */
  797. REG_OP(AvgPool1D)
  798. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  799. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  800. .REQUIRED_ATTR(ksize, Int)
  801. .REQUIRED_ATTR(strides, Int)
  802. .REQUIRED_ATTR(pads, ListInt)
  803. .ATTR(ceil_mode, Bool, false)
  804. .ATTR(count_include_pad, Bool, false)
  805. .OP_END_FACTORY_REG(AvgPool1D)
  806. /**
  807. *@brief Performs AvgPool1D on the input . \n
  808. *@par Inputs:
  809. *x: A Tensor. Must be one of the following types: int8, uint8, int16, int32, int64, float16, float32, float64 . \n
  810. *@par Attributes:
  811. *@li ksize: An required int, specifying the size of the window.
  812. *@li strides: An required int.
  813. *@li pads: A required tuple or list.
  814. *@li ceil_mode: An optional bool. Defaults to False.
  815. *@li count_include_pad: An optional bool. Defaults to False . \n
  816. *@par Outputs:
  817. *y: A Tensor. Has the same type as x . \n
  818. *@par Third-party framework compatibility
  819. *@li compatible with pytorch AvgPool1D operator.
  820. *
  821. *@par Restrictions:
  822. *Warning: THIS FUNCTION IS DEPRECATED. Please use AvgPool1D instead.
  823. */
  824. REG_OP(AvgPool1DD)
  825. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  826. .INPUT(assist_matrix, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  827. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  828. .REQUIRED_ATTR(ksize, Int)
  829. .REQUIRED_ATTR(strides, Int)
  830. .REQUIRED_ATTR(pads, ListInt)
  831. .ATTR(ceil_mode, Bool, false)
  832. .ATTR(count_include_pad, Bool, false)
  833. .OP_END_FACTORY_REG(AvgPool1DD)
  834. /**
  835. *@brief Performs max pooling on the input and outputs both max values and indices . \n
  836. *@par Inputs:
  837. * One input:
  838. *x: An NC1HWC0 Tensor of type float16.
  839. *@par Attributes:
  840. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for
  841. * each dimension of the input tensor. No default value.
  842. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for
  843. * each dimension of the input tensor. No default value.
  844. *@li pads: A required string. No default value.
  845. *@li dtype: A optional int. default value is 3.
  846. *@li dilation: A optional list of int8, int16, int32, or int64 values.
  847. *@li ceil_mode: A optional bool. default value is false . \n
  848. *@par Outputs:
  849. *y: A Tensor. Has the same type and format as input "x".
  850. *argmax: A Tensor. type:uint16, format:NC1HWC0.
  851. *@attention Constraints:
  852. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  853. *@li "strides is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1,
  854. * strides[2] <= 63, strides[2] >= 1.
  855. *@li "dilation" is a list that has length 4.
  856. *@li "ceil_mode" is a bool, default is false . \n
  857. *@par Third-party framework compatibility
  858. * Compatible with the TensorFlow operator MaxPoolWithArgmax.
  859. */
  860. REG_OP(MaxPoolWithArgmaxV2)
  861. .INPUT(x, TensorType({DT_FLOAT16}))
  862. .OUTPUT(y, TensorType({DT_FLOAT16}))
  863. .OUTPUT(argmax, TensorType({DT_UINT16}))
  864. .REQUIRED_ATTR(ksize, ListInt)
  865. .REQUIRED_ATTR(strides, ListInt)
  866. .REQUIRED_ATTR(pads, ListInt)
  867. .ATTR(dtype, Int, 3)
  868. .ATTR(dilation, ListInt, {1, 1, 1, 1})
  869. .ATTR(ceil_mode, Bool, false)
  870. .OP_END_FACTORY_REG(MaxPoolWithArgmaxV2)
  871. /**
  872. *@brief Performs the backpropagation of MaxPoolWithArgmaxV2 . \n
  873. *@par Inputs:
  874. * Three inputs, including:
  875. *@li x: An NC1HWC0 tensor of type float16.
  876. *@li grad: An NC1HWC0 tensor of type float16.
  877. *@li argmx: An NC1HWC0 tensor of type uint16 or int64 . \n
  878. *@par Attributes:
  879. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for
  880. * each dimension of the input tensor. No default value.
  881. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for
  882. * each dimension of the input tensor. No default value.
  883. *@li pads: A required string. No default value.
  884. *@li dtype: A optional int. default value is 3.
  885. *@li dilation: A optional list of int8, int16, int32, or int64 values.
  886. *@li ceil_mode: A optional bool. default value is false . \n
  887. *@par Outputs:
  888. *y: A Tensor. Has the same type and format as input "x" . \n
  889. *@attention Constraints:
  890. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  891. *@li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  892. *@li "dilation" is a list that has length 4.
  893. *@li "ceil_mode" is a bool, default is false . \n
  894. *@see max_pool_grad_with_argmaxv2
  895. *@par Third-party framework compatibility
  896. * Compatible with the TensorFlow operator MaxPoolGradWithArgmaxV2.
  897. */
  898. REG_OP(MaxPoolGradWithArgmaxV2)
  899. .INPUT(x, TensorType({DT_FLOAT16}))
  900. .INPUT(grad, TensorType({DT_FLOAT16}))
  901. .INPUT(argmax, TensorType({DT_UINT16}))
  902. .OUTPUT(y, TensorType({DT_FLOAT16}))
  903. .REQUIRED_ATTR(ksize, ListInt)
  904. .REQUIRED_ATTR(strides, ListInt)
  905. .REQUIRED_ATTR(pads, ListInt)
  906. .ATTR(dtype, Int, 3)
  907. .ATTR(dilation, ListInt, {1,1,1,1})
  908. .ATTR(ceil_mode, Bool, false)
  909. .OP_END_FACTORY_REG(MaxPoolGradWithArgmaxV2)
  910. } // namespace ge
  911. #endif // GE_OP_NN_POOLING_OPS_H

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