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 35 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744
  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. */
  253. REG_OP(DepthwiseConv2D)
  254. .INPUT(x, TensorType({DT_FLOAT16}))
  255. .INPUT(filter, TensorType({DT_FLOAT16}))
  256. .OPTIONAL_INPUT(bias, TensorType({DT_INT8}))
  257. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16}))
  258. .OUTPUT(y, TensorType({DT_FLOAT16}))
  259. .REQUIRED_ATTR(strides, ListInt)
  260. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  261. .REQUIRED_ATTR(pads, ListInt)
  262. .ATTR(data_format, String, "NHWC")
  263. .ATTR(offset_x, Int, 0)
  264. .OP_END_FACTORY_REG(DepthwiseConv2D)
  265. REG_OP(Conv2DCCE)
  266. .INPUT(x, TensorType{DT_FLOAT}) // The input tensor
  267. .INPUT(w, TensorType({DT_FLOAT, DT_INT8})) // The weight tensor ,If QuantType =1 ,shall use type""tensor(int8)
  268. .OPTIONAL_INPUT(b, TensorType{DT_FLOAT}) // Optional 1D bias to be added to the convolution, has size of M.
  269. .OUTPUT(y, TensorType{DT_FLOAT}) // The output tensor
  270. .ATTR(mode, Int, 1)
  271. .ATTR(group, Int, 1) // number of groups input channels and output channels are divided into
  272. .ATTR(num_output, Int, 0) // number of output tensor
  273. .ATTR(pad, ListInt, {0, 0, 0, 0}) // Padding for the beginning and ending along each axis
  274. .ATTR(kernel, ListInt, {0, 0})
  275. .ATTR(stride, ListInt, {1, 1}) // Stride along each axis.
  276. .ATTR(dilation, ListInt, {1, 1}) // dilation value along each axis of the filter.
  277. .ATTR(pad_mode, Int, 0) // pad mode, 0:NOTSET, 1:SAME_UPPER, SAME_LOWER or 2:VALID.defaul default value is 0:NOTSET
  278. .ATTR(algo, Int, 2)
  279. .OP_END_FACTORY_REG(Conv2DCCE)
  280. REG_OP(Conv2DBackpropFilterCCE)
  281. .INPUT(x, TensorType{DT_FLOAT})
  282. .INPUT(filter_sizes, TensorType{DT_INT8})
  283. .INPUT(out_backprop, TensorType{DT_FLOAT})
  284. .OUTPUT(y, TensorType{DT_FLOAT})
  285. .ATTR(conv_grad_filter_output_shape, ListInt, {0, 0, 0, 0})
  286. .ATTR(mode, Int, 1)
  287. .ATTR(group, Int, 1)
  288. .ATTR(pad, ListInt, {0, 0, 0, 0})
  289. .ATTR(stride, ListInt, {1, 1})
  290. .ATTR(dilation, ListInt, {1, 1})
  291. .ATTR(padding, Int, 0) //pad_mode:same valid
  292. .ATTR(algo, Int, 0)
  293. .OP_END_FACTORY_REG(Conv2DBackpropFilterCCE)
  294. REG_OP(Conv2DBackpropInputCCE)
  295. .INPUT(input_sizes, TensorType{DT_INT8})
  296. .INPUT(filter, TensorType{DT_FLOAT})
  297. .INPUT(out_backprop, TensorType{DT_FLOAT})
  298. .OUTPUT(output, TensorType{DT_FLOAT})
  299. .ATTR(conv_grad_input_output_shape, ListInt, {0, 0, 0, 0})
  300. .ATTR(mode, Int, 1)
  301. .ATTR(format, Int, 0)
  302. .ATTR(group, Int, 1)
  303. .ATTR(pad_mode, Int, 0)
  304. .ATTR(stride, ListInt, {1, 1})
  305. .ATTR(dilation, ListInt, {1, 1})
  306. .ATTR(pad, ListInt, {0, 0, 0, 0})
  307. .ATTR(algo, Int, 0)
  308. .OP_END_FACTORY_REG(Conv2DBackpropInputCCE)
  309. /**
  310. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  311. * It accumulates all the values from out_backprop into the feature
  312. * dimension. For NHWC data format, the feature dimension is the last.
  313. * For NCHW data format, the feature dimension is the third-to-last.
  314. *@par Inputs:
  315. *x: A Tensor of type TensorType::NumberType().
  316. *@par Attributes:
  317. *data_format: Data format. Defaults to "NHWC".
  318. *@par Outputs:
  319. *y: A Tensor.Has the same type as "x".
  320. */
  321. REG_OP(BiasAddGrad)
  322. .INPUT(x, TensorType::NumberType())
  323. .OUTPUT(y, TensorType::NumberType())
  324. .ATTR(data_format, String, "NHWC")
  325. .OP_END_FACTORY_REG(BiasAddGrad)
  326. /**
  327. *@brief Computes the gradients of convolution with respect to the input.
  328. *@par Inputs:
  329. * Three inputs:
  330. * @li input_size: A Tensor of type int32. An integer vector representing the shape of input,
  331. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  332. * @li filter: A Tensor. Must be one of the following types: float16, float32, float64.
  333. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  334. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  335. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  336. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  337. *@par Attributes:
  338. * Three attributes:
  339. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  340. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  341. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  342. * @li groups: Number of blocked connections from input channels to output channels.
  343. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  344. *@par Outputs:
  345. * y: A Tensor. Has the same type as filter,and has same format as input_size
  346. */
  347. REG_OP(Conv2DBackpropInput)
  348. .INPUT(input_size, TensorType({DT_INT32}))
  349. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  350. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  351. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  352. .REQUIRED_ATTR(strides, ListInt)
  353. .REQUIRED_ATTR(pads, ListInt)
  354. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  355. .ATTR(groups, Int, 1)
  356. .ATTR(data_format, String, "NHWC")
  357. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  358. /**
  359. *@brief Computes the gradients of convolution with respect to the input.
  360. *@par Inputs:
  361. * Two inputs:
  362. * @li filter: A Tensor. Types is float16.
  363. * 4-D with shape [filter_height, filter_width, in_channels, out_channels] or [out_channels, filter_height, filter_width, in_channels]
  364. * or [out_channels, in_channel, filter_height, filter_width].
  365. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  366. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  367. *@par Attributes:
  368. * Four attributes:
  369. * @li input_size A Tensor of type int32. An integer vector representing the shape of input,
  370. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  371. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  372. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  373. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  374. * @li groups: Number of blocked connections from input channels to output channels.
  375. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  376. *@par Outputs:
  377. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  378. */
  379. REG_OP(Conv2DBackpropInputD)
  380. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  381. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  382. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  383. .REQUIRED_ATTR(input_size, ListInt)
  384. .REQUIRED_ATTR(strides, ListInt)
  385. .REQUIRED_ATTR(pads, ListInt)
  386. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  387. .ATTR(groups, Int, 1)
  388. .ATTR(data_format, String, "NHWC")
  389. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  390. /**
  391. *@brief Computes the Deconvolution with respect to the input.
  392. *@par Inputs:
  393. * Three inputs:
  394. * @li x: A Tensor. Must have the same type as "filter". 4D with shape
  395. * [batch, out_height, out_width, out_channels]
  396. * or [batch, out_channels, out_height, out_width]. Gradients with respect
  397. * to the output of the convolution.
  398. * @li filter: A Tensor of type float16.
  399. * 4D with shape [filter_height, filter_width, in_channels, out_channels],
  400. * or [out_channels, filter_height, filter_width, in_channels],
  401. * or [out_channels, in_channel, filter_height, filter_width].
  402. * One optional input:
  403. * @li bias: An optional tensor of type int8
  404. *@par Attributes:
  405. * Five attributes:
  406. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  407. * for H/W dimension.
  408. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  409. * padding on the feature map
  410. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  411. * dimension of input. Must be [1, 1, 1, 1].
  412. * @li groups: Number of blocked connections from input channels to \n
  413. output channels.
  414. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".\n
  415. Specify the data format of the input and output data.
  416. *@par Outputs:
  417. * y: A Tensor. Has the same type as "filter". 4D tensor with shape
  418. * [batch, height, width, channels] or [batch, channels, height, width].
  419. */
  420. REG_OP(Deconvolution)
  421. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  422. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  423. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  424. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  425. .ATTR(strides, ListInt, {1, 1, 1, 1})
  426. .ATTR(pads, ListInt, {0, 0, 0, 0})
  427. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  428. .ATTR(groups, Int, 1)
  429. .ATTR(data_format, String, "NHWC")
  430. .OP_END_FACTORY_REG(Deconvolution)
  431. /**
  432. *@brief Computes the gradients of convolution with respect to the filter
  433. *@par Inputs:
  434. * Three inputs:
  435. * @li x: A Tensor. Must be one of the following types: float16, float32, float64.
  436. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  437. * @li filter_size: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  438. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  439. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  440. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  441. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  442. *@par Attributes:
  443. * Three attributes:
  444. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  445. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map.
  446. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  447. * @li groups: Number of blocked connections from input channels to output channels.
  448. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  449. *@par Outputs:
  450. * y: A Tensor. Has the same type as x
  451. */
  452. REG_OP(Conv2DBackpropFilter)
  453. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  454. .INPUT(filter_size, TensorType({DT_INT32}))
  455. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  456. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  457. .REQUIRED_ATTR(strides, ListInt)
  458. .REQUIRED_ATTR(pads, ListInt)
  459. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  460. .ATTR(groups, Int, 1)
  461. .ATTR(data_format, String, "NHWC")
  462. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  463. /**
  464. *@brief Computes the gradients of convolution with respect to the filter.
  465. *@par Inputs:
  466. * Two inputs:
  467. * @li x: A Tensor. Type is float16.
  468. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  469. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  470. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  471. *@par Attributes:
  472. * Four attributes:
  473. * @li filter_size: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  474. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  475. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  476. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  477. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  478. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  479. * @li groups: Number of blocked connections from input channels to output channels.
  480. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC". Specify the data format of the input and output data.
  481. *@par Outputs:
  482. * y: A Tensor. Has the same type as x
  483. */
  484. REG_OP(Conv2DBackpropFilterD)
  485. .INPUT(x, TensorType({DT_FLOAT16}))
  486. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  487. .OUTPUT(y, TensorType({DT_FLOAT}))
  488. .REQUIRED_ATTR(filter_size, ListInt)
  489. .REQUIRED_ATTR(strides, ListInt)
  490. .REQUIRED_ATTR(pads, ListInt)
  491. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  492. .ATTR(groups, Int, 1)
  493. .ATTR(data_format, String, "NHWC")
  494. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  495. /**
  496. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  497. *@par Inputs:
  498. * @li x: A 4D tensor of input images.
  499. * @li filter: A 4D tensor of filters.
  500. * @li bias: An optional 1D tensor.
  501. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.\n
  502. * \n
  503. * The input and output tensor attributes are listed as follows:
  504. * @verbatim
  505. Tensor | x | filter | bias | offset_w | y
  506. -----------|---------|---------|---------|----------|--------
  507. Data Type | float16 | float16 | float16 | _ | float16
  508. |---------|---------|---------|----------|--------
  509. | float32 | float32 | float32 | _ | float32
  510. |---------|---------|---------|----------|--------
  511. | float64 | float64 | float64 | _ | float64
  512. |---------|---------|---------|----------|--------
  513. | int8 | int8 | int32 | int8 | int32
  514. -----------|---------|---------|---------|----------|--------
  515. Format | NCHW | NCHW | ND | ND | NCHW
  516. | NHWC | NHWC | | | NHWC
  517. | | HWCN | | |
  518. @endverbatim
  519. * It should be noted that the data types must correspond to each other, but the
  520. * format does not need to.
  521. *@par Attributes:
  522. * @li strides: A list of 4 integers. Specifying the strides of the
  523. * convolution along the height and width. The dimension order is determined
  524. * by the data format of "x". By default the N and C dimensions are set to 1.
  525. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  526. * padding.
  527. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  528. * for dilated convolution. Has the same dimension order and value as "strides".
  529. * @li groups: Number of blocked connections from input channels to output
  530. * channels. Input channels and output channels must both be divisible by
  531. * "groups". Must be set to 1.
  532. * @li offset_x: An optional integer for quantized convolution.
  533. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  534. * data format of the input and output images. Reserved.
  535. *@par Outputs:
  536. * @li y: A 4D Tensor of output images.
  537. *@attention
  538. * @li The parameter scope is listed as follows:\n
  539. * @verbatim
  540. Name | Field | Scope
  541. ------------------|--------------|----------
  542. Input Image Size | H dimension | [1, 4096]
  543. | W dimension | [1, 4096]
  544. ------------------|--------------|----------
  545. Filter Size | H dimension | [1, 255]
  546. | W dimension | [1, 255]
  547. ------------------|--------------|----------
  548. Stride Size | H dimension | [1, 63]
  549. | W dimension | [1, 63]
  550. ------------------|--------------|----------
  551. Padding Size | top side | [0, 255]
  552. | bottom side | [0, 255]
  553. | left side | [0, 255]
  554. | right side | [0, 255]
  555. ------------------|--------------|----------
  556. Dilation Size | H dimension | [1, 255]
  557. | W dimension | [1, 255]
  558. @endverbatim
  559. * @li There are restrictions for certain scenarios:
  560. * @verbatim
  561. Output | Restrictions
  562. ------------------|----------------------------------------------
  563. W dimension == 1 | HxW(input) == HxW(filter) == 1x1,2x2...11x11.
  564. H dimension == 1 |
  565. ------------------|----------------------------------------------
  566. W dimension == 1 | Not supported
  567. H dimension != 1 |
  568. @endverbatim
  569. * As shown above, "HxW(input)" indicates the image size after padding and
  570. * "HxW(filter)" indicates the filter size after dilation.
  571. */
  572. REG_OP(Conv2D)
  573. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  574. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  575. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  576. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  577. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  578. .REQUIRED_ATTR(strides, ListInt)
  579. .REQUIRED_ATTR(pads, ListInt)
  580. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  581. .ATTR(groups, Int, 1)
  582. .ATTR(data_format, String, "NHWC")
  583. .ATTR(offset_x, Int, 0)
  584. .OP_END_FACTORY_REG(Conv2D)
  585. /**
  586. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  587. *@par Inputs:
  588. *@li x: A 5D tensor. Must be one of the following types: float16, float32, float64. The format is NCDHW or NDHWC.
  589. *@li filter: A 5D tensor of the same type as "x". The format is NCDHW, NDHWC or DHWCN.
  590. *@li bias: An optional 1D tensor of the same type as "x".
  591. *@par Attributes:
  592. *@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".
  593. *@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.
  594. *@li data_format: An optional string from: "NDHWC", "NCDHW". Defaults to "NDHWC". Specify the data format of the input and output data.
  595. *@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".
  596. *@par Outputs:
  597. *y: A Tensor. Has the same type as "x".
  598. *@attention Constraints:\n
  599. *The image size after padding is greater than the filter size.\n
  600. */
  601. REG_OP(Conv3D)
  602. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  603. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  604. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  605. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  606. .ATTR(strides, ListInt, {1, 1, 1, 1, 1})
  607. .ATTR(pads, ListInt, {0, 0, 0, 0, 0, 0})
  608. .ATTR(data_format, String, "NDHWC")
  609. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  610. .OP_END_FACTORY_REG(Conv3D)
  611. /**
  612. *@brief Computes the gradients of convolution 3d with respect to the input.
  613. *@par Inputs:
  614. * Three inputs:
  615. * @li input_sizes: A Tensor of type int32, int64. An integer vector representing the shape of input,
  616. * where input is a 5-D tensor [batch, depth, height, width, channels] or [batch, channels, depth, height, width].
  617. * @li filters: A Tensor. Must be one of the following types: float16, float32, float64.
  618. * @li grads: A Tensor. Must have the same type as filter. 5-D with shape [batch, depth, out_height, out_width, out_channels]
  619. * or [batch, out_channels, depth, out_height, out_width]. Gradients with respect to the output of the convolution.
  620. *@par Attributes:
  621. * Four attributes:
  622. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  623. * @li pads: A tuple/list of 6 integers
  624. * @li dilations: A tuple/list of 6 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  625. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  626. *@par Outputs:
  627. * y: A Tensor. Has the same type as filter,and has same format as input_size
  628. */
  629. REG_OP(Conv3DBackpropInput)
  630. .INPUT(input_sizes, TensorType({DT_INT32, DT_INT64}))
  631. .INPUT(filters, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  632. .INPUT(grads, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  633. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  634. .REQUIRED_ATTR(strides, ListInt)
  635. .ATTR(pads, ListInt, {0, 0, 0, 0, 0, 0})
  636. .ATTR(data_format, String, "NDHWC")
  637. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  638. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  639. /**
  640. *@brief Computes the gradients of convolution 3d with respect to the input.
  641. *@par Inputs:
  642. * Two inputs:
  643. * @li filters: A Tensor. Types is float16.
  644. * @li grads: A Tensor. Must have the same type as filter.
  645. *@par Attributes:
  646. * Five attributes:
  647. * @li input_sizes A Tensor of type int32. An integer vector representing the shape of input,
  648. * @li strides: A tuple/list of 3 integers. The stride of the sliding window for D/H/W dimension.
  649. * @li pads: A tuple/list of 4 integers
  650. * @li dilations: A tuple/list of 5 integers, The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  651. * @li data_format: An optional string from: "NDHWC", "NCHWD". Defaults to "NDHWC". Specify the data format of the input and output data.
  652. *@par Outputs:
  653. * y: A Tensor. Has the same type as filter
  654. */
  655. REG_OP(Conv3DBackpropInputD)
  656. .INPUT(filters, TensorType({DT_FLOAT16}))
  657. .INPUT(grads, TensorType({DT_FLOAT16}))
  658. .OUTPUT(y, TensorType({DT_FLOAT16}))
  659. .REQUIRED_ATTR(input_sizes, ListInt)
  660. .REQUIRED_ATTR(strides, ListInt)
  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(Conv3DBackpropInputD)
  665. REG_OP(LSTMQuant)
  666. .INPUT(x, TensorType({DT_FLOAT16,DT_INT8}))
  667. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  668. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16,DT_INT8}))
  669. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT8}))
  670. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  671. .INPUT(w_x, TensorType({DT_FLOAT16,DT_INT8}))
  672. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  673. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16,DT_INT8}))
  674. .INPUT(w_h, TensorType({DT_FLOAT16,DT_INT8}))
  675. .OPTIONAL_INPUT(w_xh_deqscale, TensorType({DT_FLOAT16}))
  676. .OPTIONAL_INPUT(w_x_static_deqscale, TensorType({DT_FLOAT16}))
  677. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT8}))
  678. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT,DT_INT8}))
  679. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  680. .ATTR(num_output, Int, 0)
  681. .ATTR(expose_hidden, Bool, false)
  682. .ATTR(xh_scale, Float,0)
  683. .ATTR(sqrt_mode_xh, Bool, false)
  684. .ATTR(sqrt_mode_x_static, Bool, false)
  685. .ATTR(xh_offset, Int,0)
  686. .ATTR(x_static_scale, Float,0.0)
  687. .ATTR(x_static_offset, Int,0)
  688. .ATTR(w_xh_offset,ListInt,{0})
  689. .ATTR(w_x_static_offset,ListInt,{0})
  690. .OP_END_FACTORY_REG(LSTMQuant)
  691. } // namespace ge
  692. #endif // GE_OP_NN_CALCULATION_OPS_H

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