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

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