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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
3 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
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 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
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654
  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, DT_FLOAT32}))
  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, DT_FLOAT32}))
  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 or int4, with shape [N, C, H, W] or [N, H, W, C]
  245. * @li filter: A 4D tensor of type float16 or int8 or int4, 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 or int4, 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, DT_INT4}))
  283. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8, DT_INT4}))
  284. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT}))
  285. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16, DT_INT8, DT_INT4}))
  286. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT}))
  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. *\n
  334. | Tensor | out_bckprop | filter | y |\n
  335. |-----------|-------------|---------|--------|\n
  336. | Data Type | float16 | float16 | float16|\n
  337. | | float32 | float32 | float32|\n
  338. | | float64 | float64 | float64|\n
  339. | Format | NCHW | NCHW | NCHW |\n
  340. | | NHWC | HWCN | NHWC |\n
  341. *\n
  342. * For float32 and float64 type, the actual calculation on the chip is based on
  343. * float16.
  344. *\n
  345. *
  346. *@par Attributes:
  347. * Five attributes:
  348. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  349. * for H/W dimension. The index of H/W is same as data_format.
  350. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads
  351. * on feature map
  352. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  353. * dimension of input, defaults to [1,1,1,1].
  354. * @li groups: Number of blocked connections from input channels to output
  355. * channels.
  356. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  357. * "NHWC". Specify the data format of the input and output data.
  358. *\n
  359. *\n
  360. * The following value range restrictions must be met:\n
  361. *\n
  362. *\n
  363. | Name | Field | Scope |\n
  364. |------------------|----------|--------------|\n
  365. | input_size | H | [1, 200000] |\n
  366. | | W | [1, 4096] |\n
  367. | Filter | H | [1, 255] |\n
  368. | | W | [1, 255] |\n
  369. | out_backprop | H*strideH| [1, 200000] |\n
  370. | | W*strideW| [1, 4096] |\n
  371. | y(fmap) | H | [1, 200000] |\n
  372. | | W | [1, 4096] |\n
  373. | Stride | H | [1, 63] |\n
  374. | | W | [1, 63] |\n
  375. | Padding | Top | [0, 255] |\n
  376. | | Bottom | [0, 255] |\n
  377. | | Left | [0, 255] |\n
  378. | | Right | [0, 255] |\n
  379. | Dilation | H | [1, 255] |\n
  380. | | W | [1, 255] |\n
  381. *\n
  382. * In Ascend910, fmap or out_backprop's H and W not support 1 when
  383. * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
  384. * and filter_width > fmap_width
  385. * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w < 4096
  386. *\n
  387. *
  388. *@par Outputs:
  389. * y: A Tensor. Has the same type as filter,and has same format as input_size.
  390. *\n
  391. * out_backprop_height = (fmap_height + pad_top + pad_bottom -
  392. * (dilation_h * (filter_height - 1) + 1))
  393. * / stride_h + 1
  394. *\n
  395. * out_backprop_width = (fmap_width + pad_left + pad_right -
  396. * (dilation_w * (filter_width - 1) + 1))
  397. * / stride_w + 1
  398. *\n
  399. *
  400. *@par Third-party framework compatibility
  401. * Compatible with Tensorflow's conv2d_backprop_input
  402. */
  403. REG_OP(Conv2DBackpropInput)
  404. .INPUT(input_size, TensorType({DT_INT32}))
  405. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  406. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  407. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  408. .REQUIRED_ATTR(strides, ListInt)
  409. .REQUIRED_ATTR(pads, ListInt)
  410. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  411. .ATTR(groups, Int, 1)
  412. .ATTR(data_format, String, "NHWC")
  413. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  414. /**
  415. *@brief Computes the gradients of convolution with respect to the input.
  416. *@par Inputs:
  417. * Two inputs:
  418. * @li filter: A Tensor. Types is float16.
  419. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  420. * or [out_channels, filter_height, filter_width, in_channels]
  421. * or [out_channels, in_channel, filter_height, filter_width].
  422. * @li out_backprop: A Tensor. Must have the same type as filter.
  423. * 4-D with shape [batch, out_height, out_width, out_channels]
  424. * or [batch, out_channels, out_height, out_width].
  425. * Gradients with respect to the output of the convolution.
  426. *@par Attributes:
  427. * Six attributes:
  428. * @li input_size A Tensor of type int32. An integer vector representing the
  429. * shape of input, where input is a 4-D tensor [batch, height, width, channels]
  430. * or [batch, channels, height, width].
  431. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  432. * for H/W dimension. The index of H/W is same as data_format.
  433. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  434. * feature map
  435. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  436. * dimension of input, defaults to [1,1,1,1].
  437. * @li groups: Number of blocked connections from input channels to output
  438. * channels.
  439. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  440. * "NHWC". Specify the data format of the input and output data.
  441. *@par Outputs:
  442. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width,
  443. * channels] or [batch, channels, height, width].
  444. *@par Third-party framework compatibility
  445. * Compatible with Tensorflow's conv2d_backprop_input
  446. *@par Restrictions:
  447. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropInput instead.
  448. */
  449. REG_OP(Conv2DBackpropInputD)
  450. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8, DT_BF16}))
  451. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8, DT_BF16}))
  452. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT32, DT_BF16}))
  453. .REQUIRED_ATTR(input_size, ListInt)
  454. .REQUIRED_ATTR(strides, ListInt)
  455. .REQUIRED_ATTR(pads, ListInt)
  456. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  457. .ATTR(groups, Int, 1)
  458. .ATTR(data_format, String, "NHWC")
  459. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  460. /**
  461. *@brief Computes the Deconvolution with respect to the input.
  462. *@par Inputs:
  463. * Two required inputs:
  464. * @li x: A Tensor of type float16 or int8. 4D with shape
  465. * [batch, out_channels, out_height, out_width]. Gradients with respect
  466. * to the output of the convolution.
  467. * @li filter: A Tensor. Must have the same type as "x".
  468. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  469. * Two optional inputs:
  470. * @li bias: An optional tensor. Must have the same type as "y".
  471. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  472. * Type is int8. Reserved.\n
  473. *\n
  474. *\n
  475. * The following are the supported data types and data formats:\n
  476. *\n
  477. *\n
  478. | Tensor | x | filter | bias | y |\n
  479. |-----------|---------|---------|---------|--------|\n
  480. | Data Type | float16 | float16 | float16 | float16|\n
  481. | | int8 | int8 | int32 | int32 |\n
  482. | Format | NCHW | NCHW | ND | NCHW |\n
  483. *\n
  484. * For int8, a dequant or requant operator must be followed.
  485. *\n
  486. *
  487. *@par Attributes:
  488. * Six attributes:
  489. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  490. * for H/W dimension, defaults to [1,1].
  491. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  492. * padding on the feature map, defaults to [0,0,0,0].
  493. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  494. * dimension of input, defaults to [1,1,1,1].
  495. * @li groups: Number of blocked connections from input channels to
  496. output channels. Defaults to "1".
  497. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  498. Specify the data format of the input and output data.
  499. * @li offset_x: An optional integer for quantized deconvolution.
  500. * The negative offset added to the input image for int8 type. Ensure offset_x
  501. * within the effective range of int8 [-128, 127]. Defaults to "0".
  502. *\n
  503. *\n
  504. * The following value range restrictions must be met:\n
  505. *\n
  506. *\n
  507. | Name | Field | Scope |\n
  508. |------------------|----------|--------------|\n
  509. | x (out_backprop) | H*strideH| [1, 200000] |\n
  510. | | W*strideW| [1, 4096] |\n
  511. | Filter | H | [1, 255] |\n
  512. | | W | [1, 255] |\n
  513. | y (fmap) | H | [1, 200000] |\n
  514. | | W | [1, 4096] |\n
  515. | Stride | H | [1, 63] |\n
  516. | | W | [1, 63] |\n
  517. | Padding | Top | [0, 255] |\n
  518. | | Bottom | [0, 255] |\n
  519. | | Left | [0, 255] |\n
  520. | | Right | [0, 255] |\n
  521. | Dilation | H | [1, 255] |\n
  522. | | W | [1, 255] |\n
  523. | Offset_x | | [-128, 127] |\n
  524. *\n
  525. * In Ascend910, fmap or out_backprop's H and W not support 1 when
  526. * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
  527. * and filter_width > fmap_width
  528. * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w < 4096
  529. *\n
  530. *
  531. *@par Outputs:
  532. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  533. *\n
  534. * out_backprop_height = (fmap_height + pad_top + pad_bottom -
  535. * (dilation_h * (filter_height - 1) + 1))
  536. * / stride_h + 1
  537. *\n
  538. * out_backprop_width = (fmap_width + pad_left + pad_right -
  539. * (dilation_w * (filter_width - 1) + 1))
  540. * / stride_w + 1
  541. *\n
  542. *
  543. * When type of x is float16, the type of y must be float16.
  544. * When type of x is int8, the type of y must be int32.
  545. */
  546. REG_OP(Deconvolution)
  547. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  548. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  549. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  550. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  551. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  552. .ATTR(strides, ListInt, {1, 1})
  553. .ATTR(pads, ListInt, {0, 0, 0, 0})
  554. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  555. .ATTR(groups, Int, 1)
  556. .ATTR(data_format, String, "NCHW")
  557. .ATTR(offset_x, Int, 0)
  558. .OP_END_FACTORY_REG(Deconvolution)
  559. /**
  560. *@brief Computes the gradients of convolution with respect to the filter
  561. *@par Inputs:
  562. * Three inputs:
  563. * @li x: A Tensor. Must be one of the following types: float16, float32,
  564. * float64.4-D with shape [batch, in_height, in_width, in_channels] or
  565. * [batch, in_channels, in_height, in_width].
  566. * @li filter_size: A const Tensor of type int32. Currently does not support
  567. * data tensor. An integer vector representing the tensor shape of filter,
  568. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  569. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  570. * or [out_channels, in_channel, filter_height, filter_width].
  571. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  572. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  573. * out_height, out_width]. Gradients with respect to the output of the
  574. * convolution.
  575. *\n
  576. *\n
  577. * The following are the supported data types and data formats:\n
  578. *\n
  579. *\n
  580. | Tensor | x | out_backprop | y |\n
  581. |-----------|---------|--------------|---------|\n
  582. | Data Type | float16 | float16 | float16 |\n
  583. | | float32 | float32 | float32 |\n
  584. | | float64 | float64 | float64 |\n
  585. | Format | NCHW | NCHW | NCHW |\n
  586. | | NHWC | NHWC | HWCN |\n
  587. *\n
  588. * For float32 and float64 type of x and outbackprop, the actual calculation on the chip
  589. * is based on float16.
  590. *\n
  591. *
  592. *@par Attributes:
  593. * Five attributes:
  594. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  595. * for H/W dimension. The index of H/W is same as data_format.
  596. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  597. * feature map.
  598. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  599. * dimension of input, defaults to [1,1,1,1].
  600. * @li groups: Number of blocked connections from input channels to output
  601. * channels.
  602. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  603. * "NHWC". Specify the data format of the input and output data.
  604. *\n
  605. *\n
  606. * The following value range restrictions must be met:\n
  607. *\n
  608. *\n
  609. | Name | Field | Scope |\n
  610. |------------------|----------|--------------|\n
  611. | x(fmap) | H | [1, 200000] |\n
  612. | | W | [1, 4096] |\n
  613. | Filter Size | H | [1, 255] |\n
  614. | | W | [1, 255] |\n
  615. | out_backprop | H | [1, 200000] |\n
  616. | | W | [1, 4096] |\n
  617. | y | H | [1, 200000] |\n
  618. | | W | [1, 4096] |\n
  619. | Stride | H | [1, 63] |\n
  620. | | W | [1, 63] |\n
  621. | Padding | Top | [0, 255] |\n
  622. | | Bottom | [0, 255] |\n
  623. | | Left | [0, 255] |\n
  624. | | Right | [0, 255] |\n
  625. | Dilation | H | [1, 255] |\n
  626. | | W | [1, 255] |\n
  627. *\n
  628. *@par Outputs:
  629. * y: A Tensor. Has the same type as x, has the same format as filter_size.
  630. *\n
  631. * out_backprop_height = (in_height + pad_top + pad_bottom -
  632. * (dilation_h * (filter_height - 1) + 1))
  633. * / stride_h + 1
  634. *\n
  635. * out_backprop_width = (in_width + pad_left + pad_right -
  636. * (dilation_w * (filter_width - 1) + 1))
  637. * / stride_w + 1
  638. *\n
  639. *
  640. *@par Third-party framework compatibility
  641. * Compatible with Tensorflow's conv2d_backprop_filter
  642. */
  643. REG_OP(Conv2DBackpropFilter)
  644. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  645. .INPUT(filter_size, TensorType({DT_INT32}))
  646. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  647. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  648. .REQUIRED_ATTR(strides, ListInt)
  649. .REQUIRED_ATTR(pads, ListInt)
  650. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  651. .ATTR(groups, Int, 1)
  652. .ATTR(data_format, String, "NHWC")
  653. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  654. /**
  655. *@brief Computes the gradients of convolution with respect to the filter.
  656. *@par Inputs:
  657. * Two inputs:
  658. * @li x: A Tensor. Type is float16.
  659. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch,
  660. * in_channels, in_height, in_width].
  661. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  662. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  663. * out_height, out_width]. Gradients with respect to the output of the
  664. * convolution.
  665. *@par Attributes:
  666. * Six attributes:
  667. * @li filter_size: A Tensor of type integers. An integer vector representing
  668. * the tensor shape of filter,
  669. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  670. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  671. * or [out_channels, in_channel, filter_height, filter_width].
  672. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  673. * for H/W dimension. The index of H/W is same as data_format.
  674. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  675. * feature map
  676. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  677. * dimension of input, defaults to [1,1,1,1].
  678. * @li groups: Number of blocked connections from input channels to output
  679. * channels.
  680. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  681. * "NHWC". Specify the data format of the input and output data.
  682. *@par Outputs:
  683. * y: A Tensor. Type is float32, a 4-D tensor [filter_height, filter_width,
  684. * in_channels, out_channels] or [out_channels, filter_height, filter_width,
  685. * in_channels] or [out_channels, in_channel, filter_height, filter_width].
  686. * Compatible with Tensorflow's conv2d_backprop_filter
  687. *@par Restrictions:
  688. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropFilter instead.
  689. */
  690. REG_OP(Conv2DBackpropFilterD)
  691. .INPUT(x, TensorType({DT_FLOAT16}))
  692. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  693. .OUTPUT(y, TensorType({DT_FLOAT}))
  694. .REQUIRED_ATTR(filter_size, ListInt)
  695. .REQUIRED_ATTR(strides, ListInt)
  696. .REQUIRED_ATTR(pads, ListInt)
  697. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  698. .ATTR(groups, Int, 1)
  699. .ATTR(data_format, String, "NHWC")
  700. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  701. /**
  702. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  703. *@par Inputs:
  704. *@li x: A 4D tensor of input image. With the format "NHWC", the data is stored
  705. * in the order of: [batch, in_height, in_width, in_channels].
  706. *@li filter: A 4D tensor of learnable filters. Must have the same type as "x".
  707. * With the format "HWCN" , the data is stored in the order of: [filter_height,
  708. * filter_width, in_channels / groups, out_channels].
  709. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  710. * The data is stored in the order of: [out_channels].
  711. *@li offset_w: Reserved.
  712. *\n
  713. *\n
  714. * The following are the supported data types and data formats:
  715. *\n
  716. *\n
  717. | Tensor | x | filter | bias | y |\n
  718. | :-------: | :-----: | :-----: | :-----: | :-----: |\n
  719. | Data Type | float16 | float16 | float16 | float16 |\n
  720. | | float32 | float32 | float32 | float32 |\n
  721. | | int8 | int8 | int32 | int32 |\n
  722. | Format | NCHW | NCHW | ND | NCHW |\n
  723. | | NHWC | HWCN | | NHWC |\n
  724. *\n
  725. * For float32 type, the actual calculation on the chip is based on
  726. * float16.
  727. *\n
  728. *
  729. *@par Attributes:
  730. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  731. * for each dimension of input. The dimension order is determined by the data
  732. * format of "x". The N and C dimensions must be set to 1.
  733. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  734. * (top, bottom, left, right) side of the input.
  735. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  736. * dimension of input. The dimension order is determined by the data format of
  737. * "x". The N and C dimensions must be set to 1. Defaults to [1, 1, 1, 1].
  738. *@li groups: Optional. An integer of type int32. The number of blocked
  739. * connections from input channels to output channels. In_channels and
  740. * out_channels must both be divisible by "groups". Defaults to 1.
  741. *@li offset_x: Optional. An integer of type int32. The negative offset added
  742. * to the input image for int8 type. Ensure that the output is within the
  743. * effective range. Defaults to 0.
  744. *@li data_format: Reserved.
  745. *\n
  746. *\n
  747. * The following value range restrictions must be met:
  748. *\n
  749. *\n
  750. | Name | Field | Scope |\n
  751. | :--------------: | :------: | :---------: |\n
  752. | Input Image Size | H | [1, 100000] |\n
  753. | | W | [1, 4096] |\n
  754. | Filter Size | H | [1, 255] |\n
  755. | | W | [1, 255] |\n
  756. | Stride | H | [1, 63] |\n
  757. | | W | [1, 63] |\n
  758. | Padding | Top | [0, 255] |\n
  759. | | Bottom | [0, 255] |\n
  760. | | Left | [0, 255] |\n
  761. | | Right | [0, 255] |\n
  762. | Dilation | H | [1, 255] |\n
  763. | | W | [1, 255] |\n
  764. | Offset_x | - | [-128, 127] |\n
  765. *\n
  766. * The W dimension of the input image supports cases exceeding 4096, but it may
  767. * cause compilation errors.
  768. *\n
  769. *
  770. *@par Outputs:
  771. * y: A 4D Tensor of output feature map. Has the same type as "x". With the
  772. * format "NHWC", the data is stored in the order of: [batch, out_height,
  773. * out_width, out_channels].
  774. *\n
  775. * out_height = (in_height + pad_top + pad_bottom -
  776. * (dilation_h * (filter_height - 1) + 1))
  777. * / stride_h + 1
  778. *\n
  779. * out_width = (in_width + pad_left + pad_right -
  780. * (dilation_w * (filter_width - 1) + 1))
  781. * / stride_w + 1
  782. *\n
  783. *
  784. *@par Quantization supported or not
  785. *@li Yes
  786. *
  787. *@par Third-party framework compatibility
  788. *@li Compatible with the TensorFlow operator "conv2d".
  789. *@li Compatible with the Caffe operator 2D "Convolution".
  790. */
  791. REG_OP(Conv2D)
  792. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_BF16}))
  793. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8, DT_BF16}))
  794. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  795. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  796. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32, DT_BF16}))
  797. .REQUIRED_ATTR(strides, ListInt)
  798. .REQUIRED_ATTR(pads, ListInt)
  799. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  800. .ATTR(groups, Int, 1)
  801. .ATTR(data_format, String, "NHWC")
  802. .ATTR(offset_x, Int, 0)
  803. .OP_END_FACTORY_REG(Conv2D)
  804. /**
  805. *@brief Computes a 2D convolution given 4D "x" and "filter_compress" tensors.
  806. *@par Inputs:
  807. *@li x: A 4D tensor of input images.
  808. *@li filter_compress: A 4D tensor of compressed filter data blocks.
  809. *@li compress_index: A 1D tensor of index for decompression.
  810. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  811. * The data is stored in the order of: [out_channels].
  812. *@li offset_w: Reserved.
  813. *\n
  814. *\n
  815. * The following are the supported data types and data formats:
  816. *\n
  817. *\n
  818. | Tensor | x | filter_compress | compress_index | bias | y |\n
  819. | :-------: | :-----: | :--------------: | :------------: | :-----: | :-----: |\n
  820. | Data Type | int8 | int8 | int8 | int32 | int32 |\n
  821. | Format | NCHW | NCHW | ND | ND | NCHW |\n
  822. | | NHWC | HWCN | | | NHWC |\n
  823. *\n
  824. * For float32 type, the actual calculation on the chip is based on
  825. * float16.
  826. *\n
  827. *
  828. *@par Attributes:
  829. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  830. * for each dimension of input. The dimension order is determined by the data
  831. * format of "x". The N and C dimensions must be set to 1.
  832. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  833. * (top, bottom, left, right) side of the input.
  834. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  835. * dimension of input. The dimension order is determined by the data format of
  836. * "x". The N and C dimensions must be set to 1. Defaults to [1, 1, 1, 1].
  837. *@li groups: Optional. An integer of type int32. The number of blocked
  838. * connections from input channels to output channels. In_channels and
  839. * out_channels must both be divisible by "groups". Only support 1.
  840. *@li offset_x: Optional. An integer of type int32. The negative offset added
  841. * to the input image for int8 type. Ensure that the output is within the
  842. * effective range. Defaults to 0.
  843. *@li data_format: Reserved.
  844. *
  845. *@par Outputs:
  846. * y: A 4D Tensor of output feature map. Has the same type as "x". With the
  847. * format "NHWC", the data is stored in the order of: [batch, out_height,
  848. * out_width, out_channels].
  849. *\n
  850. *
  851. *@par Restrictions:
  852. *Warning: THIS FUNCTION IS EXPERIMENTAL.
  853. */
  854. REG_OP(Conv2DCompress)
  855. .INPUT(x, TensorType({DT_INT8}))
  856. .INPUT(filter_compress, TensorType({DT_INT8}))
  857. .INPUT(compress_index, TensorType({DT_INT8}))
  858. .OPTIONAL_INPUT(bias, TensorType({DT_INT32}))
  859. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  860. .OUTPUT(y, TensorType({DT_INT32}))
  861. .REQUIRED_ATTR(strides, ListInt)
  862. .REQUIRED_ATTR(pads, ListInt)
  863. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  864. .ATTR(groups, Int, 1)
  865. .ATTR(data_format, String, "NHWC")
  866. .ATTR(offset_x, Int, 0)
  867. .OP_END_FACTORY_REG(Conv2DCompress)
  868. /**
  869. *@brief Computes a 2D deformable convolution given 4D "x", "filter" and
  870. * "offsets" tensors.
  871. *@par Inputs:
  872. *@li x: A 4D tensor of input image. With the format "NHWC", the data is stored
  873. * in the order of: [batch, in_height, in_width, in_channels].
  874. *@li filter: A 4D tensor of learnable filters. Must have the same type as "x".
  875. * With the format "HWCN" , the data is stored in the order of: [filter_height,
  876. * filter_width, in_channels / groups, out_channels].
  877. *@li offsets: A 4D tensor of x-y coordinates offset and mask. With the format
  878. * "NHWC", the data is stored in the order of: [batch, out_height, out_width,
  879. * deformable_groups * filter_height * filter_width * 3].
  880. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  881. * The data is stored in the order of: [out_channels].
  882. *\n
  883. *\n
  884. * The following are the supported data types and data formats:
  885. *\n
  886. *\n
  887. | Tensor | x | filter | offsets | bias | y |\n
  888. | :-------: | :-----: | :-----: | :-----: | :-----: | :-----: |\n
  889. | Data Type | float16 | float16 | float16 | float16 | float16 |\n
  890. | | float32 | float32 | float32 | float32 | float32 |\n
  891. | Format | NCHW | NCHW | NCHW | ND | NCHW |\n
  892. | | NHWC | HWCN | NCHW | | NHWC |\n
  893. *\n
  894. * For float32 type, the actual convolution calculation part on the chip is
  895. * based on float16.
  896. *\n
  897. *
  898. *@par Attributes:
  899. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  900. * for each dimension of input. The dimension order is interpreted according to
  901. * the data format of "x". The N and C dimensions must be set to 1.
  902. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  903. * (top, bottom, left, right) side of the input.
  904. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  905. * dimension of input. The dimension order is interpreted according to the data
  906. * format of "x". The N and C dimensions must be set to 1. Defaults to
  907. * [1, 1, 1, 1].
  908. *@li groups: Optional. An integer of type int32. The number of blocked
  909. * connections from input channels to output channels. In_channels and
  910. * out_channels must both be divisible by "groups". Defaults to 1.
  911. *@li data_format: Reserved.
  912. *@li deformable_groups: Optional. An integer of type int32. The number of
  913. * deformable group partitions. In_channels must be divisible by
  914. * "deformable_groups". Defaults to 1.
  915. *@li modulated: Optional. Specify version of DeformableConv2D, true means v2,
  916. * false means v1, currently only support v2.
  917. *\n
  918. *\n
  919. * The following value range restrictions must be met:
  920. *\n
  921. *\n
  922. | Name | Field | Scope |\n
  923. | :--------------: | :------: | :-------------------------: |\n
  924. | Input Image Size | H | [1, 100000 / filter_height] |\n
  925. | | W | [1, 4096 / filter_width] |\n
  926. | Filter Size | H | [1, 63] |\n
  927. | | W | [1, 63] |\n
  928. *\n
  929. *
  930. *@par Outputs:
  931. * y: A 4D Tensor of output feature map. Has the same type as "x". With the
  932. * format "NHWC", the data is stored in the order of: [batch, out_height,
  933. * out_width, out_channels].
  934. *\n
  935. * out_height = (in_height + pad_top + pad_bottom -
  936. * (dilation_h * (filter_height - 1) + 1))
  937. * / stride_h + 1
  938. *\n
  939. * out_width = (in_width + pad_left + pad_right -
  940. * (dilation_w * (filter_width - 1) + 1))
  941. * / stride_w + 1
  942. *\n
  943. *
  944. *@par Quantization supported or not
  945. *@li No
  946. *
  947. *@par Third-party framework compatibility
  948. *@li Compatible with the Mxnet operator "DeformableConvolution".
  949. *@li Compatible with the Paddlepaddle operator "deformable_conv".
  950. *@li Compatible with the Mmcv operator "deform_conv".
  951. */
  952. REG_OP(DeformableConv2D)
  953. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  954. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT}))
  955. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  956. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT}))
  957. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  958. .REQUIRED_ATTR(strides, ListInt)
  959. .REQUIRED_ATTR(pads, ListInt)
  960. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  961. .ATTR(groups, Int, 1)
  962. .ATTR(data_format, String, "NHWC")
  963. .ATTR(deformable_groups, Int, 1)
  964. .ATTR(modulated, Bool, true)
  965. .OP_END_FACTORY_REG(DeformableConv2D)
  966. /**
  967. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  968. *@par Inputs:
  969. * @li x: A 5D tensor. Must be one of the following types: float16,
  970. * (Currently does not support int8). The format of x is NCDHW or NDHWC.
  971. * @li filter: A 5D tensor of the same type as "x".
  972. * (Currently does not support int8).
  973. * The format is NCDHW, NDHWC or DHWCN.
  974. * @li bias: Optional. An 1D tensor of the same type as "x".
  975. * @li offset_w: Optional. An 1D tensor for quantized deconvolution. Reserved. \n
  976. *@par Attributes:
  977. * @li strides: Required. A list of 5 integers. Specifies the stride of the sliding window
  978. * for each dimension of "x".
  979. * The N and C dimensions must be 1. Has the same format as "x".
  980. * @li pads: Required. A list of 6 integers.
  981. * Supports only padding along the D, H and W dimensions in sequence of head,
  982. * tail, top, bottom, left and right.
  983. * @li dilations: Optional. A list of 5 integers. Specifies the dilation factor for each
  984. * dimension of "x".
  985. * @li groups: Optional. Number of blocked connections from input channels to output
  986. * channels.
  987. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  988. * Defaults to "NDHWC". Specify the data format of the input and output data.
  989. * The N, C and D dimensions must be 1. Has the same format as "x".
  990. * @li offset_x: Optional. An int. Input offset, used for quantized inference.
  991. * Defaults to 0. Reserved. \n
  992. *@par Outputs:
  993. * y: A Tensor. Has the same type and data format as "x". \n
  994. *@attention Constraints:
  995. * The image size after padding is greater than the filter size. \n
  996. *@par Third-party framework compatibility
  997. * @li Compatible with the TensorFlow operator conv3d.
  998. * @li Compatible with the Caffe operator Convolution.
  999. */
  1000. REG_OP(Conv3D)
  1001. .INPUT(x, TensorType({DT_FLOAT16}))
  1002. .INPUT(filter, TensorType({DT_FLOAT16}))
  1003. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1004. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1005. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1006. .REQUIRED_ATTR(strides, ListInt)
  1007. .REQUIRED_ATTR(pads, ListInt)
  1008. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1009. .ATTR(groups, Int, 1)
  1010. .ATTR(data_format, String, "NDHWC")
  1011. .ATTR(offset_x, Int, 0)
  1012. .OP_END_FACTORY_REG(Conv3D)
  1013. /**
  1014. *@brief Computes the gradients of convolution 3d with respect to the input.
  1015. *@par Inputs:
  1016. * @li input_size: A Tensor of type int32, int64. An integer vector representing
  1017. * the shape of input, where input is a 5-D tensor
  1018. * [batch, depth, height, width, channels] or
  1019. * [batch, channels, depth, height, width].
  1020. * @li filter: A Tensor. Must be one of the following types: float16, float32.
  1021. * Currently does not support double.
  1022. * @li out_backprop: A Tensor. Must have the same type as filter.
  1023. * 5-D with shape [batch, depth, out_height, out_width, out_channels]
  1024. * or [batch, out_channels, depth, out_height, out_width]. Gradients with
  1025. * respect to the output of the convolution. \n
  1026. *@par Attributes:
  1027. * @li strides: Required. A list of 5 integers. Specifies the stride of the sliding window
  1028. * for each dimension of "out_backprop".
  1029. * The N and C dimensions must be 1. Has the same format as "out_backprop".
  1030. * @li pads: Required. A list of 6 integers.
  1031. * Supports only padding along the D, H and W dimensions in sequence of head,
  1032. * tail, top, bottom, left and right.
  1033. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1034. * dimension of the input.
  1035. * The N, C and D dimensions must be 1. Has the same format as "out_backprop".
  1036. * @li groups: Optional. Number of blocked connections from input channels to output
  1037. * channels.
  1038. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1039. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1040. *@par Outputs:
  1041. * y: A Tensor. Has the same type as filter,and has same format as "input_size". \n
  1042. *@par Third-party framework compatibility
  1043. * Compatible with Tensorflow's conv3d_backprop_input
  1044. */
  1045. REG_OP(Conv3DBackpropInput)
  1046. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1047. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1048. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1049. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1050. .REQUIRED_ATTR(strides, ListInt)
  1051. .REQUIRED_ATTR(pads, ListInt)
  1052. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1053. .ATTR(groups, Int, 1)
  1054. .ATTR(data_format, String, "NDHWC")
  1055. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  1056. /**
  1057. *@brief Computes the gradients of convolution 3d with respect to the input.
  1058. *@par Inputs:
  1059. * @li filter: A Tensor whose type is float16. The format of filter is NCDHW,
  1060. * NDHWC or DHWCN.
  1061. * @li out_backprop: A Tensor. Must have the same type as filter. The format is
  1062. * NDHWC or NCDHW. \n
  1063. *@par Attributes:
  1064. * @li input_size: Required. A tuple/list of type int32, int64. An integer vector
  1065. * representing the shape of input, where input is a 5-D tensor
  1066. * [batch, depth, height, width, channels] or
  1067. * [batch, channels, depth, height, width].
  1068. * @li strides: Required. A list of 5 integers. Specifies the stride of the sliding window
  1069. * for each dimension of "out_backprop".
  1070. * The N and C dimensions must be 1. Has the same format as "out_backprop".
  1071. * @li pads: Required. A list of 6 integers. Supports only padding along the D, H and W
  1072. * dimensions in sequence of head, tail, top, bottom, left and right.
  1073. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1074. * dimension of input.
  1075. * The N, C and D dimensions must be 1. Has the same format as "out_backprop".
  1076. * @li groups: Optional. Number of blocked connections from input channels to output
  1077. * channels.
  1078. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1079. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1080. *@par Outputs:
  1081. * y: A Tensor. Has the same type and data format as "out_backprop". \n
  1082. *@par Third-party framework compatibility
  1083. * Compatible with Tensorflow's conv3d_backprop_input. \n
  1084. *@par Restrictions:
  1085. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropInput instead.
  1086. */
  1087. REG_OP(Conv3DBackpropInputD)
  1088. .INPUT(filter, TensorType({DT_FLOAT16}))
  1089. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  1090. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1091. .REQUIRED_ATTR(input_size, ListInt)
  1092. .REQUIRED_ATTR(strides, ListInt)
  1093. .REQUIRED_ATTR(pads, ListInt)
  1094. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1095. .ATTR(groups, Int, 1)
  1096. .ATTR(data_format, String, "NDHWC")
  1097. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  1098. /**
  1099. *@brief Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence . \n
  1100. *@par Inputs:
  1101. * @li x: A Tensor dtype of float16.
  1102. * @li cont: A Tensor dtype of float16, float32.
  1103. * @li w_x: A Tensor dtype of float16.
  1104. * @li bias: A Tensor dtype of int16, int32, float16, float32.
  1105. * @li w_h: A Tensor dtype of float16.
  1106. * @li x_static: A optinal Tensor dtype of float16.
  1107. * @li h_0: A optinal Tensor dtype of float16, float32.
  1108. * @li c_0: A optinal Tensor dtype of float16, float32.
  1109. * @li w_x_static: A optinal Tensor dtype of float16 . \n
  1110. *@par Attributes:
  1111. *@li num_output: A Scalar of output size dtype of int.
  1112. *@li expose_hidden: A Scalar(bool) of features hidden . \n
  1113. *@par Outputs:
  1114. *@li h: A Tensor dtype of float16, float32.
  1115. * @li h_t: A optinal Tensor dtype of float16, float32. The hidden state at time t.
  1116. * @li c_t: A optinal Tensor dtype of float16, float32. The cell state at time t . \n
  1117. *@par Third-party framework compatibility:
  1118. * Compatible with the Caffe operator LSTM.
  1119. */
  1120. REG_OP(LSTM)
  1121. .INPUT(x, TensorType({DT_FLOAT16}))
  1122. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  1123. .INPUT(w_x, TensorType({DT_FLOAT16}))
  1124. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  1125. .INPUT(w_h, TensorType({DT_FLOAT16}))
  1126. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  1127. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  1128. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  1129. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  1130. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  1131. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1132. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  1133. .ATTR(num_output, Int, 0)
  1134. .ATTR(expose_hidden, Bool, false)
  1135. .OP_END_FACTORY_REG(LSTM)
  1136. /**
  1137. *@brief Computes the gradients of convolution3D with respect to the filter
  1138. *@par Inputs:
  1139. * @li x: A Tensor. Must be one of the following types: float16, float32.
  1140. * Currently does not support double.
  1141. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  1142. * or [batch, in_channels, in_depth, in_height, in_width].
  1143. * @li filter_size: A Tensor of type int32. An integer vector representing the
  1144. * tensor shape of filter, where filter is a 5-D tensor
  1145. * [filter_depth, filter_height, filter_width, in_channels, out_channels]
  1146. * [out_channels, in_channels, filter_depth, filter_height, filter_width]
  1147. * or [out_channels, filter_depth, filter_height, filter_width, in_channels].
  1148. * @li out_backprop: A Tensor. Must have the same type as x.
  1149. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  1150. * or [batch, out_channels, out_depth, out_height, out_width].
  1151. * Gradients with respect to the output of the convolution. \n
  1152. *@par Attributes:
  1153. * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of the sliding
  1154. * window for each dimension of "x". The N and C dimensions must be 1.
  1155. * Has the same format as "x".
  1156. * @li pads: Required. A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  1157. * pads on feature map.
  1158. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1159. * dimension of input.
  1160. * The N, C and D dimensions must be 1. Has the same format as "x".
  1161. * @li groups: Optional. Number of blocked connections from input channels to output
  1162. * channels.
  1163. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1164. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1165. *@par Outputs:
  1166. * y: A Tensor that has the same type as "x" and the format is NDHWC, NCDHW or DHWCN. \n
  1167. *@par Third-party framework compatibility
  1168. * Compatible with Tensorflow's conv3d_backprop_filter
  1169. */
  1170. REG_OP(Conv3DBackpropFilter)
  1171. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1172. .INPUT(filter_size, TensorType({DT_INT32}))
  1173. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1174. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1175. .REQUIRED_ATTR(strides, ListInt)
  1176. .REQUIRED_ATTR(pads, ListInt)
  1177. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1178. .ATTR(groups, Int, 1)
  1179. .ATTR(data_format, String, "NDHWC")
  1180. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  1181. /**
  1182. *@brief Computes the gradients of convolution with respect to the filter.
  1183. *@par Inputs:
  1184. * @li x: A Tensor of type float16.
  1185. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  1186. * or [batch, in_channels, in_depth, in_height, in_width].
  1187. * @li out_backprop: A Tensor. Must have the same type as x.
  1188. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  1189. * or [batch, out_channels, out_depth, out_height, out_width].
  1190. * Gradients with respect to the output of the convolution. \n
  1191. *@par Attributes:
  1192. * @li filter_size: Required. A tuple/list of type integers. An integer vector
  1193. * representing the tensor shape of filter, where filter is a 5-D tensor
  1194. * [filter_depth, filter_height, filter_width, in_channels, out_channels],
  1195. * [out_channels, filter_depth, filter_height, filter_width, in_channels]
  1196. * or [out_channels, in_channels, filter_depth, filter_height, filter_width].
  1197. * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of the sliding
  1198. * window for each dimension of "x".
  1199. * The N and C dimensions must be 1. Has the same format as "x".
  1200. * @li pads: Required. A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  1201. * pads on feature map.
  1202. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1203. * dimension of input.
  1204. * The N, C and D dimensions must be 1. Has the same format as "x".
  1205. * @li groups: Optional. Number of blocked connections from input channels to output
  1206. * channels.
  1207. * @li data_format: Optional. An optional string from: "NDHWC", "NCDHW".
  1208. * Defaults to "NDHWC". Specify the data format of the input and output data. \n
  1209. *@par Outputs:
  1210. * y: A Tensor of type float32 and the format is NDHWC, NCDHW or DHWCN. \n
  1211. *@par Third-party framework compatibility
  1212. * Compatible with Tensorflow's conv3d_backprop_filter. \n
  1213. *@par Restrictions:
  1214. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropFilter instead.
  1215. */
  1216. REG_OP(Conv3DBackpropFilterD)
  1217. .INPUT(x, TensorType({DT_FLOAT16}))
  1218. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  1219. .OUTPUT(y, TensorType({DT_FLOAT}))
  1220. .REQUIRED_ATTR(filter_size, ListInt)
  1221. .REQUIRED_ATTR(strides, ListInt)
  1222. .REQUIRED_ATTR(pads, ListInt)
  1223. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1224. .ATTR(groups, Int, 1)
  1225. .ATTR(data_format, String, "NDHWC")
  1226. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  1227. /**
  1228. *@brief Computes the transpose of convolution 3d with respect to the input.
  1229. *@par Inputs:
  1230. * @li input_size: A Tensor of type int32. An integer vector representing the
  1231. * shape of input.
  1232. * @li x: A Tensor of type float16, currently does not support int8. The format
  1233. * is NDHWC or NCDHW.
  1234. * @li filter: A Tensor of type float16, currently does not support int8.
  1235. * The format is NDHWC, NCDHW or DHWCN.
  1236. * @li bias: Optional. An optional 1D tensor of the same type as "x". Reserved.
  1237. * @li offset_w: Optional. An optional 1D tensor for quantized deconvolution. Reserved. \n
  1238. *@par Attributes:
  1239. * @li strides: Required. A tuple/list of 5 integers. Specifies the stride of the sliding
  1240. * window for each dimension of "x".
  1241. * The N and C dimensions must be 1. Has the same format as "x".
  1242. * @li pads: Required. A tuple/list of 6 integers.
  1243. * @li dilations: Optional. A tuple/list of 5 integers,
  1244. * The dilation factor for each dimension of input.
  1245. * The N, C and D dimensions must be 1. Has the same format as "x".
  1246. * @li groups: Optional. Number of blocked connections from input channels to output
  1247. * channels.
  1248. * @li data_format: Optional. An string from: "NDHWC", "NCDHW".
  1249. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1250. * @li output_padding: Optional. The size will be added in the output shape.
  1251. * @li offset_x: Optional. Input offset_x value. Reserved. \n
  1252. *@par Outputs:
  1253. * y: A Tensor. Has the same type and format as "x".
  1254. */
  1255. REG_OP(Conv3DTranspose)
  1256. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1257. .INPUT(x, TensorType({DT_FLOAT16}))
  1258. .INPUT(filter, TensorType({DT_FLOAT16}))
  1259. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1260. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1261. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1262. .REQUIRED_ATTR(strides, ListInt)
  1263. .REQUIRED_ATTR(pads, ListInt)
  1264. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1265. .ATTR(groups, Int, 1)
  1266. .ATTR(data_format, String, "NDHWC")
  1267. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1268. .ATTR(offset_x, Int, 0)
  1269. .OP_END_FACTORY_REG(Conv3DTranspose)
  1270. /**
  1271. *@brief Computes the transpose of convolution 3d with respect to the input.
  1272. *@par Inputs:
  1273. * @li x: A Tensor of type float16, currently does not support int8.
  1274. * The format is NDHWC or NCDHW.
  1275. * @li filter: A Tensor of type float16, currently does not support int8.
  1276. * The format is NDHWC, NCDHW or DHWCN.
  1277. * @li bias: Optional. An 1D tensor of the same type as "x". Reserved.
  1278. * @li offset_w: Optional. An 1D tensor for quantized deconvolution. Reserved. \n
  1279. *@par Attributes:
  1280. * @li input_size: Required. A tuple/list of type int32.
  1281. * An integer vector representing the shape of input.
  1282. * @li strides: Required. A tuple/list of 5 integers.
  1283. * Specifies the stride of the sliding window for each dimension of "x".
  1284. * The N and C dimensions must be 1. Has the same format as "x".
  1285. * @li pads: Required. A tuple/list of 6 integers.
  1286. * @li dilations: Optional. A tuple/list of 5 integers, The dilation factor for each
  1287. * dimension of input.
  1288. * The N, C and D dimensions must be 1. Has the same format as "x".
  1289. * @li groups: Optional. Number of blocked connections from input channels to output
  1290. * channels.
  1291. * @li data_format: Optional. An optional string from: "NDHWC", "NCDHW".
  1292. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1293. * @li output_padding: Optional. The size will be added in the output shape.
  1294. * @li offset_x: Optional. Input offset_x value. Reserved. \n
  1295. *@par Outputs:
  1296. * y: A Tensor. Has the same type and format as "x". \n
  1297. *@par Restrictions:
  1298. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DTranspose instead.
  1299. */
  1300. REG_OP(Conv3DTransposeD)
  1301. .INPUT(x, TensorType({DT_FLOAT16}))
  1302. .INPUT(filter, TensorType({DT_FLOAT16}))
  1303. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1304. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1305. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT32}))
  1306. .REQUIRED_ATTR(input_size, ListInt)
  1307. .REQUIRED_ATTR(strides, ListInt)
  1308. .REQUIRED_ATTR(pads, ListInt)
  1309. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1310. .ATTR(groups, Int, 1)
  1311. .ATTR(data_format, String, "NDHWC")
  1312. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1313. .ATTR(offset_x, Int, 0)
  1314. .OP_END_FACTORY_REG(Conv3DTransposeD)
  1315. /**
  1316. *@brief Computes the transpose of convolution 2d with respect to the input.
  1317. *@par Inputs:
  1318. * Five inputs:
  1319. * @li input_size: A Tensor of type int32 or int64. An integer vector
  1320. * representing the shape of input, where input is a 4-D tensor
  1321. * [batch, height, width, channels] or [batch, channels, height, width].
  1322. * @li x: A Tensor of type float16, int8. 4-D with shape [batch, out_height,
  1323. * out_width, out_channels] or [batch, out_channels, out_height, out_width].
  1324. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1325. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  1326. * or [out_channels, filter_height, filter_width, in_channels]
  1327. * or [out_channels, in_channel, filter_height, filter_width].
  1328. * @li bias: An optional 1D tensor of type float16 or int32. Format is "ND".
  1329. * @li offset_w: An optional 1D tensor for quantized inference. Reserved.
  1330. *\n
  1331. *\n
  1332. * The following are the supported data types and data formats:\n
  1333. *\n
  1334. *\n
  1335. | Tensor | x | filter | bias | y |\n
  1336. |-----------|---------|---------|---------|--------|\n
  1337. | Data Type | float16 | float16 | float16 | float16|\n
  1338. | | int8 | int8 | int32 | int32 |\n
  1339. | Format | NCHW | NCHW | ND | NCHW |\n
  1340. | | NHWC | HWCN | | NHWC |\n
  1341. *\n
  1342. * For int8, a dequant or requant operator must be followed.
  1343. *\n
  1344. *
  1345. *@par Required Attributes:
  1346. * @li strides: A required tuple/list of 4 integers. The stride of the sliding
  1347. * window for H/W dimension. The index of H/W is same as data_format.
  1348. * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]
  1349. * pads on feature map.
  1350. *@par Attributes:
  1351. * Five attributes:
  1352. * @li groups: Number of blocked connections from input channels to output
  1353. * channels.
  1354. * Defaults to "1".
  1355. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  1356. * dimension of input. Must be [1, 1, 1, 1].
  1357. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1358. * Specify the data format of the input and output data.
  1359. * @li output_padding: The size will be added in the output shape. Defaults
  1360. * to [0, 0, 0, 0].
  1361. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1362. * The negative offset added to the input image for int8 type. Ensure offset_x
  1363. * within the effective range of int8 [-128, 127]. Defaults to "0".
  1364. *\n
  1365. *\n
  1366. * The following value range restrictions must be met:\n
  1367. *\n
  1368. *\n
  1369. | Name | Field | Scope |\n
  1370. |------------------|----------|--------------|\n
  1371. | input_size | H | [1, 200000] |\n
  1372. | | W | [1, 4096] |\n
  1373. | x (out_backprop) | H*strideH| [1, 200000] |\n
  1374. | | W*strideW| [1, 4096] |\n
  1375. | filter | H | [1, 255] |\n
  1376. | | W | [1, 255] |\n
  1377. | y (fmap) | H | [1, 200000] |\n
  1378. | | W | [1, 4096] |\n
  1379. | Stride | H | [1, 63] |\n
  1380. | | W | [1, 63] |\n
  1381. | Padding | Top | [0, 255] |\n
  1382. | | Bottom | [0, 255] |\n
  1383. | | Left | [0, 255] |\n
  1384. | | Right | [0, 255] |\n
  1385. | Dilation | H | [1, 255] |\n
  1386. | | W | [1, 255] |\n
  1387. | Offset_x | | [-128, 127] |\n
  1388. *\n
  1389. * In Ascend910, fmap or out_backprop's H and W not support 1 when
  1390. * fmap_h + pad_top + pad_bottom != (filter_height - 1) * dilation_h + 1
  1391. * and filter_width > fmap_width
  1392. * If filter_h = 1 and filter_w = 1, out_backprop_w * stride_h * stride_w < 4096
  1393. *\n
  1394. *
  1395. *@par Outputs:
  1396. * y: A Tensor. A Tensor of type float16 or int32, and has same format as
  1397. * input_size.
  1398. *\n
  1399. * out_backprop_height = (fmap_height + pad_top + pad_bottom -
  1400. * (dilation_h * (filter_height - 1) + 1))
  1401. * / stride_h + 1
  1402. *\n
  1403. * out_backprop_width = (fmap_width + pad_left + pad_right -
  1404. * (dilation_w * (filter_width - 1) + 1))
  1405. * / stride_w + 1
  1406. *\n
  1407. *
  1408. */
  1409. REG_OP(Conv2DTranspose)
  1410. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1411. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1412. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1413. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT32}))
  1414. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1415. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT32}))
  1416. .REQUIRED_ATTR(strides, ListInt)
  1417. .REQUIRED_ATTR(pads, ListInt)
  1418. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1419. .ATTR(groups, Int, 1)
  1420. .ATTR(data_format, String, "NHWC")
  1421. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1422. .ATTR(offset_x, Int, 0)
  1423. .OP_END_FACTORY_REG(Conv2DTranspose)
  1424. /**
  1425. *@brief Computes the transpose of convolution 2d with respect to the input.
  1426. *@par Inputs:
  1427. * Four inputs:
  1428. * @li x: A Tensor of type float16, int8.
  1429. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1430. * @li bias: An optional 1D tensor of the same type as "x".
  1431. * @li offset_w: An optional 1D tensor for quantized inference. Type is int8. Reserved.
  1432. *@par Required Attributes:
  1433. * @li input_size: A Tensor of type int32 or int64. An integer vector representing the
  1434. * shape of input.
  1435. * @li strides: A required list or tuple. The stride of the sliding window for
  1436. * height and width for H/W dimension.
  1437. * @li pads: A required list or tuple of int32. Padding added to each dimension
  1438. * of the input.
  1439. *@par Attributes:
  1440. * Five attributes:
  1441. * @li groups: Number of blocked connections from input channels to output channels.
  1442. * Defaults to "1".
  1443. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1444. * of input. Must be [1, 1, 1, 1].
  1445. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1446. * Specify the data format of the input and output data.
  1447. * @li output_padding: The size will be added in the output shape. Defaults
  1448. * to [0, 0, 0, 0].
  1449. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1450. * Defaults to "0".
  1451. *@par Outputs:
  1452. * y: A Tensor. Has the same type as "filter".
  1453. *@par Restrictions:
  1454. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DTranspose instead.
  1455. */
  1456. REG_OP(Conv2DTransposeD)
  1457. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1458. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1459. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT32}))
  1460. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1461. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32, DT_FLOAT32}))
  1462. .REQUIRED_ATTR(input_size, ListInt)
  1463. .REQUIRED_ATTR(strides, ListInt)
  1464. .REQUIRED_ATTR(pads, ListInt)
  1465. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1466. .ATTR(groups, Int, 1)
  1467. .ATTR(data_format, String, "NHWC")
  1468. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1469. .ATTR(offset_x, Int, 0)
  1470. .OP_END_FACTORY_REG(Conv2DTransposeD)
  1471. /**
  1472. *@brief Computes the deformed convolution output with the expected input
  1473. *@par Inputs:
  1474. * Two inputs:
  1475. * @li x: A Tensor of type float16,float32
  1476. * @li offsets: A Tensor of type float16,float32.Deformation offset parameter.
  1477. *@par Attributes:
  1478. * @li strides: A tuple/list of 4 integers.The stride of the sliding window for
  1479. * height and width for H/W dimension.
  1480. * @li pads: A tuple/list of 4 integers.Padding added to H/W dimension
  1481. * of the input.
  1482. * @li ksize: A tuple/list of 2 integers.kernel size.
  1483. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1484. * of input. Defaults to [1, 1, 1, 1]
  1485. * @li data_format: An optional string from: "NCHW", "NHWC". Defaults to "NCHW". Specify the data format of the input x.
  1486. * @li deformable_groups: Specify the c-axis grouping number of input x.
  1487. * @li modulated: Specify version of DeformableConv2D, true means v2, false means v1
  1488. *@par Outputs:
  1489. * y: A Tensor. A Tensor of type float16, float32.
  1490. */
  1491. REG_OP(DeformableOffsets)
  1492. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1493. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1494. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1495. .REQUIRED_ATTR(strides, ListInt)
  1496. .REQUIRED_ATTR(pads, ListInt)
  1497. .REQUIRED_ATTR(ksize, ListInt)
  1498. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1499. .ATTR(data_format, String, "NCHW")
  1500. .ATTR(deformable_groups, Int, 1)
  1501. .ATTR(modulated, Bool, true)
  1502. .OP_END_FACTORY_REG(DeformableOffsets)
  1503. /**
  1504. *@brief Computes the gradients of DeformableOffsets with respect to input and offsets
  1505. *@par Inputs:
  1506. * Three inputs:
  1507. * @li grad: A Tensor of type float16,float32. gradients with respect to DeformableOffsets output
  1508. * @li x: A Tensor of type float16,float32.
  1509. * @li offsets: A Tensor of type float16,float32.Deformation offset parameter.
  1510. *@par Attributes:
  1511. * @li strides: A tuple/list of 4 integers.The stride of the sliding window for
  1512. * height and width for H/W dimension.
  1513. * @li pads: A tuple/list of 4 integers.Padding added to H/W dimension
  1514. * of the input.
  1515. * @li ksize: A tuple/list of 2 integers.kernel size.
  1516. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1517. * of input. Defaults to [1, 1, 1, 1]
  1518. * @li data_format: An optional string from: "NCHW", "NHWC". Defaults to "NCHW". Specify the data format of the input x.
  1519. * @li deformable_groups: Specify the c-axis grouping number of input x.
  1520. * @li modulated: Specify version of DeformableConv2D, true means v2, false means v1.
  1521. *@par Outputs:
  1522. * @li grad_x: A Tensor of type float16, float32. Gradients with respect to input_x
  1523. * @li grad_offsets: A Tensor of type float16, float32. Gradients with respect to input_offsets
  1524. */
  1525. REG_OP(DeformableOffsetsGrad)
  1526. .INPUT(grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  1527. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1528. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1529. .OUTPUT(grad_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1530. .OUTPUT(grad_offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1531. .REQUIRED_ATTR(strides, ListInt)
  1532. .REQUIRED_ATTR(pads, ListInt)
  1533. .REQUIRED_ATTR(ksize, ListInt)
  1534. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1535. .ATTR(data_format, String, "NCHW")
  1536. .ATTR(deformable_groups, Int, 1)
  1537. .ATTR(modulated, Bool, true)
  1538. .OP_END_FACTORY_REG(DeformableOffsetsGrad)
  1539. /**
  1540. *@brief Computes the deformed dilation output with the expected input
  1541. *@par Inputs:
  1542. * One inputs:
  1543. * x: A Tensor of type int8, float16, float32
  1544. *@par Attributes:
  1545. * @li dilations: A tuple/list of integers.
  1546. * @li padding_value: default value filling in blank
  1547. * @li pads: A tuple/list of integers.
  1548. *@par Outputs:
  1549. * y: A Tensor. A Tensor of type int8, float16, float32.
  1550. */
  1551. REG_OP(Dilation)
  1552. .INPUT(x, TensorType({DT_INT8, DT_FLOAT16, DT_FLOAT}))
  1553. .OUTPUT(y, TensorType({DT_INT8, DT_FLOAT16, DT_FLOAT}))
  1554. .REQUIRED_ATTR(dilations, ListInt)
  1555. .ATTR(pads, ListInt, {})
  1556. .ATTR(padding_value, Float, 0.0)
  1557. .OP_END_FACTORY_REG(Dilation)
  1558. } // namespace ge
  1559. #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两部分组成,详细的架构图如下所示