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

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