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 54 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
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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 . \n
  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 . \n
  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" . \n
  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 . \n
  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 . \n
  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 . \n
  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" . \n
  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 . \n
  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 . \n
  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 . \n
  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 . \n
  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" . \n
  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 . \n
  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 . \n
  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" . \n
  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 . \n
  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 . \n
  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 . \n
  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. * @par Restrictions:
  282. * Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  283. */
  284. REG_OP(DepthwiseConv2D)
  285. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  286. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  287. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  288. .OPTIONAL_INPUT(offset_w, TensorType({DT_FLOAT16, DT_INT8}))
  289. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  290. .REQUIRED_ATTR(strides, ListInt)
  291. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  292. .REQUIRED_ATTR(pads, ListInt)
  293. .ATTR(data_format, String, "NHWC")
  294. .ATTR(offset_x, Int, 0)
  295. .OP_END_FACTORY_REG(DepthwiseConv2D)
  296. /**
  297. *@brief Performs the the backward operation for "BiasAdd" on the "bias" tensor.
  298. * It accumulates all the values from out_backprop into the feature
  299. * dimension. For NHWC data format, the feature dimension is the last.
  300. * For NCHW data format, the feature dimension is the third-to-last . \n
  301. *@par Inputs:
  302. *x: A Tensor of type NumberType . \n
  303. *@par Attributes:
  304. *data_format: Data format. Defaults to "NHWC" . \n
  305. *@par Outputs:
  306. *y: A Tensor.Has the same type as "x" . \n
  307. *@par Third-party framework compatibility
  308. * Compatible with the TensorFlow operator BiasAddGrad.
  309. */
  310. REG_OP(BiasAddGrad)
  311. .INPUT(x, TensorType::NumberType())
  312. .OUTPUT(y, TensorType::NumberType())
  313. .ATTR(data_format, String, "NHWC")
  314. .OP_END_FACTORY_REG(BiasAddGrad)
  315. /**
  316. *@brief Computes the gradients of convolution with respect to the input.
  317. *@par Inputs:
  318. * Three inputs:
  319. * @li input_size: A const Tensor of type int32. Currently does not support
  320. * data tensor. An integer vector representing the shape of input, where
  321. * input is a 4-D tensor [batch, height, width, channels]
  322. * or [batch, channels, height, width].
  323. * @li filter: A Tensor. Must be one of the following types: float16, float32,
  324. * float64. 4-D with shape
  325. * [filter_height, filter_width, in_channels, out_channels]
  326. * or [out_channels, filter_height, filter_width, in_channels]
  327. * or [out_channels, in_channel, filter_height, filter_width].
  328. * @li out_backprop: A Tensor. Must have the same type as filter.
  329. * 4-D with shape [batch, out_height, out_width, out_channels]
  330. * or [batch, out_channels, out_height, out_width].
  331. * Gradients with respect to the output of the convolution.
  332. *@par Attributes:
  333. * Five attributes:
  334. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  335. * for H/W dimension. The index of H/W is same as data_format.
  336. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads
  337. * on feature map
  338. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  339. * dimension of input, defaults to [1,1,1,1].
  340. * @li groups: Number of blocked connections from input channels to output
  341. * channels.
  342. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  343. * "NHWC". Specify the data format of the input and output data.
  344. *@par Outputs:
  345. * y: A Tensor. Has the same type as filter,and has same format as input_size.
  346. *@par Third-party framework compatibility
  347. * Compatible with Tensorflow's conv2d_backprop_input
  348. */
  349. REG_OP(Conv2DBackpropInput)
  350. .INPUT(input_size, TensorType({DT_INT32}))
  351. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  352. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  353. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  354. .REQUIRED_ATTR(strides, ListInt)
  355. .REQUIRED_ATTR(pads, ListInt)
  356. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  357. .ATTR(groups, Int, 1)
  358. .ATTR(data_format, String, "NHWC")
  359. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  360. /**
  361. *@brief Computes the gradients of convolution with respect to the input.
  362. *@par Inputs:
  363. * Two inputs:
  364. * @li filter: A Tensor. Types is float16.
  365. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  366. * or [out_channels, filter_height, filter_width, in_channels]
  367. * or [out_channels, in_channel, filter_height, filter_width].
  368. * @li out_backprop: A Tensor. Must have the same type as filter.
  369. * 4-D with shape [batch, out_height, out_width, out_channels]
  370. * or [batch, out_channels, out_height, out_width].
  371. * Gradients with respect to the output of the convolution.
  372. *@par Attributes:
  373. * Six attributes:
  374. * @li input_size A Tensor of type int32. An integer vector representing the
  375. * shape of input, where input is a 4-D tensor [batch, height, width, channels]
  376. * or [batch, channels, height, width].
  377. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  378. * for H/W dimension. The index of H/W is same as data_format.
  379. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  380. * feature map
  381. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  382. * dimension of input, defaults to [1,1,1,1].
  383. * @li groups: Number of blocked connections from input channels to output
  384. * channels.
  385. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  386. * "NHWC". Specify the data format of the input and output data.
  387. *@par Outputs:
  388. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width,
  389. * channels] or [batch, channels, height, width].
  390. *@par Third-party framework compatibility
  391. * Compatible with Tensorflow's conv2d_backprop_input
  392. *@par Restrictions:
  393. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropInput instead.
  394. */
  395. REG_OP(Conv2DBackpropInputD)
  396. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  397. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  398. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  399. .REQUIRED_ATTR(input_size, ListInt)
  400. .REQUIRED_ATTR(strides, ListInt)
  401. .REQUIRED_ATTR(pads, ListInt)
  402. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  403. .ATTR(groups, Int, 1)
  404. .ATTR(data_format, String, "NHWC")
  405. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  406. /**
  407. *@brief Computes the Deconvolution with respect to the input.
  408. *@par Inputs:
  409. * Three inputs:
  410. * @li x: A Tensor of type float16 or int8. 4D with shape
  411. * [batch, out_channels, out_height, out_width]. Gradients with respect
  412. * to the output of the convolution.
  413. * @li filter: A Tensor. Must have the same type as "x".
  414. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  415. * Two optional inputs:
  416. * @li bias: An optional tensor. Must have the same type as "y".
  417. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  418. * Type is int8. Reserved.\n
  419. *@par Attributes:
  420. * Six attributes:
  421. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  422. * for H/W dimension.
  423. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  424. * padding on the feature map.
  425. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  426. * dimension of input, defaults to [1,1,1,1].
  427. * @li groups: Number of blocked connections from input channels to
  428. output channels. Defaults to "1".
  429. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  430. Specify the data format of the input and output data.
  431. * @li offset_x: An optional integer for quantized deconvolution.
  432. * Defaults to "0".
  433. *@par Outputs:
  434. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  435. * When type of x is float16, the type of y must be float16.
  436. * When type of x is int8, the type of y must be int32.
  437. */
  438. REG_OP(Deconvolution)
  439. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  440. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  441. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  442. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  443. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  444. .REQUIRED_ATTR(strides, ListInt)
  445. .REQUIRED_ATTR(pads, ListInt)
  446. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  447. .ATTR(groups, Int, 1)
  448. .ATTR(data_format, String, "NCHW")
  449. .ATTR(offset_x, Int, 0)
  450. .OP_END_FACTORY_REG(Deconvolution)
  451. /**
  452. *@brief Computes the gradients of convolution with respect to the filter
  453. *@par Inputs:
  454. * Three inputs:
  455. * @li x: A Tensor. Must be one of the following types: float16, float32,
  456. * float64.4-D with shape [batch, in_height, in_width, in_channels] or
  457. * [batch, in_channels, in_height, in_width].
  458. * @li filter_size: A const Tensor of type int32. Currently does not support
  459. * data tensor. An integer vector representing the tensor shape of filter,
  460. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  461. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  462. * or [out_channels, in_channel, filter_height, filter_width].
  463. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  464. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  465. * out_height, out_width]. Gradients with respect to the output of the
  466. * convolution.
  467. *@par Attributes:
  468. * Five attributes:
  469. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  470. * for H/W dimension. The index of H/W is same as data_format.
  471. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  472. * feature map.
  473. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  474. * dimension of input, defaults to [1,1,1,1].
  475. * @li groups: Number of blocked connections from input channels to output
  476. * channels.
  477. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  478. * "NHWC". Specify the data format of the input and output data.
  479. *@par Outputs:
  480. * y: A Tensor. Has the same type as x, has the same format as filter_size.
  481. *@par Third-party framework compatibility
  482. * Compatible with Tensorflow's conv2d_backprop_filter
  483. */
  484. REG_OP(Conv2DBackpropFilter)
  485. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  486. .INPUT(filter_size, TensorType({DT_INT32}))
  487. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  488. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  489. .REQUIRED_ATTR(strides, ListInt)
  490. .REQUIRED_ATTR(pads, ListInt)
  491. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  492. .ATTR(groups, Int, 1)
  493. .ATTR(data_format, String, "NHWC")
  494. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  495. /**
  496. *@brief Computes the gradients of convolution with respect to the filter.
  497. *@par Inputs:
  498. * Two inputs:
  499. * @li x: A Tensor. Type is float16.
  500. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch,
  501. * in_channels, in_height, in_width].
  502. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  503. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  504. * out_height, out_width]. Gradients with respect to the output of the
  505. * convolution.
  506. *@par Attributes:
  507. * Six attributes:
  508. * @li filter_size: A Tensor of type integers. An integer vector representing
  509. * the tensor shape of filter,
  510. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  511. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  512. * or [out_channels, in_channel, filter_height, filter_width].
  513. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  514. * for H/W dimension. The index of H/W is same as data_format.
  515. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  516. * feature map
  517. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  518. * dimension of input, defaults to [1,1,1,1].
  519. * @li groups: Number of blocked connections from input channels to output
  520. * channels.
  521. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  522. * "NHWC". Specify the data format of the input and output data.
  523. *@par Outputs:
  524. * y: A Tensor. Type is float32, a 4-D tensor [filter_height, filter_width,
  525. * in_channels, out_channels] or [out_channels, filter_height, filter_width,
  526. * in_channels] or [out_channels, in_channel, filter_height, filter_width].
  527. * Compatible with Tensorflow's conv2d_backprop_filter
  528. *@par Restrictions:
  529. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropFilter instead.
  530. */
  531. REG_OP(Conv2DBackpropFilterD)
  532. .INPUT(x, TensorType({DT_FLOAT16}))
  533. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  534. .OUTPUT(y, TensorType({DT_FLOAT}))
  535. .REQUIRED_ATTR(filter_size, ListInt)
  536. .REQUIRED_ATTR(strides, ListInt)
  537. .REQUIRED_ATTR(pads, ListInt)
  538. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  539. .ATTR(groups, Int, 1)
  540. .ATTR(data_format, String, "NHWC")
  541. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  542. /**
  543. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  544. *@par Inputs:
  545. *@li x: A 4D tensor of input images. With "NHWC" format, the shape is
  546. * [batch, in_height, in_width, in_channels].
  547. *@li filter: A 4D tensor of filters. Has the same type as "x". With "HWCN"
  548. * format, the shape is [filter_height, filter_width, in_channels,
  549. * out_channels].
  550. *@li bias: An optional 1D tensor. Shape is [out_channels].
  551. *@li offset_w: An optional 1D tensor for quantized convolution. Shape is
  552. * [out_channels]. Reserved.
  553. *\n
  554. *\n
  555. * Note that there is a strict data type mapping between the input and output
  556. * tensors:
  557. *@verbatim
  558. |Tensor | x | filter | bias | offset_w | y
  559. -----------|---------|---------|---------|----------|--------
  560. |Data Type | float16 | float16 | float16 | _ | float16
  561. | |---------|---------|---------|----------|--------
  562. | | float32 | float32 | float32 | _ | float32
  563. | |---------|---------|---------|----------|--------
  564. | | int8 | int8 | int32 | int8 | int32
  565. -----------|---------|---------|---------|----------|--------
  566. |Format | NCHW | NCHW | ND | ND | NCHW
  567. | | NHWC | HWCN | | | NHWC
  568. @endverbatim
  569. * Type float32 is allowed only in mixed precision (float32->float16) scenarios.
  570. * Mixed precision is enabled by default.
  571. * \n
  572. *
  573. *@par Attributes:
  574. *@li strides: Required. A list of 4 integers. Specifying the strides of the
  575. * convolution along the height and width. The dimension order is determined
  576. * by the data format of "x". By default the N and C dimensions are set to 1.
  577. *@li pads: Required. A list of 4 integers. Specifying the top, bottom, left
  578. * and right padding.
  579. * @li dilations: Optional. A list of 4 integers. Specifying the dilation rate
  580. * to use for dilated convolution. Has the same dimension order and value as
  581. * "strides". Defaults to [1, 1, 1, 1].
  582. * @li groups: Optional. An integer of type int32, for the number of blocked
  583. * connections from input channels to output channels. Input channels and output
  584. * channels must both be divisible by "groups". "x" in_channels must be equal to
  585. * "filter" in_channels * groups. Defaults to 1.
  586. * @li offset_x: Optional. An integer of type int32, for quantized convolution.
  587. * Defaults to 0.
  588. * @li data_format: Reserved and optional. A string from: "NHWC" and "NCHW".
  589. * Specifying the data format of the input and output images. Defaults to
  590. * "NHWC".
  591. *\n
  592. *\n
  593. * The following value range restrictions must be met:
  594. *@verbatim
  595. |Name | Field | Scope
  596. ------------------|----------|----------
  597. |Input Image Size | H | [1, 4096]
  598. | | W | [1, 4096]
  599. ------------------|----------|----------
  600. |Filter Size | H | [1, 255]
  601. | | W | [1, 255]
  602. ------------------|----------|----------
  603. |Stride | H | [1, 63]
  604. | | W | [1, 63]
  605. ------------------|----------|----------
  606. |Padding | top | [0, 255]
  607. | | bottom | [0, 255]
  608. | | left | [0, 255]
  609. | | right | [0, 255]
  610. ------------------|----------|----------
  611. |Dilation | H | [1, 255]
  612. | | W | [1, 255]
  613. @endverbatim
  614. *
  615. *@par Outputs:
  616. *@li y: A 4D Tensor of output images. Has the same type and format as "x". With
  617. * "NHWC" format, the shape is [batch, out_height, out_width, out_channels].
  618. *\n
  619. * out_height = (in_height + top_pad + bottom_pad -
  620. * dilation_h * (filter_height - 1) - 1)
  621. * / stride_h + 1
  622. *\n
  623. * out_width = (in_width + left_pad + right_pad -
  624. * dilation_w * (filter_width - 1) - 1)
  625. * / stride_w + 1
  626. *
  627. *@attention Constraints:
  628. *@li The following restrictions on the output must be met:
  629. *@verbatim
  630. | Output | Restrictions
  631. -------------------|---------------------------
  632. | W dimension == 1 | H*W(input) == H*W(filter)
  633. | H dimension == 1 |
  634. -------------------|---------------------------
  635. | W dimension == 1 | Not supported
  636. | H dimension != 1 |
  637. @endverbatim
  638. * "H * W (input)" indicates the image size after padding and "H * W (filter)"
  639. * indicates the filter size after dilation.
  640. *\n
  641. *
  642. *@par Quantization supported or not
  643. *@li Yes
  644. *
  645. *@par Third-party framework compatibility
  646. *@li Compatible with the TensorFlow operator "conv2d".
  647. *@li Compatible with the Caffe operator 2D "Convolution".
  648. */
  649. REG_OP(Conv2D)
  650. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  651. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  652. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  653. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  654. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  655. .REQUIRED_ATTR(strides, ListInt)
  656. .REQUIRED_ATTR(pads, ListInt)
  657. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  658. .ATTR(groups, Int, 1)
  659. .ATTR(data_format, String, "NHWC")
  660. .ATTR(offset_x, Int, 0)
  661. .OP_END_FACTORY_REG(Conv2D)
  662. REG_OP(Conv2DCompress)
  663. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  664. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT8}))
  665. .INPUT(compress_index, TensorType({DT_INT8}))
  666. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  667. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  668. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE, DT_INT32}))
  669. .REQUIRED_ATTR(strides, ListInt)
  670. .REQUIRED_ATTR(pads, ListInt)
  671. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  672. .ATTR(groups, Int, 1)
  673. .ATTR(data_format, String, "NHWC")
  674. .ATTR(offset_x, Int, 0)
  675. .OP_END_FACTORY_REG(Conv2DCompress)
  676. /**
  677. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  678. *@par Inputs:
  679. * @li x: A 5D tensor. Must be one of the following types: float16,
  680. * (Currently does not support int8). The format of x is NCDHW or NDHWC.
  681. * @li filter: A 5D tensor of the same type as "x".
  682. * (Currently does not support int8).
  683. * The format is NCDHW, NDHWC or DHWCN . \n
  684. *@par Optional input:
  685. * @li bias: An optional 1D tensor of the same type as "x".
  686. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved . \n
  687. *@par Required Attributes:
  688. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  689. * for each dimension of "x".
  690. * The N and C dimensions must be 1. Has the same format as "x".
  691. * @li pads: A list of 6 integers.
  692. * Supports only padding along the D, H and W dimensions in sequence of head,
  693. * tail, top, bottom, left and right . \n
  694. *@par Attributes:
  695. * @li groups: Number of blocked connections from input channels to output
  696. * channels. Reserved.
  697. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  698. * Defaults to "NDHWC". Specify the data format of the input and output data.
  699. * @li dilations: A list of 5 integers. Specifies the dilation factor for each
  700. * dimension of "x", now only support [1,1,1,1,1]
  701. * The N and C dimensions must be 1. Has the same format as "x".
  702. * @li offset_x: An optional int. Input offset, used for quantized inference.
  703. * Defaults to 0. Reserved . \n
  704. *@par Outputs:
  705. *y: A Tensor. Has the same type and data format as "x". \n
  706. *@attention Constraints:
  707. *The image size after padding is greater than the filter size . \n
  708. *@par Third-party framework compatibility
  709. * @li Compatible with the TensorFlow operator conv3d.
  710. * @li Compatible with the Caffe operator Convolution.
  711. */
  712. REG_OP(Conv3D)
  713. .INPUT(x, TensorType({DT_FLOAT16}))
  714. .INPUT(filter, TensorType({DT_FLOAT16}))
  715. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  716. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  717. .OUTPUT(y, TensorType({DT_FLOAT16}))
  718. .REQUIRED_ATTR(strides, ListInt)
  719. .REQUIRED_ATTR(pads, ListInt)
  720. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  721. .ATTR(groups, Int, 1)
  722. .ATTR(data_format, String, "NDHWC")
  723. .ATTR(offset_x, Int, 0)
  724. .OP_END_FACTORY_REG(Conv3D)
  725. /**
  726. *@brief Computes the gradients of convolution 3d with respect to the input.
  727. *@par Inputs:
  728. * Three inputs:
  729. * @li input_size: A Tensor of type int32, int64. An integer vector representing
  730. * the shape of input, where input is a 5-D tensor
  731. * [batch, depth, height, width, channels] or
  732. * [batch, channels, depth, height, width].
  733. * @li filter: A Tensor. Must be one of the following types: float16, float32.
  734. * Currently does not support double.
  735. * @li out_backprop: A Tensor. Must have the same type as filter.
  736. * 5-D with shape [batch, depth, out_height, out_width, out_channels]
  737. * or [batch, out_channels, depth, out_height, out_width]. Gradients with
  738. * respect to the output of the convolution . \n
  739. *@par Required Attributes:
  740. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  741. * for each dimension of "x".
  742. * The N and C dimensions must be 1. Has the same format as "x".
  743. * @li pads: A list of 6 integers.
  744. * Supports only padding along the D, H and W dimensions in sequence of head,
  745. * tail, top, bottom, left and right . \n
  746. *@par Attributes:
  747. * Three attributes:
  748. * @li groups: Number of blocked connections from input channels to output
  749. * channels. Reserved.
  750. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  751. * Defaults to "NDHWC". Specify the data format of the input and output data.
  752. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  753. * dimension of the input, now only support [1,1,1,1,1]
  754. *@par Outputs:
  755. * y: A Tensor. Has the same type as filter,and has same format as input_size
  756. *@par Third-party framework compatibility
  757. * Compatible with Tensorflow's conv3d_backprop_input
  758. */
  759. REG_OP(Conv3DBackpropInput)
  760. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  761. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  762. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  763. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  764. .REQUIRED_ATTR(strides, ListInt)
  765. .REQUIRED_ATTR(pads, ListInt)
  766. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  767. .ATTR(groups, Int, 1)
  768. .ATTR(data_format, String, "NDHWC")
  769. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  770. /**
  771. *@brief Computes the gradients of convolution 3d with respect to the input.
  772. *@par Inputs:
  773. * Two inputs:
  774. * @li filter: A Tensor whose type is float16. The format of filter is NCDHW,
  775. * NDHWC or DHWCN.
  776. * @li out_backprop: A Tensor. Must have the same type as filter. The format is
  777. * NDHWC or NCDHW. \n
  778. *@par Required Attributes:
  779. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  780. * for each dimension of "x".
  781. * The N and C dimensions must be 1. Has the same format as "x".
  782. * @li pads: A list of 6 integers. Supports only padding along the D, H and W
  783. * dimensions in sequence of head, tail, top, bottom, left and right.
  784. * @li input_size: A tuple/list of type int32, int64. An integer vector
  785. * representing the shape of input, where input is a 5-D tensor
  786. * [batch, depth, height, width, channels] or
  787. * [batch, channels, depth, height, width] . \n
  788. *@par Attributes:
  789. * Three attributes:
  790. * @li groups: Number of blocked connections from input channels to output
  791. * channels. Reserved.
  792. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  793. * Defaults to "NDHWC". Specify the data format of the input and output data.
  794. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  795. * dimension of input, now only support [1,1,1,1,1]
  796. *@par Outputs:
  797. * y: A Tensor. Has the same type and data format as out_backprop.
  798. *@par Third-party framework compatibility
  799. * Compatible with Tensorflow's conv3d_backprop_input
  800. *@par Restrictions:
  801. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropInput instead.
  802. */
  803. REG_OP(Conv3DBackpropInputD)
  804. .INPUT(filter, TensorType({DT_FLOAT16}))
  805. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  806. .OUTPUT(y, TensorType({DT_FLOAT16}))
  807. .REQUIRED_ATTR(input_size, ListInt)
  808. .REQUIRED_ATTR(strides, ListInt)
  809. .REQUIRED_ATTR(pads, ListInt)
  810. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  811. .ATTR(groups, Int, 1)
  812. .ATTR(data_format, String, "NDHWC")
  813. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  814. /**
  815. *@brief Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence . \n
  816. *@par Inputs:
  817. * @li x: A Tensor dtype of float16.
  818. * @li cont: A Tensor dtype of float16, float32.
  819. * @li w_x: A Tensor dtype of float16.
  820. * @li bias: A Tensor dtype of int16, int32, float16, float32.
  821. * @li w_h: A Tensor dtype of float16.
  822. * @li x_static: A optinal Tensor dtype of float16.
  823. * @li h_0: A optinal Tensor dtype of float16, float32.
  824. * @li c_0: A optinal Tensor dtype of float16, float32.
  825. * @li w_x_static: A optinal Tensor dtype of float16 . \n
  826. *@par Attributes:
  827. *@li num_output: A Scalar of output size dtype of int.
  828. *@li expose_hidden: A Scalar(bool) of features hidden . \n
  829. *@par Outputs:
  830. *@li h: A Tensor dtype of float16, float32.
  831. * @li h_t: A optinal Tensor dtype of float16, float32. The hidden state at time t.
  832. * @li c_t: A optinal Tensor dtype of float16, float32. The cell state at time t . \n
  833. *@par Third-party framework compatibility:
  834. * Compatible with the Pytorch operator adds.
  835. *@par Restrictions:
  836. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  837. */
  838. REG_OP(LSTM)
  839. .INPUT(x, TensorType({DT_FLOAT16}))
  840. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  841. .INPUT(w_x, TensorType({DT_FLOAT16}))
  842. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  843. .INPUT(w_h, TensorType({DT_FLOAT16}))
  844. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  845. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  846. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  847. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  848. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  849. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  850. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  851. .ATTR(num_output, Int, 0)
  852. .ATTR(expose_hidden, Bool, false)
  853. .OP_END_FACTORY_REG(LSTM)
  854. /**
  855. *@brief Computes the gradients of convolution3D with respect to the filter
  856. *@par Inputs:
  857. * Three inputs:
  858. * @li x: A Tensor. Must be one of the following types: float16, float32.
  859. * Currently does not support double.
  860. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  861. * or [batch, in_channels, in_depth, in_height, in_width].
  862. * @li filter_size: A Tensor of type int32. An integer vector representing the
  863. * tensor shape of filter, where filter is a 5-D tensor
  864. * [filter_depth, filter_height, filter_width, in_channels, out_channels]
  865. * [out_channels, in_channels, filter_depth, filter_height, filter_width]
  866. * or [out_channels, filter_depth, filter_height, filter_width, in_channels].
  867. * @li out_backprop: A Tensor. Must have the same type as x.
  868. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  869. * or [batch, out_channels, out_depth, out_height, out_width].
  870. * Gradients with respect to the output of the convolution. \n
  871. *@par Required Attributes:
  872. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  873. * window for each dimension of "x". The N and C dimensions must be 1.
  874. * Has the same format as "x".
  875. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  876. * pads on feature map . \n
  877. *@par Attributes:
  878. * Three attributes:
  879. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  880. * dimension of input, now only support [1,1,1,1,1].
  881. * @li groups: Number of blocked connections from input channels to output
  882. * channels. Reserved.
  883. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  884. * Defaults to "NDHWC". Specify the data format of the input and output data.
  885. *@par Outputs:
  886. * y: A Tensor that has the same type as x
  887. * and the format is NDHWC, NCDHW or DHWCN.
  888. *@par Third-party framework compatibility
  889. * Compatible with Tensorflow's conv3d_backprop_filter
  890. */
  891. REG_OP(Conv3DBackpropFilter)
  892. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  893. .INPUT(filter_size, TensorType({DT_INT32}))
  894. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  895. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  896. .REQUIRED_ATTR(strides, ListInt)
  897. .REQUIRED_ATTR(pads, ListInt)
  898. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  899. .ATTR(groups, Int, 1)
  900. .ATTR(data_format, String, "NDHWC")
  901. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  902. /**
  903. *@brief Computes the gradients of convolution with respect to the filter.
  904. *@par Inputs:
  905. * Two inputs:
  906. * @li x: A Tensor of type float16.
  907. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  908. * or [batch, in_channels, in_depth, in_height, in_width].
  909. * @li out_backprop: A Tensor. Must have the same type as x.
  910. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  911. * or [batch, out_channels, out_depth, out_height, out_width].
  912. * Gradients with respect to the output of the convolution. \n
  913. *@par Required Attributes:
  914. * @li filter_size: A tuple/list of type integers. An integer vector
  915. * representing the tensor shape of filter, where filter is a 5-D tensor
  916. * [filter_depth, filter_height, filter_width, in_channels, out_channels],
  917. * [out_channels, filter_depth, filter_height, filter_width, in_channels]
  918. * or [out_channels, in_channels, filter_depth, filter_height, filter_width].
  919. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  920. * window for each dimension of "x".
  921. * The N and C dimensions must be 1. Has the same format as "x".
  922. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  923. * pads on feature map. \n
  924. *@par Attributes:
  925. * Three attributes:
  926. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  927. * dimension of input, now only support [1,1,1,1,1].
  928. * @li groups: Number of blocked connections from input channels to output
  929. * channels. Reserved.
  930. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  931. * Defaults to "NDHWC". Specify the data format of the input and output data.
  932. *@par Outputs:
  933. * y: A Tensor of type float32 and the format is NDHWC, NCDHW or DHWCN.
  934. *@par Third-party framework compatibility
  935. * Compatible with Tensorflow's conv3d_backprop_filter
  936. *@par Restrictions:
  937. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropFilter instead.
  938. */
  939. REG_OP(Conv3DBackpropFilterD)
  940. .INPUT(x, TensorType({DT_FLOAT16}))
  941. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  942. .OUTPUT(y, TensorType({DT_FLOAT}))
  943. .REQUIRED_ATTR(filter_size, ListInt)
  944. .REQUIRED_ATTR(strides, ListInt)
  945. .REQUIRED_ATTR(pads, ListInt)
  946. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  947. .ATTR(groups, Int, 1)
  948. .ATTR(data_format, String, "NDHWC")
  949. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  950. /**
  951. *@brief Computes the transpose of convolution 3d with respect to the input.
  952. *@par Inputs:
  953. * Three inputs:
  954. * @li input_size: A Tensor of type int32. An integer vector representing the
  955. * shape of input.
  956. * @li x: A Tensor of type float16, currently does not support int8. The format
  957. * is NDHWC or NCDHW.
  958. * @li filter: A Tensor of type float16, currently does not support int8.
  959. * The format is NDHWC, NCDHW or DHWCN.
  960. *@par Optional input:
  961. * Two optional inputs
  962. * @li bias: An optional 1D tensor of the same type as "x". Reserved.
  963. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved . \n
  964. *@par Required Attributes:
  965. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  966. * window for each dimension of "x".
  967. * The N and C dimensions must be 1. Has the same format as "x".
  968. * @li pads: A tuple/list of 6 integers
  969. *@par Attributes:
  970. * Five attributes:
  971. * @li groups: Number of blocked connections from input channels to output
  972. * channels. Reserved.
  973. * @li dilations: A tuple/list of 5 integers,
  974. * The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  975. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  976. * Defaults to "NDHWC". Specify the data format of the input and output data.
  977. * @li output_padding: The size will be added in the output shape.
  978. * @li offset_x: Input offset_x value. Reserved.
  979. *@par Outputs:
  980. * y: A Tensor. Has the same type and format as x.
  981. */
  982. REG_OP(Conv3DTranspose)
  983. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  984. .INPUT(x, TensorType({DT_FLOAT16}))
  985. .INPUT(filter, TensorType({DT_FLOAT16}))
  986. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  987. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  988. .OUTPUT(y, TensorType({DT_FLOAT16}))
  989. .REQUIRED_ATTR(strides, ListInt)
  990. .REQUIRED_ATTR(pads, ListInt)
  991. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  992. .ATTR(groups, Int, 1)
  993. .ATTR(data_format, String, "NDHWC")
  994. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  995. .ATTR(offset_x, Int, 0)
  996. .OP_END_FACTORY_REG(Conv3DTranspose)
  997. /**
  998. *@brief Computes the transpose of convolution 3d with respect to the input.
  999. *@par Inputs:
  1000. * @li x: A Tensor of type float16, currently does not support int8.
  1001. * The format is NDHWC or NCDHW.
  1002. * @li filter: A Tensor of type float16, currently does not support int8.
  1003. * The format is NDHWC, NCDHW or DHWCN.
  1004. *@par Optional inputs:
  1005. * @li bias: An optional 1D tensor of the same type as "x". Reserved.
  1006. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved . \n
  1007. *@par Required Attributes:
  1008. * @li input_size: A tuple/list of type int32.
  1009. * An integer vector representing the shape of input
  1010. * @li strides: A tuple/list of 5 integers.
  1011. * Specifies the stride of the sliding window for each dimension of "x".
  1012. * The N and C dimensions must be 1. Has the same format as "x".
  1013. * @li pads: A tuple/list of 6 integers . \n
  1014. *@par Attributes:
  1015. * Five attributes:
  1016. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  1017. * dimension of input, now only support [1,1,1,1,1]
  1018. * @li groups: Number of blocked connections from input channels to output
  1019. * channels. Reserved.
  1020. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  1021. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1022. * @li output_padding: The size will be added in the output shape.
  1023. * @li offset_x: Input offset_x value. Reserved.
  1024. *@par Outputs:
  1025. * y: A Tensor. Has the same type and format as x.
  1026. *@par Restrictions:
  1027. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DTranspose instead.
  1028. */
  1029. REG_OP(Conv3DTransposeD)
  1030. .INPUT(x, TensorType({DT_FLOAT16}))
  1031. .INPUT(filter, TensorType({DT_FLOAT16}))
  1032. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  1033. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1034. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1035. .REQUIRED_ATTR(input_size, ListInt)
  1036. .REQUIRED_ATTR(strides, ListInt)
  1037. .REQUIRED_ATTR(pads, ListInt)
  1038. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1039. .ATTR(groups, Int, 1)
  1040. .ATTR(data_format, String, "NDHWC")
  1041. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1042. .ATTR(offset_x, Int, 0)
  1043. .OP_END_FACTORY_REG(Conv3DTransposeD)
  1044. /**
  1045. *@brief Computes the transpose of convolution 2d with respect to the input.
  1046. *@par Inputs:
  1047. * Five inputs:
  1048. * @li input_size: A Tensor of type int32 or int64. An integer vector
  1049. * representing the shape of input, where input is a 4-D tensor
  1050. * [batch, height, width, channels] or [batch, channels, height, width].
  1051. * @li x: A Tensor of type float16, int8. 4-D with shape [batch, out_height,
  1052. * out_width, out_channels] or [batch, out_channels, out_height, out_width].
  1053. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1054. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  1055. * or [out_channels, filter_height, filter_width, in_channels]
  1056. * or [out_channels, in_channel, filter_height, filter_width].
  1057. * @li bias: An optional 1D tensor of type float16 or int32. Format is "ND".
  1058. * @li offset_w: An optional 1D tensor for quantized inference. Reserved.
  1059. *@par Required Attributes:
  1060. * @li strides: A required tuple/list of 4 integers. The stride of the sliding
  1061. * window for H/W dimension. The index of H/W is same as data_format.
  1062. * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]
  1063. * pads on feature map.
  1064. *@par Attributes:
  1065. * Five attributes:
  1066. * @li groups: Number of blocked connections from input channels to output
  1067. * channels.
  1068. * Defaults to "1".
  1069. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  1070. * dimension of input. Must be [1, 1, 1, 1].
  1071. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1072. * Specify the data format of the input and output data.
  1073. * @li output_padding: The size will be added in the output shape. Defaults
  1074. * to [0, 0, 0, 0].
  1075. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1076. * Defaults to "0".
  1077. *@par Outputs:
  1078. * y: A Tensor. A Tensor of type float16 or int32, and has same format as
  1079. * input_size.
  1080. */
  1081. REG_OP(Conv2DTranspose)
  1082. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1083. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1084. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1085. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1086. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1087. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1088. .REQUIRED_ATTR(strides, ListInt)
  1089. .REQUIRED_ATTR(pads, ListInt)
  1090. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1091. .ATTR(groups, Int, 1)
  1092. .ATTR(data_format, String, "NHWC")
  1093. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1094. .ATTR(offset_x, Int, 0)
  1095. .OP_END_FACTORY_REG(Conv2DTranspose)
  1096. /**
  1097. *@brief Computes the transpose of convolution 2d with respect to the input.
  1098. *@par Inputs:
  1099. * Four inputs:
  1100. * @li x: A Tensor of type float16, int8.
  1101. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1102. * @li bias: An optional 1D tensor of the same type as "x".
  1103. * @li offset_w: An optional 1D tensor for quantized inference. Type is int8. Reserved.
  1104. *@par Required Attributes:
  1105. * @li input_size: A Tensor of type int32 or int64. An integer vector representing the
  1106. * shape of input.
  1107. * @li strides: A required list or tuple. The stride of the sliding window for
  1108. * height and width for H/W dimension.
  1109. * @li pads: A required list or tuple of int32. Padding added to each dimension
  1110. * of the input.
  1111. *@par Attributes:
  1112. * Five attributes:
  1113. * @li groups: Number of blocked connections from input channels to output channels.
  1114. * Defaults to "1".
  1115. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1116. * of input. Must be [1, 1, 1, 1].
  1117. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1118. * Specify the data format of the input and output data.
  1119. * @li output_padding: The size will be added in the output shape. Defaults
  1120. * to [0, 0, 0, 0].
  1121. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1122. * Defaults to "0".
  1123. *@par Outputs:
  1124. * y: A Tensor. Has the same type as "filter".
  1125. *@par Restrictions:
  1126. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DTranspose instead.
  1127. */
  1128. REG_OP(Conv2DTransposeD)
  1129. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1130. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1131. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1132. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1133. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1134. .REQUIRED_ATTR(input_size, ListInt)
  1135. .REQUIRED_ATTR(strides, ListInt)
  1136. .REQUIRED_ATTR(pads, ListInt)
  1137. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1138. .ATTR(groups, Int, 1)
  1139. .ATTR(data_format, String, "NHWC")
  1140. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1141. .ATTR(offset_x, Int, 0)
  1142. .OP_END_FACTORY_REG(Conv2DTransposeD)
  1143. } // namespace ge
  1144. #endif // GE_OP_NN_CALCULATION_OPS_H

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