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

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196
  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. /*!
  17. * \file nn_calculation_ops.h
  18. * \brief
  19. */
  20. #ifndef GE_OP_NN_CALCULATION_OPS_H
  21. #define GE_OP_NN_CALCULATION_OPS_H
  22. #include "graph/operator_reg.h"
  23. namespace ge {
  24. /**
  25. * @brief Computes the gradients of depthwise convolution with respect to
  26. * the filter.
  27. * @par Inputs:
  28. * Three inputs include: \n
  29. * @li input: 4D origin shape of input tensor [N, C, H, W] or [N, H, W, C],
  30. * support float16, float32, double
  31. * @li filter_size: A 4D tensor of type int32, with shape [H, W, C, K]
  32. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  33. * Must be one of the following types: float16, float32, double.
  34. * @par Attributes:
  35. * @li strides: A required list or tuple. The stride of the sliding window
  36. * for height and width of input "x" of the convolution.
  37. * Must be with shape [1, 1, stride_height, stride_width] or
  38. * [1, stride_height, stride_width, 1].
  39. * @li dilations: An optional list or tuple. The dilation factor for each
  40. * dimension of input "x".
  41. * If set to k > 1, there will be k-1 skipped cells between each filter element
  42. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  43. * or [1, dilation_height, dilation_width, 1].
  44. * @li pads: A required list or tuple. Padding added to each dimension of the
  45. * input.
  46. * @li data_format: An optional string. Input data format, either "NHWC" or
  47. * "NCHW".
  48. * @par Outputs:
  49. * filter_grad: Gradient of the deep convolution relative to the filter with
  50. * shape [H, W, C, K]. Must be one of the following types: float16, float32,
  51. * double.
  52. * @attention Constraints:\n
  53. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  54. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  55. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  56. * [C1, Hf, Wf, K, Co, C0],
  57. * where K is fixed at 1, and Co and C0 are 16.\n
  58. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  59. * data is 5D with shape [N, C1, Ho, Wo, C0],
  60. * where C is the same as that of the feature map and C0 is 16.\n
  61. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  62. * stride_h + 32 * filter_h) * ceil(Wi, 16) <= l1_size and Hf*Wf <= l0b_size/512.
  63. * @par Third-party framework compatibility
  64. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropFilter.
  65. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropFilter.
  66. */
  67. REG_OP(DepthwiseConv2DBackpropFilter)
  68. .INPUT(input, TensorType({float16}))
  69. .INPUT(filter_size, TensorType({DT_INT32, DT_INT64}))
  70. .INPUT(out_backprop, TensorType({float16}))
  71. .OUTPUT(filter_grad, TensorType({float32}))
  72. .REQUIRED_ATTR(strides, ListInt)
  73. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  74. .REQUIRED_ATTR(pads, ListInt)
  75. .ATTR(data_format, String, "NHWC")
  76. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilter)
  77. /**
  78. * @brief Computes the gradients of depthwise convolution with respect to
  79. * the filter.
  80. * @par Inputs:
  81. * Two inputs include: \n
  82. * @li input: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of type float16
  83. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C],
  84. * of type float16
  85. * @par Attributes:
  86. * @li filter_size: A required list or tuple. Shape of filter.
  87. * @li strides: A required list or tuple. The stride of the sliding window for
  88. * height and width of input "x" of the convolution.
  89. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  90. * stride_width, 1].
  91. * @li dilations: An optional list or tuple. The dilation factor for each
  92. * dimension of input "x".
  93. * If set to k > 1, there will be k-1 skipped cells between each filter element
  94. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  95. * or [1, dilation_height, dilation_width, 1].
  96. * @li pads: A required list or tuple. Padding added to each dimension of the
  97. * input.
  98. * @li data_format: An optional string. Input data format, either "NHWC" or
  99. * "NCHW".
  100. * @par Outputs:
  101. * filter_grad: Gradient of the deep convolution relative to the filter with
  102. * shape [H, W, C, K]. Must be of type float32.
  103. * @attention Constraints:\n
  104. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  105. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  106. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  107. * [C1, Hf, Wf, K, Co, C0],
  108. * where K is fixed at 1, and Co and C0 are 16.\n
  109. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  110. * data is 5D with shape [N, C1, Ho, Wo, C0],
  111. * where C is the same as that of the feature map and C0 is 16.\n
  112. * Limited by Tiling and L1 / L0 buffer memory: 512 * ceil(Wo, 16) + (480 *
  113. * stride_h + 32 * filter_h) * ceil(Wi, 16) <= l1_size and Hf*Wf <= l0b_size/512.
  114. * @par Third-party framework compatibility
  115. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropFilter.
  116. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropFilter.
  117. *
  118. * @par Restrictions:
  119. * Warning: THIS FUNCTION IS DEPRECATED. Please use DepthwiseConv2DBackpropFilter
  120. * instead.
  121. */
  122. REG_OP(DepthwiseConv2DBackpropFilterD)
  123. .INPUT(input, TensorType({float16}))
  124. .INPUT(out_backprop, TensorType({float16}))
  125. .OUTPUT(filter_grad, TensorType({float32}))
  126. .REQUIRED_ATTR(filter_size, ListInt)
  127. .REQUIRED_ATTR(strides, ListInt)
  128. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  129. .REQUIRED_ATTR(pads, ListInt)
  130. .ATTR(data_format, String, "NHWC")
  131. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropFilterD)
  132. /**
  133. * @brief Computes the gradients of depthwise convolution with respect to the
  134. * input.
  135. * @par Inputs:
  136. * Three inputs include: \n
  137. * @li input_size: 4D shape of input tensor [N, C, H, W] or [N, H, W, C],
  138. * support int32, int64
  139. * @li filter: 4D filter tensor with shape of [H, W, C, K], support float16.
  140. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C].
  141. * Must be one of the following types: float16.
  142. * @par Attributes:
  143. * @li strides: A required list or tuple of int32. The stride of the sliding window for
  144. * height and width of input "x" of the convolution.
  145. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  146. * stride_width, 1].
  147. * @li dilations: An optional list or tuple of int32. The dilation factor for each
  148. * dimension of input "x". Defaults to "[1, 1, 1, 1]".
  149. * If set to k > 1, there will be k-1 skipped cells between each filter element
  150. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  151. * or [1, dilation_height, dilation_width, 1].
  152. * @li pads: A required list or tuple of int32. Padding added to each dimension of the
  153. * input.
  154. * @li data_format: An optional string. Input data format, either "NHWC" or
  155. * "NCHW". Defaults to "NHWC".
  156. * @par Outputs:
  157. * input_grad: Gradient of the deep convolution relative to the input with shape
  158. * [N, C, H, W] or [N, H, W, C] Must be one of the following types: float16.
  159. * @attention Constraints:\n
  160. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  161. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  162. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  163. * [C1, Hf, Wf, K, Co, C0],
  164. * where K is fixed at 1, and Co and C0 are 16.\n
  165. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  166. * data is 5D with shape [N, C1, Ho, Wo, C0],
  167. * where C is the same as that of the feature map and C0 is 16.\n
  168. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  169. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  170. * @par Third-party framework compatibility
  171. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  172. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  173. */
  174. REG_OP(DepthwiseConv2DBackpropInput)
  175. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  176. .INPUT(filter, TensorType({DT_FLOAT16}))
  177. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  178. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  179. .REQUIRED_ATTR(strides, ListInt)
  180. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  181. .REQUIRED_ATTR(pads, ListInt)
  182. .ATTR(data_format, String, "NHWC")
  183. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInput)
  184. /**
  185. * @brief Computes the gradients of depthwise convolution with respect to the
  186. * input.
  187. * @par Inputs:
  188. * Two inputs include: \n
  189. * @li filter: A 4D tensor of type float16, with shape [H, W, C, K]
  190. * @li out_backprop: 4D tensor with shape [N, C, H, W] or [N, H, W, C], of
  191. * type float16
  192. * @par Attributes:
  193. * @li input_size: A required list or tuple. The origin shape of input.
  194. * @li strides: A required list or tuple. The stride of the sliding window for
  195. * height and width of input "x" of the convolution.
  196. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  197. * stride_width, 1].
  198. * @li dilations: An optional list or tuple. The dilation factor for each
  199. * dimension of input "x".
  200. * If set to k > 1, there will be k-1 skipped cells between each filter element
  201. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  202. * or [1, dilation_height, dilation_width, 1].
  203. * @li pads: A required list or tuple. Padding added to each dimension of the
  204. * input.
  205. * @li data_format: An optional string. Input data format, either "NHWC" or
  206. * "NCHW".
  207. * @par Outputs:
  208. * input_grad: Gradient of the deep convolution relative to the input with
  209. * shape [N, C, H, W] or [N, H, W, C]. Must be of type float16.
  210. * @attention Constraints:\n
  211. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  212. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  213. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  214. * [C1, Hf, Wf, K, Co, C0],
  215. * where K is fixed at 1, and Co and C0 are 16.\n
  216. * Output backprop is 4D with shape [N, C, Ho, Wo] or [N, Ho, Wo, C], but the
  217. * data is 5D with shape [N, C1, Ho, Wo, C0],
  218. * where C is the same as that of the feature map and C0 is 16.\n
  219. * Limited by Tiling: max_h_in_l1 >= C0, where max_h_in_l1 = (l1_size - Hf *
  220. * Wf * C0 * C0 * 2) / (2 * Wo *C0).\n
  221. * @par Third-party framework compatibility
  222. * @li Compatible with the TensorFlow operator DepthwiseConv2DBackpropInput.
  223. * @li Compatible with the Caffe operator DepthwiseConv2DBackpropInput.
  224. *
  225. * @par Restrictions:
  226. * Warning: THIS FUNCTION IS DEPRECATED. Please use DepthwiseConv2DBackpropInput
  227. * instead.
  228. */
  229. REG_OP(DepthwiseConv2DBackpropInputD)
  230. .INPUT(filter, TensorType({DT_FLOAT16}))
  231. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  232. .OUTPUT(input_grad, TensorType({DT_FLOAT16}))
  233. .REQUIRED_ATTR(input_size, ListInt)
  234. .REQUIRED_ATTR(strides, ListInt)
  235. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  236. .REQUIRED_ATTR(pads, ListInt)
  237. .ATTR(data_format, String, "NHWC")
  238. .OP_END_FACTORY_REG(DepthwiseConv2DBackpropInputD)
  239. /**
  240. *@brief Computes a 2D deep convolution given a 4D input tensor and a filter
  241. * tensor.
  242. *@par Inputs:
  243. *Two required inputs and two optional inputs, including: \n
  244. * @li x: A 4D tensor of type float16 or int8, with shape [N, C, H, W] or [N, H, W, C]
  245. * @li filter: A 4D tensor of type float16 or int8, with shape [H, W, C, K]
  246. * @li bias: An optional tensor of type float16 or int32
  247. * @li offset_w: An optional float16 or int8, used for quantized inference
  248. * @par Attributes:
  249. * @li strides: A required list or tuple. The stride of the sliding window for
  250. * height and width of input "x" of the convolution.
  251. * Must be with shape [1, 1, stride_height, stride_width] or [1, stride_height,
  252. * stride_width, 1].
  253. * @li dilations: An optional list or tuple. The dilation factor for each
  254. * dimension of input "x".
  255. * If set to k > 1, there will be k-1 skipped cells between each filter element
  256. * on that dimension. Must be with shape [1, 1, dilation_height, dilation_width]
  257. * or [1, dilation_height, dilation_width, 1]. Defaults to "[1, 1, 1, 1]".
  258. * @li pads: A required list or tuple of int32. Padding added to each dimension of the
  259. * input.
  260. * @li data_format: An optional string. Input data format, either "NHWC" or
  261. * "NCHW". Defaults to "NHWC".
  262. * @li offset_x: An optional int. Input offset, used for quantized inference.
  263. * Defaults to 0.
  264. * @par Outputs:
  265. * y: 4D tensor of type float16 or int32, with shape [N, C, H, W] or [N, H, W, C]
  266. * @attention Constraints:\n
  267. * The feature map is 4D with shape [N, C, Hi, Wi] or [N, Hi, Wi, C], but
  268. * the data is 5D with shape [N, C1, Hi, Wi, C0], where C0 is 16.\n
  269. * The filter is 4D with shape [Hf, Wf, C, K], but the data is 6D with shape
  270. * [C1, Hf, Wf, K, Co, C0],
  271. * where K is fixed at 1, and Co and C0 are 16.\n
  272. * Limited by the size of L1 buffer memory: \n
  273. * (l1_size - filter_h*filter_w*BLOCK_SIZE*BLOCK_SIZE*data_size) // (Wi *
  274. * BLOCK_SIZE * data_size) >= (BLOCK_SIZE * strides_h + filter_h - strides_h).\n
  275. * @par Quantization supported or not
  276. * Yes
  277. * @par Third-party framework compatibility
  278. * @li Compatible with the TensorFlow operator DepthwiseConv2D.
  279. * @li Compatible with the Caffe operator DepthwiseConv2D.
  280. */
  281. REG_OP(DepthwiseConv2D)
  282. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  283. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  284. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  285. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16, DT_INT8}))
  286. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  287. .REQUIRED_ATTR(strides, ListInt)
  288. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  289. .REQUIRED_ATTR(pads, ListInt)
  290. .ATTR(data_format, String, "NHWC")
  291. .ATTR(offset_x, Int, 0)
  292. .OP_END_FACTORY_REG(DepthwiseConv2D)
  293. /**
  294. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  295. * It accumulates all the values from out_backprop into the feature
  296. * dimension. For NHWC data format, the feature dimension is the last.
  297. * For NCHW data format, the feature dimension is the third-to-last.
  298. *@par Inputs:
  299. *x: A Tensor of type NumberType.
  300. *@par Attributes:
  301. *data_format: Data format. Defaults to "NHWC".
  302. *@par Outputs:
  303. *y: A Tensor.Has the same type as "x".
  304. *@par Third-party framework compatibility
  305. * Compatible with the TensorFlow operator BiasAddGrad.
  306. */
  307. REG_OP(BiasAddGrad)
  308. .INPUT(x, TensorType::NumberType())
  309. .OUTPUT(y, TensorType::NumberType())
  310. .ATTR(data_format, String, "NHWC")
  311. .OP_END_FACTORY_REG(BiasAddGrad)
  312. /**
  313. *@brief Computes the gradients of convolution with respect to the input.
  314. *@par Inputs:
  315. * Three inputs:
  316. * @li input_size: A Tensor of type int32. An integer vector representing the
  317. * shape of input, where input is a 4-D tensor [batch, height, width, channels]
  318. * or [batch, channels, height, width].
  319. * @li filter: A Tensor. Must be one of the following types: float16, float32,
  320. * float64. 4-D with shape
  321. * [filter_height, filter_width, in_channels, out_channels]
  322. * or [out_channels, filter_height, filter_width, in_channels]
  323. * or [out_channels, in_channel, filter_height, filter_width].
  324. * @li out_backprop: A Tensor. Must have the same type as filter.
  325. * 4-D with shape [batch, out_height, out_width, out_channels]
  326. * or [batch, out_channels, out_height, out_width].
  327. * Gradients with respect to the output of the convolution.
  328. *@par Attributes:
  329. * Five attributes:
  330. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  331. * for H/W dimension. The index of H/W is same as data_format.
  332. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads
  333. * on feature map
  334. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  335. * dimension of input, now only support [1,1,1,1]
  336. * @li groups: Number of blocked connections from input channels to output
  337. * channels.
  338. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  339. * "NHWC". Specify the data format of the input and output data.
  340. *@par Outputs:
  341. * y: A Tensor. Has the same type as filter,and has same format as input_size
  342. *@par Third-party framework compatibility
  343. * Compatible with Tensorflow's conv2d_backprop_input
  344. */
  345. REG_OP(Conv2DBackpropInput)
  346. .INPUT(input_size, TensorType({DT_INT32}))
  347. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  348. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  349. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  350. .REQUIRED_ATTR(strides, ListInt)
  351. .REQUIRED_ATTR(pads, ListInt)
  352. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  353. .ATTR(groups, Int, 1)
  354. .ATTR(data_format, String, "NHWC")
  355. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  356. /**
  357. *@brief Computes the gradients of convolution with respect to the input.
  358. *@par Inputs:
  359. * Two inputs:
  360. * @li filter: A Tensor. Types is float16.
  361. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  362. * or [out_channels, filter_height, filter_width, in_channels]
  363. * or [out_channels, in_channel, filter_height, filter_width].
  364. * @li out_backprop: A Tensor. Must have the same type as filter.
  365. * 4-D with shape [batch, out_height, out_width, out_channels]
  366. * or [batch, out_channels, out_height, out_width].
  367. * Gradients with respect to the output of the convolution.
  368. *@par Attributes:
  369. * Six attributes:
  370. * @li input_size A Tensor of type int32. An integer vector representing the
  371. * shape of input, where input is a 4-D tensor [batch, height, width, channels]
  372. * or [batch, channels, height, width].
  373. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  374. * for H/W dimension. The index of H/W is same as data_format.
  375. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  376. * feature map
  377. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  378. * dimension of input, now only support [1,1,1,1]
  379. * @li groups: Number of blocked connections from input channels to output
  380. * channels.
  381. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  382. * "NHWC". Specify the data format of the input and output data.
  383. *@par Outputs:
  384. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width,
  385. * channels] or [batch, channels, height, width].
  386. *@par Third-party framework compatibility
  387. * Compatible with Tensorflow's conv2d_backprop_input
  388. *@par Restrictions:
  389. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropInput instead.
  390. */
  391. REG_OP(Conv2DBackpropInputD)
  392. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  393. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  394. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  395. .REQUIRED_ATTR(input_size, ListInt)
  396. .REQUIRED_ATTR(strides, ListInt)
  397. .REQUIRED_ATTR(pads, ListInt)
  398. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  399. .ATTR(groups, Int, 1)
  400. .ATTR(data_format, String, "NHWC")
  401. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  402. /**
  403. *@brief Computes the Deconvolution with respect to the input.
  404. *@par Inputs:
  405. * Three inputs:
  406. * @li x: A Tensor of type float16 or int8. 4D with shape
  407. * [batch, out_channels, out_height, out_width]. Gradients with respect
  408. * to the output of the convolution.
  409. * @li filter: A Tensor. Must have the same type as "x".
  410. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  411. * Two optional inputs:
  412. * @li bias: An optional tensor. Must have the same type as "y".
  413. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  414. * Type is int8. Reserved.\n
  415. *@par Attributes:
  416. * Six attributes:
  417. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  418. * for H/W dimension.
  419. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  420. * padding on the feature map.
  421. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  422. * dimension of input. Must be [1, 1, 1, 1].
  423. * @li groups: Number of blocked connections from input channels to
  424. output channels. Defaults to "1".
  425. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  426. Specify the data format of the input and output data.
  427. * @li offset_x: An optional integer for quantized deconvolution.
  428. * Defaults to "0".
  429. *@par Outputs:
  430. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  431. * When type of x is float16, the type of y must be float16.
  432. * When type of x is int8, the type of y must be int32.
  433. */
  434. REG_OP(Deconvolution)
  435. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  436. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  437. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  438. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  439. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  440. .REQUIRED_ATTR(strides, ListInt)
  441. .REQUIRED_ATTR(pads, ListInt)
  442. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  443. .ATTR(groups, Int, 1)
  444. .ATTR(data_format, String, "NCHW")
  445. .ATTR(offset_x, Int, 0)
  446. .OP_END_FACTORY_REG(Deconvolution)
  447. /**
  448. *@brief Computes the gradients of convolution with respect to the filter
  449. *@par Inputs:
  450. * Three inputs:
  451. * @li x: A Tensor. Must be one of the following types: float16, float32,
  452. * float64.4-D with shape [batch, in_height, in_width, in_channels] or
  453. * [batch, in_channels, in_height, in_width].
  454. * @li filter_size: A Tensor of type int32. An integer vector representing the
  455. * tensor shape of filter, where filter is a 4-D tensor [filter_height,
  456. * filter_width, in_channels, out_channels] or [out_channels, filter_height,
  457. * filter_width, in_channels] or [out_channels, in_channel, filter_height,
  458. * filter_width].
  459. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  460. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  461. * out_height, out_width]. Gradients with respect to the output of the
  462. * convolution.
  463. *@par Attributes:
  464. * Five attributes:
  465. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  466. * for H/W dimension. The index of H/W is same as data_format.
  467. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  468. * feature map.
  469. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  470. * dimension of input, now only support [1,1,1,1].
  471. * @li groups: Number of blocked connections from input channels to output
  472. * channels.
  473. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  474. * "NHWC". Specify the data format of the input and output data.
  475. *@par Outputs:
  476. * y: A Tensor. Has the same type as x
  477. *@par Third-party framework compatibility
  478. * Compatible with Tensorflow's conv2d_backprop_filter
  479. */
  480. REG_OP(Conv2DBackpropFilter)
  481. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  482. .INPUT(filter_size, TensorType({DT_INT32}))
  483. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  484. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  485. .REQUIRED_ATTR(strides, ListInt)
  486. .REQUIRED_ATTR(pads, ListInt)
  487. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  488. .ATTR(groups, Int, 1)
  489. .ATTR(data_format, String, "NHWC")
  490. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  491. /**
  492. *@brief Computes the gradients of convolution with respect to the filter.
  493. *@par Inputs:
  494. * Two inputs:
  495. * @li x: A Tensor. Type is float16.
  496. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch,
  497. * in_channels, in_height, in_width].
  498. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  499. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  500. * out_height, out_width]. Gradients with respect to the output of the
  501. * convolution.
  502. *@par Attributes:
  503. * Six attributes:
  504. * @li filter_size: A Tensor of type integers. An integer vector representing
  505. * the tensor shape of filter,
  506. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  507. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  508. * or [out_channels, in_channel, filter_height, filter_width].
  509. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  510. * for H/W dimension. The index of H/W is same as data_format.
  511. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  512. * feature map
  513. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  514. * dimension of input, now only support [1,1,1,1].
  515. * @li groups: Number of blocked connections from input channels to output
  516. * channels.
  517. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  518. * "NHWC". Specify the data format of the input and output data.
  519. *@par Outputs:
  520. * y: A Tensor. Type is float32
  521. *@par Third-party framework compatibility
  522. * Compatible with Tensorflow's conv2d_backprop_filter
  523. *@par Restrictions:
  524. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropFilter instead.
  525. */
  526. REG_OP(Conv2DBackpropFilterD)
  527. .INPUT(x, TensorType({DT_FLOAT16}))
  528. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  529. .OUTPUT(y, TensorType({DT_FLOAT}))
  530. .REQUIRED_ATTR(filter_size, ListInt)
  531. .REQUIRED_ATTR(strides, ListInt)
  532. .REQUIRED_ATTR(pads, ListInt)
  533. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  534. .ATTR(groups, Int, 1)
  535. .ATTR(data_format, String, "NHWC")
  536. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  537. /**
  538. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  539. *@par Inputs:
  540. * @li x: A 4D tensor of input images.
  541. * @li filter: A 4D tensor of filters.
  542. * @li bias: An optional 1D tensor.
  543. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.
  544. *
  545. * The input and output tensor attributes are listed as follows:
  546. * @verbatim
  547. |Tensor | x | filter | bias | offset_w | y
  548. -----------|---------|---------|---------|----------|--------
  549. |Data Type | float16 | float16 | float16 | _ | float16
  550. | |---------|---------|---------|----------|--------
  551. | | float32 | float32 | float32 | _ | float32
  552. | |---------|---------|---------|----------|--------
  553. | | int8 | int8 | int32 | int8 | int32
  554. -----------|---------|---------|---------|----------|--------
  555. |Format | NCHW | NCHW | ND | ND | NCHW
  556. | | NHWC | NHWC | | | NHWC
  557. | | | HWCN | | |
  558. @endverbatim
  559. * It should be noted that the data types must correspond to each other, but the
  560. * format does not need to.
  561. *@par Attributes:
  562. * @li strides: A list of 4 integers. Specifying the strides of the
  563. * convolution along the height and width. The dimension order is determined
  564. * by the data format of "x". By default the N and C dimensions are set to 1.
  565. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  566. * padding.
  567. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  568. * for dilated convolution. Has the same dimension order and value as "strides".
  569. * @li groups: Number of blocked connections from input channels to output
  570. * channels. Input channels and output channels must both be divisible by
  571. * "groups".Type is int32.
  572. * @li offset_x: An optional integer for quantized convolution. Type is int32. Defaults to "0".
  573. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  574. * data format of the input and output images. Type is string. Defaults to "NHWC". Reserved.
  575. *@par Outputs:
  576. * @li y: A 4D Tensor of output images.
  577. *@attention
  578. * @li The parameter scope is listed as follows:
  579. * @verbatim
  580. |Name | Field | Scope
  581. ------------------|--------------|----------
  582. |Input Image Size | H dimension | [1, 4096]
  583. | | W dimension | [1, 4096]
  584. ------------------|--------------|----------
  585. |Filter Size | H dimension | [1, 255]
  586. | | W dimension | [1, 255]
  587. ------------------|--------------|----------
  588. |Stride Size | H dimension | [1, 63]
  589. | | W dimension | [1, 63]
  590. ------------------|--------------|----------
  591. |Padding Size | top side | [0, 255]
  592. | | bottom side | [0, 255]
  593. | | left side | [0, 255]
  594. | | right side | [0, 255]
  595. ------------------|--------------|----------
  596. |Dilation Size | H dimension | [1, 255]
  597. | W dimension | [1, 255]
  598. @endverbatim
  599. * @li There are restrictions for certain scenarios:
  600. * @verbatim
  601. Output | Restrictions
  602. ------------------|----------------------------------------------
  603. W dimension == 1 | HxW(input) == HxW(filter)
  604. H dimension == 1 |
  605. ------------------|----------------------------------------------
  606. W dimension == 1 | Not supported
  607. H dimension != 1 |
  608. @endverbatim
  609. * As shown above, "HxW(input)" indicates the image size after padding and
  610. * "HxW(filter)" indicates the filter size after dilation.
  611. *@par Quantization supported or not
  612. * Yes
  613. *@par Third-party framework compatibility
  614. *@li Compatible with the TensorFlow operator "conv2d".
  615. *@li Compatible with the Caffe operator 2D "Convolution".
  616. */
  617. REG_OP(Conv2D)
  618. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  619. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  620. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  621. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  622. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  623. .REQUIRED_ATTR(strides, ListInt)
  624. .REQUIRED_ATTR(pads, ListInt)
  625. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  626. .ATTR(groups, Int, 1)
  627. .ATTR(data_format, String, "NHWC")
  628. .ATTR(offset_x, Int, 0)
  629. .OP_END_FACTORY_REG(Conv2D)
  630. REG_OP(Conv2DCompress)
  631. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  632. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  633. .INPUT(compress_index, TensorType({DT_INT8}))
  634. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  635. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  636. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  637. .REQUIRED_ATTR(strides, ListInt)
  638. .REQUIRED_ATTR(pads, ListInt)
  639. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  640. .ATTR(groups, Int, 1)
  641. .ATTR(data_format, String, "NHWC")
  642. .ATTR(offset_x, Int, 0)
  643. .OP_END_FACTORY_REG(Conv2DCompress)
  644. /**
  645. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  646. *@par Inputs:
  647. * @li x: A 5D tensor. Must be one of the following types: float16,
  648. * (Currently does not support int8). The format of x is NCDHW or NDHWC.
  649. * @li filter: A 5D tensor of the same type as "x".
  650. * (Currently does not support int8).
  651. * The format is NCDHW, NDHWC or DHWCN.
  652. *@par Optional input:
  653. * @li bias: An optional 1D tensor of the same type as "x".
  654. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  655. *@par Required Attributes:
  656. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  657. * for each dimension of "x".
  658. * The N and C dimensions must be 1. Has the same format as "x".
  659. * @li pads: A list of 6 integers.
  660. * Supports only padding along the D, H and W dimensions in sequence of head,
  661. * tail, top, bottom, left and right.
  662. *@par Attributes:
  663. * @li groups: Number of blocked connections from input channels to output
  664. * channels. Reserved.
  665. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  666. * Defaults to "NDHWC". Specify the data format of the input and output data.
  667. * @li dilations: A list of 5 integers. Specifies the dilation factor for each
  668. * dimension of "x", now only support [1,1,1,1,1]
  669. * The N and C dimensions must be 1. Has the same format as "x".
  670. * @li offset_x: An optional int. Input offset, used for quantized inference.
  671. * Defaults to 0. Reserved.
  672. *@par Outputs:
  673. *y: A Tensor. Has the same type as "x".
  674. *@attention Constraints:
  675. *The image size after padding is greater than the filter size.
  676. *@par Third-party framework compatibility
  677. * @li Compatible with the TensorFlow operator conv3d.
  678. * @li Compatible with the Caffe operator Convolution.
  679. */
  680. REG_OP(Conv3D)
  681. .INPUT(x, TensorType({DT_FLOAT16}))
  682. .INPUT(filter, TensorType({DT_FLOAT16}))
  683. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  684. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  685. .OUTPUT(y, TensorType({DT_FLOAT16}))
  686. .REQUIRED_ATTR(strides, ListInt)
  687. .REQUIRED_ATTR(pads, ListInt)
  688. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  689. .ATTR(groups, Int, 1)
  690. .ATTR(data_format, String, "NDHWC")
  691. .ATTR(offset_x, Int, 0)
  692. .OP_END_FACTORY_REG(Conv3D)
  693. /**
  694. *@brief Computes the gradients of convolution 3d with respect to the input.
  695. *@par Inputs:
  696. * Three inputs:
  697. * @li input_size: A Tensor of type int32, int64. An integer vector representing
  698. * the shape of input, where input is a 5-D tensor
  699. * [batch, depth, height, width, channels] or
  700. * [batch, channels, depth, height, width].
  701. * @li filter: A Tensor. Must be one of the following types: float16, float32,
  702. * float64.
  703. * @li out_backprop: A Tensor. Must have the same type as filter.
  704. * 5-D with shape [batch, depth, out_height, out_width, out_channels]
  705. * or [batch, out_channels, depth, out_height, out_width]. Gradients with
  706. * respect to the output of the convolution.
  707. *@par Required Attributes:
  708. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  709. * for each dimension of "x".
  710. * The N and C dimensions must be 1. Has the same format as "x".
  711. * @li pads: A list of 6 integers.
  712. * Supports only padding along the D, H and W dimensions in sequence of head,
  713. * tail, top, bottom, left and right.
  714. *@par Attributes:
  715. * Three attributes:
  716. * @li groups: Number of blocked connections from input channels to output
  717. * channels. Reserved.
  718. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  719. * Defaults to "NDHWC". Specify the data format of the input and output data.
  720. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  721. * dimension of the input, now only support [1,1,1,1,1]
  722. *@par Outputs:
  723. * y: A Tensor. Has the same type as filter,and has same format as input_size
  724. *@par Third-party framework compatibility
  725. * Compatible with Tensorflow's conv3d_backprop_input
  726. */
  727. REG_OP(Conv3DBackpropInput)
  728. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  729. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  730. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  731. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  732. .REQUIRED_ATTR(strides, ListInt)
  733. .REQUIRED_ATTR(pads, ListInt)
  734. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  735. .ATTR(groups, Int, 1)
  736. .ATTR(data_format, String, "NDHWC")
  737. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  738. /**
  739. *@brief Computes the gradients of convolution 3d with respect to the input.
  740. *@par Inputs:
  741. * Two inputs:
  742. * @li filter: A Tensor whose type is float16.
  743. * @li out_backprop: A Tensor. Must have the same type as filter.
  744. *@par Required Attributes:
  745. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  746. * for each dimension of "x".
  747. * The N and C dimensions must be 1. Has the same format as "x".
  748. * @li pads: A list of 6 integers. Supports only padding along the D, H and W
  749. * dimensions in sequence of head, tail, top, bottom, left and right.
  750. * @li input_size: A tuple/list of type int32, int64. An integer vector
  751. * representing the shape of input, where input is a 5-D tensor
  752. * [batch, depth, height, width, channels] or
  753. * [batch, channels, depth, height, width].
  754. *@par Attributes:
  755. * Three attributes:
  756. * @li groups: Number of blocked connections from input channels to output
  757. * channels. Reserved.
  758. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  759. * Defaults to "NDHWC". Specify the data format of the input and output data.
  760. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  761. * dimension of input, now only support [1,1,1,1,1]
  762. *@par Outputs:
  763. * y: A Tensor. Has the same type as filter
  764. *@par Third-party framework compatibility
  765. * Compatible with Tensorflow's conv3d_backprop_input
  766. *@par Restrictions:
  767. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropInput instead.
  768. */
  769. REG_OP(Conv3DBackpropInputD)
  770. .INPUT(filter, TensorType({DT_FLOAT16}))
  771. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  772. .OUTPUT(y, TensorType({DT_FLOAT16}))
  773. .REQUIRED_ATTR(input_size, ListInt)
  774. .REQUIRED_ATTR(strides, ListInt)
  775. .REQUIRED_ATTR(pads, ListInt)
  776. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  777. .ATTR(groups, Int, 1)
  778. .ATTR(data_format, String, "NDHWC")
  779. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  780. /**
  781. *@brief Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence.
  782. *@par Inputs:
  783. * @li x: A Tensor dtype of float16.
  784. * @li cont: A Tensor dtype of float16, float32.
  785. * @li w_x: A Tensor dtype of float16.
  786. * @li bias: A Tensor dtype of int16, int32, float16, float32.
  787. * @li w_h: A Tensor dtype of float16.
  788. * @li x_static: A optinal Tensor dtype of float16.
  789. * @li h_0: A optinal Tensor dtype of float16, float32.
  790. * @li c_0: A optinal Tensor dtype of float16, float32.
  791. * @li w_x_static: A optinal Tensor dtype of float16.
  792. *@par Attributes:
  793. *@li num_output: A Scalar of output size dtype of int.
  794. *@li expose_hidden: A Scalar(bool) of features hidden.
  795. *@par Outputs:
  796. *@li h: A Tensor dtype of float16, float32.
  797. * @li h_t: A optinal Tensor dtype of float16, float32. The hidden state at time t.
  798. * @li c_t: A optinal Tensor dtype of float16, float32. The cell state at time t.
  799. *@par Third-party framework compatibility:
  800. * Compatible with the Pytorch operator adds.
  801. */
  802. REG_OP(LSTM)
  803. .INPUT(x, TensorType({DT_FLOAT16}))
  804. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  805. .INPUT(w_x, TensorType({DT_FLOAT16}))
  806. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  807. .INPUT(w_h, TensorType({DT_FLOAT16}))
  808. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  809. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  810. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  811. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  812. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  813. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  814. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  815. .ATTR(num_output, Int, 0)
  816. .ATTR(expose_hidden, Bool, false)
  817. .OP_END_FACTORY_REG(LSTM)
  818. /**
  819. *@brief Computes the gradients of convolution3D with respect to the filter
  820. *@par Inputs:
  821. * Three inputs:
  822. * @li x: A Tensor. Must be one of the following types: float16, float32,
  823. * double.
  824. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  825. * or [batch, in_depth, in_channels, in_height, in_width].
  826. * @li filter_size: A Tensor of type int32. An integer vector representing the
  827. * tensor shape of filter, where filter is a 5-D tensor
  828. * [filter_depth, filter_height, filter_width, in_channels, out_channels]
  829. * or [out_channels, filter_depth, filter_height, filter_width, in_channels]
  830. * or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  831. * @li out_backprop: A Tensor. Must have the same type as x.
  832. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  833. * or [batch, out_depth, out_channels, out_height, out_width].
  834. * Gradients with respect to the output of the convolution.
  835. *@par Required Attributes:
  836. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  837. * window for each dimension of "x". The N and C dimensions must be 1.
  838. * Has the same format as "x".
  839. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  840. * pads on feature map.
  841. *@par Attributes:
  842. * Three attributes:
  843. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  844. * dimension of input, now only support [1,1,1,1,1].
  845. * @li groups: Number of blocked connections from input channels to output
  846. * channels. Reserved.
  847. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  848. * Defaults to "NDHWC". Specify the data format of the input and output data.
  849. *@par Outputs:
  850. * y: A Tensor. Has the same type as x
  851. *@par Third-party framework compatibility
  852. * Compatible with Tensorflow's conv3d_backprop_filter
  853. */
  854. REG_OP(Conv3DBackpropFilter)
  855. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  856. .INPUT(filter_size, TensorType({DT_INT32}))
  857. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  858. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  859. .REQUIRED_ATTR(strides, ListInt)
  860. .REQUIRED_ATTR(pads, ListInt)
  861. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  862. .ATTR(groups, Int, 1)
  863. .ATTR(data_format, String, "NDHWC")
  864. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  865. /**
  866. *@brief Computes the gradients of convolution with respect to the filter.
  867. *@par Inputs:
  868. * Two inputs:
  869. * @li x: A Tensor of type float16.
  870. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  871. * or [batch, in_depth, in_channels, in_height, in_width].
  872. * @li out_backprop: A Tensor. Must have the same type as x.
  873. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  874. * or [batch, out_depth, out_channels, out_height, out_width].
  875. * Gradients with respect to the output of the convolution.
  876. *@par Required Attributes:
  877. * @li filter_size: A tuple/list of type integers. An integer vector
  878. * representing the tensor shape of filter, where filter is a 5-D tensor
  879. * [filter_depth, filter_height, filter_width, in_channels, out_channels]
  880. * or [out_channels, filter_depth, filter_height, filter_width, in_channels]
  881. * or [out_channels, filter_depth, in_channel, filter_height, filter_width].
  882. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  883. * window for each dimension of "x".
  884. * The N and C dimensions must be 1. Has the same format as "x".
  885. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  886. * pads on feature map
  887. *@par Attributes:
  888. * Three attributes:
  889. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  890. * dimension of input, now only support [1,1,1,1,1].
  891. * @li groups: Number of blocked connections from input channels to output
  892. * channels. Reserved.
  893. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  894. * Defaults to "NDHWC". Specify the data format of the input and output data.
  895. *@par Outputs:
  896. * y: A Tensor of type float32
  897. *@par Third-party framework compatibility
  898. * Compatible with Tensorflow's conv3d_backprop_filter
  899. *@par Restrictions:
  900. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropFilter instead.
  901. */
  902. REG_OP(Conv3DBackpropFilterD)
  903. .INPUT(x, TensorType({DT_FLOAT16}))
  904. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  905. .OUTPUT(y, TensorType({DT_FLOAT}))
  906. .REQUIRED_ATTR(filter_size, ListInt)
  907. .REQUIRED_ATTR(strides, ListInt)
  908. .REQUIRED_ATTR(pads, ListInt)
  909. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  910. .ATTR(groups, Int, 1)
  911. .ATTR(data_format, String, "NDHWC")
  912. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  913. /**
  914. *@brief Computes the transpose of convolution 3d with respect to the input.
  915. *@par Inputs:
  916. * Three inputs:
  917. * @li input_size: A Tensor of type int32. An integer vector representing the
  918. * shape of input
  919. * @li x: A Tensor of type float16, currently does not support int8
  920. * @li filter: A Tensor of type float16, currently does not support int8
  921. *@par Optional input:
  922. * Two optional inputs
  923. * @li bias: An optional 1D tensor of the same type as "x". Reserved.
  924. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  925. *@par Required Attributes:
  926. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  927. * window for each dimension of "x".
  928. * The N and C dimensions must be 1. Has the same format as "x".
  929. * @li pads: A tuple/list of 6 integers
  930. *@par Attributes:
  931. * Five attributes:
  932. * @li groups: Number of blocked connections from input channels to output
  933. * channels. Reserved.
  934. * @li dilations: A tuple/list of 5 integers,
  935. * The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  936. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  937. * Defaults to "NDHWC". Specify the data format of the input and output data.
  938. * @li output_padding: The size will be added in the output shape.
  939. * @li offset_x: Input offset_x value. Reserved.
  940. *@par Outputs:
  941. * y: A Tensor. Has the same type as filter
  942. */
  943. REG_OP(Conv3DTranspose)
  944. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  945. .INPUT(x, TensorType({DT_FLOAT16}))
  946. .INPUT(filter, TensorType({DT_FLOAT16}))
  947. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  948. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  949. .OUTPUT(y, TensorType({DT_FLOAT16}))
  950. .REQUIRED_ATTR(strides, ListInt)
  951. .REQUIRED_ATTR(pads, ListInt)
  952. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  953. .ATTR(groups, Int, 1)
  954. .ATTR(data_format, String, "NDHWC")
  955. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  956. .ATTR(offset_x, Int, 0)
  957. .OP_END_FACTORY_REG(Conv3DTranspose)
  958. /**
  959. *@brief Computes the transpose of convolution 3d with respect to the input.
  960. *@par Inputs:
  961. * @li x: A Tensor of type float16, currently does not support int8
  962. * @li filter: A Tensor of type float16, currently does not support int8
  963. *@par Optional inputs:
  964. * @li bias: An optional 1D tensor of the same type as "x". Reserved.
  965. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved.
  966. *@par Required Attributes:
  967. * @li input_size: A tuple/list of type int32.
  968. * An integer vector representing the shape of input
  969. * @li strides: A tuple/list of 5 integers.
  970. * Specifies the stride of the sliding window for each dimension of "x".
  971. * The N and C dimensions must be 1. Has the same format as "x".
  972. * @li pads: A tuple/list of 6 integers.
  973. *@par Attributes:
  974. * Five attributes:
  975. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  976. * dimension of input, now only support [1,1,1,1,1]
  977. * @li groups: Number of blocked connections from input channels to output
  978. * channels. Reserved.
  979. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  980. * Defaults to "NDHWC". Specify the data format of the input and output data.
  981. * @li output_padding: The size will be added in the output shape.
  982. * @li offset_x: Input offset_x value. Reserved.
  983. *@par Outputs:
  984. * y: A Tensor. Has the same type as filter
  985. *@par Restrictions:
  986. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DTranspose instead.
  987. */
  988. REG_OP(Conv3DTransposeD)
  989. .INPUT(x, TensorType({DT_FLOAT16}))
  990. .INPUT(filter, TensorType({DT_FLOAT16}))
  991. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  992. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  993. .OUTPUT(y, TensorType({DT_FLOAT16}))
  994. .REQUIRED_ATTR(input_size, ListInt)
  995. .REQUIRED_ATTR(strides, ListInt)
  996. .REQUIRED_ATTR(pads, ListInt)
  997. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  998. .ATTR(groups, Int, 1)
  999. .ATTR(data_format, String, "NDHWC")
  1000. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1001. .ATTR(offset_x, Int, 0)
  1002. .OP_END_FACTORY_REG(Conv3DTransposeD)
  1003. /**
  1004. *@brief Computes the transpose of convolution 2d with respect to the input.
  1005. *@par Inputs:
  1006. * Five inputs:
  1007. * @li input_size: A Tensor of type int32 or int64. An integer vector
  1008. * representing the shape of input, where input is a 4-D tensor
  1009. * [batch, height, width, channels] or [batch, channels, height, width].
  1010. * @li x: A Tensor of type float16, int8. 4-D with shape [batch, out_height,
  1011. * out_width, out_channels] or [batch, out_channels, out_height, out_width].
  1012. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1013. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  1014. * or [out_channels, filter_height, filter_width, in_channels]
  1015. * or [out_channels, in_channel, filter_height, filter_width].
  1016. * @li bias: An optional 1D tensor of type float16 or int32. Format is "ND".
  1017. * @li offset_w: An optional 1D tensor for quantized inference. Reserved.
  1018. *@par Required Attributes:
  1019. * @li strides: A required tuple/list of 4 integers. The stride of the sliding
  1020. * window for H/W dimension. The index of H/W is same as data_format.
  1021. * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]
  1022. * pads on feature map.
  1023. *@par Attributes:
  1024. * Five attributes:
  1025. * @li groups: Number of blocked connections from input channels to output
  1026. * channels.
  1027. * Defaults to "1".
  1028. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  1029. * dimension of input. Must be [1, 1, 1, 1].
  1030. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1031. * Specify the data format of the input and output data.
  1032. * @li output_padding: The size will be added in the output shape. Defaults
  1033. * to [0, 0, 0, 0].
  1034. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1035. * Defaults to "0".
  1036. *@par Outputs:
  1037. * y: A Tensor. A Tensor of type float16 or int32, and has same format as
  1038. * input_size.
  1039. */
  1040. REG_OP(Conv2DTranspose)
  1041. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1042. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1043. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1044. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1045. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1046. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1047. .REQUIRED_ATTR(strides, ListInt)
  1048. .REQUIRED_ATTR(pads, ListInt)
  1049. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1050. .ATTR(groups, Int, 1)
  1051. .ATTR(data_format, String, "NHWC")
  1052. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1053. .ATTR(offset_x, Int, 0)
  1054. .OP_END_FACTORY_REG(Conv2DTranspose)
  1055. /**
  1056. *@brief Computes the transpose of convolution 2d with respect to the input.
  1057. *@par Inputs:
  1058. * Four inputs:
  1059. * @li x: A Tensor of type float16, int8.
  1060. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1061. * @li bias: An optional 1D tensor of the same type as "x".
  1062. * @li offset_w: An optional 1D tensor for quantized inference. Type is int8. Reserved.
  1063. *@par Required Attributes:
  1064. * @li input_size: A Tensor of type int32 or int64. An integer vector representing the
  1065. * shape of input.
  1066. * @li strides: A required list or tuple. The stride of the sliding window for
  1067. * height and width for H/W dimension.
  1068. * @li pads: A required list or tuple of int32. Padding added to each dimension
  1069. * of the input.
  1070. *@par Attributes:
  1071. * Five attributes:
  1072. * @li groups: Number of blocked connections from input channels to output channels.
  1073. * Defaults to "1".
  1074. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1075. * of input. Must be [1, 1, 1, 1].
  1076. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1077. * Specify the data format of the input and output data.
  1078. * @li output_padding: The size will be added in the output shape. Defaults
  1079. * to [0, 0, 0, 0].
  1080. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1081. * Defaults to "0".
  1082. *@par Outputs:
  1083. * y: A Tensor. Has the same type as "filter".
  1084. *@par Restrictions:
  1085. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DTranspose instead.
  1086. */
  1087. REG_OP(Conv2DTransposeD)
  1088. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1089. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1090. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1091. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1092. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1093. .REQUIRED_ATTR(input_size, ListInt)
  1094. .REQUIRED_ATTR(strides, ListInt)
  1095. .REQUIRED_ATTR(pads, ListInt)
  1096. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1097. .ATTR(groups, Int, 1)
  1098. .ATTR(data_format, String, "NHWC")
  1099. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1100. .ATTR(offset_x, Int, 0)
  1101. .OP_END_FACTORY_REG(Conv2DTransposeD)
  1102. } // namespace ge
  1103. #endif // GE_OP_NN_CALCULATION_OPS_H

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