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 24 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  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 the
  22. * 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]. Must be
  29. * one of the following types: float16, float32, double.
  30. * @par Attributes:
  31. * @li strides: An optional list or tuple. The stride of the sliding window for
  32. * height and width of input "x" of the convolution.
  33. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  34. * stride_width, 1].
  35. * @li dilations: An optional list or tuple. The dilation factor for each
  36. * dimension of input "x". If set to k > 1, there will be k-1 skipped cells
  37. * between each filter element on that dimension. Must be with shape [1, 1,
  38. * dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].
  39. * @li pads: An optional list or tuple. Padding added to each dimension of the
  40. * input.
  41. * @li data_format: An optional string. Input data format, either "NHWC" or
  42. * "NCHW".
  43. * @par Outputs:
  44. * filter_grad: Gradient of the deep convolution relative to the filter with
  45. * shape [H, W, C, K]. Must be one of the following types: float16, float32,
  46. * double.
  47. * @attention Constraints:\n
  48. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  49. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  50. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  51. * [C1, Hf, Wf, K, Co, C0],
  52. * where K is fixed at 1, and Co and C0 are 16.\n
  53. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  54. * data is 5D with shape [N, C1, Ho, Wo, C0],
  55. * where C is the same as that of the feature map and C0 is 16.\n
  56. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  57. * stride_h + 32 * filter_h) * ceil(Wi, 16) ≤ l1_size and Hf*Wf ≤ l0b_size/512.\n
  58. */
  59. REG_OP(DepthwiseConv2DBackpropFilter)
  60. .INPUT(input, TensorType({float16}))
  61. .INPUT(filter_size, TensorType({DT_INT32, DT_INT64}))
  62. .INPUT(out_backprop, TensorType({float16}))
  63. .OUTPUT(filter_grad, TensorType({float32}))
  64. .ATTR(strides, ListInt, {1, 1, 1, 1})
  65. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  66. .ATTR(pads, ListInt, {0, 0, 0, 0})
  67. .ATTR(data_format, String, "NHWC")
  68. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilter)
  69. /**
  70. * @brief Computes the gradients of depthwise convolution with respect to the
  71. * filter.
  72. * @par Inputs:
  73. * Two inputs include: \n
  74. * @li input: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of type float16
  75. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of type
  76. * float16
  77. * @par Attributes:
  78. * @li filter_size: An optional list or tuple. Shape of filter.
  79. * @li strides: An optional list or tuple. The stride of the sliding window for
  80. * height and width of input "x" of the convolution.
  81. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  82. * stride_width, 1].
  83. * @li dilations: An optional list or tuple. The dilation factor for each
  84. * dimension of input "x". If set to k > 1, there will be k-1 skipped cells
  85. * between each filter element on that dimension. Must be with shape [1, 1,
  86. * dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].
  87. * @li pads: An optional list or tuple. Padding added to each dimension of the
  88. * input.
  89. * @li data_format: An optional string. Input data format, either "NHWC" or
  90. * "NCHW".
  91. * @par Outputs:
  92. * filter_grad: Gradient of the deep convolution relative to the filter with
  93. * shape [H, W, C, K]. Must be of type float32.
  94. * @attention Constraints:\n
  95. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  96. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  97. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  98. * [C1, Hf, Wf, K, Co, C0], where K is fixed at 1, and Co and C0 are 16.\n
  99. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  100. * data is 5D with shape [N, C1, Ho, Wo, C0], where C is the same as that of the
  101. * feature map and C0 is 16.\n
  102. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  103. * stride_h + 32 * filter_h) * ceil(Wi, 16) ≤ l1_size and Hf*Wf ≤ l0b_size/512.\n
  104. */
  105. REG_OP(DepthwiseConv2DBackpropFilterD)
  106. .INPUT(input, TensorType({float16}))
  107. .INPUT(out_backprop, TensorType({float16}))
  108. .OUTPUT(filter_grad, TensorType({float32}))
  109. .ATTR(filter_size, ListInt, {1, 1, 1, 1})
  110. .ATTR(strides, ListInt, {1, 1, 1, 1})
  111. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  112. .ATTR(pads, ListInt, {0, 0, 0, 0})
  113. .ATTR(data_format, String, "NHWC")
  114. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilterD)
  115. /**
  116. * @brief Computes the gradients of depthwise convolution with respect to the
  117. * input.
  118. * @par Inputs:
  119. * Three inputs include: \n
  120. * @li input_size: 4D shape of input tensor [N, C, H, W] or [N, H, W, C],
  121. * support int32
  122. * @li filter: 4D filter tensor with shape of [H, W, C, K], support float16,
  123. * float32, double
  124. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  125. * Must be one of the following types: float16, float32, double.
  126. * @par Attributes:
  127. * @li strides: An optional list or tuple. The stride of the sliding window for
  128. * height and width of input "x" of the convolution.
  129. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  130. * stride_width, 1].
  131. * @li dilations: An optional list or tuple. The dilation factor for each
  132. * dimension of input "x". If set to k > 1, there will be k-1 skipped cells
  133. * between each filter element on that dimension. Must be with shape [1, 1,
  134. * dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].
  135. * @li pads: An optional list or tuple. Padding added to each dimension of the
  136. * input.
  137. * @li data_format: An optional string. Input data format, either "NHWC" or
  138. * "NCHW".
  139. * @par Outputs:
  140. * input_grad: Gradient of the deep convolution relative to the input with shape
  141. * [N, C, H, W] or [N, H, W, C] Must be one of the following types: float16,
  142. * float32, double.
  143. * @attention Constraints:\n
  144. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  145. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  146. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  147. * [C1, Hf, Wf, K, Co, C0], where K is fixed at 1, and Co and C0 are 16.\n
  148. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  149. * data is 5D with shape [N, C1, Ho, Wo, C0], where C is the same as that of the
  150. * feature map and C0 is 16.\n
  151. * Limited by Tiling: max_h_in_l1 ≥ C0, where max_h_in_l1 = (l1_size - Hf * Wf *
  152. * C0 * C0 * 2) / (2 * Wo * C0).\n
  153. */
  154. REG_OP(DepthwiseConv2DBackpropInput)
  155. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  156. .INPUT(filter, TensorType({DT_FLOAT16}))
  157. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  158. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  159. .ATTR(strides, ListInt, {1, 1, 1, 1})
  160. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  161. .ATTR(pads, ListInt, {0, 0, 0, 0})
  162. .ATTR(data_format, String, "NHWC")
  163. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInput)
  164. /**
  165. * @brief Computes the gradients of depthwise convolution with respect to the
  166. * input.
  167. * @par Inputs:
  168. * Two inputs include: \n
  169. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  170. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of type
  171. * float16
  172. * @par Attributes:
  173. * @li input_size: An optional list or tuple. The origin shape of input.
  174. * @li strides: An optional list or tuple. The stride of the sliding window for
  175. * height and width of input "x" of the convolution.
  176. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  177. * stride_width, 1].
  178. * @li dilations: An optional list or tuple. The dilation factor for each
  179. * dimension of input "x". If set to k > 1, there will be k-1 skipped cells
  180. * between each filter element on that dimension. Must be with shape [1, 1,
  181. * dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].
  182. * @li pads: An optional list or tuple. Padding added to each dimension of the
  183. * input.
  184. * @li data_format: An optional string. Input data format, either "NHWC" or
  185. * "NCHW".
  186. * @par Outputs:
  187. * input_grad: Gradient of the deep convolution relative to the input with shape
  188. * [N, C, H, W] or [N, H, W, C]. Must be of type float16.
  189. * @attention Constraints:\n
  190. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  191. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  192. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  193. * [C1, Hf, Wf, K, Co, C0], where K is fixed at 1, and Co and C0 are 16.\n
  194. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  195. * data is 5D with shape [N, C1, Ho, Wo, C0], where C is the same as that of the
  196. * feature map and C0 is 16.\n
  197. * Limited by Tiling: max_h_in_l1 ≥ C0, where max_h_in_l1 = (l1_size - Hf * Wf *
  198. * C0 * C0 * 2) / (2 * Wo * C0).\n
  199. */
  200. REG_OP(DepthwiseConv2DBackpropInputD)
  201. .INPUT(filter, TensorType({DT_FLOAT16}))
  202. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  203. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  204. .ATTR(input_size, ListInt, {1, 1, 1, 1})
  205. .ATTR(strides, ListInt, {1, 1, 1, 1})
  206. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  207. .ATTR(pads, ListInt, {0, 0, 0, 0})
  208. .ATTR(data_format, String, "NHWC")
  209. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInputD)
  210. /**
  211. *@brief Computes a 2D deep convolution given a 4D input tensor and a filter
  212. * tensor.
  213. *@par Inputs:
  214. *Two required inputs and two optional inputs, including: \n
  215. * @li x: A 4D tensor of type float16, with shape [N, C, H, W] or [N, H, W, C]
  216. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  217. * @li bias: An optional tensor of type int8
  218. * @li offset_w: An optional float16, used for quantized inference
  219. * @par Attributes:
  220. * @li strides: An optional list or tuple. The stride of the sliding window for
  221. * height and width of input "x" of the convolution.
  222. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  223. * stride_width, 1].
  224. * @li dilations: An optional list or tuple. The dilation factor for each
  225. * dimension of input "x". If set to k > 1, there will be k-1 skipped cells
  226. * between each filter element on that dimension. Must be with shape [1, 1,
  227. * dilation_height, dilation_width] or [1, dilation_height, dilation_width, 1].
  228. * @li pads: An optional list or tuple. Padding added to each dimension of the
  229. * input.
  230. * @li data_format: An optional string. Input data format, either "NHWC" or
  231. * "NCHW".
  232. * @li offset_a: An optional int. Input offset, used for quantized inference.
  233. * @par Outputs:
  234. * y: 4D tensor of type float16, with shape [N, C, H, W] or [N, H, W, C]
  235. * @attention Constraints:\n
  236. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  237. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  238. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  239. * [C1, Hf, Wf, K, Co, C0], where K is fixed at 1, and Co and C0 are 16.\n
  240. * Limited by the size of L1 buffer memory: \n
  241. * (l1_size - filter_h*filter_w*BLOCK_SIZE*BLOCK_SIZE*data_size) // (Wi *
  242. * BLOCK_SIZE * data_size) >= (BLOCK_SIZE * strides_h + filter_h - strides_h).\n
  243. */
  244. REG_OP(DepthwiseConv2D)
  245. .INPUT(x, TensorType({DT_FLOAT16}))
  246. .INPUT(filter, TensorType({DT_FLOAT16}))
  247. .OPTIONAL_INPUT(bias, TensorType({DT_INT8}))
  248. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16}))
  249. .OUTPUT(y, TensorType({DT_FLOAT16}))
  250. .ATTR(strides, ListInt, {})
  251. .ATTR(dilations, ListInt, {})
  252. .ATTR(pads, ListInt, {0, 0, 0, 0})
  253. .ATTR(data_format, String, "NHWC")
  254. .ATTR(offset_a, Int, 0)
  255. .OP_END_FACTORY_REG(DepthwiseConv2D)
  256. REG_OP(Conv2DCCE)
  257. .INPUT(x, TensorType{DT_FLOAT}) // The input tensor
  258. .INPUT(w, TensorType({DT_FLOAT, DT_INT8})) // The weight tensor ,If QuantType =1 ,shall use type""tensor(int8)
  259. .OPTIONAL_INPUT(b, TensorType{DT_FLOAT}) // Optional 1D bias to be added to the convolution, has size of M.
  260. .OUTPUT(y, TensorType{DT_FLOAT}) // The output tensor
  261. .ATTR(mode, Int, 1)
  262. .ATTR(group, Int, 1) // number of groups input channels and output channels are divided into
  263. .ATTR(num_output, Int, 0) // number of output tensor
  264. .ATTR(pad, ListInt, {0, 0, 0, 0}) // Padding for the beginning and ending along each axis
  265. .ATTR(kernel, ListInt, {0, 0})
  266. .ATTR(stride, ListInt, {1, 1}) // Stride along each axis.
  267. .ATTR(dilation, ListInt, {1, 1}) // dilation value along each axis of the filter.
  268. .ATTR(pad_mode, Int, 0) // pad mode, 0:NOTSET, 1:SAME_UPPER, SAME_LOWER or 2:VALID.defaul default value is 0:NOTSET
  269. .ATTR(algo, Int, 2)
  270. .OP_END_FACTORY_REG(Conv2DCCE)
  271. REG_OP(Conv2DBackpropFilterCCE)
  272. .INPUT(x, TensorType{DT_FLOAT})
  273. .INPUT(filter_sizes, TensorType{DT_INT8})
  274. .INPUT(out_backprop, TensorType{DT_FLOAT})
  275. .OUTPUT(y, TensorType{DT_FLOAT})
  276. .ATTR(conv_grad_filter_output_shape, ListInt, {0, 0, 0, 0})
  277. .ATTR(mode, Int, 1)
  278. .ATTR(group, Int, 1)
  279. .ATTR(pad, ListInt, {0, 0, 0, 0})
  280. .ATTR(stride, ListInt, {1, 1})
  281. .ATTR(dilation, ListInt, {1, 1})
  282. .ATTR(padding, Int, 0) //pad_mode:same valid
  283. .ATTR(algo, Int, 0)
  284. .OP_END_FACTORY_REG(Conv2DBackpropFilterCCE)
  285. REG_OP(Conv2DBackpropInputCCE)
  286. .INPUT(input_sizes, TensorType{DT_INT8})
  287. .INPUT(filter, TensorType{DT_FLOAT})
  288. .INPUT(out_backprop, TensorType{DT_FLOAT})
  289. .OUTPUT(output, TensorType{DT_FLOAT})
  290. .ATTR(conv_grad_input_output_shape, ListInt, {0, 0, 0, 0})
  291. .ATTR(mode, Int, 1)
  292. .ATTR(format, Int, 0)
  293. .ATTR(group, Int, 1)
  294. .ATTR(pad_mode, Int, 0)
  295. .ATTR(stride, ListInt, {1, 1})
  296. .ATTR(dilation, ListInt, {1, 1})
  297. .ATTR(pad, ListInt, {0, 0, 0, 0})
  298. .ATTR(algo, Int, 0)
  299. .OP_END_FACTORY_REG(Conv2DBackpropInputCCE)
  300. /**
  301. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  302. * It accumulates all the values from out_backprop into the feature
  303. * dimension. For NHWC data format, the feature dimension is the last.
  304. * For NCHW data format, the feature dimension is the third-to-last.
  305. *@par Inputs:
  306. *x: A Tensor of type TensorType::NumberType().
  307. *@par Attributes:
  308. *data_format: Data format. Defaults to "NHWC".
  309. *@par Outputs:
  310. *y: A Tensor.Has the same type as "x".
  311. */
  312. REG_OP(BiasAddGrad)
  313. .INPUT(x, TensorType::NumberType())
  314. .OUTPUT(y, TensorType::NumberType())
  315. .ATTR(data_format, String, "NHWC")
  316. .OP_END_FACTORY_REG(BiasAddGrad)
  317. /**
  318. *@brief Computes the gradients of convolution with respect to the input.
  319. *@par Inputs:
  320. * Three inputs:
  321. * @li input_sizes: A Tensor of type int32. An integer vector representing the shape of input,
  322. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  323. * @li filters: A Tensor. Must be one of the following types: float16.
  324. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  325. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  326. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  327. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  328. *@par Attributes:
  329. * Three attributes:
  330. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  331. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  332. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  333. *@par Outputs:
  334. * y: A Tensor. Has the same type as filter,and has same format as input_size
  335. */
  336. REG_OP(Conv2DBackpropInput)
  337. .INPUT(input_sizes, TensorType({DT_INT32, DT_INT64}))
  338. .INPUT(filters, TensorType{DT_FLOAT16})
  339. .INPUT(out_backprop, TensorType{DT_FLOAT16})
  340. .OUTPUT(y, TensorType{DT_FLOAT16})
  341. .REQUIRED_ATTR(strides, ListInt)
  342. .ATTR(pads, ListInt, {1, 1, 1, 1})
  343. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  344. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  345. /**
  346. *@brief Computes the gradients of convolution with respect to the input.
  347. *@par Inputs:
  348. * Two inputs:
  349. * @li filters: A Tensor. Types is float16.
  350. * 4-D with shape [filter_height, filter_width, in_channels, out_channels] or [out_channels, filter_height, filter_width, in_channels]
  351. * or [out_channels, in_channel, filter_height, filter_width].
  352. * @li out_backprop: A Tensor. Must have the same type as filter. 4-D with shape [batch, out_height, out_width, out_channels]
  353. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  354. *@par Attributes:
  355. * Four attributes:
  356. * @li input_size A Tensor of type int32. An integer vector representing the shape of input,
  357. * where input is a 4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  358. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  359. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  360. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1]
  361. *@par Outputs:
  362. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width, channels] or [batch, channels, height, width].
  363. */
  364. REG_OP(Conv2DBackpropInputD)
  365. .INPUT(filters, TensorType{DT_FLOAT16})
  366. .INPUT(out_backprop, TensorType{DT_FLOAT16})
  367. .OUTPUT(y, TensorType{DT_FLOAT16})
  368. .REQUIRED_ATTR(input_sizes, ListInt)
  369. .REQUIRED_ATTR(strides, ListInt)
  370. .ATTR(pads, ListInt, {1, 1, 1, 1})
  371. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  372. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  373. /**
  374. *@brief Computes the Deconvolution with respect to the input.
  375. *@par Inputs:
  376. * Two inputs:
  377. * @li x: A Tensor. Must have the same type as "filter". 4D with shape\n
  378. * [batch, out_height, out_width, out_channels]\n
  379. * or [batch, out_channels, out_height, out_width]. Gradients with respect\n
  380. * to the output of the convolution.
  381. * @li filter: A Tensor of type float16.
  382. * 4D with shape [filter_height, filter_width, in_channels, out_channels],\n
  383. * or [out_channels, filter_height, filter_width, in_channels], \n
  384. * or [out_channels, in_channel, filter_height, filter_width].
  385. * One optional input:
  386. * @li bias: An optional tensor of type int8
  387. *@par Attributes:
  388. * Three attributes:
  389. * @li strides: A tuple or list of 2 integers. The stride of the sliding window\n
  390. * for H/W dimension.
  391. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right] \n
  392. * padding on the feature map
  393. * @li dilations: A tuple or list of 4 integers. The dilation factor for each\n
  394. * dimension of input. Must be [1, 1, 1, 1].
  395. *@par Outputs:
  396. * y: A Tensor. Has the same type as "filter". 4D tensor with shape\n
  397. * [batch, height, width, channels] or [batch, channels, height, width].
  398. */
  399. REG_OP(Deconvolution)
  400. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  401. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  402. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  403. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE))
  404. .ATTR(strides, ListInt, {1, 1, 1, 1})
  405. .ATTR(pads, ListInt, {0, 0, 0, 0})
  406. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  407. .OP_END_FACTORY_REG(Deconvolution)
  408. /**
  409. *@brief Computes the gradients of convolution with respect to the filter
  410. *@par Inputs:
  411. * Three inputs:
  412. * @li x: A Tensor. Must be one of the following types: float16.
  413. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_width].
  414. * @li filter_sizes: A Tensor of type int32. An integer vector representing the tensor shape of filter,
  415. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  416. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  417. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape [batch, out_height, out_width, out_channels]
  418. * or [batch, out_channels, out_height, out_width]. Gradients with respect to the output of the convolution.
  419. *@par Attributes:
  420. * Three attributes:
  421. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  422. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map.
  423. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  424. *@par Outputs:
  425. * y: A Tensor. Has the same type as x
  426. */
  427. REG_OP(Conv2DBackpropFilter)
  428. .INPUT(x, TensorType{DT_FLOAT16})
  429. .INPUT(filter_sizes, TensorType({DT_INT32, DT_INT64}))
  430. .INPUT(out_backprop, TensorType{DT_FLOAT16})
  431. .OUTPUT(y, TensorType{DT_FLOAT})
  432. .REQUIRED_ATTR(strides, ListInt)
  433. .ATTR(pads, ListInt, {1, 1, 1, 1})
  434. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  435. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  436. /**
  437. *@brief Computes the gradients of convolution with respect to the filter.
  438. *@par Inputs:
  439. * Two inputs:
  440. * @li x: A Tensor. Type is float16.
  441. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch, in_channels, in_height, in_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. * Four attributes:
  446. * @li filter_sizes: A Tensor of type integers. An integer vector representing the tensor shape of filter,
  447. * where filter is a 4-D tensor [filter_height, filter_width, in_channels, out_channels]
  448. * or [out_channels, filter_height, filter_width, in_channels] or [out_channels, in_channel, filter_height, filter_width].
  449. * @li strides: A tuple/list of 2 integers. The stride of the sliding window for H/W dimension.
  450. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on feature map
  451. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension of input, now only support [1,1,1,1].
  452. *@par Outputs:
  453. * y: A Tensor. Has the same type as x
  454. */
  455. REG_OP(Conv2DBackpropFilterD)
  456. .INPUT(x, TensorType{DT_FLOAT16})
  457. .INPUT(out_backprop, TensorType{DT_FLOAT16})
  458. .OUTPUT(y, TensorType{DT_FLOAT})
  459. .REQUIRED_ATTR(filter_sizes, ListInt)
  460. .REQUIRED_ATTR(strides, ListInt)
  461. .ATTR(pads, ListInt, {1, 1, 1, 1})
  462. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  463. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  464. REG_OP(Conv2D)
  465. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8})) // the featrue map tensor
  466. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8})) // the filter tensor
  467. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32})) // optional 1D bias to be added to the conv2d
  468. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  469. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32})) // the output tensor
  470. .ATTR(strides, ListInt, {1, 1, 1, 1}) // stride on H\W, format sensitive
  471. .ATTR(pads, ListInt, {0, 0, 0, 0}) // top, bottom, left and right pads on feature map
  472. .ATTR(dilations, ListInt, {1, 1, 1, 1}) // dilation on H\W, format sensitive
  473. .ATTR(offset_a, Int, 0)
  474. .OP_END_FACTORY_REG(Conv2D)
  475. } // namespace ge
  476. #endif // GE_OP_NN_CALCULATION_OPS_H

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