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

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