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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
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
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. /**
  2. * Copyright 2019-2020 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. #ifndef GE_OP_NN_CALCULATION_OPS_H
  17. #define GE_OP_NN_CALCULATION_OPS_H
  18. #include "graph/operator_reg.h"
  19. namespace ge {
  20. /**
  21. * @brief Computes the gradients of depthwise convolution with respect to
  22. * the filter.
  23. * @par Inputs:
  24. * Three inputs include: \n
  25. * @li input: 4D origin shape of input tensor [N, C, H, W] or [N, H, W, C],
  26. * support float16, float32, double
  27. * @li filter_size: A 4D tensor of type int32, with shape [H, W, C, K]
  28. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  29. * Must be one of the following types: float16, float32, double.
  30. * @par Attributes:
  31. * @li strides: A required list or tuple. The stride of the sliding window
  32. * for height and width of input "x" of the convolution.
  33. * Must be with shape [1, 1, stride_height, stride_width] or
  34. * [1, stride_height, stride_width, 1].
  35. * @li dilations: An optional list or tuple. The dilation factor for each
  36. * dimension of input "x".
  37. * If set to k > 1, there will be k-1 skipped cells between each filter element
  38. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  39. * or [1, dilation_height, dilation_width, 1].
  40. * @li pads: A required list or tuple. Padding added to each dimension of the
  41. * input.
  42. * @li data_format: An optional string. Input data format, either "NHWC" or
  43. * "NCHW".
  44. * @par Outputs:
  45. * filter_grad: Gradient of the deep convolution relative to the filter with
  46. * shape [H, W, C, K]. Must be one of the following types: float16, float32,
  47. * double.
  48. * @attention Constraints:\n
  49. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  50. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  51. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  52. * [C1, Hf, Wf, K, Co, C0],
  53. * where K is fixed at 1, and Co and C0 are 16.\n
  54. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  55. * data is 5D with shape [N, C1, Ho, Wo, C0],
  56. * where C is the same as that of the feature map and C0 is 16.\n
  57. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  58. * stride_h + 32 * filter_h) * ceil(Wi, 16) <= l1_size and Hf*Wf <= l0b_size/512.
  59. * @par Third-party framework compatibility
  60. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropFilter.
  61. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropFilter.
  62. */
  63. REG_OP(DepthwiseConv2DBackpropFilter)
  64. .INPUT(input, TensorType({float16}))
  65. .INPUT(filter_size, TensorType({DT_INT32, DT_INT64}))
  66. .INPUT(out_backprop, TensorType({float16}))
  67. .OUTPUT(filter_grad, TensorType({float32}))
  68. .REQUIRED_ATTR(strides, ListInt)
  69. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  70. .REQUIRED_ATTR(pads, ListInt)
  71. .ATTR(data_format, String, "NHWC")
  72. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilter)
  73. /**
  74. * @brief Computes the gradients of depthwise convolution with respect to
  75. * the filter.
  76. * @par Inputs:
  77. * Two inputs include: \n
  78. * @li input: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of type float16
  79. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C],
  80. * of type float16
  81. * @par Attributes:
  82. * @li filter_size: A required list or tuple. Shape of filter.
  83. * @li strides: A required list or tuple. The stride of the sliding window for
  84. * height and width of input "x" of the convolution.
  85. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  86. * stride_width, 1].
  87. * @li dilations: An optional list or tuple. The dilation factor for each
  88. * dimension of input "x".
  89. * If set to k > 1, there will be k-1 skipped cells between each filter element
  90. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  91. * or [1, dilation_height, dilation_width, 1].
  92. * @li pads: A required list or tuple. Padding added to each dimension of the
  93. * input.
  94. * @li data_format: An optional string. Input data format, either "NHWC" or
  95. * "NCHW".
  96. * @par Outputs:
  97. * filter_grad: Gradient of the deep convolution relative to the filter with
  98. * shape [H, W, C, K]. Must be of type float32.
  99. * @attention Constraints:\n
  100. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  101. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  102. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  103. * [C1, Hf, Wf, K, Co, C0],
  104. * where K is fixed at 1, and Co and C0 are 16.\n
  105. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  106. * data is 5D with shape [N, C1, Ho, Wo, C0],
  107. * where C is the same as that of the feature map and C0 is 16.\n
  108. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  109. * stride_h + 32 * filter_h) * ceil(Wi, 16) <= l1_size and Hf*Wf <= l0b_size/512.
  110. * @par Third-party framework compatibility
  111. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropFilter.
  112. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropFilter.
  113. */
  114. REG_OP(DepthwiseConv2DBackpropFilterD)
  115. .INPUT(input, TensorType({float16}))
  116. .INPUT(out_backprop, TensorType({float16}))
  117. .OUTPUT(filter_grad, TensorType({float32}))
  118. .REQUIRED_ATTR(filter_size, ListInt)
  119. .REQUIRED_ATTR(strides, ListInt)
  120. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  121. .REQUIRED_ATTR(pads, ListInt)
  122. .ATTR(data_format, String, "NHWC")
  123. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilterD)
  124. /**
  125. * @brief Computes the gradients of depthwise convolution with respect to the
  126. * input.
  127. * @par Inputs:
  128. * Three inputs include: \n
  129. * @li input_size: 4D shape of input tensor [N, C, H, W] or [N, H, W, C],
  130. * support int32, int64
  131. * @li filter: 4D filter tensor with shape of [H, W, C, K], support float16.
  132. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  133. * Must be one of the following types: float16.
  134. * @par Attributes:
  135. * @li strides: A required list or tuple of int32. The stride of the sliding window for
  136. * height and width of input "x" of the convolution.
  137. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  138. * stride_width, 1].
  139. * @li dilations: An optional list or tuple of int32. The dilation factor for each
  140. * dimension of input "x". Defaults to "[1, 1, 1, 1]".
  141. * If set to k > 1, there will be k-1 skipped cells between each filter element
  142. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  143. * or [1, dilation_height, dilation_width, 1].
  144. * @li pads: A required list or tuple of int32. Padding added to each dimension of the
  145. * input.
  146. * @li data_format: An optional string. Input data format, either "NHWC" or
  147. * "NCHW". Defaults to "NHWC".
  148. * @par Outputs:
  149. * input_grad: Gradient of the deep convolution relative to the input with shape
  150. * [N, C, H, W] or [N, H, W, C] Must be one of the following types: float16.
  151. * @attention Constraints:\n
  152. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  153. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  154. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  155. * [C1, Hf, Wf, K, Co, C0],
  156. * where K is fixed at 1, and Co and C0 are 16.\n
  157. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  158. * data is 5D with shape [N, C1, Ho, Wo, C0],
  159. * where C is the same as that of the feature map and C0 is 16.\n
  160. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  161. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  162. * @par Third-party framework compatibility
  163. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  164. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  165. */
  166. REG_OP(DepthwiseConv2DBackpropInput)
  167. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  168. .INPUT(filter, TensorType({DT_FLOAT16}))
  169. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  170. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  171. .REQUIRED_ATTR(strides, ListInt)
  172. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  173. .REQUIRED_ATTR(pads, ListInt)
  174. .ATTR(data_format, String, "NHWC")
  175. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInput)
  176. /**
  177. * @brief Computes the gradients of depthwise convolution with respect to the
  178. * input.
  179. * @par Inputs:
  180. * Two inputs include: \n
  181. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  182. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of
  183. * type float16
  184. * @par Attributes:
  185. * @li input_size: A required list or tuple. The origin shape of input.
  186. * @li strides: A required list or tuple. The stride of the sliding window for
  187. * height and width of input "x" of the convolution.
  188. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  189. * stride_width, 1].
  190. * @li dilations: An optional list or tuple. The dilation factor for each
  191. * dimension of input "x".
  192. * If set to k > 1, there will be k-1 skipped cells between each filter element
  193. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  194. * or [1, dilation_height, dilation_width, 1].
  195. * @li pads: A required list or tuple. Padding added to each dimension of the
  196. * input.
  197. * @li data_format: An optional string. Input data format, either "NHWC" or
  198. * "NCHW".
  199. * @par Outputs:
  200. * input_grad: Gradient of the deep convolution relative to the input with
  201. * shape [N, C, H, W] or [N, H, W, C]. Must be of type float16.
  202. * @attention Constraints:\n
  203. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  204. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  205. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  206. * [C1, Hf, Wf, K, Co, C0],
  207. * where K is fixed at 1, and Co and C0 are 16.\n
  208. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  209. * data is 5D with shape [N, C1, Ho, Wo, C0],
  210. * where C is the same as that of the feature map and C0 is 16.\n
  211. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  212. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  213. * @par Third-party framework compatibility
  214. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  215. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  216. */
  217. REG_OP(DepthwiseConv2DBackpropInputD)
  218. .INPUT(filter, TensorType({DT_FLOAT16}))
  219. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  220. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  221. .REQUIRED_ATTR(input_size, ListInt)
  222. .REQUIRED_ATTR(strides, ListInt)
  223. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  224. .REQUIRED_ATTR(pads, ListInt)
  225. .ATTR(data_format, String, "NHWC")
  226. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInputD)
  227. /**
  228. *@brief Computes a 2D deep convolution given a 4D input tensor and a filter
  229. * tensor.
  230. *@par Inputs:
  231. *Two required inputs and two optional inputs, including: \n
  232. * @li x: A 4D tensor of type float16 or int8, with shape [N, C, H, W] or [N, H, W, C]
  233. * @li filter: A 4D tensor of type float16 or int8, with shape [H, W, C, K]
  234. * @li bias: An optional tensor of type float16 or int32
  235. * @li offset_w: An optional float16 or int8, used for quantized inference
  236. * @par Attributes:
  237. * @li strides: A required list or tuple. The stride of the sliding window for
  238. * height and width of input "x" of the convolution.
  239. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  240. * stride_width, 1].
  241. * @li dilations: An optional list or tuple. The dilation factor for each
  242. * dimension of input "x".
  243. * If set to k > 1, there will be k-1 skipped cells between each filter element
  244. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  245. * or [1, dilation_height, dilation_width, 1]. Defaults to "[1, 1, 1, 1]".
  246. * @li pads: A required list or tuple of int32. Padding added to each dimension of the
  247. * input.
  248. * @li data_format: An optional string. Input data format, either "NHWC" or
  249. * "NCHW". Defaults to "NHWC".
  250. * @li offset_x: An optional int. Input offset, used for quantized inference.
  251. * Defaults to 0.
  252. * @par Outputs:
  253. * y: 4D tensor of type float16 or int32, with shape [N, C, H, W] or [N, H, W, C]
  254. * @attention Constraints:\n
  255. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  256. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  257. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  258. * [C1, Hf, Wf, K, Co, C0],
  259. * where K is fixed at 1, and Co and C0 are 16.\n
  260. * Limited by the size of L1 buffer memory: \n
  261. * (l1_size - filter_h*filter_w*BLOCK_SIZE*BLOCK_SIZE*data_size) // (Wi *
  262. * BLOCK_SIZE * data_size) >= (BLOCK_SIZE * strides_h + filter_h - strides_h).\n
  263. * @par Quantization supported or not
  264. * Yes
  265. * @par Third-party framework compatibility
  266. * @li Compatible with the TensorFlow operator DepthwiseConv2D.
  267. * @li Compatible with the Caffe operator DepthwiseConv2D.
  268. */
  269. REG_OP(DepthwiseConv2D)
  270. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  271. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  272. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  273. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16, DT_INT8}))
  274. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  275. .REQUIRED_ATTR(strides, ListInt)
  276. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  277. .REQUIRED_ATTR(pads, ListInt)
  278. .ATTR(data_format, String, "NHWC")
  279. .ATTR(offset_x, Int, 0)
  280. .OP_END_FACTORY_REG(DepthwiseConv2D)
  281. /**
  282. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  283. * It accumulates all the values from out_backprop into the feature
  284. * dimension. For NHWC data format, the feature dimension is the last.
  285. * For NCHW data format, the feature dimension is the third-to-last.
  286. *@par Inputs:
  287. *x: A Tensor of type NumberType.
  288. *@par Attributes:
  289. *data_format: Data format. Defaults to "NHWC".
  290. *@par Outputs:
  291. *y: A Tensor.Has the same type as "x".
  292. *@par Third-party framework compatibility
  293. * Compatible with the TensorFlow operator BiasAddGrad.
  294. */
  295. REG_OP(BiasAddGrad)
  296. .INPUT(x, TensorType::NumberType())
  297. .OUTPUT(y, TensorType::NumberType())
  298. .ATTR(data_format, String, "NHWC")
  299. .OP_END_FACTORY_REG(BiasAddGrad)
  300. /**
  301. *@brief Computes the gradients of convolution with respect to the input.
  302. *@par Inputs:
  303. * Three inputs:
  304. * @li input_size: A Tensor of type int32. An integer vector representing the shape of input,
  305. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  306. * @li filter: A Tensor. Must be one of the following types: float16, float32, float64.
  307. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  308. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  309. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  310. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  311. *@par Attributes:
  312. * Five attributes:
  313. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  314. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  315. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  316. * @li groups: Number of blocked connections from input channels to output channels.
  317. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  318. *@par Outputs:
  319. * y: A Tensor. Has the same type as filter,and has same format as input_size
  320. *@par Third-party framework compatibility
  321. * Compatible with Tensorflow's conv2d_backprop_input
  322. */
  323. REG_OP(Conv2DBackpropInput)
  324. .INPUT(input_size, TensorType({DT_INT32}))
  325. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  326. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  327. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  328. .REQUIRED_ATTR(strides, ListInt)
  329. .REQUIRED_ATTR(pads, ListInt)
  330. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  331. .ATTR(groups, Int, 1)
  332. .ATTR(data_format, String, "NHWC")
  333. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  334. /**
  335. *@brief Computes the gradients of convolution with respect to the input.
  336. *@par Inputs:
  337. * Two inputs:
  338. * @li filter: A Tensor. Types is float16.
  339. * 4-D with shape [filter_height, filter_width, in_channels, out_channels] or [out_channels, filter_height, filter_width, in_channels]
  340. * or [out_channels, in_channel, filter_height, filter_width].
  341. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  342. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  343. *@par Attributes:
  344. * Six attributes:
  345. * @li input_size A Tensor of type int32. An integer vector representing the shape of input,
  346. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  347. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  348. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  349. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  350. * @li groups: Number of blocked connections from input channels to output channels.
  351. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  352. *@par Outputs:
  353. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  354. *@par Third-party framework compatibility
  355. * Compatible with Tensorflow's conv2d_backprop_input
  356. */
  357. REG_OP(Conv2DBackpropInputD)
  358. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  359. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  360. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  361. .REQUIRED_ATTR(input_size, ListInt)
  362. .REQUIRED_ATTR(strides, ListInt)
  363. .REQUIRED_ATTR(pads, ListInt)
  364. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  365. .ATTR(groups, Int, 1)
  366. .ATTR(data_format, String, "NHWC")
  367. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  368. /**
  369. *@brief Computes the Deconvolution with respect to the input.
  370. *@par Inputs:
  371. * Three inputs:
  372. * @li x: A Tensor of type float16 or int8. 4D with shape
  373. * [batch, out_channels, out_height, out_width]. Gradients with respect
  374. * to the output of the convolution.
  375. * @li filter: A Tensor. Must have the same type as "x".
  376. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  377. * Two optional inputs:
  378. * @li bias: An optional tensor. Must have the same type as "y".
  379. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  380. * Type is int8. Reserved.\n
  381. *@par Attributes:
  382. * Six attributes:
  383. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  384. * for H/W dimension.
  385. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  386. * padding on the feature map.
  387. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  388. * dimension of input. Must be [1, 1, 1, 1].
  389. * @li groups: Number of blocked connections from input channels to
  390. output channels. Defaults to "1".
  391. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  392. Specify the data format of the input and output data.
  393. * @li offset_x: An optional integer for quantized deconvolution. Defaults to "0".
  394. *@par Outputs:
  395. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  396. * When type of x is float16, the type of y must be float16.
  397. * When type of x is int8, the type of y must be int32.
  398. */
  399. REG_OP(Deconvolution)
  400. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  401. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  402. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  403. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  404. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  405. .REQUIRED_ATTR(strides, ListInt)
  406. .REQUIRED_ATTR(pads, ListInt)
  407. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  408. .ATTR(groups, Int, 1)
  409. .ATTR(data_format, String, "NCHW")
  410. .ATTR(offset_x, Int, 0)
  411. .OP_END_FACTORY_REG(Deconvolution)
  412. /**
  413. *@brief Computes the gradients of convolution with respect to the filter
  414. *@par Inputs:
  415. * Three inputs:
  416. * @li x: A Tensor. Must be one of the following types: float16, float32, float64.
  417. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  418. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  419. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  420. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  421. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  422. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  423. *@par Attributes:
  424. * Five attributes:
  425. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  426. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map.
  427. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  428. * @li groups: Number of blocked connections from input channels to output channels.
  429. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  430. *@par Outputs:
  431. * y: A Tensor. Has the same type as x
  432. *@par Third-party framework compatibility
  433. * Compatible with Tensorflow's conv2d_backprop_filter
  434. */
  435. REG_OP(Conv2DBackpropFilter)
  436. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  437. .INPUT(filter_size, TensorType({DT_INT32}))
  438. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  439. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  440. .REQUIRED_ATTR(strides, ListInt)
  441. .REQUIRED_ATTR(pads, ListInt)
  442. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  443. .ATTR(groups, Int, 1)
  444. .ATTR(data_format, String, "NHWC")
  445. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  446. /**
  447. *@brief Computes the gradients of convolution with respect to the filter.
  448. *@par Inputs:
  449. * Two inputs:
  450. * @li x: A Tensor. Type is float16.
  451. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  452. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  453. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  454. *@par Attributes:
  455. * Six attributes:
  456. * @li filter_size: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  457. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  458. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  459. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  460. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  461. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  462. * @li groups: Number of blocked connections from input channels to output channels.
  463. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  464. *@par Outputs:
  465. * y: A Tensor. Type is float32
  466. *@par Third-party framework compatibility
  467. * Compatible with Tensorflow's conv2d_backprop_filter
  468. */
  469. REG_OP(Conv2DBackpropFilterD)
  470. .INPUT(x, TensorType({DT_FLOAT16}))
  471. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  472. .OUTPUT(y, TensorType({DT_FLOAT}))
  473. .REQUIRED_ATTR(filter_size, ListInt)
  474. .REQUIRED_ATTR(strides, ListInt)
  475. .REQUIRED_ATTR(pads, ListInt)
  476. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  477. .ATTR(groups, Int, 1)
  478. .ATTR(data_format, String, "NHWC")
  479. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  480. /**
  481. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  482. *@par Inputs:
  483. * @li x: A 4D tensor of input images.
  484. * @li filter: A 4D tensor of filters.
  485. * @li bias: An optional 1D tensor.
  486. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.
  487. *
  488. * The input and output tensor attributes are listed as follows:
  489. * @verbatim
  490. |Tensor | x | filter | bias | offset_w | y
  491. -----------|---------|---------|---------|----------|--------
  492. |Data Type | float16 | float16 | float16 | _ | float16
  493. | |---------|---------|---------|----------|--------
  494. | | float32 | float32 | float32 | _ | float32
  495. | |---------|---------|---------|----------|--------
  496. | | int8 | int8 | int32 | int8 | int32
  497. -----------|---------|---------|---------|----------|--------
  498. |Format | NCHW | NCHW | ND | ND | NCHW
  499. | | NHWC | NHWC | | | NHWC
  500. | | | HWCN | | |
  501. @endverbatim
  502. * It should be noted that the data types must correspond to each other, but the
  503. * format does not need to.
  504. *@par Attributes:
  505. * @li strides: A list of 4 integers. Specifying the strides of the
  506. * convolution along the height and width. The dimension order is determined
  507. * by the data format of "x". By default the N and C dimensions are set to 1.
  508. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  509. * padding.
  510. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  511. * for dilated convolution. Has the same dimension order and value as "strides".
  512. * @li groups: Number of blocked connections from input channels to output
  513. * channels. Input channels and output channels must both be divisible by
  514. * "groups".Type is int32.
  515. * @li offset_x: An optional integer for quantized convolution. Type is int32. Defaults to "0".
  516. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  517. * data format of the input and output images. Type is string. Defaults to "NHWC". Reserved.
  518. *@par Outputs:
  519. * @li y: A 4D Tensor of output images.
  520. *@attention
  521. * @li The parameter scope is listed as follows:
  522. * @verbatim
  523. |Name | Field | Scope
  524. ------------------|--------------|----------
  525. |Input Image Size | H dimension | [1, 4096]
  526. | | W dimension | [1, 4096]
  527. ------------------|--------------|----------
  528. |Filter Size | H dimension | [1, 255]
  529. | | W dimension | [1, 255]
  530. ------------------|--------------|----------
  531. |Stride Size | H dimension | [1, 63]
  532. | | W dimension | [1, 63]
  533. ------------------|--------------|----------
  534. |Padding Size | top side | [0, 255]
  535. | | bottom side | [0, 255]
  536. | | left side | [0, 255]
  537. | | right side | [0, 255]
  538. ------------------|--------------|----------
  539. |Dilation Size | H dimension | [1, 255]
  540. | W dimension | [1, 255]
  541. @endverbatim
  542. * @li There are restrictions for certain scenarios:
  543. * @verbatim
  544. Output | Restrictions
  545. ------------------|----------------------------------------------
  546. W dimension == 1 | HxW(input) == HxW(filter)
  547. H dimension == 1 |
  548. ------------------|----------------------------------------------
  549. W dimension == 1 | Not supported
  550. H dimension != 1 |
  551. @endverbatim
  552. * As shown above, "HxW(input)" indicates the image size after padding and
  553. * "HxW(filter)" indicates the filter size after dilation.
  554. *@par Quantization supported or not
  555. * Yes
  556. *@par Third-party framework compatibility
  557. *@li Compatible with the TensorFlow operator "conv2d".
  558. *@li Compatible with the Caffe operator 2D "Convolution".
  559. */
  560. REG_OP(Conv2D)
  561. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  562. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  563. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  564. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  565. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  566. .REQUIRED_ATTR(strides, ListInt)
  567. .REQUIRED_ATTR(pads, ListInt)
  568. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  569. .ATTR(groups, Int, 1)
  570. .ATTR(data_format, String, "NHWC")
  571. .ATTR(offset_x, Int, 0)
  572. .OP_END_FACTORY_REG(Conv2D)
  573. REG_OP(Conv2DCompress)
  574. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  575. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  576. .INPUT(compress_index, TensorType({DT_INT8}))
  577. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  578. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  579. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  580. .REQUIRED_ATTR(strides, ListInt)
  581. .REQUIRED_ATTR(pads, ListInt)
  582. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  583. .ATTR(groups, Int, 1)
  584. .ATTR(data_format, String, "NHWC")
  585. .ATTR(offset_x, Int, 0)
  586. .OP_END_FACTORY_REG(Conv2DCompress)
  587. /**
  588. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  589. *@par Inputs:
  590. * @li x: A 5D tensor. Must be one of the following types: float16, (Currently does not support int8).
  591. * The format of x is NCDHW or NDHWC.
  592. * @li filter: A 5D tensor of the same type as "x". The format is NCDHW, NDHWC or DHWCN.
  593. *@par Optional input:
  594. * @li bias: An optional 1D tensor of the same type as "x".
  595. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  596. *@par Required Attributes:
  597. * @li strides: A list of 5 integers. Specifies the stride of the sliding window for each dimension of "x".
  598. * The N and C dimensions must be 1. Has the same format as "x".
  599. * @li pads: A list of 6 integers. Supports only padding along the D, H and W dimensions in sequence of head, tail, top, bottom, left and right.
  600. *@par Attributes:
  601. * @li groups: Number of blocked connections from input channels to output channels.
  602. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  603. * @li dilations: A list of 5 integers. Specifies the dilation factor for each dimension of "x".
  604. * The N and C dimensions must be 1. Has the same format as "x".
  605. * @li offset_x: An optional int. Input offset, used for quantized inference. Defaults to 0.
  606. *@par Outputs:
  607. *y: A Tensor. Has the same type as "x".
  608. *@attention Constraints:
  609. *The image size after padding is greater than the filter size.
  610. *@par Third-party framework compatibility
  611. * @li Compatible with the TensorFlow operator conv3d.
  612. * @li Compatible with the Caffe operator Convolution.
  613. */
  614. REG_OP(Conv3D)
  615. .INPUT(x, TensorType({DT_FLOAT16}))
  616. .INPUT(filter, TensorType({DT_FLOAT16}))
  617. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  618. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  619. .OUTPUT(y, TensorType({DT_FLOAT16}))
  620. .REQUIRED_ATTR(strides, ListInt)
  621. .REQUIRED_ATTR(pads, ListInt)
  622. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  623. .ATTR(groups, Int, 1)
  624. .ATTR(data_format, String, "NDHWC")
  625. .ATTR(offset_x, Int, 0)
  626. .OP_END_FACTORY_REG(Conv3D)
  627. /**
  628. *@brief Computes the gradients of convolution 3d with respect to the input.
  629. *@par Inputs:
  630. * Three inputs:
  631. * @li input_size: A Tensor of type int32, int64. An integer vector representing the shape of input,
  632. * where input is a 5-D tensor [batch, depth, height, width, channels] or [batch, channels, depth, height, width].
  633. * @li filter: A Tensor. Must be one of the following types: float16, float32, float64.
  634. * @li out_backprop: A Tensor. Must have the same type as filter. 5-D with shape [batch, depth, out_height, out_width, out_channels]
  635. * or [batch, out_channels, depth, out_height, out_width]. Gradients with respect to the output of the convolution.
  636. *@par Required Attributes:
  637. * @li strides: A list of 5 integers. Specifies the stride of the sliding window for each dimension of "x".
  638. * The N and C dimensions must be 1. Has the same format as "x".
  639. * @li pads: A list of 6 integers. Supports only padding along the D, H and W dimensions in sequence of head, tail, top, bottom, left and right.
  640. *@par Attributes:
  641. * Three attributes:
  642. * @li groups: Number of blocked connections from input channels to output channels.
  643. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  644. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of the input, now only support [1,1,1,1,1]
  645. *@par Outputs:
  646. * y: A Tensor. Has the same type as filter,and has same format as input_size
  647. *@par Third-party framework compatibility
  648. * Compatible with Tensorflow's conv3d_backprop_input
  649. */
  650. REG_OP(Conv3DBackpropInput)
  651. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  652. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  653. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  654. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  655. .REQUIRED_ATTR(strides, ListInt)
  656. .REQUIRED_ATTR(pads, ListInt)
  657. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  658. .ATTR(groups, Int, 1)
  659. .ATTR(data_format, String, "NDHWC")
  660. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  661. /**
  662. *@brief Computes the gradients of convolution 3d with respect to the input.
  663. *@par Inputs:
  664. * Two inputs:
  665. * @li filter: A Tensor whose type is float16.
  666. * @li out_backprop: A Tensor. Must have the same type as filter.
  667. *@par Required Attributes:
  668. * @li strides: A list of 5 integers. Specifies the stride of the sliding window for
  669. * each dimension of "x". The N and C dimensions must be 1. Has the same format as "x".
  670. * @li pads: A list of 6 integers. Supports only padding along the D, H and W
  671. * dimensions in sequence of head, tail, top, bottom, left and right.
  672. * @li input_size: A tuple/list of type int32, int64. An integer vector representing the shape of input,
  673. * where input is a 5-D tensor [batch, depth, height, width, channels] or [batch, channels, depth, height, width].
  674. *@par Attributes:
  675. * Three attributes:
  676. * @li groups: Number of blocked connections from input channels to output channels.
  677. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  678. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  679. *@par Outputs:
  680. * y: A Tensor. Has the same type as filter
  681. *@par Third-party framework compatibility
  682. * Compatible with Tensorflow's conv3d_backprop_input
  683. */
  684. REG_OP(Conv3DBackpropInputD)
  685. .INPUT(filter, TensorType({DT_FLOAT16}))
  686. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  687. .OUTPUT(y, TensorType({DT_FLOAT16}))
  688. .REQUIRED_ATTR(input_size, ListInt)
  689. .REQUIRED_ATTR(strides, ListInt)
  690. .REQUIRED_ATTR(pads, ListInt)
  691. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  692. .ATTR(groups, Int, 1)
  693. .ATTR(data_format, String, "NDHWC")
  694. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  695. /**
  696. *@brief Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence..
  697. *@par Inputs:
  698. * @li x: A Tensor dtype of float16.
  699. * @li cont: A Tensor dtype of float16, float32.
  700. * @li w_x: A Tensor dtype of float16.
  701. * @li bias: A Tensor dtype of int16, int32, float16, float32.
  702. * @li w_h: A Tensor dtype of float16.
  703. * @li x_static: A optinal Tensor dtype of float16.
  704. * @li h_0: A optinal Tensor dtype of float16, float32.
  705. * @li c_0: A optinal Tensor dtype of float16, float32.
  706. * @li w_x_static: A optinal Tensor dtype of float16.
  707. *@par Attributes:
  708. *@li num_output: A Scalar of output size dtype of int.
  709. *@li expose_hidden: A Scalar(bool) of features hidden.
  710. *@par Outputs:
  711. *@li h: A Tensor dtype of float16, float32.
  712. * @li h_t: A optinal Tensor dtype of float16, float32. The hidden state at time t.
  713. * @li c_t: A optinal Tensor dtype of float16, float32. The cell state at time t.
  714. *@par Third-party framework compatibility:
  715. * Compatible with the Pytorch operator adds.
  716. */
  717. REG_OP(LSTM)
  718. .INPUT(x, TensorType({DT_FLOAT16}))
  719. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  720. .INPUT(w_x, TensorType({DT_FLOAT16}))
  721. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  722. .INPUT(w_h, TensorType({DT_FLOAT16}))
  723. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  724. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  725. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  726. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  727. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  728. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  729. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  730. .ATTR(num_output, Int, 0)
  731. .ATTR(expose_hidden, Bool, false)
  732. .OP_END_FACTORY_REG(LSTM)
  733. /**
  734. *@brief Computes the gradients of convolution3D with respect to the filter
  735. *@par Inputs:
  736. * Three inputs:
  737. * @li x: A Tensor. Must be one of the following types: float16, float32, double.
  738. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels] or [batch, in_depth, in_channels, in_height, in_width].
  739. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  740. * where filter is a 5-D tensor [filter_depth, filter_height, filter_width, in_channels, out_channels]
  741. * or [out_channels, filter_depth, filter_height, filter_width, in_channels] or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  742. * @li out_backprop: A Tensor. Must have the same type as x. 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  743. * or [batch, out_depth, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  744. *@par Required Attributes:
  745. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding window for
  746. * each dimension of "x". The N and C dimensions must be 1. Has the same format as "x".
  747. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right] pads on feature map.
  748. *@par Attributes:
  749. * Three attributes:
  750. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1].
  751. * @li groups: Number of blocked connections from input channels to output channels.
  752. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  753. *@par Outputs:
  754. * y: A Tensor. Has the same type as x
  755. *@par Third-party framework compatibility
  756. * Compatible with Tensorflow's conv3d_backprop_filter
  757. */
  758. REG_OP(Conv3DBackpropFilter)
  759. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  760. .INPUT(filter_size, TensorType({DT_INT32}))
  761. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  762. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  763. .REQUIRED_ATTR(strides, ListInt)
  764. .REQUIRED_ATTR(pads, ListInt)
  765. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  766. .ATTR(groups, Int, 1)
  767. .ATTR(data_format, String, "NDHWC")
  768. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  769. /**
  770. *@brief Computes the gradients of convolution with respect to the filter.
  771. *@par Inputs:
  772. * Two inputs:
  773. * @li x: A Tensor of type float16.
  774. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels] or [batch, in_depth, in_channels, in_height, in_width].
  775. * @li out_backprop: A Tensor. Must have the same type as x. 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  776. * or [batch, out_depth, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  777. *@par Required Attributes:
  778. * @li filter_size: A tuple/list of type integers. An integer vector representing the tensor shape of filter,
  779. * where filter is a 5-D tensor [filter_depth, filter_height, filter_width, in_channels, out_channels]
  780. * or [out_channels, filter_depth, filter_height, filter_width, in_channels] or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  781. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding window for each dimension of "x".
  782. * The N and C dimensions must be 1. Has the same format as "x".
  783. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right] pads on feature map
  784. *@par Attributes:
  785. * Three attributes:
  786. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1].
  787. * @li groups: Number of blocked connections from input channels to output channels.
  788. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  789. *@par Outputs:
  790. * y: A Tensor. Has the same type as x
  791. *@par Third-party framework compatibility
  792. * Compatible with Tensorflow's conv3d_backprop_filter
  793. */
  794. REG_OP(Conv3DBackpropFilterD)
  795. .INPUT(x, TensorType({DT_FLOAT16}))
  796. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  797. .OUTPUT(y, TensorType({DT_FLOAT}))
  798. .REQUIRED_ATTR(filter_size, ListInt)
  799. .REQUIRED_ATTR(strides, ListInt)
  800. .REQUIRED_ATTR(pads, ListInt)
  801. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  802. .ATTR(groups, Int, 1)
  803. .ATTR(data_format, String, "NDHWC")
  804. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  805. /**
  806. *@brief Computes the transpose of convolution 3d with respect to the input.
  807. *@par Inputs:
  808. * Three inputs:
  809. * @li input_size: A Tensor of type int32. An integer vector representing the shape of input
  810. * @li x: A Tensor of type float16, currently does not support int8
  811. * @li filter: A Tensor of type float16.
  812. *@par Optional input:
  813. * Two optional inputs
  814. * @li bias: An optional 1D tensor of the same type as "x".
  815. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  816. *@par Required Attributes:
  817. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding window for each dimension of "x".
  818. * The N and C dimensions must be 1. Has the same format as "x".
  819. * @li pads: A tuple/list of 6 integers
  820. *@par Attributes:
  821. * Five attributes:
  822. * @li groups: Number of blocked connections from input channels to output channels.
  823. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  824. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  825. * @li output_padding: The size will be added in the output shape.
  826. * @li offset_x: Input offset_x value
  827. *@par Outputs:
  828. * y: A Tensor. Has the same type as filter
  829. */
  830. REG_OP(Conv3DTranspose)
  831. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  832. .INPUT(x, TensorType({DT_FLOAT16}))
  833. .INPUT(filter, TensorType({DT_FLOAT16}))
  834. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  835. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  836. .OUTPUT(y, TensorType({DT_FLOAT16}))
  837. .REQUIRED_ATTR(strides, ListInt)
  838. .REQUIRED_ATTR(pads, ListInt)
  839. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  840. .ATTR(groups, Int, 1)
  841. .ATTR(data_format, String, "NDHWC")
  842. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  843. .ATTR(offset_x, Int, 0)
  844. .OP_END_FACTORY_REG(Conv3DTranspose)
  845. /**
  846. *@brief Computes the transpose of convolution 3d with respect to the input.
  847. *@par Inputs:
  848. * @li x: A Tensor of type float16.
  849. * @li filter: A Tensor of type float16.
  850. *@par Optional inputs:
  851. * @li bias: An optional 1D tensor of the same type as "x".
  852. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  853. *@par Required Attributes:
  854. * @li input_size: A tuple/list of type int32. An integer vector representing the shape of input
  855. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding window for each dimension of "x".
  856. * The N and C dimensions must be 1. Has the same format as "x".
  857. * @li pads: A tuple/list of 6 integers.
  858. *@par Attributes:
  859. * Five attributes:
  860. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  861. * @li groups: Number of blocked connections from input channels to output channels.
  862. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  863. * @li output_padding: The size will be added in the output shape.
  864. * @li offset_x: Input offset_x value
  865. *@par Outputs:
  866. * y: A Tensor. Has the same type as filter
  867. */
  868. REG_OP(Conv3DTransposeD)
  869. .INPUT(x, TensorType({DT_FLOAT16}))
  870. .INPUT(filter, TensorType({DT_FLOAT16}))
  871. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  872. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  873. .OUTPUT(y, TensorType({DT_FLOAT16}))
  874. .REQUIRED_ATTR(input_size, ListInt)
  875. .REQUIRED_ATTR(strides, ListInt)
  876. .REQUIRED_ATTR(pads, ListInt)
  877. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  878. .ATTR(groups, Int, 1)
  879. .ATTR(data_format, String, "NDHWC")
  880. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  881. .ATTR(offset_x, Int, 0)
  882. .OP_END_FACTORY_REG(Conv3DTransposeD)
  883. /**
  884. *@brief Computes the transpose of convolution 2d with respect to the input.
  885. *@par Inputs:
  886. * Five inputs:
  887. * @li input_size: A Tensor of type int32 or int64. An integer vector representing
  888. * the shape of input.
  889. * @li x: A Tensor of type float16, int8.
  890. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  891. * @li bias: An optional 1D tensor of the same type as "x".
  892. * @li offset_w: An optional 1D tensor for quantized inference. Reserved.
  893. *@par Required Attributes:
  894. * @li strides: A required list or tuple. The stride of the sliding window for
  895. * height and width for H/W dimension.
  896. * @li pads: A required list or tuple of int32. Padding added to each dimension
  897. * of the input.
  898. *@par Attributes:
  899. * Five attributes:
  900. * @li groups: Number of blocked connections from input channels to output channels.
  901. * Defaults to "1".
  902. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  903. * of input. Must be [1, 1, 1, 1].
  904. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  905. * Specify the data format of the input and output data.
  906. * @li output_padding: The size will be added in the output shape. Defaults
  907. * to [0, 0, 0, 0].
  908. * @li offset_x: An optional int. Input offset, used for quantized inference.
  909. * Defaults to "0".
  910. *@par Outputs:
  911. * y: A Tensor. Has the same type as "filter".
  912. */
  913. REG_OP(Conv2DTranspose)
  914. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  915. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  916. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  917. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  918. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  919. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  920. .REQUIRED_ATTR(strides, ListInt)
  921. .REQUIRED_ATTR(pads, ListInt)
  922. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  923. .ATTR(groups, Int, 1)
  924. .ATTR(data_format, String, "NHWC")
  925. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  926. .ATTR(offset_x, Int, 0)
  927. .OP_END_FACTORY_REG(Conv2DTranspose)
  928. /**
  929. *@brief Computes the transpose of convolution 2d with respect to the input.
  930. *@par Inputs:
  931. * Four inputs:
  932. * @li x: A Tensor of type float16, int8.
  933. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  934. * @li bias: An optional 1D tensor of the same type as "x".
  935. * @li offset_w: An optional 1D tensor for quantized inference. Type is int8. Reserved.
  936. *@par Required Attributes:
  937. * @li input_size: A Tensor of type int32 or int64. An integer vector representing the
  938. * shape of input.
  939. * @li strides: A required list or tuple. The stride of the sliding window for
  940. * height and width for H/W dimension.
  941. * @li pads: A required list or tuple of int32. Padding added to each dimension
  942. * of the input.
  943. *@par Attributes:
  944. * Five attributes:
  945. * @li groups: Number of blocked connections from input channels to output channels.
  946. * Defaults to "1".
  947. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  948. * of input. Must be [1, 1, 1, 1].
  949. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  950. * Specify the data format of the input and output data.
  951. * @li output_padding: The size will be added in the output shape. Defaults
  952. * to [0, 0, 0, 0].
  953. * @li offset_x: An optional int. Input offset, used for quantized inference.
  954. * Defaults to "0".
  955. *@par Outputs:
  956. * y: A Tensor. Has the same type as "filter".
  957. */
  958. REG_OP(Conv2DTransposeD)
  959. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  960. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  961. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  962. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  963. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  964. .REQUIRED_ATTR(input_size, ListInt)
  965. .REQUIRED_ATTR(strides, ListInt)
  966. .REQUIRED_ATTR(pads, ListInt)
  967. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  968. .ATTR(groups, Int, 1)
  969. .ATTR(data_format, String, "NHWC")
  970. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  971. .ATTR(offset_x, Int, 0)
  972. .OP_END_FACTORY_REG(Conv2DTransposeD)
  973. } // namespace ge
  974. #endif // GE_OP_NN_CALCULATION_OPS_H

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