You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

nn_calculation_ops.h 74 kB

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