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

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