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 44 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927
  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. Must have the same type as "filter". 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 of type float16, float32, double or int8.
  376. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  377. * Two optional inputs:
  378. * @li bias: An optional tensor of type float16, float32, int32 or int64.
  379. * @li offset_w: An optional 1D tensor for quantized deconvolution. Type is int8. Reserved.\n
  380. *@par Attributes:
  381. * Six attributes:
  382. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  383. * for H/W dimension. Defaults to [1, 1, 1, 1].
  384. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  385. * padding on the feature map. Defaults to [0, 0, 0, 0].
  386. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  387. * dimension of input. Must be [1, 1, 1, 1].
  388. * @li groups: Number of blocked connections from input channels to
  389. output channels. Defaults to "1".
  390. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  391. Specify the data format of the input and output data.
  392. * @li offset_x: An optional integer for quantized deconvolution. Defaults to "0".
  393. *@par Outputs:
  394. * y: A Tensor. Has the same type as "filter". 4D tensor with shape
  395. * [batch, channels, height, width].
  396. */
  397. REG_OP(Deconvolution)
  398. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  399. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  400. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  401. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  402. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  403. .ATTR(strides, ListInt, {1, 1})
  404. .ATTR(pads, ListInt, {0, 0, 0, 0})
  405. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  406. .ATTR(groups, Int, 1)
  407. .ATTR(data_format, String, "NCHW")
  408. .ATTR(offset_x, Int, 0)
  409. .OP_END_FACTORY_REG(Deconvolution)
  410. /**
  411. *@brief Computes the gradients of convolution with respect to the filter
  412. *@par Inputs:
  413. * Three inputs:
  414. * @li x: A Tensor. Must be one of the following types: float16, float32, float64.
  415. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  416. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  417. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  418. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  419. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  420. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  421. *@par Attributes:
  422. * Five attributes:
  423. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  424. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map.
  425. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  426. * @li groups: Number of blocked connections from input channels to output channels.
  427. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  428. *@par Outputs:
  429. * y: A Tensor. Has the same type as x
  430. *@par Third-party framework compatibility
  431. * Compatible with Tensorflow's conv2d_backprop_filter
  432. */
  433. REG_OP(Conv2DBackpropFilter)
  434. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  435. .INPUT(filter_size, TensorType({DT_INT32}))
  436. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  437. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  438. .REQUIRED_ATTR(strides, ListInt)
  439. .REQUIRED_ATTR(pads, ListInt)
  440. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  441. .ATTR(groups, Int, 1)
  442. .ATTR(data_format, String, "NHWC")
  443. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  444. /**
  445. *@brief Computes the gradients of convolution with respect to the filter.
  446. *@par Inputs:
  447. * Two inputs:
  448. * @li x: A Tensor. Type is float16.
  449. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  450. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  451. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  452. *@par Attributes:
  453. * Six attributes:
  454. * @li filter_size: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  455. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  456. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  457. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  458. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  459. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  460. * @li groups: Number of blocked connections from input channels to output channels.
  461. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  462. *@par Outputs:
  463. * y: A Tensor. Has the same type as x
  464. *@par Third-party framework compatibility
  465. * Compatible with Tensorflow's conv2d_backprop_filter
  466. */
  467. REG_OP(Conv2DBackpropFilterD)
  468. .INPUT(x, TensorType({DT_FLOAT16}))
  469. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  470. .OUTPUT(y, TensorType({DT_FLOAT}))
  471. .REQUIRED_ATTR(filter_size, ListInt)
  472. .REQUIRED_ATTR(strides, ListInt)
  473. .REQUIRED_ATTR(pads, ListInt)
  474. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  475. .ATTR(groups, Int, 1)
  476. .ATTR(data_format, String, "NHWC")
  477. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  478. /**
  479. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  480. *@par Inputs:
  481. * @li x: A 4D tensor of input images.
  482. * @li filter: A 4D tensor of filters.
  483. * @li bias: An optional 1D tensor.
  484. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.
  485. *
  486. * The input and output tensor attributes are listed as follows:
  487. * @verbatim
  488. |Tensor | x | filter | bias | offset_w | y
  489. -----------|---------|---------|---------|----------|--------
  490. |Data Type | float16 | float16 | float16 | _ | float16
  491. | |---------|---------|---------|----------|--------
  492. | | float32 | float32 | float32 | _ | float32
  493. | |---------|---------|---------|----------|--------
  494. | | int8 | int8 | int32 | int8 | int32
  495. -----------|---------|---------|---------|----------|--------
  496. |Format | NCHW | NCHW | ND | ND | NCHW
  497. | | NHWC | NHWC | | | NHWC
  498. | | | HWCN | | |
  499. @endverbatim
  500. * It should be noted that the data types must correspond to each other, but the
  501. * format does not need to.
  502. *@par Attributes:
  503. * @li strides: A list of 4 integers. Specifying the strides of the
  504. * convolution along the height and width. The dimension order is determined
  505. * by the data format of "x". By default the N and C dimensions are set to 1.
  506. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  507. * padding.
  508. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  509. * for dilated convolution. Has the same dimension order and value as "strides".
  510. * @li groups: Number of blocked connections from input channels to output
  511. * channels. Input channels and output channels must both be divisible by
  512. * "groups".Type is int32.
  513. * @li offset_x: An optional integer for quantized convolution. Type is int32. Defaults to "0".
  514. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  515. * data format of the input and output images. Type is string. Defaults to "NHWC". Reserved.
  516. *@par Outputs:
  517. * @li y: A 4D Tensor of output images.
  518. *@attention
  519. * @li The parameter scope is listed as follows:
  520. * @verbatim
  521. |Name | Field | Scope
  522. ------------------|--------------|----------
  523. |Input Image Size | H dimension | [1, 4096]
  524. | | W dimension | [1, 4096]
  525. ------------------|--------------|----------
  526. |Filter Size | H dimension | [1, 255]
  527. | | W dimension | [1, 255]
  528. ------------------|--------------|----------
  529. |Stride Size | H dimension | [1, 63]
  530. | | W dimension | [1, 63]
  531. ------------------|--------------|----------
  532. |Padding Size | top side | [0, 255]
  533. | | bottom side | [0, 255]
  534. | | left side | [0, 255]
  535. | | right side | [0, 255]
  536. ------------------|--------------|----------
  537. |Dilation Size | H dimension | [1, 255]
  538. | W dimension | [1, 255]
  539. @endverbatim
  540. * @li There are restrictions for certain scenarios:
  541. * @verbatim
  542. Output | Restrictions
  543. ------------------|----------------------------------------------
  544. W dimension == 1 | HxW(input) == HxW(filter)
  545. H dimension == 1 |
  546. ------------------|----------------------------------------------
  547. W dimension == 1 | Not supported
  548. H dimension != 1 |
  549. @endverbatim
  550. * As shown above, "HxW(input)" indicates the image size after padding and
  551. * "HxW(filter)" indicates the filter size after dilation.
  552. *@par Quantization supported or not
  553. * Yes
  554. *@par Third-party framework compatibility
  555. *@li Compatible with the TensorFlow operator "conv2d".
  556. *@li Compatible with the Caffe operator 2D "Convolution".
  557. */
  558. REG_OP(Conv2D)
  559. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  560. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  561. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  562. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  563. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  564. .REQUIRED_ATTR(strides, ListInt)
  565. .REQUIRED_ATTR(pads, ListInt)
  566. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  567. .ATTR(groups, Int, 1)
  568. .ATTR(data_format, String, "NHWC")
  569. .ATTR(offset_x, Int, 0)
  570. .OP_END_FACTORY_REG(Conv2D)
  571. REG_OP(Conv2DCompress)
  572. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  573. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  574. .INPUT(compress_index, TensorType({DT_INT8}))
  575. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  576. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  577. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  578. .REQUIRED_ATTR(strides, ListInt)
  579. .REQUIRED_ATTR(pads, ListInt)
  580. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  581. .ATTR(groups, Int, 1)
  582. .ATTR(data_format, String, "NHWC")
  583. .ATTR(offset_x, Int, 0)
  584. .OP_END_FACTORY_REG(Conv2DCompress)
  585. /**
  586. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  587. *@par Inputs:
  588. * @li x: A 5D tensor. Must be one of the following types: float16, float32, float64. The format is NCDHW or NDHWC.
  589. * @li filter: A 5D tensor of the same type as "x". The format is NCDHW, NDHWC or DHWCN.
  590. *@par Optional input:
  591. * @li bias: An optional 1D tensor of the same type as "x".
  592. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  593. *@par Required Attributes:
  594. * @li strides: A list of 5 ints. Specifies the stride of the sliding window for each dimension of "x". The N and C dimensions must be 1. Has the same format as "x".
  595. * @li pads: A list of 6 ints. Supports only padding along the D, H and W dimensions in sequence of head, tail, top, bottom, left and right.
  596. *@par Attributes:
  597. * @li groups: Number of blocked connections from input channels to output channels.
  598. * @li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  599. * @li dilations: A list of 5 ints. Specifies the dilation factor for each dimension of "x". The N and C dimensions must be 1. Has the same format as "x".
  600. * @li offset_x: An optional int. Input offset, used for quantized inference. Defaults to 0.
  601. *@par Outputs:
  602. *y: A Tensor. Has the same type as "x".
  603. *@attention Constraints:
  604. *The image size after padding is greater than the filter size.
  605. *@par Third-party framework compatibility
  606. * @li Compatible with the TensorFlow operator conv3d.
  607. * @li Compatible with the Caffe operator Convolution.
  608. */
  609. REG_OP(Conv3D)
  610. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  611. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  612. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  613. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  614. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  615. .REQUIRED_ATTR(strides, ListInt)
  616. .REQUIRED_ATTR(pads, ListInt)
  617. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  618. .ATTR(groups, Int, 1)
  619. .ATTR(data_format, String, "NDHWC")
  620. .ATTR(offset_x, Int, 0)
  621. .OP_END_FACTORY_REG(Conv3D)
  622. /**
  623. *@brief Computes the gradients of convolution 3d with respect to the input.
  624. *@par Inputs:
  625. * Three inputs:
  626. * @li input_size: A Tensor of type int32, int64. An integer vector representing the shape of input,
  627. * where input is a 5-D tensor [batch, depth, height, width, channels] or [batch, channels, depth, height, width].
  628. * @li filter: A Tensor. Must be one of the following types: float16, float32, float64.
  629. * @li out_backprop: A Tensor. Must have the same type as filter. 5-D with shape [batch, depth, out_height, out_width, out_channels]
  630. * or [batch, out_channels, depth, out_height, out_width]. Gradients with respect to the output of the convolution.
  631. *@par Required Attributes:
  632. * @li strides: A list of 5 ints. Specifies the stride of the sliding window for each dimension of "x". The N and C dimensions must be 1. Has the same format as "x".
  633. * @li pads: A list of 6 ints. Supports only padding along the D, H and W dimensions in sequence of head, tail, top, bottom, left and right.
  634. *@par Attributes:
  635. * Three attributes:
  636. * @li groups: Number of blocked connections from input channels to output channels.
  637. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  638. * @li dilations: A tuple/list of 6 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  639. *@par Outputs:
  640. * y: A Tensor. Has the same type as filter,and has same format as input_size
  641. *@par Third-party framework compatibility
  642. * Compatible with Tensorflow's conv3d_backprop_input
  643. */
  644. REG_OP(Conv3DBackpropInput)
  645. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  646. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  647. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  648. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  649. .REQUIRED_ATTR(strides, ListInt)
  650. .REQUIRED_ATTR(pads, ListInt)
  651. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  652. .ATTR(groups, Int, 1)
  653. .ATTR(data_format, String, "NDHWC")
  654. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  655. /**
  656. *@brief Computes the gradients of convolution 3d with respect to the input.
  657. *@par Inputs:
  658. * Two inputs:
  659. * @li filter: A Tensor. Types is float16.
  660. * @li out_backprop: A Tensor. Must have the same type as filter.
  661. *@par Required Attributes:
  662. *@li strides: A list of 5 ints. Specifies the stride of the sliding window for
  663. each dimension of "x". The N and C dimensions must be 1. Has the same format as "x".
  664. *@li pads: A list of 6 ints. Supports only padding along the D, H and W
  665. dimensions in sequence of head, tail, top, bottom, left and right.
  666. *@li input_size: A Tensor of type int32, int64. An integer vector representing the shape of input,
  667. * where input is a 5-D tensor [batch, depth, height, width, channels] or [batch, channels, depth, height, width].
  668. *@par Attributes:
  669. * Three attributes:
  670. * @li groups: Number of blocked connections from input channels to output channels.
  671. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  672. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  673. *@par Outputs:
  674. * y: A Tensor. Has the same type as filter
  675. *@par Third-party framework compatibility
  676. * Compatible with Tensorflow's conv3d_backprop_input
  677. */
  678. REG_OP(Conv3DBackpropInputD)
  679. .INPUT(filter, TensorType({DT_FLOAT16}))
  680. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  681. .OUTPUT(y, TensorType({DT_FLOAT16}))
  682. .REQUIRED_ATTR(input_size, ListInt)
  683. .REQUIRED_ATTR(strides, ListInt)
  684. .REQUIRED_ATTR(pads, ListInt)
  685. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  686. .ATTR(groups, Int, 1)
  687. .ATTR(data_format, String, "NDHWC")
  688. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  689. REG_OP(LSTM)
  690. .INPUT(x, TensorType({DT_FLOAT16}))
  691. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  692. .INPUT(w_x, TensorType({DT_FLOAT16}))
  693. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  694. .INPUT(w_h, TensorType({DT_FLOAT16}))
  695. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  696. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  697. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  698. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  699. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  700. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  701. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  702. .ATTR(num_output, Int, 0)
  703. .ATTR(expose_hidden, Bool, false)
  704. .OP_END_FACTORY_REG(LSTM)
  705. /**
  706. *@brief Computes the gradients of convolution3D with respect to the filter
  707. *@par Inputs:
  708. * Three inputs:
  709. * @li x: A Tensor. Must be one of the following types: float16
  710. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels] or [batch, in_depth, in_channels, in_height, in_width].
  711. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  712. * where filter is a 5-D tensor [filter_depth, filter_height, filter_width, in_channels, out_channels]
  713. * or [out_channels, filter_depth, filter_height, filter_width, in_channels] or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  714. * @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]
  715. * or [batch, out_depth, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  716. *@par Attributes:
  717. * Three attributes:
  718. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  719. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right] pads on feature map.
  720. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1].
  721. * @li groups: Number of blocked connections from input channels to output channels.
  722. * @li data_format: An optional string from: "NDHWC", "NDCHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  723. *@par Outputs:
  724. * y: A Tensor. Has the same type as x
  725. *@par Third-party framework compatibility
  726. * Compatible with Tensorflow's conv3d_backprop_filter
  727. */
  728. REG_OP(Conv3DBackpropFilter)
  729. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  730. .INPUT(filter_size, TensorType({DT_INT32}))
  731. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  732. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  733. .REQUIRED_ATTR(strides, ListInt)
  734. .REQUIRED_ATTR(pads, ListInt)
  735. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  736. .ATTR(groups, Int, 1)
  737. .ATTR(data_format, String, "NDHWC")
  738. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  739. /**
  740. *@brief Computes the gradients of convolution with respect to the filter.
  741. *@par Inputs:
  742. * Two inputs:
  743. * @li x: A Tensor. Type is float16.
  744. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels] or [batch, in_depth, in_channels, in_height, in_width].
  745. * @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]
  746. * or [batch, out_depth, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  747. *@par Attributes:
  748. * Four attributes:
  749. * @li filter_size: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  750. * where filter is a 5-D tensor [filter_depth, filter_height, filter_width, in_channels, out_channels]
  751. * or [out_channels, filter_depth, filter_height, filter_width, in_channels] or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  752. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  753. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right] pads on feature map
  754. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1].
  755. * @li groups: Number of blocked connections from input channels to output channels.
  756. * @li data_format: An optional string from: "NDHWC", "NDCHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  757. *@par Outputs:
  758. * y: A Tensor. Has the same type as x
  759. *@par Third-party framework compatibility
  760. * Compatible with Tensorflow's conv3d_backprop_filter
  761. */
  762. REG_OP(Conv3DBackpropFilterD)
  763. .INPUT(x, TensorType({DT_FLOAT16}))
  764. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  765. .OUTPUT(y, TensorType({DT_FLOAT}))
  766. .REQUIRED_ATTR(filter_size, ListInt)
  767. .REQUIRED_ATTR(strides, ListInt)
  768. .REQUIRED_ATTR(pads, ListInt)
  769. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  770. .ATTR(groups, Int, 1)
  771. .ATTR(data_format, String, "NDHWC")
  772. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  773. /**
  774. *@brief Computes the transpose of convolution 3d with respect to the input.
  775. *@par Inputs:
  776. * Five inputs:
  777. * @li input_size: A Tensor of type int32. An integer vector representing the shape of input
  778. * @li x: A Tensor.
  779. * @li filter: A Tensor. Types is float16.
  780. * @li bias: An optional 1D tensor of the same type as "x".
  781. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  782. *@par Required Attributes:
  783. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  784. * @li pads: A tuple/list of 6 integers
  785. *@par Attributes:
  786. * Five attributes:
  787. * @li groups: Number of blocked connections from input channels to output channels.
  788. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  789. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  790. * @li output_padding: The size will be added in the output shape.
  791. * @li offset_x: Input offset_x value
  792. *@par Outputs:
  793. * y: A Tensor. Has the same type as filter
  794. */
  795. REG_OP(Conv3DTranspose)
  796. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  797. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  798. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  799. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  800. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  801. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  802. .REQUIRED_ATTR(strides, ListInt)
  803. .REQUIRED_ATTR(pads, ListInt)
  804. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  805. .ATTR(groups, Int, 1)
  806. .ATTR(data_format, String, "NDHWC")
  807. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  808. .ATTR(offset_x, Int, 0)
  809. .OP_END_FACTORY_REG(Conv3DTranspose)
  810. /**
  811. *@brief Computes the transpose of convolution 3d with respect to the input.
  812. *@par Inputs:
  813. * Four inputs:
  814. * @li x: A Tensor.
  815. * @li filter: A Tensor. Types is float16.
  816. * @li bias: An optional 1D tensor of the same type as "x".
  817. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  818. *@par Required Attributes:
  819. * @li input_size: A Tensor of type int32. An integer vector representing the shape of input
  820. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  821. * @li pads: A tuple/list of 6 integers
  822. *@par Attributes:
  823. * Five attributes:
  824. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  825. * @li groups: Number of blocked connections from input channels to output channels.
  826. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  827. * @li output_padding: The size will be added in the output shape.
  828. * @li offset_x: Input offset_x value
  829. *@par Outputs:
  830. * y: A Tensor. Has the same type as filter
  831. */
  832. REG_OP(Conv3DTransposeD)
  833. .INPUT(x, TensorType({DT_FLOAT16}))
  834. .INPUT(filter, TensorType({DT_FLOAT16}))
  835. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  836. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  837. .OUTPUT(y, TensorType({DT_FLOAT16}))
  838. .REQUIRED_ATTR(input_size, ListInt)
  839. .REQUIRED_ATTR(strides, ListInt)
  840. .REQUIRED_ATTR(pads, ListInt)
  841. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  842. .ATTR(groups, Int, 1)
  843. .ATTR(data_format, String, "NDHWC")
  844. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  845. .ATTR(offset_x, Int, 0)
  846. .OP_END_FACTORY_REG(Conv3DTransposeD)
  847. } // namespace ge
  848. #endif // GE_OP_NN_CALCULATION_OPS_H

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