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