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 42 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  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
  131. * @li filter: 4D filter tensor with shape of [H, W, C, K], support float16,
  132. * float32, double
  133. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  134. * Must be one of the following types: float16, float32, double.
  135. * @par Attributes:
  136. * @li strides: A required list or tuple. The stride of the sliding window for
  137. * height and width of input "x" of the convolution.
  138. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  139. * stride_width, 1].
  140. * @li dilations: An optional list or tuple. The dilation factor for each
  141. * dimension of input "x".
  142. * If set to k > 1, there will be k-1 skipped cells between each filter element
  143. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  144. * or [1, dilation_height, dilation_width, 1].
  145. * @li pads: A required list or tuple. Padding added to each dimension of the
  146. * input.
  147. * @li data_format: An optional string. Input data format, either "NHWC" or
  148. * "NCHW".
  149. * @par Outputs:
  150. * input_grad: Gradient of the deep convolution relative to the input with shape
  151. * [N, C, H, W] or [N, H, W, C] Must be one of the following types: float16,
  152. * float32, double.
  153. * @attention Constraints:\n
  154. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  155. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  156. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  157. * [C1, Hf, Wf, K, Co, C0],
  158. * where K is fixed at 1, and Co and C0 are 16.\n
  159. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  160. * data is 5D with shape [N, C1, Ho, Wo, C0],
  161. * where C is the same as that of the feature map and C0 is 16.\n
  162. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  163. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  164. * @par Third-party framework compatibility
  165. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  166. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  167. */
  168. REG_OP(DepthwiseConv2DBackpropInput)
  169. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  170. .INPUT(filter, TensorType({DT_FLOAT16}))
  171. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  172. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  173. .REQUIRED_ATTR(strides, ListInt)
  174. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  175. .REQUIRED_ATTR(pads, ListInt)
  176. .ATTR(data_format, String, "NHWC")
  177. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInput)
  178. /**
  179. * @brief Computes the gradients of depthwise convolution with respect to the
  180. * input.
  181. * @par Inputs:
  182. * Two inputs include: \n
  183. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  184. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of
  185. * type float16
  186. * @par Attributes:
  187. * @li input_size: A required list or tuple. The origin shape of input.
  188. * @li strides: A required list or tuple. The stride of the sliding window for
  189. * height and width of input "x" of the convolution.
  190. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  191. * stride_width, 1].
  192. * @li dilations: An optional list or tuple. The dilation factor for each
  193. * dimension of input "x".
  194. * If set to k > 1, there will be k-1 skipped cells between each filter element
  195. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  196. * or [1, dilation_height, dilation_width, 1].
  197. * @li pads: A required list or tuple. Padding added to each dimension of the
  198. * input.
  199. * @li data_format: An optional string. Input data format, either "NHWC" or
  200. * "NCHW".
  201. * @par Outputs:
  202. * input_grad: Gradient of the deep convolution relative to the input with
  203. * shape [N, C, H, W] or [N, H, W, C]. Must be of type float16.
  204. * @attention Constraints:\n
  205. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  206. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  207. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  208. * [C1, Hf, Wf, K, Co, C0],
  209. * where K is fixed at 1, and Co and C0 are 16.\n
  210. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  211. * data is 5D with shape [N, C1, Ho, Wo, C0],
  212. * where C is the same as that of the feature map and C0 is 16.\n
  213. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  214. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  215. * @par Third-party framework compatibility
  216. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  217. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  218. */
  219. REG_OP(DepthwiseConv2DBackpropInputD)
  220. .INPUT(filter, TensorType({DT_FLOAT16}))
  221. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  222. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  223. .REQUIRED_ATTR(input_size, ListInt)
  224. .REQUIRED_ATTR(strides, ListInt)
  225. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  226. .REQUIRED_ATTR(pads, ListInt)
  227. .ATTR(data_format, String, "NHWC")
  228. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInputD)
  229. /**
  230. *@brief Computes a 2D deep convolution given a 4D input tensor and a filter
  231. * tensor.
  232. *@par Inputs:
  233. *Two required inputs and two optional inputs, including: \n
  234. * @li x: A 4D tensor of type float16, with shape [N, C, H, W] or [N, H, W, C]
  235. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  236. * @li bias: An optional tensor of type float16 or int32
  237. * @li offset_w: An optional float16 or int8, used for quantized inference
  238. * @par Attributes:
  239. * @li strides: A required list or tuple. The stride of the sliding window for
  240. * height and width of input "x" of the convolution.
  241. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  242. * stride_width, 1].
  243. * @li dilations: An optional list or tuple. The dilation factor for each
  244. * dimension of input "x".
  245. * If set to k > 1, there will be k-1 skipped cells between each filter element
  246. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  247. * or [1, dilation_height, dilation_width, 1].
  248. * @li pads: A required list or tuple. Padding added to each dimension of the
  249. * input.
  250. * @li data_format: An optional string. Input data format, either "NHWC" or
  251. * "NCHW". Defaults to "NHWC".
  252. * @li offset_x: An optional int. Input offset, used for quantized inference.
  253. * Defaults to 0.
  254. * @par Outputs:
  255. * y: 4D tensor of type float16, with shape [N, C, H, W] or [N, H, W, C]
  256. * @attention Constraints:\n
  257. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  258. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  259. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  260. * [C1, Hf, Wf, K, Co, C0],
  261. * where K is fixed at 1, and Co and C0 are 16.\n
  262. * Limited by the size of L1 buffer memory: \n
  263. * (l1_size - filter_h*filter_w*BLOCK_SIZE*BLOCK_SIZE*data_size) // (Wi *
  264. * BLOCK_SIZE * data_size) >= (BLOCK_SIZE * strides_h + filter_h - strides_h).\n
  265. * @par Quantization supported or not
  266. * Yes
  267. * @par Third-party framework compatibility
  268. * @li Compatible with the TensorFlow operator DepthwiseConv2D.
  269. * @li Compatible with the Caffe operator DepthwiseConv2D.
  270. */
  271. REG_OP(DepthwiseConv2D)
  272. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  273. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  274. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  275. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16, DT_INT8}))
  276. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  277. .REQUIRED_ATTR(strides, ListInt)
  278. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  279. .REQUIRED_ATTR(pads, ListInt)
  280. .ATTR(data_format, String, "NHWC")
  281. .ATTR(offset_x, Int, 0)
  282. .OP_END_FACTORY_REG(DepthwiseConv2D)
  283. REG_OP(Conv2DCCE)
  284. .INPUT(x, TensorType{DT_FLOAT}) // The input tensor
  285. .INPUT(w, TensorType({DT_FLOAT, DT_INT8})) // The weight tensor ,If QuantType =1 ,shall use type""tensor(int8)
  286. .OPTIONAL_INPUT(b, TensorType{DT_FLOAT}) // Optional 1D bias to be added to the convolution, has size of M.
  287. .OUTPUT(y, TensorType{DT_FLOAT}) // The output tensor
  288. .ATTR(mode, Int, 1)
  289. .ATTR(group, Int, 1) // number of groups input channels and output channels are divided into
  290. .ATTR(num_output, Int, 0) // number of output tensor
  291. .ATTR(pad, ListInt, {0, 0, 0, 0}) // Padding for the beginning and ending along each axis
  292. .ATTR(kernel, ListInt, {0, 0})
  293. .ATTR(stride, ListInt, {1, 1}) // Stride along each axis.
  294. .ATTR(dilation, ListInt, {1, 1}) // dilation value along each axis of the filter.
  295. .ATTR(pad_mode, Int, 0) // pad mode, 0:NOTSET, 1:SAME_UPPER, SAME_LOWER or 2:VALID.defaul default value is 0:NOTSET
  296. .ATTR(algo, Int, 2)
  297. .OP_END_FACTORY_REG(Conv2DCCE)
  298. REG_OP(Conv2DBackpropFilterCCE)
  299. .INPUT(x, TensorType{DT_FLOAT})
  300. .INPUT(filter_sizes, TensorType{DT_INT8})
  301. .INPUT(out_backprop, TensorType{DT_FLOAT})
  302. .OUTPUT(y, TensorType{DT_FLOAT})
  303. .ATTR(conv_grad_filter_output_shape, ListInt, {0, 0, 0, 0})
  304. .ATTR(mode, Int, 1)
  305. .ATTR(group, Int, 1)
  306. .ATTR(pad, ListInt, {0, 0, 0, 0})
  307. .ATTR(stride, ListInt, {1, 1})
  308. .ATTR(dilation, ListInt, {1, 1})
  309. .ATTR(padding, Int, 0) //pad_mode:same valid
  310. .ATTR(algo, Int, 0)
  311. .OP_END_FACTORY_REG(Conv2DBackpropFilterCCE)
  312. REG_OP(Conv2DBackpropInputCCE)
  313. .INPUT(input_sizes, TensorType{DT_INT8})
  314. .INPUT(filter, TensorType{DT_FLOAT})
  315. .INPUT(out_backprop, TensorType{DT_FLOAT})
  316. .OUTPUT(output, TensorType{DT_FLOAT})
  317. .ATTR(conv_grad_input_output_shape, ListInt, {0, 0, 0, 0})
  318. .ATTR(mode, Int, 1)
  319. .ATTR(format, Int, 0)
  320. .ATTR(group, Int, 1)
  321. .ATTR(pad_mode, Int, 0)
  322. .ATTR(stride, ListInt, {1, 1})
  323. .ATTR(dilation, ListInt, {1, 1})
  324. .ATTR(pad, ListInt, {0, 0, 0, 0})
  325. .ATTR(algo, Int, 0)
  326. .OP_END_FACTORY_REG(Conv2DBackpropInputCCE)
  327. /**
  328. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  329. * It accumulates all the values from out_backprop into the feature
  330. * dimension. For NHWC data format, the feature dimension is the last.
  331. * For NCHW data format, the feature dimension is the third-to-last.
  332. *@par Inputs:
  333. *x: A Tensor of type NumberType.
  334. *@par Attributes:
  335. *data_format: Data format. Defaults to "NHWC".
  336. *@par Outputs:
  337. *y: A Tensor.Has the same type as "x".
  338. *@par Third-party framework compatibility
  339. * Compatible with the TensorFlow operator BiasAddGrad.
  340. */
  341. REG_OP(BiasAddGrad)
  342. .INPUT(x, TensorType::NumberType())
  343. .OUTPUT(y, TensorType::NumberType())
  344. .ATTR(data_format, String, "NHWC")
  345. .OP_END_FACTORY_REG(BiasAddGrad)
  346. /**
  347. *@brief Computes the gradients of convolution with respect to the input.
  348. *@par Inputs:
  349. * Three inputs:
  350. * @li input_size: A Tensor of type int32. An integer vector representing the shape of input,
  351. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  352. * @li filter: A Tensor. Must be one of the following types: float16, float32, float64.
  353. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  354. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  355. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  356. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  357. *@par Attributes:
  358. * Five attributes:
  359. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  360. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  361. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  362. * @li groups: Number of blocked connections from input channels to output channels.
  363. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  364. *@par Outputs:
  365. * y: A Tensor. Has the same type as filter,and has same format as input_size
  366. *@par Third-party framework compatibility
  367. * Compatible with Tensorflow's conv2d_backprop_input
  368. */
  369. REG_OP(Conv2DBackpropInput)
  370. .INPUT(input_size, TensorType({DT_INT32}))
  371. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  372. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  373. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  374. .REQUIRED_ATTR(strides, ListInt)
  375. .REQUIRED_ATTR(pads, ListInt)
  376. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  377. .ATTR(groups, Int, 1)
  378. .ATTR(data_format, String, "NHWC")
  379. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  380. /**
  381. *@brief Computes the gradients of convolution with respect to the input.
  382. *@par Inputs:
  383. * Two inputs:
  384. * @li filter: A Tensor. Types is float16.
  385. * 4-D with shape [filter_height, filter_width, in_channels, out_channels] or [out_channels, filter_height, filter_width, in_channels]
  386. * or [out_channels, in_channel, filter_height, filter_width].
  387. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  388. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  389. *@par Attributes:
  390. * Six attributes:
  391. * @li input_size A Tensor of type int32. An integer vector representing the shape of input,
  392. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  393. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  394. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  395. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  396. * @li groups: Number of blocked connections from input channels to output channels.
  397. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  398. *@par Outputs:
  399. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  400. *@par Third-party framework compatibility
  401. * Compatible with Tensorflow's conv2d_backprop_input
  402. */
  403. REG_OP(Conv2DBackpropInputD)
  404. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  405. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  406. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  407. .REQUIRED_ATTR(input_size, ListInt)
  408. .REQUIRED_ATTR(strides, ListInt)
  409. .REQUIRED_ATTR(pads, ListInt)
  410. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  411. .ATTR(groups, Int, 1)
  412. .ATTR(data_format, String, "NHWC")
  413. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  414. /**
  415. *@brief Computes the Deconvolution with respect to the input.
  416. *@par Inputs:
  417. * Three inputs:
  418. * @li x: A Tensor of type float16 or int8. 4D with shape
  419. * [batch, out_channels, out_height, out_width]. Gradients with respect
  420. * to the output of the convolution.
  421. * @li filter: A Tensor. Must have the same type as "x".
  422. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  423. * Two optional inputs:
  424. * @li bias: An optional tensor. Must have the same type as "y".
  425. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  426. * Type is int8. Reserved.\n
  427. *@par Attributes:
  428. * Six attributes:
  429. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  430. * for H/W dimension.
  431. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  432. * padding on the feature map.
  433. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  434. * dimension of input. Must be [1, 1, 1, 1].
  435. * @li groups: Number of blocked connections from input channels to
  436. output channels. Defaults to "1".
  437. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  438. Specify the data format of the input and output data.
  439. * @li offset_x: An optional integer for quantized deconvolution. Defaults to "0".
  440. *@par Outputs:
  441. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  442. * When type of x is float16, the type of y must be float16.
  443. * When type of x is int8, the type of y must be int32.
  444. */
  445. REG_OP(Deconvolution)
  446. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  447. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  448. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  449. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  450. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  451. .REQUIRED_ATTR(strides, ListInt)
  452. .REQUIRED_ATTR(pads, ListInt)
  453. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  454. .ATTR(groups, Int, 1)
  455. .ATTR(data_format, String, "NCHW")
  456. .ATTR(offset_x, Int, 0)
  457. .OP_END_FACTORY_REG(Deconvolution)
  458. /**
  459. *@brief Computes the gradients of convolution with respect to the filter
  460. *@par Inputs:
  461. * Three inputs:
  462. * @li x: A Tensor. Must be one of the following types: float16, float32, float64.
  463. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  464. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  465. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  466. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  467. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  468. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  469. *@par Attributes:
  470. * Five attributes:
  471. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  472. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map.
  473. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  474. * @li groups: Number of blocked connections from input channels to output channels.
  475. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  476. *@par Outputs:
  477. * y: A Tensor. Has the same type as x
  478. *@par Third-party framework compatibility
  479. * Compatible with Tensorflow's conv2d_backprop_filter
  480. */
  481. REG_OP(Conv2DBackpropFilter)
  482. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  483. .INPUT(filter_size, TensorType({DT_INT32}))
  484. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  485. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  486. .REQUIRED_ATTR(strides, ListInt)
  487. .REQUIRED_ATTR(pads, ListInt)
  488. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  489. .ATTR(groups, Int, 1)
  490. .ATTR(data_format, String, "NHWC")
  491. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  492. /**
  493. *@brief Computes the gradients of convolution with respect to the filter.
  494. *@par Inputs:
  495. * Two inputs:
  496. * @li x: A Tensor. Type is float16.
  497. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  498. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  499. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  500. *@par Attributes:
  501. * Six attributes:
  502. * @li filter_size: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  503. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  504. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  505. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  506. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  507. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  508. * @li groups: Number of blocked connections from input channels to output channels.
  509. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  510. *@par Outputs:
  511. * y: A Tensor. Type is float32
  512. *@par Third-party framework compatibility
  513. * Compatible with Tensorflow's conv2d_backprop_filter
  514. */
  515. REG_OP(Conv2DBackpropFilterD)
  516. .INPUT(x, TensorType({DT_FLOAT16}))
  517. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  518. .OUTPUT(y, TensorType({DT_FLOAT}))
  519. .REQUIRED_ATTR(filter_size, ListInt)
  520. .REQUIRED_ATTR(strides, ListInt)
  521. .REQUIRED_ATTR(pads, ListInt)
  522. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  523. .ATTR(groups, Int, 1)
  524. .ATTR(data_format, String, "NHWC")
  525. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  526. /**
  527. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  528. *@par Inputs:
  529. * @li x: A 4D tensor of input images.
  530. * @li filter: A 4D tensor of filters.
  531. * @li bias: An optional 1D tensor.
  532. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.
  533. *
  534. * The input and output tensor attributes are listed as follows:
  535. * @verbatim
  536. Tensor | x | filter | bias | offset_w | y
  537. -----------|---------|---------|---------|----------|--------
  538. Data Type | float16 | float16 | float16 | _ | float16
  539. |---------|---------|---------|----------|--------
  540. | float32 | float32 | float32 | _ | float32
  541. |---------|---------|---------|----------|--------
  542. | int8 | int8 | int32 | int8 | int32
  543. -----------|---------|---------|---------|----------|--------
  544. Format | NCHW | NCHW | ND | ND | NCHW
  545. | NHWC | NHWC | | | NHWC
  546. | | HWCN | | |
  547. @endverbatim
  548. * It should be noted that the data types must correspond to each other, but the
  549. * format does not need to.
  550. *@par Attributes:
  551. * @li strides: A list of 4 integers. Specifying the strides of the
  552. * convolution along the height and width. The dimension order is determined
  553. * by the data format of "x". By default the N and C dimensions are set to 1.
  554. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  555. * padding.
  556. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  557. * for dilated convolution. Has the same dimension order and value as "strides".
  558. * @li groups: Number of blocked connections from input channels to output
  559. * channels. Input channels and output channels must both be divisible by
  560. * "groups".
  561. * @li offset_x: An optional integer for quantized convolution.
  562. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  563. * data format of the input and output images. Reserved.
  564. *@par Outputs:
  565. * @li y: A 4D Tensor of output images.
  566. *@attention
  567. * @li The parameter scope is listed as follows:
  568. * @verbatim
  569. Name | Field | Scope
  570. ------------------|--------------|----------
  571. Input Image Size | H dimension | [1, 4096]
  572. | W dimension | [1, 4096]
  573. ------------------|--------------|----------
  574. Filter Size | H dimension | [1, 255]
  575. | W dimension | [1, 255]
  576. ------------------|--------------|----------
  577. Stride Size | H dimension | [1, 63]
  578. | W dimension | [1, 63]
  579. ------------------|--------------|----------
  580. Padding Size | top side | [0, 255]
  581. | bottom side | [0, 255]
  582. | left side | [0, 255]
  583. | right side | [0, 255]
  584. ------------------|--------------|----------
  585. Dilation Size | H dimension | [1, 255]
  586. | W dimension | [1, 255]
  587. @endverbatim
  588. * @li There are restrictions for certain scenarios:
  589. * @verbatim
  590. Output | Restrictions
  591. ------------------|----------------------------------------------
  592. W dimension == 1 | HxW(input) == HxW(filter)
  593. H dimension == 1 |
  594. ------------------|----------------------------------------------
  595. W dimension == 1 | Not supported
  596. H dimension != 1 |
  597. @endverbatim
  598. * As shown above, "HxW(input)" indicates the image size after padding and
  599. * "HxW(filter)" indicates the filter size after dilation.
  600. *@par Quantization supported or not
  601. * Yes
  602. *@par Third-party framework compatibility
  603. *@li Compatible with the TensorFlow operator "conv2d".
  604. *@li Compatible with the Caffe operator 2D "Convolution".
  605. */
  606. REG_OP(Conv2D)
  607. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  608. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  609. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  610. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  611. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  612. .REQUIRED_ATTR(strides, ListInt)
  613. .REQUIRED_ATTR(pads, ListInt)
  614. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  615. .ATTR(groups, Int, 1)
  616. .ATTR(data_format, String, "NHWC")
  617. .ATTR(offset_x, Int, 0)
  618. .OP_END_FACTORY_REG(Conv2D)
  619. REG_OP(Conv2DCompress)
  620. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  621. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  622. .INPUT(compress_index, TensorType({DT_INT8}))
  623. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  624. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  625. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  626. .REQUIRED_ATTR(strides, ListInt)
  627. .REQUIRED_ATTR(pads, ListInt)
  628. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  629. .ATTR(groups, Int, 1)
  630. .ATTR(data_format, String, "NHWC")
  631. .ATTR(offset_x, Int, 0)
  632. .OP_END_FACTORY_REG(Conv2DCompress)
  633. /**
  634. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  635. *@par Inputs:
  636. *@li x: A 5D tensor. Must be one of the following types: float16, float32, float64. The format is NCDHW or NDHWC.
  637. *@li filter: A 5D tensor of the same type as "x". The format is NCDHW, NDHWC or DHWCN.
  638. *@li bias: An optional 1D tensor of the same type as "x".
  639. *@par Attributes:
  640. *@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".
  641. *@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.
  642. *@li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  643. *@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".
  644. *@par Outputs:
  645. *y: A Tensor. Has the same type as "x".
  646. *@attention Constraints:\n
  647. *The image size after padding is greater than the filter size.\n
  648. *@par Third-party framework compatibility
  649. *@li Compatible with the TensorFlow operator conv3d.
  650. *@li Compatible with the Caffe operator Convolution.
  651. */
  652. REG_OP(Conv3D)
  653. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  654. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  655. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  656. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  657. .ATTR(strides, ListInt, {1, 1, 1, 1, 1})
  658. .ATTR(pads, ListInt, {0, 0, 0, 0, 0, 0})
  659. .ATTR(data_format, String, "NDHWC")
  660. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  661. .OP_END_FACTORY_REG(Conv3D)
  662. /**
  663. *@brief Computes the gradients of convolution 3d with respect to the input.
  664. *@par Inputs:
  665. * Three inputs:
  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. * @li filter: A Tensor. Must be one of the following types: float16, float32, float64.
  669. * @li grads: A Tensor. Must have the same type as filter. 5-D with shape [batch, depth, out_height, out_width, out_channels]
  670. * or [batch, out_channels, depth, out_height, out_width]. Gradients with respect to the output of the convolution.
  671. *@par Attributes:
  672. * Four attributes:
  673. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  674. * @li pads: A tuple/list of 6 integers
  675. * @li dilations: A tuple/list of 6 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  676. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  677. *@par Outputs:
  678. * y: A Tensor. Has the same type as filter,and has same format as input_size
  679. *@par Third-party framework compatibility
  680. * Compatible with Tensorflow's conv3d_backprop_input
  681. */
  682. REG_OP(Conv3DBackpropInput)
  683. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  684. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  685. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  686. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  687. .REQUIRED_ATTR(strides, ListInt)
  688. .ATTR(pads, ListInt, {0, 0, 0, 0, 0, 0})
  689. .ATTR(data_format, String, "NDHWC")
  690. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  691. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  692. /**
  693. *@brief Computes the gradients of convolution 3d with respect to the input.
  694. *@par Inputs:
  695. * Two inputs:
  696. * @li filter: A Tensor. Types is float16.
  697. * @li grads: A Tensor. Must have the same type as filter.
  698. *@par Attributes:
  699. * Five attributes:
  700. * @li input_size A Tensor of type int32. An integer vector representing the shape of input,
  701. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  702. * @li pads: A tuple/list of 4 integers
  703. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  704. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  705. *@par Outputs:
  706. * y: A Tensor. Has the same type as filter
  707. *@par Third-party framework compatibility
  708. * Compatible with Tensorflow's conv3d_backprop_input
  709. */
  710. REG_OP(Conv3DBackpropInputD)
  711. .INPUT(filter, TensorType({DT_FLOAT16}))
  712. .INPUT(grads, TensorType({DT_FLOAT16}))
  713. .OUTPUT(y, TensorType({DT_FLOAT16}))
  714. .REQUIRED_ATTR(input_size, ListInt)
  715. .REQUIRED_ATTR(strides, ListInt)
  716. .ATTR(pads, ListInt, {0, 0, 0, 0, 0, 0})
  717. .ATTR(data_format, String, "NDHWC")
  718. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  719. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  720. REG_OP(LSTM)
  721. .INPUT(x, TensorType({DT_FLOAT16}))
  722. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  723. .INPUT(w_x, TensorType({DT_FLOAT16}))
  724. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  725. .INPUT(w_h, TensorType({DT_FLOAT16}))
  726. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  727. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  728. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  729. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  730. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  731. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  732. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  733. .ATTR(num_output, Int, 0)
  734. .ATTR(expose_hidden, Bool, false)
  735. .OP_END_FACTORY_REG(LSTM)
  736. /**
  737. *@brief Computes the gradients of convolution3D with respect to the filter
  738. *@par Inputs:
  739. * Three inputs:
  740. * @li x: A Tensor. Must be one of the following types: float16
  741. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels] or [batch, in_depth, in_channels, in_height, in_width].
  742. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  743. * where filter is a 5-D tensor [filter_depth, filter_height, filter_width, in_channels, out_channels]
  744. * or [out_channels, filter_depth, filter_height, filter_width, in_channels] or [out_channels, filter_depth, in_channel, filter_height, filter_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. * Three attributes:
  749. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  750. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right] pads on feature map.
  751. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1].
  752. * @li groups: Number of blocked connections from input channels to output channels.
  753. * @li data_format: An optional string from: "NDHWC", "NDCHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  754. *@par Outputs:
  755. * y: A Tensor. Has the same type as x
  756. *@par Third-party framework compatibility
  757. * Compatible with Tensorflow's conv3d_backprop_filter
  758. */
  759. REG_OP(Conv3DBackpropFilter)
  760. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  761. .INPUT(filter_size, TensorType({DT_INT32}))
  762. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  763. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  764. .REQUIRED_ATTR(strides, ListInt)
  765. .REQUIRED_ATTR(pads, ListInt)
  766. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  767. .ATTR(groups, Int, 1)
  768. .ATTR(data_format, String, "NDHWC")
  769. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  770. /**
  771. *@brief Computes the gradients of convolution with respect to the filter.
  772. *@par Inputs:
  773. * Two inputs:
  774. * @li x: A Tensor. Type is float16.
  775. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels] or [batch, in_depth, in_channels, in_height, in_width].
  776. * @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]
  777. * or [batch, out_depth, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  778. *@par Attributes:
  779. * Four attributes:
  780. * @li filter_size: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  781. * where filter is a 5-D tensor [filter_depth, filter_height, filter_width, in_channels, out_channels]
  782. * or [out_channels, filter_depth, filter_height, filter_width, in_channels] or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  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, [front, back, top, bottom, left, right] pads on feature map
  785. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1].
  786. * @li groups: Number of blocked connections from input channels to output channels.
  787. * @li data_format: An optional string from: "NDHWC", "NDCHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  788. *@par Outputs:
  789. * y: A Tensor. Has the same type as x
  790. *@par Third-party framework compatibility
  791. * Compatible with Tensorflow's conv3d_backprop_filter
  792. */
  793. REG_OP(Conv3DBackpropFilterD)
  794. .INPUT(x, TensorType({DT_FLOAT16}))
  795. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  796. .OUTPUT(y, TensorType({DT_FLOAT}))
  797. .REQUIRED_ATTR(filter_size, ListInt)
  798. .REQUIRED_ATTR(strides, ListInt)
  799. .REQUIRED_ATTR(pads, ListInt)
  800. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  801. .ATTR(groups, Int, 1)
  802. .ATTR(data_format, String, "NDHWC")
  803. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  804. } // namespace ge
  805. #endif // GE_OP_NN_CALCULATION_OPS_H

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