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 23 kB

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

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