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 64 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461
  1. /**
  2. * Copyright 2019 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 OPS_BUILT_IN_OP_PROTO_INC_NN_CALCULATION_OPS_H_
  21. #define OPS_BUILT_IN_OP_PROTO_INC_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. 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 . \n
  298. *@par Inputs:
  299. *x: A Tensor of type NumberType . \n
  300. *@par Attributes:
  301. *data_format: Data format. Defaults to "NHWC" . \n
  302. *@par Outputs:
  303. *y: A Tensor.Has the same type as "x" . \n
  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 const Tensor of type int32. Currently does not support
  317. * data tensor. An integer vector representing the shape of input, where
  318. * input is a 4-D tensor [batch, height, width, channels]
  319. * or [batch, channels, height, width].
  320. * @li filter: A Tensor. Must be one of the following types: float16, float32,
  321. * float64. 4-D with shape
  322. * [filter_height, filter_width, in_channels, out_channels]
  323. * or [out_channels, filter_height, filter_width, in_channels]
  324. * or [out_channels, in_channel, filter_height, filter_width].
  325. * @li out_backprop: A Tensor. Must have the same type as filter.
  326. * 4-D with shape [batch, out_height, out_width, out_channels]
  327. * or [batch, out_channels, out_height, out_width].
  328. * Gradients with respect to the output of the convolution.
  329. *@par Attributes:
  330. * Five attributes:
  331. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  332. * for H/W dimension. The index of H/W is same as data_format.
  333. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads
  334. * on feature map
  335. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  336. * dimension of input, defaults to [1,1,1,1].
  337. * @li groups: Number of blocked connections from input channels to output
  338. * channels.
  339. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  340. * "NHWC". Specify the data format of the input and output data.
  341. *@par Outputs:
  342. * y: A Tensor. Has the same type as filter,and has same format as input_size.
  343. *@par Third-party framework compatibility
  344. * Compatible with Tensorflow's conv2d_backprop_input
  345. */
  346. REG_OP(Conv2DBackpropInput)
  347. .INPUT(input_size, TensorType({DT_INT32}))
  348. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  349. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  350. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  351. .REQUIRED_ATTR(strides, ListInt)
  352. .REQUIRED_ATTR(pads, ListInt)
  353. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  354. .ATTR(groups, Int, 1)
  355. .ATTR(data_format, String, "NHWC")
  356. .OP_END_FACTORY_REG(Conv2DBackpropInput)
  357. /**
  358. *@brief Computes the gradients of convolution with respect to the input.
  359. *@par Inputs:
  360. * Two inputs:
  361. * @li filter: A Tensor. Types is float16.
  362. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  363. * or [out_channels, filter_height, filter_width, in_channels]
  364. * or [out_channels, in_channel, filter_height, filter_width].
  365. * @li out_backprop: A Tensor. Must have the same type as filter.
  366. * 4-D with shape [batch, out_height, out_width, out_channels]
  367. * or [batch, out_channels, out_height, out_width].
  368. * Gradients with respect to the output of the convolution.
  369. *@par Attributes:
  370. * Six attributes:
  371. * @li input_size A Tensor of type int32. An integer vector representing the
  372. * shape of input, where input is a 4-D tensor [batch, height, width, channels]
  373. * or [batch, channels, height, width].
  374. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  375. * for H/W dimension. The index of H/W is same as data_format.
  376. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  377. * feature map
  378. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  379. * dimension of input, defaults to [1,1,1,1].
  380. * @li groups: Number of blocked connections from input channels to output
  381. * channels.
  382. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  383. * "NHWC". Specify the data format of the input and output data.
  384. *@par Outputs:
  385. * y: A Tensor. Has the same type as filter,4-D tensor [batch, height, width,
  386. * channels] or [batch, channels, height, width].
  387. *@par Third-party framework compatibility
  388. * Compatible with Tensorflow's conv2d_backprop_input
  389. *@par Restrictions:
  390. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropInput instead.
  391. */
  392. REG_OP(Conv2DBackpropInputD)
  393. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  394. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_INT8}))
  395. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  396. .REQUIRED_ATTR(input_size, ListInt)
  397. .REQUIRED_ATTR(strides, ListInt)
  398. .REQUIRED_ATTR(pads, ListInt)
  399. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  400. .ATTR(groups, Int, 1)
  401. .ATTR(data_format, String, "NHWC")
  402. .OP_END_FACTORY_REG(Conv2DBackpropInputD)
  403. /**
  404. *@brief Computes the Deconvolution with respect to the input.
  405. *@par Inputs:
  406. * Three inputs:
  407. * @li x: A Tensor of type float16 or int8. 4D with shape
  408. * [batch, out_channels, out_height, out_width]. Gradients with respect
  409. * to the output of the convolution.
  410. * @li filter: A Tensor. Must have the same type as "x".
  411. * 4D with shape [out_channels, in_channel, filter_height, filter_width].\n
  412. * Two optional inputs:
  413. * @li bias: An optional tensor. Must have the same type as "y".
  414. * @li offset_w: An optional 1D tensor for quantized deconvolution.
  415. * Type is int8. Reserved.\n
  416. *@par Attributes:
  417. * Six attributes:
  418. * @li strides: A tuple or list of 2 integers. The stride of the sliding window
  419. * for H/W dimension, defaults to [1,1].
  420. * @li pads: A tuple or list of 4 integers. The [top, bottom, left, right]
  421. * padding on the feature map, defaults to [0,0,0,0].
  422. * @li dilations: A tuple or list of 4 integers. The dilation factor for each
  423. * dimension of input, defaults to [1,1,1,1].
  424. * @li groups: Number of blocked connections from input channels to
  425. output channels. Defaults to "1".
  426. * @li data_format: An optional string from: "NCHW". Defaults to "NCHW". \n
  427. Specify the data format of the input and output data.
  428. * @li offset_x: An optional integer for quantized deconvolution.
  429. * Defaults to "0".
  430. *@par Outputs:
  431. * y: A Tensor. 4D tensor with shape [batch, channels, height, width].
  432. * When type of x is float16, the type of y must be float16.
  433. * When type of x is int8, the type of y must be int32.
  434. */
  435. REG_OP(Deconvolution)
  436. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  437. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  438. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  439. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  440. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  441. .ATTR(strides, ListInt, {1, 1})
  442. .ATTR(pads, ListInt, {0, 0, 0, 0})
  443. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  444. .ATTR(groups, Int, 1)
  445. .ATTR(data_format, String, "NCHW")
  446. .ATTR(offset_x, Int, 0)
  447. .OP_END_FACTORY_REG(Deconvolution)
  448. /**
  449. *@brief Computes the gradients of convolution with respect to the filter
  450. *@par Inputs:
  451. * Three inputs:
  452. * @li x: A Tensor. Must be one of the following types: float16, float32,
  453. * float64.4-D with shape [batch, in_height, in_width, in_channels] or
  454. * [batch, in_channels, in_height, in_width].
  455. * @li filter_size: A const Tensor of type int32. Currently does not support
  456. * data tensor. An integer vector representing the tensor shape of filter,
  457. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  458. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  459. * or [out_channels, in_channel, filter_height, filter_width].
  460. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  461. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  462. * out_height, out_width]. Gradients with respect to the output of the
  463. * convolution.
  464. *@par Attributes:
  465. * Five attributes:
  466. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  467. * for H/W dimension. The index of H/W is same as data_format.
  468. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  469. * feature map.
  470. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  471. * dimension of input, defaults to [1,1,1,1].
  472. * @li groups: Number of blocked connections from input channels to output
  473. * channels.
  474. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  475. * "NHWC". Specify the data format of the input and output data.
  476. *@par Outputs:
  477. * y: A Tensor. Has the same type as x, has the same format as filter_size.
  478. *@par Third-party framework compatibility
  479. * Compatible with Tensorflow's conv2d_backprop_filter
  480. */
  481. REG_OP(Conv2DBackpropFilter)
  482. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  483. .INPUT(filter_size, TensorType({DT_INT32}))
  484. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  485. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  486. .REQUIRED_ATTR(strides, ListInt)
  487. .REQUIRED_ATTR(pads, ListInt)
  488. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  489. .ATTR(groups, Int, 1)
  490. .ATTR(data_format, String, "NHWC")
  491. .OP_END_FACTORY_REG(Conv2DBackpropFilter)
  492. /**
  493. *@brief Computes the gradients of convolution with respect to the filter.
  494. *@par Inputs:
  495. * Two inputs:
  496. * @li x: A Tensor. Type is float16.
  497. * 4-D with shape [batch, in_height, in_width, in_channels] or [batch,
  498. * in_channels, in_height, in_width].
  499. * @li out_backprop: A Tensor. Must have the same type as x. 4-D with shape
  500. * [batch, out_height, out_width, out_channels] or [batch, out_channels,
  501. * out_height, out_width]. Gradients with respect to the output of the
  502. * convolution.
  503. *@par Attributes:
  504. * Six attributes:
  505. * @li filter_size: A Tensor of type integers. An integer vector representing
  506. * the tensor shape of filter,
  507. * where filter is a 4-D tensor [filter_height, filter_width, in_channels,
  508. * out_channels] or [out_channels, filter_height, filter_width, in_channels]
  509. * or [out_channels, in_channel, filter_height, filter_width].
  510. * @li strides: A tuple/list of 4 integers. The stride of the sliding window
  511. * for H/W dimension. The index of H/W is same as data_format.
  512. * @li pads: A tuple/list of 4 integers, [top, bottom, left, right] pads on
  513. * feature map
  514. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  515. * dimension of input, defaults to [1,1,1,1].
  516. * @li groups: Number of blocked connections from input channels to output
  517. * channels.
  518. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to
  519. * "NHWC". Specify the data format of the input and output data.
  520. *@par Outputs:
  521. * y: A Tensor. Type is float32, a 4-D tensor [filter_height, filter_width,
  522. * in_channels, out_channels] or [out_channels, filter_height, filter_width,
  523. * in_channels] or [out_channels, in_channel, filter_height, filter_width].
  524. * Compatible with Tensorflow's conv2d_backprop_filter
  525. *@par Restrictions:
  526. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DBackpropFilter instead.
  527. */
  528. REG_OP(Conv2DBackpropFilterD)
  529. .INPUT(x, TensorType({DT_FLOAT16}))
  530. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  531. .OUTPUT(y, TensorType({DT_FLOAT}))
  532. .REQUIRED_ATTR(filter_size, ListInt)
  533. .REQUIRED_ATTR(strides, ListInt)
  534. .REQUIRED_ATTR(pads, ListInt)
  535. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  536. .ATTR(groups, Int, 1)
  537. .ATTR(data_format, String, "NHWC")
  538. .OP_END_FACTORY_REG(Conv2DBackpropFilterD)
  539. /**
  540. *@brief Computes a 2D convolution given 4D "x" and "filter" tensors.
  541. *@par Inputs:
  542. *@li x: A 4D tensor of input image. With the format "NHWC", the data is stored
  543. * in the order of: [batch, in_height, in_width, in_channels].
  544. *@li filter: A 4D tensor of learnable filters. Must have the same type as "x".
  545. * With the format "HWCN" , the data is stored in the order of: [filter_height,
  546. * filter_width, in_channels / groups, out_channels].
  547. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  548. * The data is stored in the order of: [out_channels].
  549. *@li offset_w: Reserved.
  550. *\n
  551. *\n
  552. * The following are the supported data types and data formats:
  553. *@verbatim
  554. | Tensor | x | filter | bias | y
  555. ------------|---------|---------|---------|--------
  556. | Data Type | float16 | float16 | float16 | float16
  557. | |---------|---------|---------|--------
  558. | | float32 | float32 | float32 | float32
  559. | |---------|---------|---------|--------
  560. | | int8 | int8 | int32 | int32
  561. ------------|---------|---------|---------|--------
  562. | Format | NCHW | NCHW | ND | NCHW
  563. | | NHWC | HWCN | | NHWC
  564. @endverbatim
  565. * For float32 type, the actual calculation on the chip is based on
  566. * float16. For int8, a dequant or requant operator must be followed.
  567. *\n
  568. *
  569. *@par Attributes:
  570. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  571. * for each dimension of input. The dimension order is determined by the data
  572. * format of "x". The N and C dimensions must be set to 1.
  573. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  574. * (top, bottom, left, right) side of the input.
  575. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  576. * dimension of input. The dimension order is determined by the data format of
  577. * "x". The N and C dimensions must be set to 1. Defaults to [1, 1, 1, 1].
  578. *@li groups: Optional. An integer of type int32. The number of blocked
  579. * connections from input channels to output channels. In_channels and
  580. * out_channels must both be divisible by "groups". Defaults to 1.
  581. *@li offset_x: Optional. An integer of type int32. The negative offset added
  582. * to the input image for int8 type. Ensure that the output is within the
  583. * effective range. Defaults to 0.
  584. *@li data_format: Reserved.
  585. *\n
  586. *\n
  587. * The following value range restrictions must be met:
  588. *@verbatim
  589. | Name | Field | Scope
  590. -------------------|----------|--------------
  591. | Input Image Size | H | [1, 100000]
  592. | | W | [1, 4096]
  593. -------------------|----------|--------------
  594. | Filter Size | H | [1, 255]
  595. | | W | [1, 255]
  596. -------------------|----------|--------------
  597. | Stride | H | [1, 63]
  598. | | W | [1, 63]
  599. -------------------|----------|--------------
  600. | Padding | Top | [0, 255]
  601. | | Bottom | [0, 255]
  602. | | Left | [0, 255]
  603. | | Right | [0, 255]
  604. -------------------|----------|--------------
  605. | Dilation | H | [1, 255]
  606. | | W | [1, 255]
  607. -------------------|----------|--------------
  608. | Offset_x | | [-128, 127]
  609. @endverbatim
  610. * The W dimension of the input image supports cases exceeding 4096, but it may
  611. * cause compilation errors.
  612. *\n
  613. *
  614. *@par Outputs:
  615. *@li y: A 4D Tensor of output feature map. Has the same type as "x". With the
  616. * format "NHWC", the data is stored in the order of: [batch, out_height,
  617. * out_width, out_channels].
  618. *\n
  619. * out_height = (in_height + pad_top + pad_bottom -
  620. * (dilation_h * (filter_height - 1) + 1))
  621. * / stride_h + 1
  622. *\n
  623. * out_width = (in_width + pad_left + pad_right -
  624. * (dilation_w * (filter_width - 1) + 1))
  625. * / stride_w + 1
  626. *\n
  627. *
  628. *@par Quantization supported or not
  629. *@li Yes
  630. *
  631. *@par Third-party framework compatibility
  632. *@li Compatible with the TensorFlow operator "conv2d".
  633. *@li Compatible with the Caffe operator 2D "Convolution".
  634. */
  635. REG_OP(Conv2D)
  636. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  637. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  638. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  639. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  640. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  641. .REQUIRED_ATTR(strides, ListInt)
  642. .REQUIRED_ATTR(pads, ListInt)
  643. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  644. .ATTR(groups, Int, 1)
  645. .ATTR(data_format, String, "NHWC")
  646. .ATTR(offset_x, Int, 0)
  647. .OP_END_FACTORY_REG(Conv2D)
  648. /**
  649. *@brief Computes a 2D convolution given 4D "x" and "filter_compress" tensors.
  650. *@par Inputs:
  651. * @li x: A 4D tensor of input images.
  652. * @li filter_compress: A 4D tensor of compressed filters.
  653. * @li compress_index: A 1D Tensor dtype of int8.
  654. * @li bias: An optional 1D tensor.
  655. * @li offset_w: An optional 1D tensor for quantized convolution. Reserved.
  656. *
  657. * The input and output tensor attributes are listed as follows:
  658. * @verbatim
  659. |Tensor | x | filter_compress | bias | offset_w | y
  660. -----------|---------|---------|---------|----------|--------
  661. |Data Type | float16 | float16 | float16 | _ | float16
  662. | |---------|---------|---------|----------|--------
  663. | | float32 | float32 | float32 | _ | float32
  664. | |---------|---------|---------|----------|--------
  665. | | int8 | int8 | int32 | int8 | int32
  666. -----------|---------|---------|---------|----------|--------
  667. |Format | NCHW | NCHW | ND | ND | NCHW
  668. | | NHWC | NHWC | | | NHWC
  669. | | | HWCN | | |
  670. @endverbatim
  671. * It should be noted that the data types must correspond to each other, but the
  672. * format does not need to . \n
  673. *@par Attributes:
  674. * @li strides: A list of 4 integers. Specifying the strides of the
  675. * convolution along the height and width. The dimension order is determined
  676. * by the data format of "x". By default the N and C dimensions are set to 1.
  677. * @li pads: A list of 4 integers. Specifying the top, bottom, left and right
  678. * padding.
  679. * @li dilations: A list of 4 integers. Specifying the dilation rate to use
  680. * for dilated convolution. Has the same dimension order and value as "strides".
  681. * @li groups: Number of blocked connections from input channels to output
  682. * channels. Input channels and output channels must both be divisible by
  683. * "groups".Type is int32.
  684. * @li offset_x: An optional integer for quantized convolution. Type is int32.
  685. * Defaults to "0".
  686. * @li data_format: An optional string from: "NHWC", "NCHW". Specifying the
  687. * data format of the input and output images. Type is string.
  688. * Defaults to "NHWC". Reserved . \n
  689. *@par Outputs:
  690. * @li y: A 4D Tensor of output images . \n
  691. *@par Restrictions:
  692. *Warning: THIS FUNCTION IS DEPRECATED.
  693. */
  694. REG_OP(Conv2DCompress)
  695. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  696. .INPUT(filter_compress, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT8}))
  697. .INPUT(compress_index, TensorType({DT_INT8}))
  698. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  699. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  700. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_INT32}))
  701. .REQUIRED_ATTR(strides, ListInt)
  702. .REQUIRED_ATTR(pads, ListInt)
  703. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  704. .ATTR(groups, Int, 1)
  705. .ATTR(data_format, String, "NHWC")
  706. .ATTR(offset_x, Int, 0)
  707. .OP_END_FACTORY_REG(Conv2DCompress)
  708. /**
  709. *@brief Computes a 2D deformable convolution given 4D "x", "filter" and
  710. * "offsets" tensors.
  711. *@par Inputs:
  712. *@li x: A 4D tensor of input image. With the format "NHWC", the data is stored
  713. * in the order of: [batch, in_height, in_width, in_channels].
  714. *@li filter: A 4D tensor of learnable filters. Must have the same type as "x".
  715. * With the format "HWCN" , the data is stored in the order of: [filter_height,
  716. * filter_width, in_channels / groups, out_channels].
  717. *@li offsets: A 4D tensor of x-y coordinates offset and mask. With the format
  718. * "NHWC", the data is stored in the order of: [batch, out_height, out_width,
  719. * deformable_groups * filter_height * filter_width * 3].
  720. *@li bias: An optional 1D tensor of additive biases to the filter outputs.
  721. * The data is stored in the order of: [out_channels].
  722. *\n
  723. *\n
  724. * The following are the supported data types and data formats:
  725. *@verbatim
  726. | Tensor | x | filter | offsets | bias | y
  727. ------------|---------|---------|---------|----------|--------
  728. | Data Type | float16 | float16 | float16 | float16 | float16
  729. | |---------|---------|---------|----------|--------
  730. | | float32 | float32 | float32 | float32 | float32
  731. ------------|---------|---------|---------|----------|--------
  732. | Format | NCHW | NCHW | NCHW | ND | NCHW
  733. | | NHWC | HWCN | NHWC | | NHWC
  734. @endverbatim
  735. * For float32 type, the actual convolution calculation part on the chip is
  736. * based on float16.
  737. *\n
  738. *
  739. *@par Attributes:
  740. *@li strides: Required. A list of 4 integers. The stride of the sliding window
  741. * for each dimension of input. The dimension order is interpreted according to
  742. * the data format of "x". The N and C dimensions must be set to 1.
  743. *@li pads: Required. A list of 4 integers. The number of pixels to add to each
  744. * (top, bottom, left, right) side of the input.
  745. *@li dilations: Optional. A list of 4 integers. The dilation factor for each
  746. * dimension of input. The dimension order is interpreted according to the data
  747. * format of "x". The N and C dimensions must be set to 1. Defaults to
  748. * [1, 1, 1, 1].
  749. *@li groups: Optional. An integer of type int32. The number of blocked
  750. * connections from input channels to output channels. In_channels and
  751. * out_channels must both be divisible by "groups". Defaults to 1.
  752. *@li data_format: Reserved.
  753. *@li deformable_groups: Optional. An integer of type int32. The number of
  754. * deformable group partitions. In_channels must be divisible by
  755. * "deformable_groups". Defaults to 1.
  756. *\n
  757. *\n
  758. * The following value range restrictions must be met:
  759. *@verbatim
  760. | Name | Field | Scope
  761. --------------------|--------|----------------------------
  762. | Input Image Size | H | [1, 100000 / filter_height]
  763. | | W | [1, 4096 / filter_width]
  764. --------------------|--------|----------------------------
  765. | Filter Size | H | [1, 63]
  766. | | W | [1, 63]
  767. @endverbatim
  768. *\n
  769. *
  770. *@par Outputs:
  771. *@li y: A 4D Tensor of output feature map. Has the same type as "x". With the
  772. * format "NHWC", the data is stored in the order of: [batch, out_height,
  773. * out_width, out_channels].
  774. *\n
  775. * out_height = (in_height + pad_top + pad_bottom -
  776. * (dilation_h * (filter_height - 1) + 1))
  777. * / stride_h + 1
  778. *\n
  779. * out_width = (in_width + pad_left + pad_right -
  780. * (dilation_w * (filter_width - 1) + 1))
  781. * / stride_w + 1
  782. *\n
  783. *
  784. *@par Quantization supported or not
  785. *@li No
  786. *
  787. *@par Third-party framework compatibility
  788. *@li Compatible with the Mxnet operator "DeformableConvolution".
  789. *@li Compatible with the Paddlepaddle operator "deformable_conv".
  790. *@li Compatible with the Mmcv operator "deform_conv".
  791. */
  792. REG_OP(DeformableConv2D)
  793. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  794. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT}))
  795. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  796. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_FLOAT}))
  797. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  798. .REQUIRED_ATTR(strides, ListInt)
  799. .REQUIRED_ATTR(pads, ListInt)
  800. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  801. .ATTR(groups, Int, 1)
  802. .ATTR(data_format, String, "NHWC")
  803. .ATTR(deformable_groups, Int, 1)
  804. .OP_END_FACTORY_REG(DeformableConv2D)
  805. /**
  806. *@brief Computes a 3D convolution given 5D "x" and "filter" tensors.
  807. *@par Inputs:
  808. * @li x: A 5D tensor. Must be one of the following types: float16,
  809. * (Currently does not support int8). The format of x is NCDHW or NDHWC.
  810. * @li filter: A 5D tensor of the same type as "x".
  811. * (Currently does not support int8).
  812. * The format is NCDHW, NDHWC or DHWCN . \n
  813. *@par Optional input:
  814. * @li bias: An optional 1D tensor of the same type as "x".
  815. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved . \n
  816. *@par Required Attributes:
  817. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  818. * for each dimension of "x".
  819. * The N and C dimensions must be 1. Has the same format as "x".
  820. * @li pads: A list of 6 integers.
  821. * Supports only padding along the D, H and W dimensions in sequence of head,
  822. * tail, top, bottom, left and right . \n
  823. *@par Attributes:
  824. * @li groups: Number of blocked connections from input channels to output
  825. * channels. Reserved.
  826. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  827. * Defaults to "NDHWC". Specify the data format of the input and output data.
  828. * @li dilations: A list of 5 integers. Specifies the dilation factor for each
  829. * dimension of "x", now only support [1,1,1,1,1]
  830. * The N and C dimensions must be 1. Has the same format as "x".
  831. * @li offset_x: An optional int. Input offset, used for quantized inference.
  832. * Defaults to 0. Reserved . \n
  833. *@par Outputs:
  834. *y: A Tensor. Has the same type and data format as "x". \n
  835. *@attention Constraints:
  836. *The image size after padding is greater than the filter size . \n
  837. *@par Third-party framework compatibility
  838. * @li Compatible with the TensorFlow operator conv3d.
  839. * @li Compatible with the Caffe operator Convolution.
  840. */
  841. REG_OP(Conv3D)
  842. .INPUT(x, TensorType({DT_FLOAT16}))
  843. .INPUT(filter, TensorType({DT_FLOAT16}))
  844. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  845. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  846. .OUTPUT(y, TensorType({DT_FLOAT16}))
  847. .REQUIRED_ATTR(strides, ListInt)
  848. .REQUIRED_ATTR(pads, ListInt)
  849. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  850. .ATTR(groups, Int, 1)
  851. .ATTR(data_format, String, "NDHWC")
  852. .ATTR(offset_x, Int, 0)
  853. .OP_END_FACTORY_REG(Conv3D)
  854. /**
  855. *@brief Computes the gradients of convolution 3d with respect to the input.
  856. *@par Inputs:
  857. * Three inputs:
  858. * @li input_size: A Tensor of type int32, int64. An integer vector representing
  859. * the shape of input, where input is a 5-D tensor
  860. * [batch, depth, height, width, channels] or
  861. * [batch, channels, depth, height, width].
  862. * @li filter: A Tensor. Must be one of the following types: float16, float32.
  863. * Currently does not support double.
  864. * @li out_backprop: A Tensor. Must have the same type as filter.
  865. * 5-D with shape [batch, depth, out_height, out_width, out_channels]
  866. * or [batch, out_channels, depth, out_height, out_width]. Gradients with
  867. * respect to the output of the convolution . \n
  868. *@par Required Attributes:
  869. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  870. * for each dimension of "x".
  871. * The N and C dimensions must be 1. Has the same format as "x".
  872. * @li pads: A list of 6 integers.
  873. * Supports only padding along the D, H and W dimensions in sequence of head,
  874. * tail, top, bottom, left and right . \n
  875. *@par Attributes:
  876. * Three attributes:
  877. * @li groups: Number of blocked connections from input channels to output
  878. * channels. Reserved.
  879. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  880. * Defaults to "NDHWC". Specify the data format of the input and output data.
  881. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  882. * dimension of the input, now only support [1,1,1,1,1]
  883. *@par Outputs:
  884. * y: A Tensor. Has the same type as filter,and has same format as input_size
  885. *@par Third-party framework compatibility
  886. * Compatible with Tensorflow's conv3d_backprop_input
  887. */
  888. REG_OP(Conv3DBackpropInput)
  889. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  890. .INPUT(filter, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  891. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  892. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  893. .REQUIRED_ATTR(strides, ListInt)
  894. .REQUIRED_ATTR(pads, ListInt)
  895. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  896. .ATTR(groups, Int, 1)
  897. .ATTR(data_format, String, "NDHWC")
  898. .OP_END_FACTORY_REG(Conv3DBackpropInput)
  899. /**
  900. *@brief Computes the gradients of convolution 3d with respect to the input.
  901. *@par Inputs:
  902. * Two inputs:
  903. * @li filter: A Tensor whose type is float16. The format of filter is NCDHW,
  904. * NDHWC or DHWCN.
  905. * @li out_backprop: A Tensor. Must have the same type as filter. The format is
  906. * NDHWC or NCDHW. \n
  907. *@par Required Attributes:
  908. * @li strides: A list of 5 integers. Specifies the stride of the sliding window
  909. * for each dimension of "x".
  910. * The N and C dimensions must be 1. Has the same format as "x".
  911. * @li pads: A list of 6 integers. Supports only padding along the D, H and W
  912. * dimensions in sequence of head, tail, top, bottom, left and right.
  913. * @li input_size: A tuple/list of type int32, int64. An integer vector
  914. * representing the shape of input, where input is a 5-D tensor
  915. * [batch, depth, height, width, channels] or
  916. * [batch, channels, depth, height, width] . \n
  917. *@par Attributes:
  918. * Three attributes:
  919. * @li groups: Number of blocked connections from input channels to output
  920. * channels. Reserved.
  921. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  922. * Defaults to "NDHWC". Specify the data format of the input and output data.
  923. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  924. * dimension of input, now only support [1,1,1,1,1]
  925. *@par Outputs:
  926. * y: A Tensor. Has the same type and data format as out_backprop.
  927. *@par Third-party framework compatibility
  928. * Compatible with Tensorflow's conv3d_backprop_input
  929. *@par Restrictions:
  930. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropInput instead.
  931. */
  932. REG_OP(Conv3DBackpropInputD)
  933. .INPUT(filter, TensorType({DT_FLOAT16}))
  934. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  935. .OUTPUT(y, TensorType({DT_FLOAT16}))
  936. .REQUIRED_ATTR(input_size, ListInt)
  937. .REQUIRED_ATTR(strides, ListInt)
  938. .REQUIRED_ATTR(pads, ListInt)
  939. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  940. .ATTR(groups, Int, 1)
  941. .ATTR(data_format, String, "NDHWC")
  942. .OP_END_FACTORY_REG(Conv3DBackpropInputD)
  943. /**
  944. *@brief Applies a multi-layer long short-term memory (LSTM) RNN to an input sequence . \n
  945. *@par Inputs:
  946. * @li x: A Tensor dtype of float16.
  947. * @li cont: A Tensor dtype of float16, float32.
  948. * @li w_x: A Tensor dtype of float16.
  949. * @li bias: A Tensor dtype of int16, int32, float16, float32.
  950. * @li w_h: A Tensor dtype of float16.
  951. * @li x_static: A optinal Tensor dtype of float16.
  952. * @li h_0: A optinal Tensor dtype of float16, float32.
  953. * @li c_0: A optinal Tensor dtype of float16, float32.
  954. * @li w_x_static: A optinal Tensor dtype of float16 . \n
  955. *@par Attributes:
  956. *@li num_output: A Scalar of output size dtype of int.
  957. *@li expose_hidden: A Scalar(bool) of features hidden . \n
  958. *@par Outputs:
  959. *@li h: A Tensor dtype of float16, float32.
  960. * @li h_t: A optinal Tensor dtype of float16, float32. The hidden state at time t.
  961. * @li c_t: A optinal Tensor dtype of float16, float32. The cell state at time t . \n
  962. *@par Third-party framework compatibility:
  963. * Compatible with the Pytorch operator adds.
  964. *@par Restrictions:
  965. *Warning: THIS FUNCTION IS EXPERIMENTAL. Please do not use.
  966. */
  967. REG_OP(LSTM)
  968. .INPUT(x, TensorType({DT_FLOAT16}))
  969. .INPUT(cont, TensorType({DT_FLOAT32,DT_FLOAT16}))
  970. .INPUT(w_x, TensorType({DT_FLOAT16}))
  971. .INPUT(bias, TensorType({DT_FLOAT16,DT_FLOAT32,DT_INT16,DT_INT32}))
  972. .INPUT(w_h, TensorType({DT_FLOAT16}))
  973. .OPTIONAL_INPUT(x_static, TensorType({DT_FLOAT16}))
  974. .OPTIONAL_INPUT(h_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  975. .OPTIONAL_INPUT(c_0, TensorType({DT_FLOAT16,DT_FLOAT32}))
  976. .OPTIONAL_INPUT(w_x_static, TensorType({DT_FLOAT16}))
  977. .OUTPUT(h, TensorType({DT_FLOAT16, DT_FLOAT}))
  978. .OUTPUT(h_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  979. .OUTPUT(c_t, TensorType({DT_FLOAT16, DT_FLOAT}))
  980. .ATTR(num_output, Int, 0)
  981. .ATTR(expose_hidden, Bool, false)
  982. .OP_END_FACTORY_REG(LSTM)
  983. /**
  984. *@brief Computes the gradients of convolution3D with respect to the filter
  985. *@par Inputs:
  986. * Three inputs:
  987. * @li x: A Tensor. Must be one of the following types: float16, float32.
  988. * Currently does not support double.
  989. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  990. * or [batch, in_channels, in_depth, in_height, in_width].
  991. * @li filter_size: A Tensor of type int32. An integer vector representing the
  992. * tensor shape of filter, where filter is a 5-D tensor
  993. * [filter_depth, filter_height, filter_width, in_channels, out_channels]
  994. * [out_channels, in_channels, filter_depth, filter_height, filter_width]
  995. * or [out_channels, filter_depth, filter_height, filter_width, in_channels].
  996. * @li out_backprop: A Tensor. Must have the same type as x.
  997. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  998. * or [batch, out_channels, out_depth, out_height, out_width].
  999. * Gradients with respect to the output of the convolution. \n
  1000. *@par Required Attributes:
  1001. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  1002. * window for each dimension of "x". The N and C dimensions must be 1.
  1003. * Has the same format as "x".
  1004. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  1005. * pads on feature map . \n
  1006. *@par Attributes:
  1007. * Three attributes:
  1008. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  1009. * dimension of input, now only support [1,1,1,1,1].
  1010. * @li groups: Number of blocked connections from input channels to output
  1011. * channels. Reserved.
  1012. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  1013. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1014. *@par Outputs:
  1015. * y: A Tensor that has the same type as x
  1016. * and the format is NDHWC, NCDHW or DHWCN.
  1017. *@par Third-party framework compatibility
  1018. * Compatible with Tensorflow's conv3d_backprop_filter
  1019. */
  1020. REG_OP(Conv3DBackpropFilter)
  1021. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1022. .INPUT(filter_size, TensorType({DT_INT32}))
  1023. .INPUT(out_backprop, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1024. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT, DT_DOUBLE}))
  1025. .REQUIRED_ATTR(strides, ListInt)
  1026. .REQUIRED_ATTR(pads, ListInt)
  1027. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1028. .ATTR(groups, Int, 1)
  1029. .ATTR(data_format, String, "NDHWC")
  1030. .OP_END_FACTORY_REG(Conv3DBackpropFilter)
  1031. /**
  1032. *@brief Computes the gradients of convolution with respect to the filter.
  1033. *@par Inputs:
  1034. * Two inputs:
  1035. * @li x: A Tensor of type float16.
  1036. * 5-D with shape [batch, in_depth, in_height, in_width, in_channels]
  1037. * or [batch, in_channels, in_depth, in_height, in_width].
  1038. * @li out_backprop: A Tensor. Must have the same type as x.
  1039. * 5-D with shape [batch, out_depth, out_height, out_width, out_channels]
  1040. * or [batch, out_channels, out_depth, out_height, out_width].
  1041. * Gradients with respect to the output of the convolution. \n
  1042. *@par Required Attributes:
  1043. * @li filter_size: A tuple/list of type integers. An integer vector
  1044. * representing the tensor shape of filter, where filter is a 5-D tensor
  1045. * [filter_depth, filter_height, filter_width, in_channels, out_channels],
  1046. * [out_channels, filter_depth, filter_height, filter_width, in_channels]
  1047. * or [out_channels, in_channels, filter_depth, filter_height, filter_width].
  1048. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  1049. * window for each dimension of "x".
  1050. * The N and C dimensions must be 1. Has the same format as "x".
  1051. * @li pads: A tuple/list of 6 integers, [front, back, top, bottom, left, right]
  1052. * pads on feature map. \n
  1053. *@par Attributes:
  1054. * Three attributes:
  1055. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  1056. * dimension of input, now only support [1,1,1,1,1].
  1057. * @li groups: Number of blocked connections from input channels to output
  1058. * channels. Reserved.
  1059. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  1060. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1061. *@par Outputs:
  1062. * y: A Tensor of type float32 and the format is NDHWC, NCDHW or DHWCN.
  1063. *@par Third-party framework compatibility
  1064. * Compatible with Tensorflow's conv3d_backprop_filter
  1065. *@par Restrictions:
  1066. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DBackpropFilter instead.
  1067. */
  1068. REG_OP(Conv3DBackpropFilterD)
  1069. .INPUT(x, TensorType({DT_FLOAT16}))
  1070. .INPUT(out_backprop, TensorType({DT_FLOAT16}))
  1071. .OUTPUT(y, TensorType({DT_FLOAT}))
  1072. .REQUIRED_ATTR(filter_size, ListInt)
  1073. .REQUIRED_ATTR(strides, ListInt)
  1074. .REQUIRED_ATTR(pads, ListInt)
  1075. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1076. .ATTR(groups, Int, 1)
  1077. .ATTR(data_format, String, "NDHWC")
  1078. .OP_END_FACTORY_REG(Conv3DBackpropFilterD)
  1079. /**
  1080. *@brief Computes the transpose of convolution 3d with respect to the input.
  1081. *@par Inputs:
  1082. * Three inputs:
  1083. * @li input_size: A Tensor of type int32. An integer vector representing the
  1084. * shape of input.
  1085. * @li x: A Tensor of type float16, currently does not support int8. The format
  1086. * is NDHWC or NCDHW.
  1087. * @li filter: A Tensor of type float16, currently does not support int8.
  1088. * The format is NDHWC, NCDHW or DHWCN.
  1089. *@par Optional input:
  1090. * Two optional inputs
  1091. * @li bias: An optional 1D tensor of the same type as "x". Reserved.
  1092. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved . \n
  1093. *@par Required Attributes:
  1094. * @li strides: A tuple/list of 5 integers. Specifies the stride of the sliding
  1095. * window for each dimension of "x".
  1096. * The N and C dimensions must be 1. Has the same format as "x".
  1097. * @li pads: A tuple/list of 6 integers
  1098. *@par Attributes:
  1099. * Five attributes:
  1100. * @li groups: Number of blocked connections from input channels to output
  1101. * channels. Reserved.
  1102. * @li dilations: A tuple/list of 5 integers,
  1103. * The dilation factor for each dimension of input, now only support [1,1,1,1,1]
  1104. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  1105. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1106. * @li output_padding: The size will be added in the output shape.
  1107. * @li offset_x: Input offset_x value. Reserved.
  1108. *@par Outputs:
  1109. * y: A Tensor. Has the same type and format as x.
  1110. */
  1111. REG_OP(Conv3DTranspose)
  1112. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1113. .INPUT(x, TensorType({DT_FLOAT16}))
  1114. .INPUT(filter, TensorType({DT_FLOAT16}))
  1115. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  1116. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1117. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1118. .REQUIRED_ATTR(strides, ListInt)
  1119. .REQUIRED_ATTR(pads, ListInt)
  1120. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1121. .ATTR(groups, Int, 1)
  1122. .ATTR(data_format, String, "NDHWC")
  1123. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1124. .ATTR(offset_x, Int, 0)
  1125. .OP_END_FACTORY_REG(Conv3DTranspose)
  1126. /**
  1127. *@brief Computes the transpose of convolution 3d with respect to the input.
  1128. *@par Inputs:
  1129. * @li x: A Tensor of type float16, currently does not support int8.
  1130. * The format is NDHWC or NCDHW.
  1131. * @li filter: A Tensor of type float16, currently does not support int8.
  1132. * The format is NDHWC, NCDHW or DHWCN.
  1133. *@par Optional inputs:
  1134. * @li bias: An optional 1D tensor of the same type as "x". Reserved.
  1135. * @li offset_w: An optional 1D tensor for quantized deconvolution. Reserved . \n
  1136. *@par Required Attributes:
  1137. * @li input_size: A tuple/list of type int32.
  1138. * An integer vector representing the shape of input
  1139. * @li strides: A tuple/list of 5 integers.
  1140. * Specifies the stride of the sliding window for each dimension of "x".
  1141. * The N and C dimensions must be 1. Has the same format as "x".
  1142. * @li pads: A tuple/list of 6 integers . \n
  1143. *@par Attributes:
  1144. * Five attributes:
  1145. * @li dilations: A tuple/list of 5 integers, The dilation factor for each
  1146. * dimension of input, now only support [1,1,1,1,1]
  1147. * @li groups: Number of blocked connections from input channels to output
  1148. * channels. Reserved.
  1149. * @li data_format: An optional string from: "NDHWC", "NCDHW".
  1150. * Defaults to "NDHWC". Specify the data format of the input and output data.
  1151. * @li output_padding: The size will be added in the output shape.
  1152. * @li offset_x: Input offset_x value. Reserved.
  1153. *@par Outputs:
  1154. * y: A Tensor. Has the same type and format as x.
  1155. *@par Restrictions:
  1156. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv3DTranspose instead.
  1157. */
  1158. REG_OP(Conv3DTransposeD)
  1159. .INPUT(x, TensorType({DT_FLOAT16}))
  1160. .INPUT(filter, TensorType({DT_FLOAT16}))
  1161. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16}))
  1162. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1163. .OUTPUT(y, TensorType({DT_FLOAT16}))
  1164. .REQUIRED_ATTR(input_size, ListInt)
  1165. .REQUIRED_ATTR(strides, ListInt)
  1166. .REQUIRED_ATTR(pads, ListInt)
  1167. .ATTR(dilations, ListInt, {1, 1, 1, 1, 1})
  1168. .ATTR(groups, Int, 1)
  1169. .ATTR(data_format, String, "NDHWC")
  1170. .ATTR(output_padding, ListInt, {0, 0, 0, 0, 0})
  1171. .ATTR(offset_x, Int, 0)
  1172. .OP_END_FACTORY_REG(Conv3DTransposeD)
  1173. /**
  1174. *@brief Computes the transpose of convolution 2d with respect to the input.
  1175. *@par Inputs:
  1176. * Five inputs:
  1177. * @li input_size: A Tensor of type int32 or int64. An integer vector
  1178. * representing the shape of input, where input is a 4-D tensor
  1179. * [batch, height, width, channels] or [batch, channels, height, width].
  1180. * @li x: A Tensor of type float16, int8. 4-D with shape [batch, out_height,
  1181. * out_width, out_channels] or [batch, out_channels, out_height, out_width].
  1182. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1183. * 4-D with shape [filter_height, filter_width, in_channels, out_channels]
  1184. * or [out_channels, filter_height, filter_width, in_channels]
  1185. * or [out_channels, in_channel, filter_height, filter_width].
  1186. * @li bias: An optional 1D tensor of type float16 or int32. Format is "ND".
  1187. * @li offset_w: An optional 1D tensor for quantized inference. Reserved.
  1188. *@par Required Attributes:
  1189. * @li strides: A required tuple/list of 4 integers. The stride of the sliding
  1190. * window for H/W dimension. The index of H/W is same as data_format.
  1191. * @li pads: A required tuple/list of 4 integers, [top, bottom, left, right]
  1192. * pads on feature map.
  1193. *@par Attributes:
  1194. * Five attributes:
  1195. * @li groups: Number of blocked connections from input channels to output
  1196. * channels.
  1197. * Defaults to "1".
  1198. * @li dilations: A tuple/list of 4 integers, The dilation factor for each
  1199. * dimension of input. Must be [1, 1, 1, 1].
  1200. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1201. * Specify the data format of the input and output data.
  1202. * @li output_padding: The size will be added in the output shape. Defaults
  1203. * to [0, 0, 0, 0].
  1204. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1205. * Defaults to "0".
  1206. *@par Outputs:
  1207. * y: A Tensor. A Tensor of type float16 or int32, and has same format as
  1208. * input_size.
  1209. */
  1210. REG_OP(Conv2DTranspose)
  1211. .INPUT(input_size, TensorType({DT_INT32, DT_INT64}))
  1212. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1213. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1214. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1215. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1216. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1217. .REQUIRED_ATTR(strides, ListInt)
  1218. .REQUIRED_ATTR(pads, ListInt)
  1219. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1220. .ATTR(groups, Int, 1)
  1221. .ATTR(data_format, String, "NHWC")
  1222. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1223. .ATTR(offset_x, Int, 0)
  1224. .OP_END_FACTORY_REG(Conv2DTranspose)
  1225. /**
  1226. *@brief Computes the transpose of convolution 2d with respect to the input.
  1227. *@par Inputs:
  1228. * Four inputs:
  1229. * @li x: A Tensor of type float16, int8.
  1230. * @li filter: A Tensor of type float16, int8. Must have the same type as "x".
  1231. * @li bias: An optional 1D tensor of the same type as "x".
  1232. * @li offset_w: An optional 1D tensor for quantized inference. Type is int8. Reserved.
  1233. *@par Required Attributes:
  1234. * @li input_size: A Tensor of type int32 or int64. An integer vector representing the
  1235. * shape of input.
  1236. * @li strides: A required list or tuple. The stride of the sliding window for
  1237. * height and width for H/W dimension.
  1238. * @li pads: A required list or tuple of int32. Padding added to each dimension
  1239. * of the input.
  1240. *@par Attributes:
  1241. * Five attributes:
  1242. * @li groups: Number of blocked connections from input channels to output channels.
  1243. * Defaults to "1".
  1244. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1245. * of input. Must be [1, 1, 1, 1].
  1246. * @li data_format: An optional string from: "NHWC", "NCHW". Defaults to "NHWC".
  1247. * Specify the data format of the input and output data.
  1248. * @li output_padding: The size will be added in the output shape. Defaults
  1249. * to [0, 0, 0, 0].
  1250. * @li offset_x: An optional int. Input offset, used for quantized inference.
  1251. * Defaults to "0".
  1252. *@par Outputs:
  1253. * y: A Tensor. Has the same type as "filter".
  1254. *@par Restrictions:
  1255. * Warning: THIS FUNCTION IS DEPRECATED. Please use Conv2DTranspose instead.
  1256. */
  1257. REG_OP(Conv2DTransposeD)
  1258. .INPUT(x, TensorType({DT_FLOAT16, DT_INT8}))
  1259. .INPUT(filter, TensorType({DT_FLOAT16, DT_INT8}))
  1260. .OPTIONAL_INPUT(bias, TensorType({DT_FLOAT16, DT_INT32}))
  1261. .OPTIONAL_INPUT(offset_w, TensorType({DT_INT8}))
  1262. .OUTPUT(y, TensorType({DT_FLOAT16, DT_INT32}))
  1263. .REQUIRED_ATTR(input_size, ListInt)
  1264. .REQUIRED_ATTR(strides, ListInt)
  1265. .REQUIRED_ATTR(pads, ListInt)
  1266. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1267. .ATTR(groups, Int, 1)
  1268. .ATTR(data_format, String, "NHWC")
  1269. .ATTR(output_padding, ListInt, {0, 0, 0, 0})
  1270. .ATTR(offset_x, Int, 0)
  1271. .OP_END_FACTORY_REG(Conv2DTransposeD)
  1272. /**
  1273. *@brief Computes the deformed convolution output with the expected input
  1274. *@par Inputs:
  1275. * Two inputs:
  1276. * @li x: A Tensor of type float16,float32
  1277. * @li offsets: A Tensor of type float16,float32.Deformation offset parameter.
  1278. *@par Required Attributes:
  1279. * @li strides: A tuple/list of 4 integers.The stride of the sliding window for
  1280. * height and width for H/W dimension.
  1281. * @li pads: A tuple/list of 4 integers.Padding added to H/W dimension
  1282. * of the input.
  1283. * @li ksize: A tuple/list of 2 integers.kernel size.
  1284. *@par Attributes:
  1285. * Three attributes:
  1286. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1287. * of input. Defaults to [1, 1, 1, 1]
  1288. * @li data_format: An optional string from: "NCHW", "NHWC". Defaults to "NCHW". Specify the data format of the input x.
  1289. * @li deformable_groups: Specify the c-axis grouping number of input x.
  1290. * @li modulated: Specify version of DeformableConv2D, true means v2, false means v1
  1291. *@par Outputs:
  1292. * y: A Tensor. A Tensor of type float16, float32.
  1293. */
  1294. REG_OP(DeformableOffsets)
  1295. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1296. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1297. .OUTPUT(y, TensorType({DT_FLOAT16, DT_FLOAT}))
  1298. .REQUIRED_ATTR(strides, ListInt)
  1299. .REQUIRED_ATTR(pads, ListInt)
  1300. .REQUIRED_ATTR(ksize, ListInt)
  1301. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1302. .ATTR(data_format, String, "NCHW")
  1303. .ATTR(deformable_groups, Int, 1)
  1304. .ATTR(modulated, Bool, true)
  1305. .OP_END_FACTORY_REG(DeformableOffsets)
  1306. /**
  1307. *@brief Computes the gradients of DeformableOffsets with respect to input and offsets
  1308. *@par Inputs:
  1309. * Three inputs:
  1310. * @li grad: A Tensor of type float16,float32. gradients with respect to DeformableOffsets output
  1311. * @li x: A Tensor of type float16,float32.
  1312. * @li offsets: A Tensor of type float16,float32.Deformation offset parameter.
  1313. *@par Required Attributes:
  1314. * @li strides: A tuple/list of 4 integers.The stride of the sliding window for
  1315. * height and width for H/W dimension.
  1316. * @li pads: A tuple/list of 4 integers.Padding added to H/W dimension
  1317. * of the input.
  1318. * @li ksize: A tuple/list of 2 integers.kernel size.
  1319. *@par Attributes:
  1320. * Three attributes:
  1321. * @li dilations: A tuple/list of 4 integers, The dilation factor for each dimension
  1322. * of input. Defaults to [1, 1, 1, 1]
  1323. * @li data_format: An optional string from: "NCHW", "NHWC". Defaults to "NCHW". Specify the data format of the input x.
  1324. * @li deformable_groups: Specify the c-axis grouping number of input x.
  1325. * @li modulated: Specify version of DeformableConv2D, true means v2, false means v1.
  1326. *@par Outputs:
  1327. * grad_x: A Tensor of type float16, float32. Gradients with respect to input_x
  1328. * grad_offsets: A Tensor of type float16, float32. Gradients with respect to input_offsets
  1329. */
  1330. REG_OP(DeformableOffsetsGrad)
  1331. .INPUT(grad, TensorType({DT_FLOAT16, DT_FLOAT}))
  1332. .INPUT(x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1333. .INPUT(offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1334. .OUTPUT(grad_x, TensorType({DT_FLOAT16, DT_FLOAT}))
  1335. .OUTPUT(grad_offsets, TensorType({DT_FLOAT16, DT_FLOAT}))
  1336. .REQUIRED_ATTR(strides, ListInt)
  1337. .REQUIRED_ATTR(pads, ListInt)
  1338. .REQUIRED_ATTR(ksize, ListInt)
  1339. .ATTR(dilations, ListInt, {1, 1, 1, 1})
  1340. .ATTR(data_format, String, "NCHW")
  1341. .ATTR(deformable_groups, Int, 1)
  1342. .ATTR(modulated, Bool, true)
  1343. .OP_END_FACTORY_REG(DeformableOffsetsGrad)
  1344. /**
  1345. *@brief Computes the deformed dilation output with the expected input
  1346. *@par Inputs:
  1347. * One inputs:
  1348. * @li x: A Tensor of type int8, float16, float32
  1349. *@par Required Attributes:
  1350. * @li dilations: A tuple/list of integers.
  1351. *@par Attributes:
  1352. * Two attributes:
  1353. * @li padding_value: default value filling in blank
  1354. * @li pads: A tuple/list of integers.
  1355. *@par Outputs:
  1356. * y: A Tensor. A Tensor of type int8, float16, float32.
  1357. */
  1358. REG_OP(Dilation)
  1359. .INPUT(x, TensorType({DT_INT8, DT_FLOAT16, DT_FLOAT}))
  1360. .OUTPUT(y, TensorType({DT_INT8, DT_FLOAT16, DT_FLOAT}))
  1361. .REQUIRED_ATTR(dilations, ListInt)
  1362. .ATTR(pads, ListInt, {})
  1363. .ATTR(padding_value, Float, 0.0)
  1364. .OP_END_FACTORY_REG(Dilation)
  1365. } // namespace ge
  1366. #endif // OPS_BUILT_IN_OP_PROTO_INC_NN_CALCULATION_OPS_H_

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