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_calculation_ops.h 74 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
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
4 years ago
4 years ago
5 years ago
4 years ago
4 years ago
4 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
5 years ago
5 years ago
4 years ago
4 years ago
5 years ago
4 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  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_calculation_ops.h
  18. * \brief
  19. */
  20. #ifndef OPS_BUILT_IN_OP_PROTO_INC_NN_CALCULATION_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_NN_CALCULATION_OPS_H_
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. * @brief Computes the gradients of depthwise convolution with respect to
  26. * the filter . \n
  27. * @par Inputs:
  28. * Three inputs include: \n
  29. * @li input: 4D origin shape of input tensor [N, C, H, W] or [N, H, W, C],
  30. * support float16, float32, double
  31. * @li filter_size: A 4D tensor of type int32, with shape [H, W, C, K]
  32. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  33. * Must be one of the following types: float16, float32, double . \n
  34. * @par Attributes:
  35. * @li strides: A required list or tuple. The stride of the sliding window
  36. * for height and width of input "x" of the convolution.
  37. * Must be with shape [1, 1, stride_height, stride_width] or
  38. * [1, stride_height, stride_width, 1].
  39. * @li dilations: An optional list or tuple. The dilation factor for each
  40. * dimension of input "x".
  41. * If set to k > 1, there will be k-1 skipped cells between each filter element
  42. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  43. * or [1, dilation_height, dilation_width, 1].
  44. * @li pads: A required list or tuple. Padding added to each dimension of the
  45. * input.
  46. * @li data_format: An optional string. Input data format, either "NHWC" or
  47. * "NCHW" . \n
  48. * @par Outputs:
  49. * filter_grad: Gradient of the deep convolution relative to the filter with
  50. * shape [H, W, C, K]. Must be one of the following types: float16, float32,
  51. * double . \n
  52. * @attention Constraints:\n
  53. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  54. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  55. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  56. * [C1, Hf, Wf, K, Co, C0],
  57. * where K is fixed at 1, and Co and C0 are 16.\n
  58. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  59. * data is 5D with shape [N, C1, Ho, Wo, C0],
  60. * where C is the same as that of the feature map and C0 is 16.\n
  61. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  62. * stride_h + 32 * filter_h) * ceil(Wi, 16) <= l1_size and Hf*Wf <= l0b_size/512 . \n
  63. * @par Third-party framework compatibility
  64. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropFilter.
  65. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropFilter.
  66. */
  67. REG_OP(DepthwiseConv2DBackpropFilter)
  68. .INPUT(input, TensorType({float16}))
  69. .INPUT(filter_size, TensorType({DT_INT32, DT_INT64}))
  70. .INPUT(out_backprop, TensorType({float16}))
  71. .OUTPUT(filter_grad, TensorType({float32}))
  72. .REQUIRED_ATTR(strides, ListInt)
  73. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  74. .REQUIRED_ATTR(pads, ListInt)
  75. .ATTR(data_format, String, "NHWC")
  76. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilter)
  77. /**
  78. * @brief Computes the gradients of depthwise convolution with respect to
  79. * the filter . \n
  80. * @par Inputs:
  81. * Two inputs include: \n
  82. * @li input: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of type float16
  83. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C],
  84. * of type float16
  85. * @par Attributes:
  86. * @li filter_size: A required list or tuple. Shape of filter.
  87. * @li strides: A required list or tuple. The stride of the sliding window for
  88. * height and width of input "x" of the convolution.
  89. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  90. * stride_width, 1].
  91. * @li dilations: An optional list or tuple. The dilation factor for each
  92. * dimension of input "x".
  93. * If set to k > 1, there will be k-1 skipped cells between each filter element
  94. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  95. * or [1, dilation_height, dilation_width, 1].
  96. * @li pads: A required list or tuple. Padding added to each dimension of the
  97. * input.
  98. * @li data_format: An optional string. Input data format, either "NHWC" or
  99. * "NCHW" . \n
  100. * @par Outputs:
  101. * filter_grad: Gradient of the deep convolution relative to the filter with
  102. * shape [H, W, C, K]. Must be of type float32 . \n
  103. * @attention Constraints:\n
  104. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  105. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  106. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  107. * [C1, Hf, Wf, K, Co, C0],
  108. * where K is fixed at 1, and Co and C0 are 16.\n
  109. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  110. * data is 5D with shape [N, C1, Ho, Wo, C0],
  111. * where C is the same as that of the feature map and C0 is 16.\n
  112. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  113. * stride_h + 32 * filter_h) * ceil(Wi, 16) <= l1_size and Hf*Wf <= l0b_size/512 . \n
  114. * @par Third-party framework compatibility
  115. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropFilter.
  116. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropFilter.
  117. *
  118. * @par Restrictions:
  119. * Warning: THIS FUNCTION IS DEPRECATED. Please use DepthwiseConv2DBackpropFilter
  120. * instead.
  121. */
  122. REG_OP(DepthwiseConv2DBackpropFilterD)
  123. .INPUT(input, TensorType({float16}))
  124. .INPUT(out_backprop, TensorType({float16}))
  125. .OUTPUT(filter_grad, TensorType({float32}))
  126. .REQUIRED_ATTR(filter_size, ListInt)
  127. .REQUIRED_ATTR(strides, ListInt)
  128. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  129. .REQUIRED_ATTR(pads, ListInt)
  130. .ATTR(data_format, String, "NHWC")
  131. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilterD)
  132. /**
  133. * @brief Computes the gradients of depthwise convolution with respect to the
  134. * input . \n
  135. * @par Inputs:
  136. * Three inputs include: \n
  137. * @li input_size: 4D shape of input tensor [N, C, H, W] or [N, H, W, C],
  138. * support int32, int64
  139. * @li filter: 4D filter tensor with shape of [H, W, C, K], support float16.
  140. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  141. * Must be one of the following types: float16 . \n
  142. * @par Attributes:
  143. * @li strides: A required list or tuple of int32. The stride of the sliding window for
  144. * height and width of input "x" of the convolution.
  145. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  146. * stride_width, 1].
  147. * @li dilations: An optional list or tuple of int32. The dilation factor for each
  148. * dimension of input "x". Defaults to "[1, 1, 1, 1]".
  149. * If set to k > 1, there will be k-1 skipped cells between each filter element
  150. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  151. * or [1, dilation_height, dilation_width, 1].
  152. * @li pads: A required list or tuple of int32. Padding added to each dimension of the
  153. * input.
  154. * @li data_format: An optional string. Input data format, either "NHWC" or
  155. * "NCHW". Defaults to "NHWC" . \n
  156. * @par Outputs:
  157. * input_grad: Gradient of the deep convolution relative to the input with shape
  158. * [N, C, H, W] or [N, H, W, C] Must be one of the following types: float16 . \n
  159. * @attention Constraints:\n
  160. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  161. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  162. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  163. * [C1, Hf, Wf, K, Co, C0],
  164. * where K is fixed at 1, and Co and C0 are 16.\n
  165. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  166. * data is 5D with shape [N, C1, Ho, Wo, C0],
  167. * where C is the same as that of the feature map and C0 is 16.\n
  168. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  169. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  170. * @par Third-party framework compatibility
  171. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  172. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  173. */
  174. REG_OP(DepthwiseConv2DBackpropInput)
  175. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  176. .INPUT(filter, TensorType({DT_FLOAT16}))
  177. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  178. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  179. .REQUIRED_ATTR(strides, ListInt)
  180. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  181. .REQUIRED_ATTR(pads, ListInt)
  182. .ATTR(data_format, String, "NHWC")
  183. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInput)
  184. /**
  185. * @brief Computes the gradients of depthwise convolution with respect to the
  186. * input . \n
  187. * @par Inputs:
  188. * Two inputs include: \n
  189. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  190. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of
  191. * type float16
  192. * @par Attributes:
  193. * @li input_size: A required list or tuple. The origin shape of input.
  194. * @li strides: A required list or tuple. The stride of the sliding window for
  195. * height and width of input "x" of the convolution.
  196. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  197. * stride_width, 1].
  198. * @li dilations: An optional list or tuple. The dilation factor for each
  199. * dimension of input "x".
  200. * If set to k > 1, there will be k-1 skipped cells between each filter element
  201. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  202. * or [1, dilation_height, dilation_width, 1].
  203. * @li pads: A required list or tuple. Padding added to each dimension of the
  204. * input.
  205. * @li data_format: An optional string. Input data format, either "NHWC" or
  206. * "NCHW" . \n
  207. * @par Outputs:
  208. * input_grad: Gradient of the deep convolution relative to the input with
  209. * shape [N, C, H, W] or [N, H, W, C]. Must be of type float16 . \n
  210. * @attention Constraints:\n
  211. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  212. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  213. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  214. * [C1, Hf, Wf, K, Co, C0],
  215. * where K is fixed at 1, and Co and C0 are 16.\n
  216. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  217. * data is 5D with shape [N, C1, Ho, Wo, C0],
  218. * where C is the same as that of the feature map and C0 is 16.\n
  219. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  220. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  221. * @par Third-party framework compatibility
  222. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  223. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  224. *
  225. * @par Restrictions:
  226. * Warning: THIS FUNCTION IS DEPRECATED. Please use DepthwiseConv2DBackpropInput
  227. * instead.
  228. */
  229. REG_OP(DepthwiseConv2DBackpropInputD)
  230. .INPUT(filter, TensorType({DT_FLOAT16}))
  231. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  232. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  233. .REQUIRED_ATTR(input_size, ListInt)
  234. .REQUIRED_ATTR(strides, ListInt)
  235. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  236. .REQUIRED_ATTR(pads, ListInt)
  237. .ATTR(data_format, String, "NHWC")
  238. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInputD)
  239. /**
  240. *@brief Computes a 2D deep convolution given a 4D input tensor and a filter
  241. * tensor . \n
  242. *@par Inputs:
  243. *Two required inputs and two optional inputs, including: \n
  244. * @li x: A 4D tensor of type float16 or int8, with shape [N, C, H, W] or [N, H, W, C]
  245. * @li filter: A 4D tensor of type float16 or int8, with shape [H, W, C, K]
  246. * @li bias: An optional tensor of type float16 or int32
  247. * @li offset_w: An optional float16 or int8, used for quantized inference
  248. * @par Attributes:
  249. * @li strides: A required list or tuple. The stride of the sliding window for
  250. * height and width of input "x" of the convolution.
  251. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  252. * stride_width, 1].
  253. * @li dilations: An optional list or tuple. The dilation factor for each
  254. * dimension of input "x".
  255. * If set to k > 1, there will be k-1 skipped cells between each filter element
  256. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  257. * or [1, dilation_height, dilation_width, 1]. Defaults to "[1, 1, 1, 1]".
  258. * @li pads: A required list or tuple of int32. Padding added to each dimension of the
  259. * input.
  260. * @li data_format: An optional string. Input data format, either "NHWC" or
  261. * "NCHW". Defaults to "NHWC".
  262. * @li offset_x: An optional int. Input offset, used for quantized inference.
  263. * Defaults to 0 . \n
  264. * @par Outputs:
  265. * y: 4D tensor of type float16 or int32, with shape [N, C, H, W] or [N, H, W, C]
  266. * @attention Constraints:\n
  267. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  268. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  269. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  270. * [C1, Hf, Wf, K, Co, C0],
  271. * where K is fixed at 1, and Co and C0 are 16.\n
  272. * Limited by the size of L1 buffer memory: \n
  273. * (l1_size - filter_h*filter_w*BLOCK_SIZE*BLOCK_SIZE*data_size) // (Wi *
  274. * BLOCK_SIZE * data_size) >= (BLOCK_SIZE * strides_h + filter_h - strides_h).\n
  275. * @par Quantization supported or not
  276. * Yes
  277. * @par Third-party framework compatibility
  278. * @li Compatible with the TensorFlow operator DepthwiseConv2D.
  279. * @li Compatible with the Caffe operator DepthwiseConv2D.
  280. */
  281. REG_OP(DepthwiseConv2D)
  282. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  283. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  284. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  285. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16, DT_INT8}))
  286. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  287. .REQUIRED_ATTR(strides, ListInt)
  288. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  289. .REQUIRED_ATTR(pads, ListInt)
  290. .ATTR(data_format, String, "NHWC")
  291. .ATTR(offset_x, Int, 0)
  292. .OP_END_FACTORY_REG(DepthwiseConv2D)
  293. /**
  294. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  295. * It accumulates all the values from out_backprop into the feature
  296. * dimension. For NHWC data format, the feature dimension is the last.
  297. * For NCHW data format, the feature dimension is the third-to-last . \n
  298. *@par Inputs:
  299. *x: A Tensor of type NumberType . \n
  300. *@par Attributes:
  301. *data_format: Data format. Defaults to "NHWC" . \n
  302. *@par Outputs:
  303. *y: A Tensor.Has the same type as "x" . \n
  304. *@par Third-party framework compatibility
  305. * Compatible with the TensorFlow operator BiasAddGrad.
  306. */
  307. REG_OP(BiasAddGrad)
  308. .INPUT(x, TensorType::NumberType())
  309. .OUTPUT(y, TensorType::NumberType())
  310. .ATTR(data_format, String, "NHWC")
  311. .OP_END_FACTORY_REG(BiasAddGrad)
  312. /**
  313. *@brief Computes the gradients of convolution with respect to the input.
  314. *@par Inputs:
  315. * Three inputs:
  316. * @li input_size: A const Tensor of type int32. Currently does not support
  317. * data tensor. An integer vector representing the shape of input, where
  318. * input is a 4-D tensor [batch, height, width, channels]
  319. * or [batch, channels, height, width].
  320. * @li filter: A Tensor. Must be one of the following types: float16, float32,
  321. * float64. 4-D with shape
  322. * [filter_height, filter_width, in_channels, out_channels]
  323. * or [out_channels, filter_height, filter_width, in_channels]
  324. * or [out_channels, in_channel, filter_height, filter_width].
  325. * @li out_backprop: A Tensor. Must have the same type as filter.
  326. * 4-D with shape [batch, out_height, out_width, out_channels]
  327. * or [batch, out_channels, out_height, out_width].
  328. * Gradients with respect to the output of the convolution.
  329. *\n
  330. *\n
  331. * The following are the supported data types and data formats:\n
  332. *\n
  333. | Tensor | out_bckprop | filter | y\n
  334. ------------|-------------|---------|--------\n
  335. | Data Type | float16 | float16 | float16\n
  336. | |-------------|---------|--------\n
  337. | | float32 | float32 | float32\n
  338. | |-------------|---------|--------\n
  339. | | float64 | float64 | float64\n
  340. ------------|-------------|---------|--------\n
  341. | Format | NCHW | NCHW | NCHW\n
  342. | | NHWC | HWCN | NHWC\n
  343. *\n
  344. * For float32 and float64 type, the actual calculation on the chip is based on
  345. * float16.
  346. *\n
  347. *
  348. *@par Attributes:
  349. * Five attributes:
  350. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  351. * for H/W dimension. The index of H/W is same as data_format.
  352. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads
  353. * on feature map
  354. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  355. * dimension of input, defaults to [1,1,1,1].
  356. * @li groups: Number of blocked connections from input channels to output
  357. * channels.
  358. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  359. * "NHWC". Specify the data format of the input and output data.
  360. *\n
  361. *\n
  362. * The following value range restrictions must be met:\n
  363. *\n
  364. | Name | Field | Scope\n
  365. -------------------|----------|--------------\n
  366. | input_size | H | [1, 200000]\n
  367. | | W | [1, 4096]\n
  368. -------------------|----------|--------------\n
  369. | Filter | H | [1, 255]\n
  370. | | W | [1, 255]\n
  371. -------------------|----------|--------------\n
  372. | out_backprop | H*strideH| [1, 200000]\n
  373. | | W*strideW| [1, 4096]\n
  374. -------------------|----------|--------------\n
  375. | y(fmap) | H | [1, 200000]\n
  376. | | W | [1, 4096]\n
  377. -------------------|----------|--------------\n
  378. | Stride | H | [1, 63]\n
  379. | | W | [1, 63]\n
  380. -------------------|----------|--------------\n
  381. | Padding | Top | [0, 255]\n
  382. | | Bottom | [0, 255]\n
  383. | | Left | [0, 255]\n
  384. | | Right | [0, 255]\n
  385. -------------------|----------|--------------\n
  386. | Dilation | H | [1, 255]\n
  387. | | W | [1, 255]\n
  388. *\n
  389. * In Ascend910, fmap or out_backprop's H and W not support 1 when
  390. * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
  391. * and filter_width > fmap_width
  392. * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w < 4096
  393. *\n
  394. *
  395. *@par Outputs:
  396. * y: A Tensor. Has the same type as filter,and has same format as input_size.
  397. *\n
  398. * out_backprop_height = (fmap_height + pad_top + pad_bottom -
  399. * (dilation_h * (filter_height - 1) + 1))
  400. * / stride_h + 1
  401. *\n
  402. * out_backprop_width = (fmap_width + pad_left + pad_right -
  403. * (dilation_w * (filter_width - 1) + 1))
  404. * / stride_w + 1
  405. *\n
  406. *
  407. *@par Third-party framework compatibility
  408. * Compatible with Tensorflow's conv2d_backprop_input
  409. */
  410. REG_OP(Conv2DBackpropInput)
  411. .INPUT(input_size, TensorType({DT_INT32}))
  412. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  413. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  414. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  415. .REQUIRED_ATTR(strides, ListInt)
  416. .REQUIRED_ATTR(pads, ListInt)
  417. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  418. .ATTR(groups, Int, 1)
  419. .ATTR(data_format, String, "NHWC")
  420. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  421. /**
  422. *@brief Computes the gradients of convolution with respect to the input.
  423. *@par Inputs:
  424. * Two inputs:
  425. * @li filter: A Tensor. Types is float16.
  426. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  427. * or [out_channels, filter_height, filter_width, in_channels]
  428. * or [out_channels, in_channel, filter_height, filter_width].
  429. * @li out_backprop: A Tensor. Must have the same type as filter.
  430. * 4-D with shape [batch, out_height, out_width, out_channels]
  431. * or [batch, out_channels, out_height, out_width].
  432. * Gradients with respect to the output of the convolution.
  433. *@par Attributes:
  434. * Six attributes:
  435. * @li input_size A Tensor of type int32. An integer vector representing the
  436. * shape of input, where input is a 4-D tensor [batch, height, width, channels]
  437. * or [batch, channels, height, width].
  438. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  439. * for H/W dimension. The index of H/W is same as data_format.
  440. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  441. * feature map
  442. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  443. * dimension of input, defaults to [1,1,1,1].
  444. * @li groups: Number of blocked connections from input channels to output
  445. * channels.
  446. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  447. * "NHWC". Specify the data format of the input and output data.
  448. *@par Outputs:
  449. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width,
  450. * channels] or [batch, channels, height, width].
  451. *@par Third-party framework compatibility
  452. * Compatible with Tensorflow's conv2d_backprop_input
  453. *@par Restrictions:
  454. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropInput instead.
  455. */
  456. REG_OP(Conv2DBackpropInputD)
  457. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  458. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  459. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  460. .REQUIRED_ATTR(input_size, ListInt)
  461. .REQUIRED_ATTR(strides, ListInt)
  462. .REQUIRED_ATTR(pads, ListInt)
  463. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  464. .ATTR(groups, Int, 1)
  465. .ATTR(data_format, String, "NHWC")
  466. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  467. /**
  468. *@brief Computes the Deconvolution with respect to the input.
  469. *@par Inputs:
  470. * Two required inputs:
  471. * @li x: A Tensor of type float16 or int8. 4D with shape
  472. * [batch, out_channels, out_height, out_width]. Gradients with respect
  473. * to the output of the convolution.
  474. * @li filter: A Tensor. Must have the same type as "x".
  475. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  476. * Two optional inputs:
  477. * @li bias: An optional tensor. Must have the same type as "y".
  478. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  479. * Type is int8. Reserved.\n
  480. *\n
  481. *\n
  482. * The following are the supported data types and data formats:\n
  483. *\n
  484. | Tensor | x | filter | bias | y\n
  485. ------------|---------|---------|---------|--------\n
  486. | Data Type | float16 | float16 | float16 | float16\n
  487. | |---------|---------|---------|--------\n
  488. | | int8 | int8 | int32 | int32\n
  489. ------------|---------|---------|---------|--------\n
  490. | Format | NCHW | NCHW | ND | NCHW\n
  491. *\n
  492. * For int8, a dequant or requant operator must be followed.
  493. *\n
  494. *
  495. *@par Attributes:
  496. * Six attributes:
  497. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  498. * for H/W dimension, defaults to [1,1].
  499. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  500. * padding on the feature map, defaults to [0,0,0,0].
  501. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  502. * dimension of input, defaults to [1,1,1,1].
  503. * @li groups: Number of blocked connections from input channels to
  504. output channels. Defaults to "1".
  505. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  506. Specify the data format of the input and output data.
  507. * @li offset_x: An optional integer for quantized deconvolution.
  508. * The negative offset added to the input image for int8 type. Ensure offset_x
  509. * within the effective range of int8 [-128, 127]. Defaults to "0".
  510. *\n
  511. *\n
  512. * The following value range restrictions must be met:\n
  513. *\n
  514. | Name | Field | Scope\n
  515. -------------------|----------|--------------\n
  516. | x (out_backprop) | H*strideH| [1, 200000]\n
  517. | | W*strideW| [1, 4096]\n
  518. -------------------|----------|--------------\n
  519. | Filter | H | [1, 255]\n
  520. | | W | [1, 255]\n
  521. -------------------|----------|--------------\n
  522. | y (fmap) | H | [1, 200000]\n
  523. | | W | [1, 4096]\n
  524. -------------------|----------|--------------\n
  525. | Stride | H | [1, 63]\n
  526. | | W | [1, 63]\n
  527. -------------------|----------|--------------\n
  528. | Padding | Top | [0, 255]\n
  529. | | Bottom | [0, 255]\n
  530. | | Left | [0, 255]\n
  531. | | Right | [0, 255]\n
  532. -------------------|----------|--------------\n
  533. | Dilation | H | [1, 255]\n
  534. | | W | [1, 255]\n
  535. -------------------|----------|--------------\n
  536. | Offset_x | | [-128, 127]\n
  537. *\n
  538. * In Ascend910, fmap or out_backprop's H and W not support 1 when
  539. * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
  540. * and filter_width > fmap_width
  541. * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w < 4096
  542. *\n
  543. *
  544. *@par Outputs:
  545. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  546. *\n
  547. * out_backprop_height = (fmap_height + pad_top + pad_bottom -
  548. * (dilation_h * (filter_height - 1) + 1))
  549. * / stride_h + 1
  550. *\n
  551. * out_backprop_width = (fmap_width + pad_left + pad_right -
  552. * (dilation_w * (filter_width - 1) + 1))
  553. * / stride_w + 1
  554. *\n
  555. *
  556. * When type of x is float16, the type of y must be float16.
  557. * When type of x is int8, the type of y must be int32.
  558. */
  559. REG_OP(Deconvolution)
  560. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  561. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  562. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  563. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  564. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  565. .ATTR(strides, ListInt, {1, 1})
  566. .ATTR(pads, ListInt, {0, 0, 0, 0})
  567. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  568. .ATTR(groups, Int, 1)
  569. .ATTR(data_format, String, "NCHW")
  570. .ATTR(offset_x, Int, 0)
  571. .OP_END_FACTORY_REG(Deconvolution)
  572. /**
  573. *@brief Computes the gradients of convolution with respect to the filter
  574. *@par Inputs:
  575. * Three inputs:
  576. * @li x: A Tensor. Must be one of the following types: float16, float32,
  577. * float64.4-D with shape [batch, in_height, in_width, in_channels] or
  578. * [batch, in_channels, in_height, in_width].
  579. * @li filter_size: A const Tensor of type int32. Currently does not support
  580. * data tensor. An integer vector representing the tensor shape of filter,
  581. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  582. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  583. * or [out_channels, in_channel, filter_height, filter_width].
  584. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  585. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  586. * out_height, out_width]. Gradients with respect to the output of the
  587. * convolution.
  588. *\n
  589. *\n
  590. * The following are the supported data types and data formats:\n
  591. *\n
  592. | Tensor | x | out_backprop | y\n
  593. ------------|---------|--------------|---------\n
  594. | Data Type | float16 | float16 | float16\n
  595. | |---------|--------------|---------\n
  596. | | float32 | float32 | float32\n
  597. | |---------|--------------|---------\n
  598. | | float64 | float64 | float64\n
  599. |-----------|---------|--------------|---------\n
  600. | Format | NCHW | NCHW | NCHW\n
  601. | | NHWC | NHWC | HWCN\n
  602. *\n
  603. * For float32 and float64 type of x and outbackprop, the actual calculation on the chip
  604. * is based on float16.
  605. *\n
  606. *
  607. *@par Attributes:
  608. * Five attributes:
  609. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  610. * for H/W dimension. The index of H/W is same as data_format.
  611. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  612. * feature map.
  613. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  614. * dimension of input, defaults to [1,1,1,1].
  615. * @li groups: Number of blocked connections from input channels to output
  616. * channels.
  617. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  618. * "NHWC". Specify the data format of the input and output data.
  619. *\n
  620. *\n
  621. * The following value range restrictions must be met:\n
  622. *\n
  623. | Name | Field | Scope\n
  624. -------------------|----------|--------------\n
  625. | x(fmap) | H | [1, 200000]\n
  626. | | W | [1, 4096]\n
  627. -------------------|----------|--------------\n
  628. | Filter Size | H | [1, 255]\n
  629. | | W | [1, 255]\n
  630. -------------------|----------|--------------\n
  631. | out_backprop | H | [1, 200000]\n
  632. | | W | [1, 4096]\n
  633. -------------------|----------|--------------\n
  634. | y | H | [1, 200000]\n
  635. | | W | [1, 4096]\n
  636. -------------------|----------|--------------\n
  637. | Stride | H | [1, 63]\n
  638. | | W | [1, 63]\n
  639. -------------------|----------|--------------\n
  640. | Padding | Top | [0, 255]\n
  641. | | Bottom | [0, 255]\n
  642. | | Left | [0, 255]\n
  643. | | Right | [0, 255]\n
  644. -------------------|----------|--------------\n
  645. | Dilation | H | [1, 255]\n
  646. | | W | [1, 255]\n
  647. *\n
  648. *@par Outputs:
  649. * y: A Tensor. Has the same type as x, has the same format as filter_size.
  650. *\n
  651. * out_backprop_height = (in_height + pad_top + pad_bottom -
  652. * (dilation_h * (filter_height - 1) + 1))
  653. * / stride_h + 1
  654. *\n
  655. * out_backprop_width = (in_width + pad_left + pad_right -
  656. * (dilation_w * (filter_width - 1) + 1))
  657. * / stride_w + 1
  658. *\n
  659. *
  660. *@par Third-party framework compatibility
  661. * Compatible with Tensorflow's conv2d_backprop_filter
  662. */
  663. REG_OP(Conv2DBackpropFilter)
  664. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  665. .INPUT(filter_size, TensorType({DT_INT32}))
  666. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  667. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  668. .REQUIRED_ATTR(strides, ListInt)
  669. .REQUIRED_ATTR(pads, ListInt)
  670. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  671. .ATTR(groups, Int, 1)
  672. .ATTR(data_format, String, "NHWC")
  673. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  674. /**
  675. *@brief Computes the gradients of convolution with respect to the filter.
  676. *@par Inputs:
  677. * Two inputs:
  678. * @li x: A Tensor. Type is float16.
  679. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch,
  680. * in_channels, in_height, in_width].
  681. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  682. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  683. * out_height, out_width]. Gradients with respect to the output of the
  684. * convolution.
  685. *@par Attributes:
  686. * Six attributes:
  687. * @li filter_size: A Tensor of type integers. An integer vector representing
  688. * the tensor shape of filter,
  689. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  690. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  691. * or [out_channels, in_channel, filter_height, filter_width].
  692. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  693. * for H/W dimension. The index of H/W is same as data_format.
  694. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  695. * feature map
  696. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  697. * dimension of input, defaults to [1,1,1,1].
  698. * @li groups: Number of blocked connections from input channels to output
  699. * channels.
  700. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  701. * "NHWC". Specify the data format of the input and output data.
  702. *@par Outputs:
  703. * y: A Tensor. Type is float32, a 4-D tensor [filter_height, filter_width,
  704. * in_channels, out_channels] or [out_channels, filter_height, filter_width,
  705. * in_channels] or [out_channels, in_channel, filter_height, filter_width].
  706. * Compatible with Tensorflow's conv2d_backprop_filter
  707. *@par Restrictions:
  708. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropFilter instead.
  709. */
  710. REG_OP(Conv2DBackpropFilterD)
  711. .INPUT(x, TensorType({DT_FLOAT16}))
  712. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  713. .OUTPUT(y, TensorType({DT_FLOAT}))
  714. .REQUIRED_ATTR(filter_size, ListInt)
  715. .REQUIRED_ATTR(strides, ListInt)
  716. .REQUIRED_ATTR(pads, ListInt)
  717. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  718. .ATTR(groups, Int, 1)
  719. .ATTR(data_format, String, "NHWC")
  720. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  721. /**
  722. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  723. *@par Inputs:
  724. *@li x: A 4D tensor of input image. With the format "NHWC", the data is stored
  725. * in the order of: [batch, in_height, in_width, in_channels].
  726. *@li filter: A 4D tensor of learnable filters. Must have the same type as "x".
  727. * With the format "HWCN" , the data is stored in the order of: [filter_height,
  728. * filter_width, in_channels / groups, out_channels].
  729. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  730. * The data is stored in the order of: [out_channels].
  731. *@li offset_w: Reserved.
  732. *\n
  733. *\n
  734. * The following are the supported data types and data formats:
  735. *\n
  736. | Tensor | x | filter | bias | y |\n
  737. | :-------: | :-----: | :-----: | :-----: | :-----: |\n
  738. | Data Type | float16 | float16 | float16 | float16 |\n
  739. | | float32 | float32 | float32 | float32 |\n
  740. | | int8 | int8 | int32 | int32 |\n
  741. | Format | NCHW | NCHW | ND | NCHW |\n
  742. | | NHWC | HWCN | | NHWC |\n
  743. * For float32 type, the actual calculation on the chip is based on
  744. * float16.
  745. *\n
  746. *
  747. *@par Attributes:
  748. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  749. * for each dimension of input. The dimension order is determined by the data
  750. * format of "x". The N and C dimensions must be set to 1.
  751. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  752. * (top, bottom, left, right) side of the input.
  753. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  754. * dimension of input. The dimension order is determined by the data format of
  755. * "x". The N and C dimensions must be set to 1. Defaults to [1, 1, 1, 1].
  756. *@li groups: Optional. An integer of type int32. The number of blocked
  757. * connections from input channels to output channels. In_channels and
  758. * out_channels must both be divisible by "groups". Defaults to 1.
  759. *@li offset_x: Optional. An integer of type int32. The negative offset added
  760. * to the input image for int8 type. Ensure that the output is within the
  761. * effective range. Defaults to 0.
  762. *@li data_format: Reserved.
  763. *\n
  764. *\n
  765. * The following value range restrictions must be met:
  766. *\n
  767. | Name | Field | Scope |\n
  768. | :--------------: | :------: | :---------: |\n
  769. | Input Image Size | H | [1, 100000] |\n
  770. | | W | [1, 4096] |\n
  771. | Filter Size | H | [1, 255] |\n
  772. | | W | [1, 255] |\n
  773. | Stride | H | [1, 63] |\n
  774. | | W | [1, 63] |\n
  775. | Padding | Top | [0, 255] |\n
  776. | | Bottom | [0, 255] |\n
  777. | | Left | [0, 255] |\n
  778. | | Right | [0, 255] |\n
  779. | Dilation | H | [1, 255] |\n
  780. | | W | [1, 255] |\n
  781. | Offset_x | - | [-128, 127] |\n
  782. * The W dimension of the input image supports cases exceeding 4096, but it may
  783. * cause compilation errors.
  784. *\n
  785. *
  786. *@par Outputs:
  787. * y: A 4D Tensor of output feature map. Has the same type as "x". With the
  788. * format "NHWC", the data is stored in the order of: [batch, out_height,
  789. * out_width, out_channels].
  790. *\n
  791. * out_height = (in_height + pad_top + pad_bottom -
  792. * (dilation_h * (filter_height - 1) + 1))
  793. * / stride_h + 1
  794. *\n
  795. * out_width = (in_width + pad_left + pad_right -
  796. * (dilation_w * (filter_width - 1) + 1))
  797. * / stride_w + 1
  798. *\n
  799. *
  800. *@par Quantization supported or not
  801. *@li Yes
  802. *
  803. *@par Third-party framework compatibility
  804. *@li Compatible with the TensorFlow operator "conv2d".
  805. *@li Compatible with the Caffe operator 2D "Convolution".
  806. */
  807. REG_OP(Conv2D)
  808. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  809. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  810. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  811. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  812. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  813. .REQUIRED_ATTR(strides, ListInt)
  814. .REQUIRED_ATTR(pads, ListInt)
  815. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  816. .ATTR(groups, Int, 1)
  817. .ATTR(data_format, String, "NHWC")
  818. .ATTR(offset_x, Int, 0)
  819. .OP_END_FACTORY_REG(Conv2D)
  820. /**
  821. *@brief Computes a 2D convolution given 4D "x" and "filter_compress" tensors.
  822. *@par Inputs:
  823. * @li x: A 4D tensor of input images.
  824. * @li filter_compress: A 4D tensor of compressed filters.
  825. * @li compress_index: A 1D Tensor dtype of int8.
  826. * @li bias: An optional 1D tensor.
  827. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.
  828. *
  829. * The input and output tensor attributes are listed as follows:
  830. * @verbatim
  831. |Tensor | x | filter_compress | bias | offset_w | y
  832. -----------|---------|---------|---------|----------|--------
  833. |Data Type | float16 | float16 | float16 | _ | float16
  834. | |---------|---------|---------|----------|--------
  835. | | float32 | float32 | float32 | _ | float32
  836. | |---------|---------|---------|----------|--------
  837. | | int8 | int8 | int32 | int8 | int32
  838. -----------|---------|---------|---------|----------|--------
  839. |Format | NCHW | NCHW | ND | ND | NCHW
  840. | | NHWC | NHWC | | | NHWC
  841. | | | HWCN | | |
  842. @endverbatim
  843. * It should be noted that the data types must correspond to each other, but the
  844. * format does not need to . \n
  845. *@par Attributes:
  846. * @li strides: A list of 4 integers. Specifying the strides of the
  847. * convolution along the height and width. The dimension order is determined
  848. * by the data format of "x". By default the N and C dimensions are set to 1.
  849. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  850. * padding.
  851. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  852. * for dilated convolution. Has the same dimension order and value as "strides".
  853. * @li groups: Number of blocked connections from input channels to output
  854. * channels. Input channels and output channels must both be divisible by
  855. * "groups".Type is int32.
  856. * @li offset_x: An optional integer for quantized convolution. Type is int32.
  857. * Defaults to "0".
  858. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  859. * data format of the input and output images. Type is string.
  860. * Defaults to "NHWC". Reserved . \n
  861. *@par Outputs:
  862. * @li y: A 4D Tensor of output images . \n
  863. *@par Restrictions:
  864. *Warning: THIS FUNCTION IS DEPRECATED.
  865. */
  866. REG_OP(Conv2DCompress)
  867. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  868. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  869. .INPUT(compress_index, TensorType({DT_INT8}))
  870. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  871. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  872. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  873. .REQUIRED_ATTR(strides, ListInt)
  874. .REQUIRED_ATTR(pads, ListInt)
  875. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  876. .ATTR(groups, Int, 1)
  877. .ATTR(data_format, String, "NHWC")
  878. .ATTR(offset_x, Int, 0)
  879. .OP_END_FACTORY_REG(Conv2DCompress)
  880. /**
  881. *@brief Computes a 2D deformable convolution given 4D "x", "filter" and
  882. * "offsets" tensors.
  883. *@par Inputs:
  884. *@li x: A 4D tensor of input image. With the format "NHWC", the data is stored
  885. * in the order of: [batch, in_height, in_width, in_channels].
  886. *@li filter: A 4D tensor of learnable filters. Must have the same type as "x".
  887. * With the format "HWCN" , the data is stored in the order of: [filter_height,
  888. * filter_width, in_channels / groups, out_channels].
  889. *@li offsets: A 4D tensor of x-y coordinates offset and mask. With the format
  890. * "NHWC", the data is stored in the order of: [batch, out_height, out_width,
  891. * deformable_groups * filter_height * filter_width * 3].
  892. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  893. * The data is stored in the order of: [out_channels].
  894. *\n
  895. *\n
  896. * The following are the supported data types and data formats:
  897. *\n
  898. | Tensor | x | filter | offsets | bias | y |\n
  899. | :-------: | :-----: | :-----: | :-----: | :-----: | :-----: |\n
  900. | Data Type | float16 | float16 | float16 | float16 | float16 |\n
  901. | | float32 | float32 | float32 | float32 | float32 |\n
  902. | Format | NCHW | NCHW | NCHW | ND | NCHW |\n
  903. | | NHWC | HWCN | NCHW | | NHWC |\n
  904. * For float32 type, the actual convolution calculation part on the chip is
  905. * based on float16.
  906. *\n
  907. *
  908. *@par Attributes:
  909. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  910. * for each dimension of input. The dimension order is interpreted according to
  911. * the data format of "x". The N and C dimensions must be set to 1.
  912. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  913. * (top, bottom, left, right) side of the input.
  914. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  915. * dimension of input. The dimension order is interpreted according to the data
  916. * format of "x". The N and C dimensions must be set to 1. Defaults to
  917. * [1, 1, 1, 1].
  918. *@li groups: Optional. An integer of type int32. The number of blocked
  919. * connections from input channels to output channels. In_channels and
  920. * out_channels must both be divisible by "groups". Defaults to 1.
  921. *@li data_format: Reserved.
  922. *@li deformable_groups: Optional. An integer of type int32. The number of
  923. * deformable group partitions. In_channels must be divisible by
  924. * "deformable_groups". Defaults to 1.
  925. *@li modulated: Optional. Specify version of DeformableConv2D, true means v2,
  926. * false means v1, currently only support v2.
  927. *\n
  928. *\n
  929. * The following value range restrictions must be met:
  930. *\n
  931. | Name | Field | Scope |\n
  932. | :--------------: | :------: | :-------------------------: |\n
  933. | Input Image Size | H | [1, 100000 / filter_height] |\n
  934. | | W | [1, 4096 / filter_width] |\n
  935. | Filter Size | H | [1, 63] |\n
  936. | | W | [1, 63] |\n
  937. *\n
  938. *
  939. *@par Outputs:
  940. * y: A 4D Tensor of output feature map. Has the same type as "x". With the
  941. * format "NHWC", the data is stored in the order of: [batch, out_height,
  942. * out_width, out_channels].
  943. *\n
  944. * out_height = (in_height + pad_top + pad_bottom -
  945. * (dilation_h * (filter_height - 1) + 1))
  946. * / stride_h + 1
  947. *\n
  948. * out_width = (in_width + pad_left + pad_right -
  949. * (dilation_w * (filter_width - 1) + 1))
  950. * / stride_w + 1
  951. *\n
  952. *
  953. *@par Quantization supported or not
  954. *@li No
  955. *
  956. *@par Third-party framework compatibility
  957. *@li Compatible with the Mxnet operator "DeformableConvolution".
  958. *@li Compatible with the Paddlepaddle operator "deformable_conv".
  959. *@li Compatible with the Mmcv operator "deform_conv".
  960. */
  961. REG_OP(DeformableConv2D)
  962. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  963. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT}))
  964. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  965. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT}))
  966. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  967. .REQUIRED_ATTR(strides, ListInt)
  968. .REQUIRED_ATTR(pads, ListInt)
  969. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  970. .ATTR(groups, Int, 1)
  971. .ATTR(data_format, String, "NHWC")
  972. .ATTR(deformable_groups, Int, 1)
  973. .ATTR(modulated, Bool, true)
  974. .OP_END_FACTORY_REG(DeformableConv2D)
  975. /**
  976. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  977. *@par Inputs:
  978. * @li x: A 5D tensor. Must be one of the following types: float16,
  979. * (Currently does not support int8). The format of x is NCDHW or NDHWC.
  980. * @li filter: A 5D tensor of the same type as "x".
  981. * (Currently does not support int8).
  982. * The format is NCDHW, NDHWC or DHWCN.
  983. * @li bias: Optional. An 1D tensor of the same type as "x".
  984. * @li offset_w: Optional. An 1D tensor for quantized deconvolution. Reserved. \n
  985. *@par Attributes:
  986. * @li strides: Required. A list of 5 integers. Specifies the stride of the sliding window
  987. * for each dimension of "x".
  988. * The N and C dimensions must be 1. Has the same format as "x".
  989. * @li pads: Required. A list of 6 integers.
  990. * Supports only padding along the D, H and W dimensions in sequence of head,
  991. * tail, top, bottom, left and right.
  992. * @li dilations: Optional. A list of 5 integers. Specifies the dilation factor for each
  993. * dimension of "x".
  994. * @li groups: Optional. Number of blocked connections from input channels to output
  995. * channels.
  996. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  997. * Defaults to "NDHWC". Specify the data format of the input and output data.
  998. * The N, C and D dimensions must be 1. Has the same format as "x".
  999. * @li offset_x: Optional. An int. Input offset, used for quantized inference.
  1000. * Defaults to 0. Reserved. \n
  1001. *@par Outputs:
  1002. * y: A Tensor. Has the same type and data format as "x". \n
  1003. *@attention Constraints:
  1004. * The image size after padding is greater than the filter size. \n
  1005. *@par Third-party framework compatibility
  1006. * @li Compatible with the TensorFlow operator conv3d.
  1007. * @li Compatible with the Caffe operator Convolution.
  1008. */
  1009. REG_OP(Conv3D)
  1010. .INPUT(x, TensorType({DT_FLOAT16}))
  1011. .INPUT(filter, TensorType({DT_FLOAT16}))
  1012. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  1013. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1014. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1015. .REQUIRED_ATTR(strides, ListInt)
  1016. .REQUIRED_ATTR(pads, ListInt)
  1017. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1018. .ATTR(groups, Int, 1)
  1019. .ATTR(data_format, String, "NDHWC")
  1020. .ATTR(offset_x, Int, 0)
  1021. .OP_END_FACTORY_REG(Conv3D)
  1022. /**
  1023. *@brief Computes the gradients of convolution 3d with respect to the input.
  1024. *@par Inputs:
  1025. * @li input_size: A Tensor of type int32, int64. An integer vector representing
  1026. * the shape of input, where input is a 5-D tensor
  1027. * [batch, depth, height, width, channels] or
  1028. * [batch, channels, depth, height, width].
  1029. * @li filter: A Tensor. Must be one of the following types: float16, float32.
  1030. * Currently does not support double.
  1031. * @li out_backprop: A Tensor. Must have the same type as filter.
  1032. * 5-D with shape [batch, depth, out_height, out_width, out_channels]
  1033. * or [batch, out_channels, depth, out_height, out_width]. Gradients with
  1034. * respect to the output of the convolution. \n
  1035. *@par Attributes:
  1036. * @li strides: Required. A list of 5 integers. Specifies the stride of the sliding window
  1037. * for each dimension of "out_backprop".
  1038. * The N and C dimensions must be 1. Has the same format as "out_backprop".
  1039. * @li pads: Required. A list of 6 integers.
  1040. * Supports only padding along the D, H and W dimensions in sequence of head,
  1041. * tail, top, bottom, left and right.
  1042. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1043. * dimension of the input.
  1044. * The N, C and D dimensions must be 1. Has the same format as "out_backprop".
  1045. * @li groups: Optional. Number of blocked connections from input channels to output
  1046. * channels.
  1047. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1048. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1049. *@par Outputs:
  1050. * y: A Tensor. Has the same type as filter,and has same format as "input_size". \n
  1051. *@par Third-party framework compatibility
  1052. * Compatible with Tensorflow's conv3d_backprop_input
  1053. */
  1054. REG_OP(Conv3DBackpropInput)
  1055. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1056. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1057. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1058. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1059. .REQUIRED_ATTR(strides, ListInt)
  1060. .REQUIRED_ATTR(pads, ListInt)
  1061. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1062. .ATTR(groups, Int, 1)
  1063. .ATTR(data_format, String, "NDHWC")
  1064. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  1065. /**
  1066. *@brief Computes the gradients of convolution 3d with respect to the input.
  1067. *@par Inputs:
  1068. * @li filter: A Tensor whose type is float16. The format of filter is NCDHW,
  1069. * NDHWC or DHWCN.
  1070. * @li out_backprop: A Tensor. Must have the same type as filter. The format is
  1071. * NDHWC or NCDHW. \n
  1072. *@par Attributes:
  1073. * @li input_size: Required. A tuple/list of type int32, int64. An integer vector
  1074. * representing the shape of input, where input is a 5-D tensor
  1075. * [batch, depth, height, width, channels] or
  1076. * [batch, channels, depth, height, width].
  1077. * @li strides: Required. A list of 5 integers. Specifies the stride of the sliding window
  1078. * for each dimension of "out_backprop".
  1079. * The N and C dimensions must be 1. Has the same format as "out_backprop".
  1080. * @li pads: Required. A list of 6 integers. Supports only padding along the D, H and W
  1081. * dimensions in sequence of head, tail, top, bottom, left and right.
  1082. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1083. * dimension of input.
  1084. * The N, C and D dimensions must be 1. Has the same format as "out_backprop".
  1085. * @li groups: Optional. Number of blocked connections from input channels to output
  1086. * channels.
  1087. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1088. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1089. *@par Outputs:
  1090. * y: A Tensor. Has the same type and data format as "out_backprop". \n
  1091. *@par Third-party framework compatibility
  1092. * Compatible with Tensorflow's conv3d_backprop_input. \n
  1093. *@par Restrictions:
  1094. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropInput instead.
  1095. */
  1096. REG_OP(Conv3DBackpropInputD)
  1097. .INPUT(filter, TensorType({DT_FLOAT16}))
  1098. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  1099. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1100. .REQUIRED_ATTR(input_size, ListInt)
  1101. .REQUIRED_ATTR(strides, ListInt)
  1102. .REQUIRED_ATTR(pads, ListInt)
  1103. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1104. .ATTR(groups, Int, 1)
  1105. .ATTR(data_format, String, "NDHWC")
  1106. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  1107. /**
  1108. *@brief Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence . \n
  1109. *@par Inputs:
  1110. * @li x: A Tensor dtype of float16.
  1111. * @li cont: A Tensor dtype of float16, float32.
  1112. * @li w_x: A Tensor dtype of float16.
  1113. * @li bias: A Tensor dtype of int16, int32, float16, float32.
  1114. * @li w_h: A Tensor dtype of float16.
  1115. * @li x_static: A optinal Tensor dtype of float16.
  1116. * @li h_0: A optinal Tensor dtype of float16, float32.
  1117. * @li c_0: A optinal Tensor dtype of float16, float32.
  1118. * @li w_x_static: A optinal Tensor dtype of float16 . \n
  1119. *@par Attributes:
  1120. *@li num_output: A Scalar of output size dtype of int.
  1121. *@li expose_hidden: A Scalar(bool) of features hidden . \n
  1122. *@par Outputs:
  1123. *@li h: A Tensor dtype of float16, float32.
  1124. * @li h_t: A optinal Tensor dtype of float16, float32. The hidden state at time t.
  1125. * @li c_t: A optinal Tensor dtype of float16, float32. The cell state at time t . \n
  1126. *@par Third-party framework compatibility:
  1127. * Compatible with the Caffe operator LSTM.
  1128. */
  1129. REG_OP(LSTM)
  1130. .INPUT(x, TensorType({DT_FLOAT16}))
  1131. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  1132. .INPUT(w_x, TensorType({DT_FLOAT16}))
  1133. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  1134. .INPUT(w_h, TensorType({DT_FLOAT16}))
  1135. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  1136. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  1137. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  1138. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  1139. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1140. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1141. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1142. .ATTR(num_output, Int, 0)
  1143. .ATTR(expose_hidden, Bool, false)
  1144. .OP_END_FACTORY_REG(LSTM)
  1145. /**
  1146. *@brief Computes the gradients of convolution3D with respect to the filter
  1147. *@par Inputs:
  1148. * @li x: A Tensor. Must be one of the following types: float16, float32.
  1149. * Currently does not support double.
  1150. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  1151. * or [batch, in_channels, in_depth, in_height, in_width].
  1152. * @li filter_size: A Tensor of type int32. An integer vector representing the
  1153. * tensor shape of filter, where filter is a 5-D tensor
  1154. * [filter_depth, filter_height, filter_width, in_channels, out_channels]
  1155. * [out_channels, in_channels, filter_depth, filter_height, filter_width]
  1156. * or [out_channels, filter_depth, filter_height, filter_width, in_channels].
  1157. * @li out_backprop: A Tensor. Must have the same type as x.
  1158. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  1159. * or [batch, out_channels, out_depth, out_height, out_width].
  1160. * Gradients with respect to the output of the convolution. \n
  1161. *@par Attributes:
  1162. * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of the sliding
  1163. * window for each dimension of "x". The N and C dimensions must be 1.
  1164. * Has the same format as "x".
  1165. * @li pads: Required. A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  1166. * pads on feature map.
  1167. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1168. * dimension of input.
  1169. * The N, C and D dimensions must be 1. Has the same format as "x".
  1170. * @li groups: Optional. Number of blocked connections from input channels to output
  1171. * channels.
  1172. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1173. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1174. *@par Outputs:
  1175. * y: A Tensor that has the same type as "x" and the format is NDHWC, NCDHW or DHWCN. \n
  1176. *@par Third-party framework compatibility
  1177. * Compatible with Tensorflow's conv3d_backprop_filter
  1178. */
  1179. REG_OP(Conv3DBackpropFilter)
  1180. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1181. .INPUT(filter_size, TensorType({DT_INT32}))
  1182. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1183. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1184. .REQUIRED_ATTR(strides, ListInt)
  1185. .REQUIRED_ATTR(pads, ListInt)
  1186. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1187. .ATTR(groups, Int, 1)
  1188. .ATTR(data_format, String, "NDHWC")
  1189. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  1190. /**
  1191. *@brief Computes the gradients of convolution with respect to the filter.
  1192. *@par Inputs:
  1193. * @li x: A Tensor of type float16.
  1194. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  1195. * or [batch, in_channels, in_depth, in_height, in_width].
  1196. * @li out_backprop: A Tensor. Must have the same type as x.
  1197. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  1198. * or [batch, out_channels, out_depth, out_height, out_width].
  1199. * Gradients with respect to the output of the convolution. \n
  1200. *@par Attributes:
  1201. * @li filter_size: Required. A tuple/list of type integers. An integer vector
  1202. * representing the tensor shape of filter, where filter is a 5-D tensor
  1203. * [filter_depth, filter_height, filter_width, in_channels, out_channels],
  1204. * [out_channels, filter_depth, filter_height, filter_width, in_channels]
  1205. * or [out_channels, in_channels, filter_depth, filter_height, filter_width].
  1206. * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of the sliding
  1207. * window for each dimension of "x".
  1208. * The N and C dimensions must be 1. Has the same format as "x".
  1209. * @li pads: Required. A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  1210. * pads on feature map.
  1211. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1212. * dimension of input.
  1213. * The N, C and D dimensions must be 1. Has the same format as "x".
  1214. * @li groups: Optional. Number of blocked connections from input channels to output
  1215. * channels.
  1216. * @li data_format: Optional. An optional string from: "NDHWC", "NCDHW".
  1217. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1218. *@par Outputs:
  1219. * y: A Tensor of type float32 and the format is NDHWC, NCDHW or DHWCN. \n
  1220. *@par Third-party framework compatibility
  1221. * Compatible with Tensorflow's conv3d_backprop_filter. \n
  1222. *@par Restrictions:
  1223. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropFilter instead.
  1224. */
  1225. REG_OP(Conv3DBackpropFilterD)
  1226. .INPUT(x, TensorType({DT_FLOAT16}))
  1227. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  1228. .OUTPUT(y, TensorType({DT_FLOAT}))
  1229. .REQUIRED_ATTR(filter_size, ListInt)
  1230. .REQUIRED_ATTR(strides, ListInt)
  1231. .REQUIRED_ATTR(pads, ListInt)
  1232. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1233. .ATTR(groups, Int, 1)
  1234. .ATTR(data_format, String, "NDHWC")
  1235. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  1236. /**
  1237. *@brief Computes the transpose of convolution 3d with respect to the input.
  1238. *@par Inputs:
  1239. * @li input_size: A Tensor of type int32. An integer vector representing the
  1240. * shape of input.
  1241. * @li x: A Tensor of type float16, currently does not support int8. The format
  1242. * is NDHWC or NCDHW.
  1243. * @li filter: A Tensor of type float16, currently does not support int8.
  1244. * The format is NDHWC, NCDHW or DHWCN.
  1245. * @li bias: Optional. An optional 1D tensor of the same type as "x". Reserved.
  1246. * @li offset_w: Optional. An optional 1D tensor for quantized deconvolution. Reserved. \n
  1247. *@par Attributes:
  1248. * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of the sliding
  1249. * window for each dimension of "x".
  1250. * The N and C dimensions must be 1. Has the same format as "x".
  1251. * @li pads: Required. A tuple/list of 6 integers.
  1252. * @li dilations: Optional. A tuple/list of 5 integers,
  1253. * The dilation factor for each dimension of input.
  1254. * The N, C and D dimensions must be 1. Has the same format as "x".
  1255. * @li groups: Optional. Number of blocked connections from input channels to output
  1256. * channels.
  1257. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1258. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1259. * @li output_padding: Optional. The size will be added in the output shape.
  1260. * @li offset_x: Optional. Input offset_x value. Reserved. \n
  1261. *@par Outputs:
  1262. * y: A Tensor. Has the same type and format as "x".
  1263. */
  1264. REG_OP(Conv3DTranspose)
  1265. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1266. .INPUT(x, TensorType({DT_FLOAT16}))
  1267. .INPUT(filter, TensorType({DT_FLOAT16}))
  1268. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  1269. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1270. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1271. .REQUIRED_ATTR(strides, ListInt)
  1272. .REQUIRED_ATTR(pads, ListInt)
  1273. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1274. .ATTR(groups, Int, 1)
  1275. .ATTR(data_format, String, "NDHWC")
  1276. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1277. .ATTR(offset_x, Int, 0)
  1278. .OP_END_FACTORY_REG(Conv3DTranspose)
  1279. /**
  1280. *@brief Computes the transpose of convolution 3d with respect to the input.
  1281. *@par Inputs:
  1282. * @li x: A Tensor of type float16, currently does not support int8.
  1283. * The format is NDHWC or NCDHW.
  1284. * @li filter: A Tensor of type float16, currently does not support int8.
  1285. * The format is NDHWC, NCDHW or DHWCN.
  1286. * @li bias: Optional. An 1D tensor of the same type as "x". Reserved.
  1287. * @li offset_w: Optional. An 1D tensor for quantized deconvolution. Reserved. \n
  1288. *@par Attributes:
  1289. * @li input_size: Required. A tuple/list of type int32.
  1290. * An integer vector representing the shape of input.
  1291. * @li strides: Required. A tuple/list of 5 integers.
  1292. * Specifies the stride of the sliding window for each dimension of "x".
  1293. * The N and C dimensions must be 1. Has the same format as "x".
  1294. * @li pads: Required. A tuple/list of 6 integers.
  1295. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1296. * dimension of input.
  1297. * The N, C and D dimensions must be 1. Has the same format as "x".
  1298. * @li groups: Optional. Number of blocked connections from input channels to output
  1299. * channels.
  1300. * @li data_format: Optional. An optional string from: "NDHWC", "NCDHW".
  1301. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1302. * @li output_padding: Optional. The size will be added in the output shape.
  1303. * @li offset_x: Optional. Input offset_x value. Reserved. \n
  1304. *@par Outputs:
  1305. * y: A Tensor. Has the same type and format as "x". \n
  1306. *@par Restrictions:
  1307. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DTranspose instead.
  1308. */
  1309. REG_OP(Conv3DTransposeD)
  1310. .INPUT(x, TensorType({DT_FLOAT16}))
  1311. .INPUT(filter, TensorType({DT_FLOAT16}))
  1312. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  1313. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1314. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1315. .REQUIRED_ATTR(input_size, ListInt)
  1316. .REQUIRED_ATTR(strides, ListInt)
  1317. .REQUIRED_ATTR(pads, ListInt)
  1318. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1319. .ATTR(groups, Int, 1)
  1320. .ATTR(data_format, String, "NDHWC")
  1321. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1322. .ATTR(offset_x, Int, 0)
  1323. .OP_END_FACTORY_REG(Conv3DTransposeD)
  1324. /**
  1325. *@brief Computes the transpose of convolution 2d with respect to the input.
  1326. *@par Inputs:
  1327. * Five inputs:
  1328. * @li input_size: A Tensor of type int32 or int64. An integer vector
  1329. * representing the shape of input, where input is a 4-D tensor
  1330. * [batch, height, width, channels] or [batch, channels, height, width].
  1331. * @li x: A Tensor of type float16, int8. 4-D with shape [batch, out_height,
  1332. * out_width, out_channels] or [batch, out_channels, out_height, out_width].
  1333. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1334. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  1335. * or [out_channels, filter_height, filter_width, in_channels]
  1336. * or [out_channels, in_channel, filter_height, filter_width].
  1337. * @li bias: An optional 1D tensor of type float16 or int32. Format is "ND".
  1338. * @li offset_w: An optional 1D tensor for quantized inference. Reserved.
  1339. *\n
  1340. *\n
  1341. * The following are the supported data types and data formats:\n
  1342. *\n
  1343. | Tensor | x | filter | bias | y\n
  1344. ------------|---------|---------|---------|--------\n
  1345. | Data Type | float16 | float16 | float16 | float16\n
  1346. | |---------|---------|---------|--------\n
  1347. | | int8 | int8 | int32 | int32\n
  1348. ------------|---------|---------|---------|--------\n
  1349. | Format | NCHW | NCHW | ND | NCHW\n
  1350. | | NHWC | HWCN | | NHWC\n
  1351. *\n
  1352. * For int8, a dequant or requant operator must be followed.
  1353. *\n
  1354. *
  1355. *@par Required Attributes:
  1356. * @li strides: A required tuple/list of 4 integers. The stride of the sliding
  1357. * window for H/W dimension. The index of H/W is same as data_format.
  1358. * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]
  1359. * pads on feature map.
  1360. *@par Attributes:
  1361. * Five attributes:
  1362. * @li groups: Number of blocked connections from input channels to output
  1363. * channels.
  1364. * Defaults to "1".
  1365. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  1366. * dimension of input. Must be [1, 1, 1, 1].
  1367. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1368. * Specify the data format of the input and output data.
  1369. * @li output_padding: The size will be added in the output shape. Defaults
  1370. * to [0, 0, 0, 0].
  1371. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1372. * The negative offset added to the input image for int8 type. Ensure offset_x
  1373. * within the effective range of int8 [-128, 127]. Defaults to "0".
  1374. *\n
  1375. *\n
  1376. * The following value range restrictions must be met:\n
  1377. *\n
  1378. | Name | Field | Scope\n
  1379. -------------------|----------|--------------\n
  1380. | input_size | H | [1, 200000]\n
  1381. | | W | [1, 4096]\n
  1382. -------------------|----------|--------------\n
  1383. | x (out_backprop) | H*strideH| [1, 200000]\n
  1384. | | W*strideW| [1, 4096]\n
  1385. -------------------|----------|--------------\n
  1386. | filter | H | [1, 255]\n
  1387. | | W | [1, 255]\n
  1388. -------------------|----------|--------------\n
  1389. | y (fmap) | H | [1, 200000]\n
  1390. | | W | [1, 4096]\n
  1391. -------------------|----------|--------------\n
  1392. | Stride | H | [1, 63]\n
  1393. | | W | [1, 63]\n
  1394. -------------------|----------|--------------\n
  1395. | Padding | Top | [0, 255]\n
  1396. | | Bottom | [0, 255]\n
  1397. | | Left | [0, 255]\n
  1398. | | Right | [0, 255]\n
  1399. -------------------|----------|--------------\n
  1400. | Dilation | H | [1, 255]\n
  1401. | | W | [1, 255]\n
  1402. -------------------|----------|--------------\n
  1403. | Offset_x | | [-128, 127]\n
  1404. *\n
  1405. * In Ascend910, fmap or out_backprop's H and W not support 1 when
  1406. * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
  1407. * and filter_width > fmap_width
  1408. * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w < 4096
  1409. *\n
  1410. *
  1411. *@par Outputs:
  1412. * y: A Tensor. A Tensor of type float16 or int32, and has same format as
  1413. * input_size.
  1414. *\n
  1415. * out_backprop_height = (fmap_height + pad_top + pad_bottom -
  1416. * (dilation_h * (filter_height - 1) + 1))
  1417. * / stride_h + 1
  1418. *\n
  1419. * out_backprop_width = (fmap_width + pad_left + pad_right -
  1420. * (dilation_w * (filter_width - 1) + 1))
  1421. * / stride_w + 1
  1422. *\n
  1423. *
  1424. */
  1425. REG_OP(Conv2DTranspose)
  1426. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1427. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1428. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1429. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1430. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1431. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1432. .REQUIRED_ATTR(strides, ListInt)
  1433. .REQUIRED_ATTR(pads, ListInt)
  1434. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1435. .ATTR(groups, Int, 1)
  1436. .ATTR(data_format, String, "NHWC")
  1437. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1438. .ATTR(offset_x, Int, 0)
  1439. .OP_END_FACTORY_REG(Conv2DTranspose)
  1440. /**
  1441. *@brief Computes the transpose of convolution 2d with respect to the input.
  1442. *@par Inputs:
  1443. * Four inputs:
  1444. * @li x: A Tensor of type float16, int8.
  1445. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1446. * @li bias: An optional 1D tensor of the same type as "x".
  1447. * @li offset_w: An optional 1D tensor for quantized inference. Type is int8. Reserved.
  1448. *@par Required Attributes:
  1449. * @li input_size: A Tensor of type int32 or int64. An integer vector representing the
  1450. * shape of input.
  1451. * @li strides: A required list or tuple. The stride of the sliding window for
  1452. * height and width for H/W dimension.
  1453. * @li pads: A required list or tuple of int32. Padding added to each dimension
  1454. * of the input.
  1455. *@par Attributes:
  1456. * Five attributes:
  1457. * @li groups: Number of blocked connections from input channels to output channels.
  1458. * Defaults to "1".
  1459. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1460. * of input. Must be [1, 1, 1, 1].
  1461. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1462. * Specify the data format of the input and output data.
  1463. * @li output_padding: The size will be added in the output shape. Defaults
  1464. * to [0, 0, 0, 0].
  1465. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1466. * Defaults to "0".
  1467. *@par Outputs:
  1468. * y: A Tensor. Has the same type as "filter".
  1469. *@par Restrictions:
  1470. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DTranspose instead.
  1471. */
  1472. REG_OP(Conv2DTransposeD)
  1473. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1474. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1475. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1476. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1477. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1478. .REQUIRED_ATTR(input_size, ListInt)
  1479. .REQUIRED_ATTR(strides, ListInt)
  1480. .REQUIRED_ATTR(pads, ListInt)
  1481. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1482. .ATTR(groups, Int, 1)
  1483. .ATTR(data_format, String, "NHWC")
  1484. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1485. .ATTR(offset_x, Int, 0)
  1486. .OP_END_FACTORY_REG(Conv2DTransposeD)
  1487. /**
  1488. *@brief Computes the deformed convolution output with the expected input
  1489. *@par Inputs:
  1490. * Two inputs:
  1491. * @li x: A Tensor of type float16,float32
  1492. * @li offsets: A Tensor of type float16,float32.Deformation offset parameter.
  1493. *@par Required Attributes:
  1494. * @li strides: A tuple/list of 4 integers.The stride of the sliding window for
  1495. * height and width for H/W dimension.
  1496. * @li pads: A tuple/list of 4 integers.Padding added to H/W dimension
  1497. * of the input.
  1498. * @li ksize: A tuple/list of 2 integers.kernel size.
  1499. *@par Attributes:
  1500. * Four attributes:
  1501. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1502. * of input. Defaults to [1, 1, 1, 1]
  1503. * @li data_format: An optional string from: "NCHW", "NHWC". Defaults to "NCHW". Specify the data format of the input x.
  1504. * @li deformable_groups: Specify the c-axis grouping number of input x.
  1505. * @li modulated: Specify version of DeformableConv2D, true means v2, false means v1
  1506. *@par Outputs:
  1507. * y: A Tensor. A Tensor of type float16, float32.
  1508. */
  1509. REG_OP(DeformableOffsets)
  1510. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1511. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1512. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1513. .REQUIRED_ATTR(strides, ListInt)
  1514. .REQUIRED_ATTR(pads, ListInt)
  1515. .REQUIRED_ATTR(ksize, ListInt)
  1516. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1517. .ATTR(data_format, String, "NCHW")
  1518. .ATTR(deformable_groups, Int, 1)
  1519. .ATTR(modulated, Bool, true)
  1520. .OP_END_FACTORY_REG(DeformableOffsets)
  1521. /**
  1522. *@brief Computes the gradients of DeformableOffsets with respect to input and offsets
  1523. *@par Inputs:
  1524. * Three inputs:
  1525. * @li grad: A Tensor of type float16,float32. gradients with respect to DeformableOffsets output
  1526. * @li x: A Tensor of type float16,float32.
  1527. * @li offsets: A Tensor of type float16,float32.Deformation offset parameter.
  1528. *@par Required Attributes:
  1529. * @li strides: A tuple/list of 4 integers.The stride of the sliding window for
  1530. * height and width for H/W dimension.
  1531. * @li pads: A tuple/list of 4 integers.Padding added to H/W dimension
  1532. * of the input.
  1533. * @li ksize: A tuple/list of 2 integers.kernel size.
  1534. *@par Attributes:
  1535. * Three attributes:
  1536. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1537. * of input. Defaults to [1, 1, 1, 1]
  1538. * @li data_format: An optional string from: "NCHW", "NHWC". Defaults to "NCHW". Specify the data format of the input x.
  1539. * @li deformable_groups: Specify the c-axis grouping number of input x.
  1540. * @li modulated: Specify version of DeformableConv2D, true means v2, false means v1.
  1541. *@par Outputs:
  1542. * grad_x: A Tensor of type float16, float32. Gradients with respect to input_x
  1543. * grad_offsets: A Tensor of type float16, float32. Gradients with respect to input_offsets
  1544. */
  1545. REG_OP(DeformableOffsetsGrad)
  1546. .INPUT(grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  1547. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1548. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1549. .OUTPUT(grad_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1550. .OUTPUT(grad_offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1551. .REQUIRED_ATTR(strides, ListInt)
  1552. .REQUIRED_ATTR(pads, ListInt)
  1553. .REQUIRED_ATTR(ksize, ListInt)
  1554. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1555. .ATTR(data_format, String, "NCHW")
  1556. .ATTR(deformable_groups, Int, 1)
  1557. .ATTR(modulated, Bool, true)
  1558. .OP_END_FACTORY_REG(DeformableOffsetsGrad)
  1559. /**
  1560. *@brief Computes the deformed dilation output with the expected input
  1561. *@par Inputs:
  1562. * One inputs:
  1563. * @li x: A Tensor of type int8, float16, float32
  1564. *@par Required Attributes:
  1565. * @li dilations: A tuple/list of integers.
  1566. *@par Attributes:
  1567. * Two attributes:
  1568. * @li padding_value: default value filling in blank
  1569. * @li pads: A tuple/list of integers.
  1570. *@par Outputs:
  1571. * y: A Tensor. A Tensor of type int8, float16, float32.
  1572. */
  1573. REG_OP(Dilation)
  1574. .INPUT(x, TensorType({DT_INT8, DT_FLOAT16, DT_FLOAT}))
  1575. .OUTPUT(y, TensorType({DT_INT8, DT_FLOAT16, DT_FLOAT}))
  1576. .REQUIRED_ATTR(dilations, ListInt)
  1577. .ATTR(pads, ListInt, {})
  1578. .ATTR(padding_value, Float, 0.0)
  1579. .OP_END_FACTORY_REG(Dilation)
  1580. } // namespace ge
  1581. #endif // OPS_BUILT_IN_OP_PROTO_INC_NN_CALCULATION_OPS_H_

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