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 70 kB

5 years ago
4 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
4 years ago
5 years ago
5 years ago
4 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
4 years ago
5 years ago
4 years ago
4 years ago
4 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
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700
  1. /**
  2. * Copyright 2019 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 average pooling on the input.
  166. *@par Inputs:
  167. *@li x: A 5-D Tensor of shape [batch, depth, height, width, channels] and type float16, float32, double.
  168. *@li filter: An optional tensor of type float16, float32, double, fractal_z_3d layout.
  169. *@li multiplier: An optional tensor of float16, float32, double.
  170. *@par Attributes:
  171. *@li ksize: List of ints that has length 1, 3 or 5. The size of the window for each dimension of the input tensor.
  172. *@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.
  173. *@li pads: List of ints, implicit zero paddings on both sides of the input.
  174. *@li ceil_mode: When true, will use ceil instead of floor in the formula to compute the output shape.
  175. *@li count_include_pad: When true, will include the zero-padding in the averaging calculation.
  176. *@li divisor_override: if specified, it will be used as divisor, otherwise size of the pooling region will be used.
  177. *@li data_format: A string, format of input data . \n
  178. *@par Outputs:
  179. *y: The average pooled output tensor . \n
  180. *@attention Constraints:
  181. *@li "ksize" is in the range [1, 255]. "strides" is in the range [1, 63]
  182. *@par Third-party framework compatibility
  183. * Compatible with the TensorFlow operator AvgPool3D.
  184. */
  185. REG_OP(AvgPool3DD)
  186. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  187. .OPTIONAL_INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  188. .OPTIONAL_INPUT(multiplier, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  189. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  190. .REQUIRED_ATTR(ksize, ListInt)
  191. .REQUIRED_ATTR(strides, ListInt)
  192. .REQUIRED_ATTR(pads, ListInt)
  193. .ATTR(ceil_mode, Bool, false)
  194. .ATTR(count_include_pad, Bool, true)
  195. .ATTR(divisor_override, Int, 0)
  196. .ATTR(data_format, String, "NDHWC")
  197. .OP_END_FACTORY_REG(AvgPool3DD)
  198. /**
  199. * @brief Computes AvgPool3DGrad function.
  200. * @par Inputs:
  201. * @li orig_input_shape: An NDHWC tensor of type float16, float32, or double.
  202. * @li grads: An NDHWC tensor of type int32.
  203. * @par Attributes:
  204. * @li ksize: List of ints that has length 1, 3 or 5. The size of the window for each dimension of the input tensor.
  205. * @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.
  206. * @li pads: List of ints, implicit zero paddings on both sides of the input.
  207. * @li ceil_mode: When true, will use ceil instead of floor in the formula to compute the output shape.
  208. * @li count_include_pad: When true, will include the zero-padding in the averaging calculation.
  209. * @li divisor_override: if specified, it will be used as divisor, otherwise size of the pooling region will be used.
  210. * @li data_format: A string, format of input data .
  211. * @par Outputs:
  212. * @output: A mutable tensor with the same shape and type as "orig_input".
  213. * @par Third-party framework compatibility
  214. * @li Compatible with the TensorFlow operator AvgPoolGrad.
  215. */
  216. REG_OP(AvgPool3DGrad)
  217. .INPUT(orig_input_shape, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  218. .INPUT(grads, TensorType({DT_INT32}))
  219. .OUTPUT(output, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  220. .REQUIRED_ATTR(ksize, ListInt)
  221. .REQUIRED_ATTR(strides, ListInt)
  222. .REQUIRED_ATTR(pads, ListInt)
  223. .ATTR(ceil_mode, Bool, false)
  224. .ATTR(count_include_pad, Bool, true)
  225. .ATTR(divisor_override, Int, 0)
  226. .ATTR(data_format, String, "NDHWC")
  227. .OP_END_FACTORY_REG(AvgPool3DGrad)
  228. /**
  229. * @brief Performs average pooling on the input.
  230. * @par Inputs:
  231. * @li grads: An NDHWC tensor of type float16.
  232. * @li filter: An optional tensor of type float16, fractal_z_3d layout.
  233. * @li multiplier: An optional tensor of float16.
  234. * @par Attributes:
  235. * @li orig_input_shape: List of ints that has length 5. The size of the window for each dimension of the input tensor.
  236. * @li ksize: List of ints that has length 3. The size of the window for each dimension of the input tensor.
  237. * @li strides:List of ints that has length 3. The stride of the sliding window for each dimension of the input tensor.
  238. * @li pads: List of ints, implicit zero paddings on both sides of the input.
  239. * @li ceil_mode: When true, will use ceil instead of floor in the formula to compute the output shape.
  240. * @li count_include_pad: When true, will include the zero-padding in the averaging calculation.
  241. * @li divisor_override: if specified, it will be used as divisor, otherwise size of the pooling region will be used.
  242. * @li data_format: A string, format of input data . \n
  243. * @par Outputs:
  244. * @output: The average pooled output tensor . \n
  245. * @attention Constraints:
  246. * @li "ksize" is in the range [1, 255]. "strides" is in the range [1, 63]
  247. * @par Third-party framework compatibility
  248. * Compatible with the TensorFlow operator AvgPool3DGradD.
  249. */
  250. REG_OP(AvgPool3DGradD)
  251. .INPUT(grads, TensorType({DT_FLOAT16}))
  252. .OPTIONAL_INPUT(filter, TensorType({DT_FLOAT16}))
  253. .OPTIONAL_INPUT(multiplier, TensorType({DT_FLOAT16}))
  254. .OUTPUT(output, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  255. .REQUIRED_ATTR(orig_input_shape, ListInt)
  256. .REQUIRED_ATTR(ksize, ListInt)
  257. .REQUIRED_ATTR(strides, ListInt)
  258. .REQUIRED_ATTR(pads, ListInt)
  259. .ATTR(ceil_mode, Bool, false)
  260. .ATTR(count_include_pad, Bool, true)
  261. .ATTR(divisor_override, Int, 0)
  262. .ATTR(data_format, String, "NDHWC")
  263. .OP_END_FACTORY_REG(AvgPool3DGradD)
  264. /**
  265. *@brief Performs max_pool_ext2 on the input . \n
  266. *@par Inputs:
  267. * One input:
  268. *x: An NC1HWC0 Tensor of type float16.
  269. *@par Attributes:
  270. *@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.
  271. *@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.
  272. *@li padding: A required string. No default value.
  273. *@li data_format: An optional string. Defaults to "NC1HWC0" . \n
  274. *@par Outputs:
  275. *y: A Tensor. Has the same type and format as input "x" . \n
  276. *@attention Constraints:
  277. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  278. *@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.
  279. *@li "padding" is either "SAME" or "VALID" . \n
  280. *@par Third-party framework compatibility
  281. * Compatible with the TensorFlow operator MaxPoolV2.
  282. */
  283. REG_OP(MaxPoolExt2)
  284. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  285. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  286. DT_UINT16, DT_QINT8}))
  287. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  288. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  289. DT_UINT16, DT_QINT8}))
  290. .REQUIRED_ATTR(ksize, ListInt)
  291. .REQUIRED_ATTR(strides, ListInt)
  292. .REQUIRED_ATTR(padding, String)
  293. .ATTR(data_format, String, "NHWC")
  294. .OP_END_FACTORY_REG(MaxPoolExt2)
  295. /**
  296. *@brief Performs max pooling on the input . \n
  297. *@par Inputs:
  298. * One input:
  299. *x: An NC1HWC0 Tensor. Supported type:float16, float32, double, int8, int16,
  300. * int32, int64, uint8, uint16, qint8
  301. *@par Attributes:
  302. *@li ksize: A required list of int8, int16, int32, or int64 values,
  303. * specifying the size of the window for each dimension of the input tensor.
  304. * No default value.
  305. *@li strides: A required list of int8, int16, int32, or int64 values,
  306. * specifying the stride of the sliding window for each dimension of
  307. * the input tensor. No default value.
  308. *@li padding: A required string. No default value.
  309. *@li data_format: An optional string. Defaults to "NHWC" . \n
  310. *@par Outputs:
  311. *y: A Tensor. Has the same type and format as input "x" . \n
  312. *@attention Constraints:
  313. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  314. * ksize[1] * ksize[2] <= 255.
  315. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  316. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  317. *@li "padding" is either "SAME" or "VALID".
  318. *@par Third-party framework compatibility
  319. * Compatible with the TensorFlow operator MaxPool.
  320. */
  321. REG_OP(MaxPool)
  322. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  323. DT_INT16, DT_INT32, DT_INT64, DT_UINT8,
  324. DT_UINT16, DT_QINT8}))
  325. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT8,
  326. DT_INT16, DT_INT32, DT_INT64, DT_UINT8, DT_UINT16, DT_QINT8}))
  327. .REQUIRED_ATTR(ksize, ListInt)
  328. .REQUIRED_ATTR(strides, ListInt)
  329. .REQUIRED_ATTR(padding, String)
  330. .ATTR(data_format, String, "NHWC")
  331. .OP_END_FACTORY_REG(MaxPool)
  332. /**
  333. *@brief Performs max 3d pooling on the input . \n
  334. *@par Inputs:
  335. *x: An NC1HWC0 Tensor. Supported type float16, float32, double . \n
  336. *@par Attributes:
  337. *@li ksize: A required list of int8, int16, int32, or int64 values,
  338. specifying the size of the window for each dimension of the input tensor.
  339. No default value.
  340. *@li strides: A required list of int8, int16, int32, or int64 values,
  341. specifying the stride of the sliding window for each dimension of
  342. the input tensor. No default value.
  343. *@li padding: A required string type of float16.
  344. *@li pads: A list type of int32. Default value {0,0,0,0,0,0}.
  345. *@li dilation: A list type of int32. Default value {1,1,1,1,1,1}.
  346. *@li ceil_mode: A ceil mode number of int32 . Default value 0.
  347. *@li data_format: An optional string. Defaults to "NDHWC" . \n
  348. *@par Outputs:
  349. *y: A Tensor. Has the same type and format as input "x" . \n
  350. *@attention Constraints:
  351. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  352. * ksize[1] * ksize[2] <= 255.
  353. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  354. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  355. *@li "padding" is either "SAME" or "VALID" . \n
  356. *@par Third-party framework compatibility
  357. * Compatible with the TensorFlow operator MaxPool3D.
  358. */
  359. REG_OP(MaxPool3D)
  360. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  361. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  362. .REQUIRED_ATTR(ksize, ListInt)
  363. .REQUIRED_ATTR(strides, ListInt)
  364. .REQUIRED_ATTR(padding, String)
  365. .ATTR(pads, ListInt, {0,0,0,0,0,0})
  366. .ATTR(dilation, ListInt, {1,1,1,1,1,1})
  367. .ATTR(ceil_mode, Int, 0)
  368. .ATTR(data_format, String, "NDHWC")
  369. .OP_END_FACTORY_REG(MaxPool3D)
  370. /**
  371. *@brief Applies a 2D adaptive max pooling over an input signal conposed of several input planes. \n
  372. * The output is of size H x W, for any input size.
  373. * @par Inputs:
  374. * One input, including:
  375. * @li x: A Tensor. Must be one of the following data types:
  376. * float16, float32, float64. \n
  377. * @par Attributes:
  378. * @li output_size: A required list of 2 ints
  379. * specifying the size (H,W) of the output tensor. \n
  380. * @par Outputs:
  381. * @li y: A Tensor. Has the same data type as "x" \n
  382. * @par Third-party framework compatibility
  383. * Compatible with the Pytorch operator AdaptiveMaxPool2d.
  384. */
  385. REG_OP(AdaptiveMaxPool2d)
  386. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  387. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  388. .OUTPUT(argmax, TensorType::IndexNumberType())
  389. .REQUIRED_ATTR(output_size, ListInt)
  390. .OP_END_FACTORY_REG(AdaptiveMaxPool2d)
  391. /**
  392. * @brief Computes second-order gradients of the maxpooling3d function . \n
  393. * @par Inputs:
  394. * @li orig_x: Original forward input tensor(NDC1HWC0) of type float16
  395. * @li orig_y: Original forward output tensor(NDC1HWC0) of type float16
  396. * @li grads: Gradient tensor(NDC1HWC0) of type float16
  397. * @li assist: Assist tensor(NDC1HWC0) of type float16
  398. * @par Attributes:
  399. * @li ksize: A required list or tuple,
  400. * specifying the size of the sliding window.
  401. * @li strides: A required list or tuple,
  402. * specifying the stride of the sliding window.
  403. * @li pads: A required list or tuple
  404. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  405. * @li data_format: An optional string.
  406. * Format of the original input, either NCDHW or NDHWC. Defaults to NDHWC . \n
  407. * @attention Constraints:
  408. * @li Only the Ascend 910 platform is supported.
  409. * @li "orig_x" and "grads" must have the same shape.
  410. * @li "orig_y" and "y" must have the same shape. Otherwise, an error is reported.
  411. * @li "orig_x", "orig_y", "grads", and "y" must be NDC1HWC0 tensors . \n
  412. * @par Outputs:
  413. * @li y: Result tensor of type float16
  414. * @par Third-party framework compatibility
  415. * @li Compatible with the TensorFlow operator MaxPool3DGradGrad.
  416. */
  417. REG_OP(MaxPool3DGradGrad)
  418. .INPUT(orig_x, TensorType::RealNumberType())
  419. .INPUT(orig_y, TensorType::RealNumberType())
  420. .INPUT(grads, TensorType::RealNumberType())
  421. .OUTPUT(y, TensorType::RealNumberType())
  422. .REQUIRED_ATTR(ksize, ListInt)
  423. .REQUIRED_ATTR(strides, ListInt)
  424. .REQUIRED_ATTR(pads, ListInt)
  425. .ATTR(data_format, String, "NDHWC")
  426. .OP_END_FACTORY_REG(MaxPool3DGradGrad)
  427. /**
  428. * @brief Computes gradients of the maxpooling function . \n
  429. * @par Inputs:
  430. * @li x1: A mutable NC1HWC0 tensor of type RealNumberType.
  431. * @li x2: A mutable NC1HWC0 tensor of type RealNumberTypex.
  432. * @li grad: A mutable NC1HWC0 tensor of type RealNumberType . \n
  433. * @par Attributes:
  434. * @li ksize: A required tuple or list, specifying the size of the window for
  435. * each dimension of the input tensor.
  436. * @li strides: A required tuple or list, specifying the stride of the sliding
  437. * window for each dimension of the input tensor.
  438. * @li padding: A required string, specifying the type of padding algorithm
  439. * to use.
  440. * @li data_format: An optional string, Specify the data format of the input and
  441. * output data. With the default format "NHWC" . \n
  442. * @par Outputs:
  443. * y: A mutable tensor. Has the same shape and type as "x1" . \n
  444. * @attention Constraints:
  445. * @li Computing gradients of global pooling is not supported, which means
  446. * "ksize < x1".
  447. * @li "ksize" is in the range [1, 255]. "strides" is in the range [1, 63]
  448. * @par Third-party framework compatibility
  449. * Compatible with the TensorFlow operator MaxPoolGrad.
  450. */
  451. REG_OP(MaxPoolGrad)
  452. .INPUT(x1, TensorType::RealNumberType())
  453. .INPUT(x2, TensorType::RealNumberType())
  454. .INPUT(grad, TensorType::RealNumberType())
  455. .OUTPUT(y, TensorType::RealNumberType())
  456. .REQUIRED_ATTR(ksize, ListInt)
  457. .REQUIRED_ATTR(strides, ListInt)
  458. .REQUIRED_ATTR(padding, String)
  459. .ATTR(data_format, String, "NHWC")
  460. .OP_END_FACTORY_REG(MaxPoolGrad)
  461. /**
  462. * @brief Computes second-order gradients of the maxpooling function . \n
  463. * @par Inputs:
  464. * @li x1: Original forward input tensor. Supported type:float, double, int32,
  465. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  466. * @li x2: Has the same type and format as input "x1".
  467. * @li grad:Has the same type and format as input "x1" . \n
  468. * @par Attributes:
  469. * @li ksize: A required list or tuple,
  470. * specifying the size of the sliding window.
  471. * @li strides: A required list or tuple,
  472. * specifying the stride of the sliding window.
  473. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  474. * @li data_format: An optional string.
  475. * Format of the original input, either NCHW or NHWC. Defaults to NHWC . \n
  476. * @attention Constraints:
  477. * @li Only the Ascend 910 platform is supported.
  478. * @li "x1" and "grads" must have the same shape.
  479. * @li "x2" and "y" must have the same shape. Otherwise, an error is reported.
  480. * @li "x1", "x2", "grads", and "y" must be 5D tensors.
  481. * @li ksize[H] and ksize[W] is in the range [1, 255].
  482. * @li strides[H] and strides[W] is in the range [1, 63].
  483. * @li Other dimensions of ksize and strides is 1 . \n
  484. * @par Outputs:
  485. * @li y: Has the same type and format as input "x1" . \n
  486. * @par Third-party framework compatibility
  487. * @li Compatible with the TensorFlow operator MaxPoolGradGrad.
  488. */
  489. REG_OP(MaxPoolGradGrad)
  490. .INPUT(x1, TensorType::RealNumberType())
  491. .INPUT(x2, TensorType::RealNumberType())
  492. .INPUT(grad, TensorType::RealNumberType())
  493. .OUTPUT(y, TensorType::RealNumberType())
  494. .REQUIRED_ATTR(ksize, ListInt)
  495. .REQUIRED_ATTR(strides, ListInt)
  496. .REQUIRED_ATTR(padding, String)
  497. .ATTR(data_format, String, "NHWC")
  498. .OP_END_FACTORY_REG(MaxPoolGradGrad)
  499. /**
  500. *@brief Performs max_pool_ext2 on the input . \n
  501. *@par Inputs:
  502. * Two inputs:
  503. *@li x: An NC1HWC0 Tensor of type float16.
  504. *@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.
  505. *@li ksize: A required type of int32 values, specifying the size of the window for each dimension of the input tensor. No default value.
  506. *@par Attributes:
  507. *@li padding: A required string. No default value.
  508. *@li data_format: An optional string. Defaults to "NC1HWC0" . \n
  509. *@par Outputs:
  510. *y: A Tensor. Has the same type and format as input "x" . \n
  511. *@attention Constraints:
  512. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  513. *@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.
  514. *@li "padding" is either "SAME" or "VALID" . \n
  515. *@par Third-party framework compatibility
  516. * Compatible with the TensorFlow operator MaxPoolV2.
  517. */
  518. REG_OP(MaxPoolV2)
  519. .INPUT(x, TensorType({DT_FLOAT16}))
  520. .INPUT(ksize, TensorType({DT_INT32}))
  521. .INPUT(strides, TensorType({DT_INT32}))
  522. .OUTPUT(y, TensorType({DT_FLOAT16}))
  523. .REQUIRED_ATTR(padding, String)
  524. .ATTR(data_format, String, "NHWC")
  525. .OP_END_FACTORY_REG(MaxPoolV2)
  526. /**
  527. *@brief Performs max pooling on the input and outputs both max values and
  528. * indices . \n
  529. *@par Inputs:
  530. * One input:
  531. *x: An 4D Tensor. Supported type: float, double, int32,
  532. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  533. * Must set the format, supported format list ["NCHW, NHWC"]. \n
  534. *@par Attributes:
  535. *@li ksize: A required list of int8, int16, int32, or int64 values,
  536. * specifying the size of the window for each dimension of the input tensor.
  537. * No default value.
  538. *@li strides: A required list of int8, int16, int32, or int64 values,
  539. * specifying the stride of the sliding window for each dimension of
  540. * the input tensor. No default value.
  541. *@li padding: A required string. No default value . \n
  542. *@par Outputs:
  543. *y: A Tensor. Has the same type and format as input "x".
  544. *argmax: A Tensor. Has the same type and format as input "x".
  545. *@attention Constraints:
  546. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  547. * ksize[1] * ksize[2] <= 255.
  548. *@li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  549. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  550. *@li "padding" is either "SAME" or "VALID" . \n
  551. *@par Third-party framework compatibility
  552. * Compatible with the TensorFlow operator MaxPoolWithArgmax.
  553. */
  554. REG_OP(MaxPoolWithArgmax)
  555. .INPUT(x, TensorType::RealNumberType())
  556. .OUTPUT(y, TensorType::RealNumberType())
  557. .OUTPUT(argmax, TensorType::IndexNumberType())
  558. .REQUIRED_ATTR(ksize, ListInt)
  559. .REQUIRED_ATTR(strides, ListInt)
  560. .REQUIRED_ATTR(padding, String)
  561. .ATTR(Targmax, Int, 7)
  562. .OP_END_FACTORY_REG(MaxPoolWithArgmax)
  563. /**
  564. *@brief Performs the backpropagation of MaxPoolWithArgmax . \n
  565. *@par Inputs:
  566. * Three inputs, including:
  567. *@li x: An 4d tensor. Supported type: float, double, int32,
  568. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  569. * Must set the format, supported format list ["NCHW, NHWC"]
  570. *@li grad: An 4d tensor. Supported type: float, double, int32,
  571. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  572. * Must set the format, supported format list ["NCHW, NHWC"]
  573. *@li argmx: An NC1HWC0 tensor of type int32 or int64 . \n
  574. *@par Attributes:
  575. *@li ksize: A required list of int8, int16, int32, or int64 values,
  576. * specifying the size of the window for each dimension of the input tensor.
  577. * No default value.
  578. *@li strides: A required list of int8, int16, int32, or int64 values,
  579. * specifying the stride of the sliding window for each dimension of
  580. * the input tensor. No default value.
  581. *@li padding: A required string. No default value . \n
  582. *@par Outputs:
  583. *y: A Tensor. Has the same type and format as input "x" . \n
  584. *@attention Constraints:
  585. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  586. * ksize[1] * ksize[2] <= 255.
  587. *@li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  588. *@li "padding" is either "SAME" or "VALID".
  589. *@see max_pool_with_argmax
  590. *@par Third-party framework compatibility
  591. * Compatible with the TensorFlow operator MaxPoolGradWithArgmax.
  592. */
  593. REG_OP(MaxPoolGradWithArgmax)
  594. .INPUT(x, TensorType::RealNumberType())
  595. .INPUT(grad, TensorType::RealNumberType())
  596. .INPUT(argmax, TensorType::IndexNumberType())
  597. .OUTPUT(y, TensorType::RealNumberType())
  598. .REQUIRED_ATTR(ksize, ListInt)
  599. .REQUIRED_ATTR(strides, ListInt)
  600. .REQUIRED_ATTR(padding, String)
  601. .OP_END_FACTORY_REG(MaxPoolGradWithArgmax)
  602. /**
  603. *@brief Performs transform mask to argmax . \n
  604. *@par Inputs:
  605. * Two input:
  606. *x: An NC1HWC0 Tensor of type float16.
  607. *mask: An NC1HWC0 Tensor of type uint16 . \n
  608. *@par Attributes:
  609. *@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.
  610. *@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.
  611. *@li padding: A required string. No default value . \n
  612. *@par Outputs:
  613. *argmax: An NC1HWC0 Tensor of type int32 . \n
  614. *@attention Constraints:
  615. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  616. *@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.
  617. *@li "padding" is either "SAME" or "VALID" . \n
  618. *@par Third-party framework compatibility
  619. * Compatible with the TensorFlow operator Mask2Argmax.
  620. */
  621. REG_OP(Mask2Argmax)
  622. .INPUT(x, TensorType::RealNumberType())
  623. .INPUT(mask, TensorType::IndexNumberType())
  624. .OUTPUT(argmax, TensorType::IndexNumberType())
  625. .REQUIRED_ATTR(ksize, ListInt)
  626. .REQUIRED_ATTR(strides, ListInt)
  627. .REQUIRED_ATTR(padding, String)
  628. .REQUIRED_ATTR(originshape, ListInt)
  629. .OP_END_FACTORY_REG(Mask2Argmax)
  630. /**
  631. * @brief Computes second-order gradients of the maxpooling function . \n
  632. * @par Inputs:
  633. * @li x: Original forward input tensor. Supported type: float, double, int32,
  634. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  635. * @li grad: Gradient tensor. Supported type: float, double, int32,
  636. * uint8, int16, int8, int64, uint16, half, uint32, uint64.
  637. * @li argmax: An tensor of type int32 or int64.
  638. * @par Attributes:
  639. * @li ksize: A required list, specifying the size of the sliding window.
  640. * @li strides: A required list, specifying the stride of the sliding window.
  641. * @li padding: A required string, window sliding mode. Either SAME or VALID.
  642. * @par Outputs:
  643. * @li y:Result tensor. Supported type: float, double, int32,
  644. * uint8, int16, int8, int64, uint16, half, uint32, uint64
  645. * @attention Constraints:
  646. * @li Only the cloud platform is supported.
  647. * @li "x1" and "grads" must have the same shape.
  648. * @li length of the shape of x, grads, argmax, y must be 5.
  649. * @li shape of argmax must be (fmap_n, fmap_c1, kernel_h * kernel_w,
  650. * (shape_max_pool[2] * shape_max_pool[3] + 15) // 16 * 16, 1),
  651. * or (fmap_n, fmap_c1, kernel_h * kernel_w,
  652. * (shape_max_pool[2] * shape_max_pool[3] + 31) // 16, 16), else failed . \n
  653. * @par Third-party framework compatibility
  654. * @li Compatible with the TensorFlow operator MaxPoolGradGradWithArgmax.
  655. */
  656. REG_OP(MaxPoolGradGradWithArgmax)
  657. .INPUT(x, TensorType::RealNumberType())
  658. .INPUT(grad, TensorType::RealNumberType())
  659. .INPUT(argmax, TensorType::IndexNumberType())
  660. .OUTPUT(y, TensorType::RealNumberType())
  661. .REQUIRED_ATTR(ksize, ListInt)
  662. .REQUIRED_ATTR(strides, ListInt)
  663. .REQUIRED_ATTR(padding, String)
  664. .OP_END_FACTORY_REG(MaxPoolGradGradWithArgmax)
  665. /**
  666. * @brief Computes avgpoograd function . \n
  667. * @par Inputs:
  668. * @li orig_input_shape: An NHWC tensor of type int32.
  669. * @li input_grad: An NHWC tensor of type float16, float32, or double . \n
  670. * @par Attributes:
  671. * @li ksize: A required tuple or list, specifying the size of the window for
  672. * each dimension of the input tensor.
  673. * @li strides: A required tuple or list, specifying the stride of the sliding
  674. * window for each dimension of the input tensor.
  675. * @li padding: A required string, specifying the type of
  676. * the padding algorithm to use.
  677. * @li data_format: An optional string. Defaults to "NHWC" . \n
  678. * @par Outputs:
  679. * @out_grad: A mutable tensor with the same shape and type as "orig_input" . \n
  680. * @par Third-party framework compatibility
  681. * @li Compatible with the TensorFlow operator AvgPoolGrad.
  682. */
  683. REG_OP(AvgPoolGrad)
  684. .INPUT(orig_input_shape, TensorType({DT_INT32}))
  685. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  686. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  687. .REQUIRED_ATTR(ksize, ListInt)
  688. .REQUIRED_ATTR(strides, ListInt)
  689. .REQUIRED_ATTR(padding, String)
  690. .ATTR(data_format, String, "NHWC")
  691. .OP_END_FACTORY_REG(AvgPoolGrad)
  692. /**
  693. * @brief Computes gradients of average pooling function . \n
  694. * @par Inputs:
  695. * @input_grad: An NHWC tensor of type float16.
  696. * @mean_matrix: Assist matrix, an NHWC tensor of type float16.
  697. * @kernel_matrix: Assist matrix, an NHWC tensor of type float16.
  698. * @par Attributes:
  699. * @li orig_input_shape: A required Original input dimensions.
  700. * @li ksize: A required tuple or list, specifying the size of the window
  701. * for each dimension of the input tensor.
  702. * @li strides: A required tuple or list, specifying the stride of
  703. * the sliding window for each dimension of the input tensor.
  704. * @li padding: A required string, specifying the type of the padding algorithm
  705. * to use.
  706. * @li data_format: An optional string. Defaults to "NHWC" . \n
  707. * @par Outputs:
  708. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  709. *
  710. * @par Restrictions:
  711. * Warning: THIS FUNCTION IS DEPRECATED. Please use AvgPoolGrad instead.
  712. */
  713. REG_OP(AvgPoolGradD)
  714. .INPUT(input_grad, TensorType({DT_FLOAT16}))
  715. .INPUT(mean_matrix, TensorType({DT_FLOAT16}))
  716. .INPUT(kernel_matrix, TensorType({DT_FLOAT16}))
  717. .OUTPUT(out_grad, TensorType({DT_FLOAT16}))
  718. .REQUIRED_ATTR(orig_input_shape, ListInt)
  719. .REQUIRED_ATTR(ksize, ListInt)
  720. .REQUIRED_ATTR(strides, ListInt)
  721. .REQUIRED_ATTR(padding, String)
  722. .ATTR(data_format, String, "NHWC")
  723. .OP_END_FACTORY_REG(AvgPoolGradD)
  724. /**
  725. * @brief Computes avgpoolv2grad function.
  726. * @par Inputs:
  727. * @li orig_input_shape: An NHWC tensor of type int32.
  728. * @li input_grad: An NHWC tensor of type float16, float32, or double.
  729. * @par Attributes:
  730. * @li ksize: A required tuple or list, specifying the size of the window for
  731. * each dimension of the input tensor.
  732. * @li strides: A required tuple or list, specifying the stride of the sliding
  733. * window for each dimension of the input tensor.
  734. * @li padding_mode: A required string, specifying the type of
  735. * the padding algorithm to use.
  736. * @li global_pooling: Whether to use the global pooling. If global_pooling=true,
  737. * ksize and pads will be ignored. Default False.
  738. * @li ceil_mode: Whether to use the ceil function to calculate output height and
  739. * width. Default False.
  740. * @li exclusive: Whether to exclude padding points. default is true.
  741. * @li data_format: An optional string. Defaults to "NHWC".
  742. * @par Outputs:
  743. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  744. * @par Third-party framework compatibility
  745. * @li Compatible with the TensorFlow operator AvgPoolGrad.
  746. */
  747. REG_OP(AvgPoolV2Grad)
  748. .INPUT(orig_input_shape, TensorType({DT_INT32}))
  749. .INPUT(input_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  750. .OUTPUT(out_grad, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE}))
  751. .REQUIRED_ATTR(ksize, ListInt)
  752. .REQUIRED_ATTR(strides, ListInt)
  753. .ATTR(padding_mode, String, "CALCULATED")
  754. .ATTR(pads, ListInt, {0,0,0,0})
  755. .ATTR(data_format, String, "NCHW")
  756. .ATTR(global_pooling, Bool, false)
  757. .ATTR(ceil_mode, Bool, false)
  758. .ATTR(exclusive, Bool, true)
  759. .OP_END_FACTORY_REG(AvgPoolV2Grad)
  760. /**
  761. * @brief Computes gradients of averagev2 pooling function.
  762. * @par Inputs:
  763. * @li input_grad: An NHWC tensor of type float16, float32, or double.
  764. * @par Attributes:
  765. * @li orig_input_shape: A required tuple or list of type int32.
  766. * @li ksize: A required tuple or list, specifying the size of the window for
  767. * each dimension of the input tensor.
  768. * @li strides: A required tuple or list, specifying the stride of the sliding
  769. * window for each dimension of the input tensor.
  770. * @li padding_mode: A required string, specifying the type of
  771. * the padding algorithm to use.
  772. * @li global_pooling: Whether to use the global pooling. If global_pooling=true,
  773. * ksize and pads will be ignored. Default False.
  774. * @li ceil_mode: Whether to use the ceil function to calculate output height and
  775. * width. Default False.
  776. * @li exclusive: Whether to exclude padding points. default is true.
  777. * @li data_format: An optional string. Defaults to "NHWC".
  778. * @par Outputs:
  779. * @out_grad: A mutable tensor with the same shape and type as "orig_input".
  780. * @par Third-party framework compatibility
  781. * @li Compatible with the TensorFlow operator AvgPoolGrad.
  782. */
  783. REG_OP(AvgPoolV2GradD)
  784. .INPUT(input_grad, TensorType({DT_FLOAT16}))
  785. .OPTIONAL_INPUT(mean_matrix, TensorType({DT_FLOAT16}))
  786. .OPTIONAL_INPUT(kernel_matrix, TensorType({DT_FLOAT16}))
  787. .OUTPUT(out_grad, TensorType({DT_FLOAT16}))
  788. .REQUIRED_ATTR(orig_input_shape, ListInt)
  789. .REQUIRED_ATTR(ksize, ListInt)
  790. .REQUIRED_ATTR(strides, ListInt)
  791. .ATTR(padding_mode, String, "CALCULATED")
  792. .ATTR(pads, ListInt, {0,0,0,0})
  793. .ATTR(data_format, String, "NCHW")
  794. .ATTR(global_pooling, Bool, false)
  795. .ATTR(ceil_mode, Bool, false)
  796. .ATTR(exclusive, Bool, true)
  797. .OP_END_FACTORY_REG(AvgPoolV2GradD)
  798. /**
  799. *@brief :upsample the layer
  800. *@par Inputs:
  801. * one input, including:
  802. *@li x: A tensor of type float16 or float32.
  803. *@par Attributes:
  804. *@li scale: A optional float32, scale factor of x. Defaults to "1.0".
  805. *@li stride_h: An optional int32, broadcast the axis of h. Defaults to "2".
  806. *@li stride_w: An optional int32, broadcast the axis of w. Defaults to "2".
  807. *@par Outputs:
  808. *y: A tensor of type float16 or float32.
  809. */
  810. REG_OP(Upsample)
  811. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  812. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  813. .ATTR(scale, Float, 1)
  814. .ATTR(stride_h, Int, 2)
  815. .ATTR(stride_w, Int, 2)
  816. .OP_END_FACTORY_REG(Upsample)
  817. /**
  818. *@brief Computes gradient of the FractionalMaxPool function . \n
  819. *@par Inputs:
  820. *Inputs include:
  821. * @li orig_input: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  822. * @li orig_output: A Tensor. Must have the same type as orig_input.
  823. * @li out_backprop: A Tensor. Must have the same type as orig_input.
  824. 4-D with shape [batch, height, width, channels].
  825. * @li row_pooling_sequence: A Tensor of type int64.
  826. * @li col_pooling_sequence: A Tensor of type int64 . \n
  827. *@par Attributes:
  828. *overlapping: An optional bool. Defaults to False . \n
  829. *@par Outputs:
  830. *y: A Tensor. Has the same type as orig_input . \n
  831. *@attention Constraints:
  832. *The implementation for FractionalMaxPoolGrad on Ascend uses AICPU, with bad performance.
  833. *@par Third-party framework compatibility
  834. *@li compatible with tensorflow FractionalMaxPoolGrad operator.
  835. */
  836. REG_OP(FractionalMaxPoolGrad)
  837. .INPUT(orig_input, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  838. .INPUT(orig_output, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  839. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  840. .INPUT(row_pooling_sequence, TensorType({ DT_INT64 }))
  841. .INPUT(col_pooling_sequence, TensorType({ DT_INT64 }))
  842. .OUTPUT(y, TensorType({ DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64 }))
  843. .ATTR(overlapping, Bool, false)
  844. .OP_END_FACTORY_REG(FractionalMaxPoolGrad)
  845. /**
  846. *@brief Performs fractional average pooling on the input . \n
  847. *@par Inputs:
  848. *Inputs include:
  849. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  850. 4-D with shape [batch, height, width, channels] . \n
  851. *@par Attributes:
  852. *@li pooling_ratio: A list of floats that has length >= 4.
  853. *@li pseudo_random: An optional bool. Defaults to False.
  854. *@li overlapping: An optional bool. Defaults to False. When set to True, it means when pooling.
  855. *@li deterministic: An optional bool. Defaults to False.
  856. *@li seed: An optional int. Defaults to 0.
  857. *@li seed2: An optional int. Defaults to 0 . \n
  858. *@par Outputs:
  859. *@li y: A Tensor. Has the same type as x.
  860. *@li row_pooling_sequence: A Tensor of type int64.
  861. *@li col_pooling_sequence: A Tensor of type int64 . \n
  862. *@attention Constraints:
  863. *The implementation for FractionalAvgPool on Ascend uses AICPU, with bad performance.
  864. *@par Third-party framework compatibility
  865. *@li compatible with tensorflow FractionalAvgPool operator.
  866. */
  867. REG_OP(FractionalAvgPool)
  868. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  869. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  870. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  871. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  872. .ATTR(pooling_ratio, ListFloat, {})
  873. .ATTR(pseudo_random, Bool, false)
  874. .ATTR(overlapping, Bool, false)
  875. .ATTR(deterministic, Bool, false)
  876. .ATTR(seed, Int, 0)
  877. .ATTR(seed2, Int, 0)
  878. .OP_END_FACTORY_REG(FractionalAvgPool)
  879. /**
  880. *@brief Performs fractional max pooling on the input . \n
  881. *@par Inputs:
  882. *Inputs include:
  883. *x: A Tensor. Must be one of the following types: float32, float64, int32, int64.
  884. 4-D with shape [batch, height, width, channels] . \n
  885. *@par Attributes:
  886. *@li pooling_ratio: A list of floats that has length >= 4. Pooling ratio for each dimension of value.
  887. *@li pseudo_random: An optional bool. Defaults to False.
  888. *@li overlapping: An optional bool. Defaults to False.
  889. *@li deterministic: An optional bool. Defaults to False.
  890. *@li seed: An optional int. Defaults to 0.
  891. *@li seed2: An optional int. Defaults to 0 . \n
  892. *@par Outputs:
  893. *@li y: A Tensor. Has the same type as x.
  894. *@li row_pooling_sequence: A Tensor of type int64.
  895. *@li col_pooling_sequence: A Tensor of type int64 . \n
  896. *@attention Constraints:
  897. *The implementation for FractionalMaxPool on Ascend uses AICPU, with bad performance.
  898. *@par Third-party framework compatibility
  899. *@li compatible with tensorflow FractionalMaxPool operator.
  900. */
  901. REG_OP(FractionalMaxPool)
  902. .INPUT(x, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  903. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  904. .OUTPUT(row_pooling_sequence, TensorType({DT_INT64}))
  905. .OUTPUT(col_pooling_sequence, TensorType({DT_INT64}))
  906. .ATTR(pooling_ratio, ListFloat, {})
  907. .ATTR(pseudo_random, Bool, false)
  908. .ATTR(overlapping, Bool, false)
  909. .ATTR(deterministic, Bool, false)
  910. .ATTR(seed, Int, 0)
  911. .ATTR(seed2, Int, 0)
  912. .OP_END_FACTORY_REG(FractionalMaxPool)
  913. /**
  914. *@brief Finds values of the n-th order statistic for the last dimension . \n
  915. *@par Inputs:
  916. *Inputs include:
  917. * @li x: A Tensor. Must be one of the following types: float32, float64, int32, uint8,
  918. int16, int8, int64, bfloat16, uint16, half, uint32, uint64.
  919. * @li n: A Tensor of type int32. 0-D . \n
  920. *@par Attributes:
  921. *reverse: An optional bool. Defaults to False . \n
  922. *@par Outputs:
  923. *y: A Tensor. Has the same type as x . \n
  924. *@attention Constraints:
  925. *The implementation for NthElement on Ascend uses AICPU, with bad performance.
  926. *@par Third-party framework compatibility
  927. *@li compatible with tensorflow NthElement operator.
  928. */
  929. REG_OP(NthElement)
  930. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  931. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  932. .INPUT(n, TensorType({DT_INT32}))
  933. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16, DT_INT8, DT_INT16,
  934. DT_UINT16, DT_UINT8, DT_INT32, DT_INT64, DT_DOUBLE}))
  935. .ATTR(reverse, Bool, false)
  936. .OP_END_FACTORY_REG(NthElement)
  937. /**
  938. *@brief Computes gradient of the FractionalAvgPool function . \n
  939. *@par Inputs:
  940. *Inputs include:
  941. * @li orig_input_tensor_shape: A Tensor of type int64.
  942. * @li out_backprop: A Tensor. Must be one of the following types: float32, float64,
  943. int32, int64. 4-D with shape [batch, height, width, channels].
  944. * @li row_pooling_sequence: A Tensor of type int64.
  945. * @li col_pooling_sequence: A Tensor of type int64 . \n
  946. *@par Attributes:
  947. *overlapping: An optional bool. Defaults to False . \n
  948. *@par Outputs:
  949. *y: A Tensor. Has the same type as out_backprop . \n
  950. *@attention Constraints:
  951. *The implementation for FractionalAvgPoolGrad on Ascend uses AICPU, with bad performance.
  952. *@par Third-party framework compatibility
  953. *@li compatible with tensorflow FractionalAvgPoolGrad operator.
  954. */
  955. REG_OP(FractionalAvgPoolGrad)
  956. .INPUT(orig_input_tensor_shape, TensorType({DT_INT64}))
  957. .INPUT(out_backprop, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  958. .INPUT(row_pooling_sequence, TensorType({DT_INT64}))
  959. .INPUT(col_pooling_sequence, TensorType({DT_INT64}))
  960. .OUTPUT(y, TensorType({DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64}))
  961. .ATTR(overlapping, Bool, false)
  962. .OP_END_FACTORY_REG(FractionalAvgPoolGrad)
  963. /**
  964. *@brief Returns the permuted vector/tensor in the destination data format given the . \n
  965. *@par Inputs:
  966. *Inputs include:
  967. *x: A Tensor. Must be one of the following types: int32, int64. Vector of size 4
  968. or Tensor of shape (4, 2) in source data format . \n
  969. *@par Attributes:
  970. *@li src_format: An optional string. Defaults to "NHWC". source data format.
  971. *@li dst_format: An optional string. Defaults to "NCHW". destination data format . \n
  972. *@par Outputs:
  973. *y: A Tensor. Has the same type as x . \n
  974. *@attention Constraints:
  975. *The implementation for DataFormatVecPermute on Ascend uses AICPU, with bad performance.
  976. *@par Third-party framework compatibility
  977. *@li compatible with tensorflow DataFormatVecPermute operator.
  978. */
  979. REG_OP(DataFormatVecPermute)
  980. .INPUT(x, TensorType({ DT_INT32, DT_INT64 }))
  981. .OUTPUT(y, TensorType({ DT_INT32, DT_INT64 }))
  982. .ATTR(src_format, String, "NHWC")
  983. .ATTR(dst_format, String, "NCHW")
  984. .OP_END_FACTORY_REG(DataFormatVecPermute)
  985. /**
  986. * @brief Computes gradients of the MaxPool3D function . \n
  987. * @par Inputs:
  988. * @li orig_x: A mutable NDC1HWC0 tensor of type float16.
  989. * @li orig_y: A mutable NDC1HWC0 tensor of type float16.
  990. * @li grads: A mutable NDC1HWC0 tensor of type float16 . \n
  991. * @par Attributes:
  992. * @li ksize: A required tuple or list, specifying the size of the window for
  993. * each dimension of the input tensor.
  994. * @li strides: A required tuple or list, specifying the stride of the sliding
  995. * window for each dimension of the input tensor.
  996. * @li pads: A list of 6 ints. Supports only padding along the D,
  997. * H and W dimensions in sequence of head, tail, top, bottom, left and right.
  998. * to use.
  999. * @li data_format: An optional string, Specify the data format of the input and
  1000. * output data. With the default format "NDHWC" . \n
  1001. * @par Outputs:
  1002. * y: A mutable tensor. Has the same shape as "orig_x", but type is float32 . \n
  1003. * @par Third-party framework compatibility
  1004. * Compatible with the TensorFlow operator MaxPool3DGrad.
  1005. */
  1006. REG_OP(MaxPool3DGrad)
  1007. .INPUT(orig_x, TensorType::RealNumberType())
  1008. .INPUT(orig_y, TensorType::RealNumberType())
  1009. .INPUT(grads, TensorType::RealNumberType())
  1010. .OUTPUT(y, TensorType::RealNumberType())
  1011. .REQUIRED_ATTR(ksize, ListInt)
  1012. .REQUIRED_ATTR(strides, ListInt)
  1013. .ATTR(padding, String, "SAME")
  1014. .REQUIRED_ATTR(pads, ListInt)
  1015. .ATTR(data_format, String, "NDHWC")
  1016. .OP_END_FACTORY_REG(MaxPool3DGrad)
  1017. /**
  1018. *@brief Performs AvgPool1D on the input . \n
  1019. *@par Inputs:
  1020. *x: A Tensor. Must be one of the following types: int8, uint8, int16, int32, int64, float16, float32, float64 . \n
  1021. *@par Attributes:
  1022. *@li ksize: An required int, specifying the size of the window.
  1023. *@li strides: An required int.
  1024. *@li pads: A required tuple or list.
  1025. *@li ceil_mode: An optional bool. Defaults to False.
  1026. *@li count_include_pad: An optional bool. Defaults to False . \n
  1027. *@par Outputs:
  1028. *y: A Tensor. Has the same type as x . \n
  1029. *@par Third-party framework compatibility
  1030. *@li compatible with pytorch AvgPool1D operator.
  1031. */
  1032. REG_OP(AvgPool1D)
  1033. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1034. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1035. .REQUIRED_ATTR(ksize, Int)
  1036. .REQUIRED_ATTR(strides, Int)
  1037. .REQUIRED_ATTR(pads, ListInt)
  1038. .ATTR(ceil_mode, Bool, false)
  1039. .ATTR(count_include_pad, Bool, false)
  1040. .OP_END_FACTORY_REG(AvgPool1D)
  1041. /**
  1042. *@brief Performs AvgPool1D on the input . \n
  1043. *@par Inputs:
  1044. *x: A Tensor. Must be one of the following types: int8, uint8, int16, int32, int64, float16, float32, float64 . \n
  1045. *@par Attributes:
  1046. *@li ksize: An required int, specifying the size of the window.
  1047. *@li strides: An required int.
  1048. *@li pads: A required tuple or list.
  1049. *@li ceil_mode: An optional bool. Defaults to False.
  1050. *@li count_include_pad: An optional bool. Defaults to False . \n
  1051. *@par Outputs:
  1052. *y: A Tensor. Has the same type as x . \n
  1053. *@par Third-party framework compatibility
  1054. *@li compatible with pytorch AvgPool1D operator.
  1055. *
  1056. *@par Restrictions:
  1057. *Warning: THIS FUNCTION IS DEPRECATED. Please use AvgPool1D instead.
  1058. */
  1059. REG_OP(AvgPool1DD)
  1060. .INPUT(x, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1061. .INPUT(assist_matrix, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1062. .OUTPUT(y, TensorType({DT_INT8, DT_UINT8, DT_INT16, DT_INT32, DT_INT64, DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1063. .REQUIRED_ATTR(ksize, Int)
  1064. .REQUIRED_ATTR(strides, Int)
  1065. .REQUIRED_ATTR(pads, ListInt)
  1066. .ATTR(ceil_mode, Bool, false)
  1067. .ATTR(count_include_pad, Bool, false)
  1068. .OP_END_FACTORY_REG(AvgPool1DD)
  1069. /**
  1070. *@brief Performs max pooling on the input and outputs both max values and indices . \n
  1071. *@par Inputs:
  1072. * One input:
  1073. *x: An 4d Tensor of type float16. Must set the format, supported format list ["NCHW, NHWC"].
  1074. *@par Attributes:
  1075. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for
  1076. * each dimension of the input tensor. No default value.
  1077. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for
  1078. * each dimension of the input tensor. No default value.
  1079. *@li pads: A required string. No default value.
  1080. *@li dtype: A optional int. default value is 3.
  1081. *@li dilation: A optional list of int8, int16, int32, or int64 values.
  1082. *@li ceil_mode: A optional bool. default value is false . \n
  1083. *@par Outputs:
  1084. *y: A Tensor. Has the same type and format as input "x".
  1085. *argmax: A Tensor. type:uint16, format:NC1HWC0.
  1086. *@attention Constraints:
  1087. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  1088. *@li "strides is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1,
  1089. * strides[2] <= 63, strides[2] >= 1.
  1090. *@li "dilation" is a list that has length 4.
  1091. *@li "ceil_mode" is a bool, default is false . \n
  1092. *@par Third-party framework compatibility
  1093. * Compatible with the TensorFlow operator MaxPoolWithArgmax.
  1094. */
  1095. REG_OP(MaxPoolWithArgmaxV2)
  1096. .INPUT(x, TensorType({DT_FLOAT16}))
  1097. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1098. .OUTPUT(argmax, TensorType({DT_UINT16}))
  1099. .REQUIRED_ATTR(ksize, ListInt)
  1100. .REQUIRED_ATTR(strides, ListInt)
  1101. .REQUIRED_ATTR(pads, ListInt)
  1102. .ATTR(dtype, Int, 3)
  1103. .ATTR(dilation, ListInt, {1, 1, 1, 1})
  1104. .ATTR(ceil_mode, Bool, false)
  1105. .OP_END_FACTORY_REG(MaxPoolWithArgmaxV2)
  1106. /**
  1107. *@brief Performs the backpropagation of MaxPoolWithArgmaxV2 . \n
  1108. *@par Inputs:
  1109. * Three inputs, including:
  1110. *@li x: An 4d tensor of type float16. Must set the format, supported format list ["NCHW, NHWC"]
  1111. *@li grad: An 4d tensor of type float16. Must set the format, supported format list ["NCHW, NHWC"]
  1112. *@li argmx: An 4d tensor of type uint16 or int64. Must set the format, supported format list ["NCHW, NHWC"] \n
  1113. *@par Attributes:
  1114. *@li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for
  1115. * each dimension of the input tensor. No default value.
  1116. *@li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for
  1117. * each dimension of the input tensor. No default value.
  1118. *@li pads: A required string. No default value.
  1119. *@li dtype: A optional int. default value is 3.
  1120. *@li dilation: A optional list of int8, int16, int32, or int64 values.
  1121. *@li ceil_mode: A optional bool. default value is false . \n
  1122. *@par Outputs:
  1123. *y: A Tensor. Has the same type and format as input "x" . \n
  1124. *@attention Constraints:
  1125. *@li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  1126. *@li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  1127. *@li "dilation" is a list that has length 4.
  1128. *@li "ceil_mode" is a bool, default is false . \n
  1129. *@see max_pool_grad_with_argmaxv2
  1130. *@par Third-party framework compatibility
  1131. * Compatible with the TensorFlow operator MaxPoolGradWithArgmaxV2.
  1132. */
  1133. REG_OP(MaxPoolGradWithArgmaxV2)
  1134. .INPUT(x, TensorType({DT_FLOAT16}))
  1135. .INPUT(grad, TensorType({DT_FLOAT16}))
  1136. .INPUT(argmax, TensorType({DT_UINT16}))
  1137. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1138. .REQUIRED_ATTR(ksize, ListInt)
  1139. .REQUIRED_ATTR(strides, ListInt)
  1140. .REQUIRED_ATTR(pads, ListInt)
  1141. .ATTR(dtype, Int, 3)
  1142. .ATTR(dilation, ListInt, {1,1,1,1})
  1143. .ATTR(ceil_mode, Bool, false)
  1144. .OP_END_FACTORY_REG(MaxPoolGradWithArgmaxV2)
  1145. /**
  1146. * @brief Performs max pooling on the input . \n
  1147. * @par Inputs:
  1148. * One input:
  1149. * x: An NC1HWC0 Tensor. Supported type:float16, float32, double, int32, int64,
  1150. * uint8, int16, int8, uint16, qint8
  1151. * @par Attributes:
  1152. * @li ksize: A required list of int8, int16, int32, or int64 values,
  1153. * specifying the size of the window for each dimension of the input tensor.
  1154. * No default value.
  1155. * @li strides: A required list of int8, int16, int32, or int64 values,
  1156. * specifying the stride of the sliding window for each dimension of
  1157. * the input tensor. No default value.
  1158. * @li padding_mode: A required string. Defaults to "CALCULATED".
  1159. * @li pads:A required list of int8, int16, int32, or int64 values,
  1160. * a data to caculate when padding_mode is "CALCULATED".
  1161. * @li data_format: An optional string. Defaults to "NHWC" .
  1162. * @li global_pooling bool, Whether to use the global pooling.
  1163. * If global_pooling = true, kernel size and paddings will be ignored.
  1164. * Default False
  1165. * @li ceil_mode: Whether to use the ceil function to calculate output
  1166. * height and width. False is the default. If it is set to False,
  1167. * the floor function will be used. Default False \n
  1168. * @par Outputs:
  1169. * y: A Tensor. Has the same type and format as input "x" . \n
  1170. * @attention Constraints:
  1171. * @li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1,
  1172. * ksize[1] * ksize[2] <= 255.
  1173. * @li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1,
  1174. * strides[1] <= 63, strides[0] >= 1, strides[2] <= 63, strides[2] >= 1.
  1175. * @li "padding" is "SAME" "VALID" or "CACULATE" .
  1176. * @par Third-party framework compatibility
  1177. * Compatible with the TensorFlow operator MaxPool.
  1178. */
  1179. REG_OP(MaxPoolV3)
  1180. .INPUT(x,TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16, DT_QINT8}))
  1181. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16, DT_QINT8}))
  1182. .REQUIRED_ATTR(ksize, ListInt)
  1183. .REQUIRED_ATTR(strides, ListInt)
  1184. .ATTR(padding_mode, String, "CALCULATED")
  1185. .ATTR(pads, ListInt, {0,0,0,0})
  1186. .ATTR(data_format, String, "NCHW")
  1187. .ATTR(global_pooling,Bool,false)
  1188. .ATTR(ceil_mode, Bool, false)
  1189. .OP_END_FACTORY_REG(MaxPoolV3)
  1190. /**
  1191. * @brief Computes gradients of the maxpooling function . \n
  1192. * @par Inputs:
  1193. * @li orig_input: A mutable NC1HWC0 tensor of type RealNumberType.
  1194. * @li orig_output: A mutable NC1HWC0 tensor of type RealNumberTypex.
  1195. * @li grad: A mutable NC1HWC0 tensor of type RealNumberType . \n
  1196. * @par Attributes:
  1197. * @li ksize: A required list of int8, int16, int32, or int64 values,
  1198. * specifying the size of the window for each dimension of the input tensor.
  1199. * No default value.
  1200. * @li strides: A required list of int8, int16, int32, or int64 values,
  1201. * specifying the stride of the sliding window for each dimension of
  1202. * the input tensor. No default value.
  1203. * @li padding_mode: A required string. Defaults to "CALCULATED".
  1204. * @li pads:A required list of int8, int16, int32, or int64 values,
  1205. * a data to caculate when padding_mode is "CALCULATED".
  1206. * @li data_format: An optional string. Defaults to "NHWC" .
  1207. * @li global_pooling bool, Whether to use the global pooling.
  1208. * If global_pooling = true, kernel size and paddings will be ignored.
  1209. * Default False
  1210. * @li ceil_mode: Whether to use the ceil function to calculate output
  1211. * height and width. False is the default. If it is set to False,
  1212. * the floor function will be used. Default False \n
  1213. * @par Outputs:
  1214. * y: A mutable tensor. Has the same shape and type as "x1" . \n
  1215. * @attention Constraints:
  1216. * @li Computing gradients of global pooling is not supported, which means
  1217. * "ksize < x1".
  1218. * @li "ksize" is in the range [1, 255]. "strides" is in the range [1, 63]
  1219. * @par Third-party framework compatibility
  1220. * Compatible with the TensorFlow operator MaxPoolGrad.
  1221. */
  1222. REG_OP(MaxPoolV3Grad)
  1223. .INPUT(orig_input, TensorType::RealNumberType())
  1224. .INPUT(orig_output, TensorType::RealNumberType())
  1225. .INPUT(grad, TensorType::RealNumberType())
  1226. .OUTPUT(out_grad, TensorType::RealNumberType())
  1227. .REQUIRED_ATTR(ksize, ListInt)
  1228. .REQUIRED_ATTR(strides, ListInt)
  1229. .ATTR(padding_mode, String, "CALCULATED")
  1230. .ATTR(pads, ListInt, {0, 0, 0, 0})
  1231. .ATTR(data_format, String, "NCHW")
  1232. .ATTR(global_pooling, Bool, false)
  1233. .ATTR(ceil_mode, Bool, false)
  1234. .OP_END_FACTORY_REG(MaxPoolV3Grad)
  1235. /**
  1236. *@brief Performs dilation2d on the input . \n
  1237. *@par Inputs:
  1238. *x: A tensor of shape is 4d, format is support NHWC.
  1239. *filter: A tensor of shape is 3d, the type is same with x, and the c dimension is same with x. \n
  1240. *@par Attributes:
  1241. *@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.
  1242. *@li rates: A required list of 4 ints. The rates of the N and C dimensions are 1.
  1243. *@li padding_mode: A optional string. Defaults to "SAME", it support SAME and VALID.
  1244. *@li pads: An optional list of 4 ints.
  1245. *@li ceil_mode: An optional bool. Defaults to "false". Use ceil or floor to calculate the output size when padding_mode is "CALCULATED".
  1246. *@li data_format: An optional string, specifying the data format of "rates" and "strides", either "NCHW" or "NHWC" (default). \n
  1247. *@par Outputs:
  1248. *y: The output tensor. Has the same type and format as input "x" . \n
  1249. *@par Third-party framework compatibility
  1250. * Compatible with the TensorFlow operator Dilation2D.
  1251. */
  1252. REG_OP(Dilation2D)
  1253. .INPUT(x,TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1254. .INPUT(filter,TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1255. .OUTPUT(y,TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1256. .REQUIRED_ATTR(strides, ListInt)
  1257. .REQUIRED_ATTR(rates, ListInt)
  1258. .ATTR(padding_mode, String, "SAME")
  1259. .ATTR(pads, ListInt, {0,0,0,0})
  1260. .ATTR(ceil_mode, Bool, false)
  1261. .ATTR(data_format, String, "NHWC")
  1262. .OP_END_FACTORY_REG(Dilation2D)
  1263. /*
  1264. * @brief Performs Dilation2DBackpropFilter on the input. \n
  1265. *@par Inputs:
  1266. *x: A tensor of shape is 4d, format is support NHWC
  1267. *filter: A tensor of shape is 3d the type is same with x,
  1268. *out_backprop: Has the same type and format as input "x" and the c dimension is same with x. \n
  1269. *@par Attributes
  1270. *@li stride: A required list of 4 ints, specifying the stride of the sliding window. The strides of the N and C
  1271. dimension are 1
  1272. *@li rates: A required list of 4 ints, the rates of the N and C dimensions are 1
  1273. *@li padding_mode: A optional string. Defaults to "SAME", it support SAME and VALID
  1274. *@li pads: A optional list of 4 ints. \n
  1275. *@par Outputs:
  1276. *y: The output tensor. Has the same type and format as input "filter" . \n
  1277. *@par Third-party framework compatibility
  1278. * Compatible with the TensorFlow operator Dilation2D
  1279. */
  1280. REG_OP(Dilation2DBackpropFilter)
  1281. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1282. .INPUT(filter,
  1283. TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1284. .INPUT(out_backprop,
  1285. TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1286. .OUTPUT(y,
  1287. TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1288. .REQUIRED_ATTR(strides, ListInt)
  1289. .REQUIRED_ATTR(rates, ListInt)
  1290. .ATTR(padding_mode, String, "SAME")
  1291. .ATTR(pads, ListInt, {0, 0, 0, 0})
  1292. .ATTR(ceil_mode, Bool, false)
  1293. .ATTR(data_format, String, "NHWC")
  1294. .OP_END_FACTORY_REG(Dilation2DBackpropFilter)
  1295. /*
  1296. * @brief Performs Dilation2DBackpropInput on the input. \n
  1297. *@par Inputs:
  1298. *x: A tensor of shape is 4d, format is support NHWC
  1299. *filter: A tensor of shape is 3d the type is same with x,
  1300. *out_backprop: Has the same type and format as input "x" and the c dimension is same with x. \n
  1301. *@par Attributes
  1302. *@li stride: A required list of 4 ints, specifying the stride of the sliding window. The strides of the N and C
  1303. dimension are 1
  1304. *@li rates: A required list of 4 ints, the rates of the N and C dimensions are 1
  1305. *@li padding_mode: A optional string. Defaults to "SAME", it support SAME and VALID
  1306. *@li pads: A optional list of 4 ints. \n
  1307. *@par Outputs:
  1308. *y: The output tensor. Has the same type and format as input "filter" . \n
  1309. *@par Third-party framework compatibility
  1310. * Compatible with the TensorFlow operator Dilation2D
  1311. */
  1312. REG_OP(Dilation2DBackpropInput)
  1313. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1314. .INPUT(filter,
  1315. TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1316. .INPUT(out_backprop,
  1317. TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1318. .OUTPUT(y,
  1319. TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32, DT_INT64, DT_UINT8, DT_INT16, DT_INT8, DT_UINT16}))
  1320. .REQUIRED_ATTR(strides, ListInt)
  1321. .REQUIRED_ATTR(rates, ListInt)
  1322. .ATTR(padding_mode, String, "SAME")
  1323. .ATTR(pads, ListInt, {0, 0, 0, 0})
  1324. .ATTR(ceil_mode, Bool, false)
  1325. .ATTR(data_format, String, "NHWC")
  1326. .OP_END_FACTORY_REG(Dilation2DBackpropInput)
  1327. /**
  1328. * @brief Applies a 2D adaptive average pooling over
  1329. * an input signal composed of several input planes. \n
  1330. * @par Inputs:
  1331. * One input, including:
  1332. * @li x: A Tensor. Must be one of the following data types:
  1333. * float16, float32. \n
  1334. * @par Attributes:
  1335. * @li output_size: A required list of 2 ints
  1336. * specifying the size (H,W) of the output tensor. \n
  1337. * @par Outputs:
  1338. * @li y: A Tensor. Has the same data type as "x" \n
  1339. * @par Third-party framework compatibility
  1340. * Compatible with the Pytorch operator AdaptiveAvgPool2d.
  1341. */
  1342. REG_OP(AdaptiveAvgPool2d)
  1343. .INPUT(x, TensorType({DT_FLOAT, DT_FLOAT16}))
  1344. .OUTPUT(y, TensorType({DT_FLOAT, DT_FLOAT16}))
  1345. .REQUIRED_ATTR(output_size, ListInt)
  1346. .OP_END_FACTORY_REG(AdaptiveAvgPool2d)
  1347. /**
  1348. * @brief Compute gradients of adaptive averagev2 pooling function.
  1349. * @par Inputs:
  1350. * @li input_grad: A Tensor. Must be one of the following data types:
  1351. * float16, float32.
  1352. * @par Attributes:
  1353. * @li orig_input_shape: A required tuple or list of type int32.
  1354. * @par Outputs:
  1355. * @li output_grad: A tensor with the same type as "input_grad".
  1356. * @par Third-party framework compatibility
  1357. * Compatible with the Pytorch operator AdaptiveAvgPool2dGrad.
  1358. */
  1359. REG_OP(AdaptiveAvgPool2dGrad)
  1360. .INPUT(input_grad, TensorType({DT_FLOAT, DT_FLOAT16}))
  1361. .OUTPUT(output_grad, TensorType({DT_FLOAT, DT_FLOAT16}))
  1362. .REQUIRED_ATTR(orig_input_shape, ListInt)
  1363. .OP_END_FACTORY_REG(AdaptiveAvgPool2dGrad)
  1364. /**
  1365. * @brief Performs the backpropagation of MaxPoolWithGradArgmaxV1.
  1366. * @par Inputs:
  1367. * Three inputs, including:
  1368. * @li x: An NC1HWC0 tensor of type float16.
  1369. * @li grad: An NC1HWC0 tensor of type float16.
  1370. * @li argmax: An NC1HWC0 tensor of type uint16 or int64. \n
  1371. * @par Attributes:
  1372. * @li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for
  1373. * each dimension of the input tensor. No default value.
  1374. * @li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for
  1375. * each dimension of the input tensor. No default value.
  1376. * @li pads: A required listint. \n
  1377. * @par Outputs:
  1378. * y: A Tensor. Has the same type and format as input "x". \n
  1379. * @attention Constraints:
  1380. * @li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  1381. * @li "strides" is a list that has length 4: strides[0] = 1 or strides[3] = 1
  1382. * @li "pads" is listint.
  1383. * @li "ceil_mode" defaults to False.
  1384. * @li "data_format" defaults to "NC1HWC0". \n
  1385. * @par Third-party framework compatibility
  1386. * Compatible with the TensorFlow operator MaxPoolGradWithArgmaxV1.
  1387. */
  1388. REG_OP(MaxPoolGradWithArgmaxV1)
  1389. .INPUT(x, TensorType({DT_FLOAT16}))
  1390. .INPUT(grad, TensorType({DT_FLOAT16}))
  1391. .INPUT(argmax, TensorType({DT_UINT16}))
  1392. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1393. .REQUIRED_ATTR(ksize, ListInt)
  1394. .REQUIRED_ATTR(strides, ListInt)
  1395. .REQUIRED_ATTR(pads, ListInt)
  1396. .ATTR(dtype, Int, 3)
  1397. .ATTR(dilation, ListInt, {1, 1, 1, 1})
  1398. .ATTR(ceil_mode, Bool, false)
  1399. .OP_END_FACTORY_REG(MaxPoolGradWithArgmaxV1)
  1400. /**
  1401. * @brief Performs max pooling on the input and outputs both max values and indices.
  1402. * @par Inputs:
  1403. * One input:
  1404. * x: An NC1HWC0 Tensor of type float16. \n
  1405. * @par Attributes:
  1406. * @li ksize: A required list of int8, int16, int32, or int64 values, specifying the size of the window for
  1407. * each dimension of the input tensor. No default value.
  1408. * @li strides: A required list of int8, int16, int32, or int64 values, specifying the stride of the sliding window for
  1409. * each dimension of the input tensor. No default value.
  1410. * @li pads: A required string. No default value. \n
  1411. * @par Outputs:
  1412. * y: A Tensor. Has the same type and format as input "x".
  1413. * argmax: A Tensor. type:uint16, format:NC1HWC0. \n
  1414. * @attention Constraints:
  1415. * @li "ksize" is a list that has length 4: ksize[0] = 1 or ksize[3] = 1, ksize[1] * ksize[2] <= 255.
  1416. * @li "stride is a list that has length 4: strides[0] = 1 or strides[3] = 1, strides[1] <= 63, strides[0] >= 1,
  1417. * strides[2] <= 63, strides[2] >= 1.
  1418. * @li "pads" is listint.
  1419. * @li "ceil_mode" defaults to False.
  1420. * @li "data_format" defaults to "NC1HWC0". \n
  1421. * @par Third-party framework compatibility
  1422. * Compatible with the TensorFlow operator MaxPoolWithArgmaxV1.
  1423. */
  1424. REG_OP(MaxPoolWithArgmaxV1)
  1425. .INPUT(x, TensorType({DT_FLOAT16}))
  1426. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1427. .OUTPUT(argmax, TensorType({DT_UINT16}))
  1428. .REQUIRED_ATTR(ksize, ListInt)
  1429. .REQUIRED_ATTR(strides, ListInt)
  1430. .REQUIRED_ATTR(pads, ListInt)
  1431. .ATTR(dtype, Int, 3)
  1432. .ATTR(dilation, ListInt, {1, 1, 1, 1})
  1433. .ATTR(ceil_mode, Bool, false)
  1434. .OP_END_FACTORY_REG(MaxPoolWithArgmaxV1)
  1435. // SubSample
  1436. REG_OP(SubSample)
  1437. .INPUT(labels, TensorType({DT_INT32}))
  1438. .OUTPUT(y, TensorType({DT_INT32}))
  1439. .REQUIRED_ATTR(batch_size_per_images, Int)
  1440. .REQUIRED_ATTR(positive_fraction, Float)
  1441. .OP_END_FACTORY_REG(SubSample)
  1442. // SubSampleLabels
  1443. REG_OP(SubSampleLabels)
  1444. .INPUT(labels, TensorType({DT_INT32}))
  1445. .INPUT(shuffle_matrix, TensorType({DT_INT32}))
  1446. .OUTPUT(y, TensorType({DT_INT32}))
  1447. .REQUIRED_ATTR(batch_size_per_images, Int)
  1448. .REQUIRED_ATTR(positive_fraction, Float)
  1449. .OP_END_FACTORY_REG(SubSampleLabels)
  1450. } // namespace ge
  1451. #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两部分组成,详细的架构图如下所示