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.

opr_param_defs.py 60 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  1. pdef('Empty')
  2. pdef('Axis').add_fields('int32', 'axis', 0)
  3. (pdef('Convolution', version=0, is_legacy=True).
  4. add_enum('Mode', 'CROSS_CORRELATION = 0', 'CONVOLUTION = 1').
  5. add_fields(
  6. 'uint32',
  7. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  8. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  9. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  10. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  11. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  12. 'on the second dimension'), 1,
  13. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  14. 'on the second dimension'), 1
  15. ).
  16. add_enum('DataType',
  17. Doc('FLOAT = 0', 'input/output both float32/float16'),
  18. 'INT8x8x16 = 1',
  19. 'INT8x8x32 = 2',
  20. Doc('FLOAT_IO16xC32 = 3', 'input/output both float16, the internal '
  21. 'compute is float32'),
  22. Doc('QUINT8x8x32 = 4', 'input QuantizedAsymm8, output QuantizedS32'),
  23. Doc('INT8x8xX = 5', 'input int8, output specified by tensor DType'),
  24. Doc('QUINT4x4x32 = 6', 'input QuantizedAsymm4, output QuantizedS32'),
  25. name_field='data_type').
  26. add_enum('Sparse',
  27. Doc('DENSE = 0', 'dense convolution: filter shape should be '
  28. '[oc, ic, spatial...] if format is NCHW, '
  29. '[oc, spatial..., ic] if format is NHWC'),
  30. Doc('GROUP = 1', 'group convolution: filter shape should be '
  31. '[group, oc_per_group, ic_per_group, spatial...] if format is NCHW, '
  32. '[group, oc_per_group, spatial..., ic_per_group] if format is NHWC')
  33. ).
  34. add_enum(Doc('Format', 'convolution data/filter/output format; see '
  35. ':class:`RelayoutFormat` for more details'),
  36. 'NCHW = 0', 'NHWC = 1', 'NHWCD4 = 2', 'NCHW4 = 3', 'NCHW8 = 4', 'NCHW32 = 5', 'NCHW88 = 6',
  37. 'NCHW44 = 7','NCHW44_DOT = 8',
  38. Doc('NCHW_WINOGRAD = 9', 'NCHW layout with weights tranformed by winograd'),
  39. Doc('NCHW88_WINOGRAD = 10', 'NCHW88 layout with weights tranformed by winograd'),
  40. Doc('NCHW44_WINOGRAD = 11', 'NCHW44 layout with weights tranformed by winograd'),
  41. Doc('NCHW4_NCHW32 = 12', 'NCHW4_NCHW32 means input tensors are nchw4 layout, output tensor is nchw32 layout'),
  42. Doc('NCHW32_NCHW4 = 13', 'NCHW32_NCHW4 means input tensors are nchw32 layout, output tensor is nchw4 layout'),
  43. Doc('NCHW4_NCHW = 14', 'NCHW4_NCHW means input tensors are nchw4 layout, output tensor is nchw layout'),
  44. Doc('NHWC_NCHW = 15', 'NHWC_NCHW means input tensors are nhwc layout, '
  45. 'output tensor is nchw layout'),
  46. Doc('NHWC_NCHW4_IC_SMALL = 16', 'NHWC_NCHW4_IC_SMALL means input tensors are nhwc(c < 4) layout, '
  47. 'output tensor is nchw4 layout, padding c=4'),
  48. Doc('NCHW_NCHW4_IC_SMALL = 17', 'NCHW_NCHW4_IC_SMALL means input tensors are nchw(c < 4) layout, '
  49. 'output tensor is nchw4 layout, padding c=4'),
  50. Doc('CHWN4 = 18', 'CHWN4 is currently only used on Nvidia platform for fast implementation '
  51. 'of convolution using CUDA/SASS. The channels are splitted to groups of 4 channels.'),
  52. Doc('NCHW4_NHWC = 19', 'NCHW4_NHWC means input tensors are nchw4 layout, output tensor is nhwc layout'))
  53. )
  54. (pdef('Convolution', version=1, is_legacy=True).
  55. add_enum_alias('Mode', 'ConvolutionV0').
  56. add_fields(
  57. 'uint32',
  58. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  59. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  60. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  61. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  62. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  63. 'on the second dimension'), 1,
  64. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  65. 'on the second dimension'), 1
  66. ).
  67. add_enum_alias('Sparse', 'ConvolutionV0').
  68. add_enum_alias('Format', 'ConvolutionV0').
  69. add_enum(Doc('ComputeMode', 'Specifies special computation modes, e.g. '
  70. 'different combinations of intermediate result '
  71. 'data types.'),
  72. Doc('DEFAULT = 0', 'No special requirements on the precision of '
  73. 'intermediate results.'),
  74. Doc('FLOAT32 = 1', 'Use Float32 accumulator and intermediate result. '
  75. 'Only supported when input and output is Float16.'),
  76. name_field='compute_mode')
  77. )
  78. (pdef('Convolution', version=2).
  79. add_enum_alias('Mode', 'ConvolutionV0').
  80. add_fields(
  81. 'uint32',
  82. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  83. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  84. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  85. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  86. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  87. 'on the second dimension'), 1,
  88. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  89. 'on the second dimension'), 1
  90. ).
  91. add_enum_alias('Sparse', 'ConvolutionV0').
  92. add_enum(Doc('Format', 'convolution data/filter/output format; see '
  93. ':class:`RelayoutFormat` for more details'),
  94. 'NCHW = 0', 'NHWC = 1', 'NHWCD4 = 2', 'NCHW4 = 3', 'NCHW8 = 4', 'NCHW32 = 5', 'NCHW88 = 6',
  95. 'NCHW44 = 7','NCHW44_DOT = 8',
  96. Doc('NCHW4_NCHW32 = 9', 'NCHW4_NCHW32 means input tensors are nchw4 layout, output tensor is nchw32 layout'),
  97. Doc('NCHW32_NCHW4 = 10', 'NCHW32_NCHW4 means input tensors are nchw32 layout, output tensor is nchw4 layout'),
  98. Doc('NCHW4_NCHW = 11', 'NCHW4_NCHW means input tensors are nchw4 layout, output tensor is nchw layout'),
  99. Doc('NHWC_NCHW = 12', 'NHWC_NCHW means input tensors are nhwc layout, '
  100. 'output tensor is nchw layout'),
  101. Doc('NHWC_NCHW4_IC_SMALL = 13', 'NHWC_NCHW4_IC_SMALL means input tensors are nhwc(c < 4) layout, '
  102. 'output tensor is nchw4 layout, padding c=4'),
  103. Doc('NCHW_NCHW4_IC_SMALL = 14', 'NCHW_NCHW4_IC_SMALL means input tensors are nchw(c < 4) layout, '
  104. 'output tensor is nchw4 layout, padding c=4'),
  105. Doc('CHWN4 = 15', 'CHWN4 is currently only used on Nvidia platform for fast implementation '
  106. 'of convolution using CUDA/SASS. The channels are splitted to groups of 4 channels.'),
  107. Doc('NCHW64 = 16', 'NCHW64 is designed for convolution implementation to utilizing TensorCore '
  108. 'instructions for 4-bit integers on Nvidia platforms'),
  109. Doc('NCHW4_NHWC = 17', 'NCHW4_NHWC means input tensors are nchw4 layout, output tensor is nhwc layout')).
  110. add_enum_alias('ComputeMode', 'ConvolutionV1',name_field='compute_mode')
  111. )
  112. (pdef('MaskPropagate').
  113. add_fields(
  114. 'uint32',
  115. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  116. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  117. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  118. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  119. Doc('kernel_h', 'kernel height'), 1,
  120. Doc('kernel_w', 'kernel width'), 1,
  121. Doc('dilate_h', 'dilate height'), 1,
  122. Doc('dilate_w', 'dilate width'), 1)
  123. )
  124. (pdef('ConvPooling').
  125. add_enum('Method', 'WITH_TEXTURE_OBJ = 0', 'WITH_SHARED_MEM = 1').
  126. add_enum_alias('ConvMode', 'ConvolutionV0', 'Mode').
  127. add_enum('PoolMode', 'AVERAGE = 0', 'MAX = 1').
  128. add_enum('NonlineMode', 'IDENTITY = 0', 'RELU = 1', 'SIGMOID = 2').
  129. add_fields('uint32', 'pool_shape_h', 1, 'pool_shape_w', 1, 'pool_stride_h', 1, 'pool_stride_w', 1, \
  130. 'pool_pad_h', 0, 'pool_pad_w', 0, 'conv_stride_h', 1, 'conv_stride_w', 1, 'conv_pad_h', 0, 'conv_pad_w', 0))
  131. (pdef('ConvBias', 'legacy conv_bias', version=0, is_legacy=True).
  132. add_enum('NonlineMode', 'IDENTITY = 0', 'RELU = 1', 'SIGMOID = 2', 'H_SWISH = 3').
  133. add_enum_alias('Mode', 'ConvolutionV0').
  134. add_fields('uint32', 'pad_h', 0, 'pad_w', 0, 'stride_h', 1, 'stride_w', 1))
  135. (pdef('ConvBias', 'active(conv(x, w) + bias)', version=1, is_legacy=True).
  136. add_enum_alias('NonlineMode', 'ConvBiasV0').
  137. add_enum_alias('Mode', 'ConvolutionV0').
  138. add_enum_alias('DataType', 'ConvolutionV0', name_field='data_type').
  139. add_enum_alias('Sparse', 'ConvolutionV0').
  140. add_enum_alias('Format', 'ConvolutionV0').
  141. add_fields(
  142. 'uint32',
  143. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  144. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  145. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  146. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  147. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  148. 'on the second dimension'), 1,
  149. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  150. 'on the second dimension'), 1)
  151. )
  152. (pdef('ConvBias', 'active(conv(x, w) + bias)', version=2, is_legacy=True).
  153. add_enum_alias('NonlineMode', 'ConvBiasV0').
  154. add_enum_alias('Mode', 'ConvolutionV0').
  155. add_enum_alias('Sparse', 'ConvolutionV0').
  156. add_enum_alias('Format', 'ConvolutionV0').
  157. add_fields(
  158. 'uint32',
  159. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  160. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  161. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  162. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  163. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  164. 'on the second dimension'), 1,
  165. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  166. 'on the second dimension'), 1).
  167. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field='compute_mode')
  168. )
  169. (pdef('ConvBias', 'active(conv(x, w) + bias)', version=3, is_legacy=True).
  170. add_enum_alias('NonlineMode', 'ConvBiasV0').
  171. add_enum_alias('Mode', 'ConvolutionV0').
  172. add_enum_alias('Sparse', 'ConvolutionV0').
  173. add_enum_alias('Format', 'ConvolutionV0').
  174. add_fields(
  175. 'uint32',
  176. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  177. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  178. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  179. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  180. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  181. 'on the second dimension'), 1,
  182. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  183. 'on the second dimension'), 1,
  184. Doc('output_block_size', 'detail meaning \see winograd in conv bias'), 0).
  185. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field='compute_mode')
  186. )
  187. (pdef('ConvBias', 'active(conv(x, w) + bias)', version=4).
  188. add_enum_alias('NonlineMode', 'ConvBiasV0').
  189. add_enum_alias('Mode', 'ConvolutionV0').
  190. add_enum_alias('Sparse', 'ConvolutionV0').
  191. add_enum_alias('Format', 'Convolution').
  192. add_fields(
  193. 'uint32',
  194. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  195. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  196. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  197. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  198. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  199. 'on the second dimension'), 1,
  200. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  201. 'on the second dimension'), 1).
  202. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field='compute_mode')
  203. )
  204. (pdef('SeparableConv').
  205. add_enum_alias('Mode', 'ConvolutionV0').
  206. add_enum('BorderMode', 'BORDER_REPLICATE = 0', 'BORDER_REFLECT = 1',
  207. 'BORDER_REFLECT_101 = 2','BORDER_WRAP = 3',
  208. 'BORDER_CONSTANT = 4', 'BORDER_TRANSPARENT = 5','BORDER_ISOLATED = 6').
  209. add_fields('bool', 'is_symm_kernel', 'true').
  210. add_fields('uint32', 'pad_h', 0, 'pad_w', 0, 'stride_h', 1, 'stride_w', 1,
  211. 'ksize_h', 3, 'ksize_w', 3, 'anchor_h', 1, 'anchor_w', 1))
  212. (pdef('Images2Neibs').
  213. add_fields('uint32', 'pad_h', 0, 'pad_w', 0, 'stride_h', 1, 'stride_w', 1,
  214. 'dilate_h', 1, 'dilate_w', 1, 'window_h', 3, 'window_w', 3))
  215. (pdef('SlidingWindowTranspose').
  216. add_fields('uint32', 'out_h', 0, 'out_w', 0, 'pad_h', 0, 'pad_w', 0, 'stride_h', 1, 'stride_w', 1,
  217. 'dilate_h', 1, 'dilate_w', 1, 'window_h', 3, 'window_w', 3))
  218. (pdef('Pooling', version=0, is_legacy=True).
  219. add_enum(
  220. 'Mode',
  221. Doc('MAX = 0', 'maximum value inside pooling window'),
  222. Doc('AVERAGE = 1',
  223. 'arithmetic mean of all values inside pooling window. Padding values '
  224. 'are taken into account and are viewed as zero'),
  225. Doc('AVERAGE_COUNT_EXCLUDE_PADDING = 2',
  226. 'arithmetic mean of all values inside pooling window. No padding is'
  227. 'used.')
  228. ).
  229. add_fields('uint32', 'pad_h', 0, 'pad_w', 0, 'stride_h', 2, 'stride_w', 2,
  230. 'window_h', 2, 'window_w', 2).
  231. add_enum_alias('Format', 'ConvolutionV0')
  232. )
  233. (pdef('Pooling', version=1).
  234. add_enum_alias('Mode','PoolingV0').
  235. add_fields('uint32', 'pad_h', 0, 'pad_w', 0, 'stride_h', 2, 'stride_w', 2,
  236. 'window_h', 2, 'window_w', 2).
  237. add_enum_alias('Format', 'Convolution')
  238. )
  239. (pdef('Softmax').
  240. add_fields('int32', 'axis', -1)
  241. )
  242. (pdef('AdaptivePooling', version=0, is_legacy=True).
  243. add_enum_alias('Mode', 'PoolingV0').
  244. add_enum_alias('Format', 'ConvolutionV0')
  245. )
  246. (pdef('AdaptivePooling', version=1).
  247. add_enum_alias('Mode', 'PoolingV0').
  248. add_enum_alias('Format', 'Convolution')
  249. )
  250. (pdef('LRN',
  251. 'see ImageNet Classification with Deep Convolutional Neural Networks for'
  252. ' meaning of the fields').
  253. add_fields('uint32', Doc('n', 'must be odd'), 5).
  254. add_fields('float32', 'k', '2.f', 'alpha', '1e-4f', 'beta', '0.75f')
  255. )
  256. (pdef('BN').
  257. add_enum(
  258. 'ParamDim',
  259. Doc('DIM_11HW = 0', 'Dim of params (Sigma, Mu) is 1 x 1 x H x W'),
  260. Doc('DIM_1CHW = 1', 'Dim of params (Sigma, Mu) is 1 x C x H x W'),
  261. Doc('DIM_1C11 = 2', 'Dim of params (Sigma, Mu) is 1 x C x 1 x 1'),
  262. Doc('DIM_111C = 3', 'Dim of params (Sigma, Mu) is 1 x 1 x 1 x C'),
  263. name_field='param_dim'
  264. ).
  265. add_enum(
  266. 'FwdMode',
  267. Doc('TRAINING = 0', 'Training phase.'),
  268. Doc('INFERENCE = 1', 'Inference phase.'),
  269. name_field='fwd_mode'
  270. ).
  271. add_fields('float64', 'epsilon', '1e-4f').
  272. add_fields('float64', 'avg_factor', '1.f').
  273. add_fields('float32', 'scale', '1.f').
  274. add_fields('float32', 'bias', '0.f')
  275. )
  276. (pdef('ROIPooling').
  277. add_enum(
  278. 'Mode',
  279. Doc('MAX = 0', 'maximum value inside pooling window; pooling result would '
  280. 'be 0 if pooling window is empty'),
  281. Doc('AVERAGE = 1',
  282. 'arithmetic mean of all values inside pooling window; pooling result '
  283. 'would be 0 if pooling window is empty')
  284. ).
  285. add_fields('float32', 'scale', '1.f'))
  286. INTERP_MODES = ['NEAREST = 0', 'LINEAR = 1', 'AREA = 2', 'CUBIC = 3', 'LANCZOS4 = 4']
  287. BORDER_MODES = [Doc('REPLICATE = 0', 'aaaaaa|abcdefgh|hhhhhhh'),
  288. Doc('REFLECT = 1', 'fedcba|abcdefgh|hgfedcb'),
  289. Doc('REFLECT_101 = 2', 'gfedcb|abcdefgh|gfedcba'),
  290. Doc('WRAP = 3', 'cdefgh|abcdefgh|abcdefg'),
  291. Doc('CONSTANT = 4', 'iiiiii|abcdefgh|iiiiiii'),
  292. Doc('TRANSPARENT = 5', ''),
  293. Doc('ISOLATED = 6', '')]
  294. (pdef('WarpPerspective', version=1, is_legacy=True).
  295. add_enum('InterpolationMode', *INTERP_MODES,
  296. name_field='imode', default=1,
  297. member_alias=[(i, 'INTER_{}'.format(i)) for i in INTERP_MODES]
  298. ).
  299. add_enum('BorderMode', *BORDER_MODES,
  300. name_field='bmode',
  301. member_alias=[(i, 'BORDER_{}'.format(i)) for i in BORDER_MODES]
  302. ).
  303. add_enum_alias('Format', 'ConvolutionV0').
  304. add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f'))
  305. (pdef('WarpPerspective', version=2).
  306. add_enum_alias('InterpolationMode','WarpPerspectiveV1',name_field="imode").
  307. add_enum_alias('BorderMode','WarpPerspectiveV1',name_field="bmode").
  308. add_enum_alias('Format', 'Convolution').
  309. add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f'))
  310. pdef('SpatialTfGridGenerator').add_enum('Mode', 'AFFINE = 0')
  311. pdef('SpatialTfSampler').add_enum('Mode', 'BILINEAR = 0')
  312. pdef('AddUpdate').add_fields(
  313. 'float32', 'alpha', '1.f', 'beta', '1.f', 'bias', '0.f')
  314. pdef('Elemwise').add_enum(
  315. 'Mode',
  316. Doc('RELU = 0', 'unary: max(x, 0)'),
  317. Doc('ABS = 1', 'unary: abs(x)'),
  318. Doc('ACOS = 2', 'unary: acos(x)'),
  319. Doc('ASIN = 3', 'unary: asin(x)'),
  320. Doc('CEIL = 4', 'unary: ceil(x)'),
  321. Doc('COS = 5', 'unary: cos(x)'),
  322. Doc('EXP = 6', 'unary: exp(x)'),
  323. Doc('EXPM1 = 7', 'unary: numerically stable exp(x)-1'),
  324. Doc('FLOOR = 8', 'unary: floor(x)'),
  325. Doc('LOG = 9', 'unary: natural logarithm, log(x)'),
  326. Doc('LOG1P = 10', 'unary: numerically stable log(x+1)'),
  327. Doc('NEGATE = 11', 'unary: -x'),
  328. Doc('SIGMOID = 12', 'unary: 1/(1+exp(-x))'),
  329. Doc('SIN = 13', 'unary: sin(x)'),
  330. Doc('TANH = 14', 'unary: tanh(x)'),
  331. Doc('ABS_GRAD = 15', 'binary: x > 0 ? y : -y'),
  332. Doc('ADD = 16', 'binary: x + y'),
  333. Doc('FLOOR_DIV = 17', 'binary: floor(x / y)'),
  334. Doc('MAX = 18', 'binary: max(x, y)'),
  335. Doc('MIN = 19', 'binary: min(x, y)'),
  336. Doc('MOD = 20', 'binary: x % y or fmodf(x, y)'),
  337. Doc('MUL = 21', 'binary: x * y'),
  338. Doc('POW = 22', 'binary: pow(x, y)'),
  339. Doc('SIGMOID_GRAD = 23', 'binary: x * (1 - x) * y'),
  340. Doc('SUB = 24', 'binary: x - y'),
  341. Doc('SWITCH_GT0 = 25', 'binary: (x > 0) * y'),
  342. Doc('TANH_GRAD = 26', 'binary: (1 - x * x) * y'),
  343. Doc('TRUE_DIV = 27', 'binary: x / y'),
  344. Doc('LOG_SUM_EXP = 28', 'binary: numerically stable log(exp(x) + exp(y))'),
  345. Doc('LT = 29', 'binary: x < y'),
  346. Doc('LEQ = 30', 'binary: x <= y'),
  347. Doc('EQ = 31', 'binary: x == y'),
  348. Doc('SHL = 32', 'bitwise binary: x << y. '
  349. 'Note that result is undefined if y < 0 or y >= bitwidth. Logical '
  350. 'shift is performed for unsigned intergers, and arithmetic shift for '
  351. 'signed ones.'),
  352. Doc('SHR = 33', 'bitwise binary: x >> y; see SHL mode for more details'),
  353. Doc('COND_LEQ_MOV = 34', 'ternary: x <= y ? z : 0'),
  354. Doc('FUSE_MUL_ADD3 = 35',
  355. 'compute ``a * b + c`` where c must either have same layout as '
  356. 'a or b, or be a scalar'),
  357. Doc('FUSE_MUL_ADD4 = 36',
  358. 'compute ``a * A + b * B`` where a and b must have equal layout, '
  359. 'and A and B must have equal layout. In the inputs ``b`` and ``B`` '
  360. 'can be swapped'),
  361. Doc('FUSE_ADD_RELU = 37', 'binary: max(x+y, 0)'),
  362. Doc('FUSE_ADD_SIGMOID = 38', 'binary: 1/(1+exp(-(x+y)))'),
  363. Doc('FUSE_ADD_TANH = 39', 'binary: tanh(x+y)'),
  364. Doc('FAST_TANH = 40', 'unary: rational approximation of tanh(x)'),
  365. Doc('FAST_TANH_GRAD = 41', 'binary: grad of the rational approximation of tanh(x)'),
  366. Doc('ROUND = 42', 'unary: round(x), the nearest integer value to x, rounding '
  367. 'halfway cases away from zero. Float only.'),
  368. Doc('RMULH = 43', 'binary: rounded higher l bits of x * y, where l is the bit '
  369. 'length of x.'),
  370. Doc('ATAN2 = 44','binary: atan2(y,x)'),
  371. Doc('ERF = 45', 'unary: erf(x)'),
  372. Doc('ERFINV = 46', 'unary: inverse function of erf(x)'),
  373. Doc('ERFC = 47', 'unary: erfc(x)'),
  374. Doc('ERFCINV = 48', 'unary: inverse function of erfc(x)'),
  375. Doc('H_SWISH = 49', 'unary: x * clip(x + 3, 0, 6) / 6'),
  376. Doc('H_SWISH_GRAD = 50', 'binary: x < -3 ? 0 : (x > 3 ? y : (2 * x + 3) / 6 * y)'),
  377. Doc('FUSE_ADD_H_SWISH = 51', 'binary: hswish(x+y)'),
  378. Doc('NOT = 52', 'unary: !x'),
  379. Doc('AND = 53', 'binary: x && y'),
  380. Doc('OR = 54', 'binary: x || y'),
  381. Doc('XOR = 55', 'binary: x ^ y'),
  382. Doc('SILU = 56', 'unary: x / (1 + exp(-x))'),
  383. Doc('SILU_GRAD = 57', 'binary: grad(x / (1 + exp(-x))'),
  384. Doc('GELU = 58', 'unary: x Phi(x)'),
  385. Doc('GELU_GRAD = 59', 'binary: grad(x Phi(x))'),
  386. Doc('COND_LT_MOV = 60', 'ternary: x < y ? z : 0'),
  387. )
  388. pdef('ElemwiseMultiType').add_enum(
  389. 'Mode',
  390. Doc('FUSE_MUL_ADD3_INT16x32x32x32 = 0',
  391. 'compute ``a * b + c`` requiring that ``a`` be int16 and ``b`` and '
  392. '``c`` int32, and the result is int32. This mode is optimized for '
  393. 'the channel-broadacsted case, i.e. ``a`` has shape (A, B, C) and '
  394. '``b`` and ``c`` have shape (1, C, 1)'),
  395. Doc('FUSE_MUL_ADD3_IXxF32xF32xI8 = 1',
  396. 'compuate ``a * b + c`` where the inputs ``a`` is an integer type '
  397. '``b`` and ``c`` are both ``float32``, the result is '
  398. '``int8``. This is currently only optimized for ``(1, x)`` '
  399. 'broadcast for ``b`` and ``c``. Computation is carried in floating '
  400. 'points and results are rounded towards zero with saturated cast to '
  401. 'int.'),
  402. Doc('ROUND_SHR_SATURATE_IXxI8xI8 = 2',
  403. 'Compute ``a >> b``, round the result according to lower ``b`` bits '
  404. 'of ``a``` and make a saturating conversion to int8. Where ``a`` should'
  405. ' be an integer tensor and ``b`` should be an int8 scalar.'),
  406. Doc('FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8 = 3',
  407. 'Fused operation of an int16 elemwise add, an int16 rounding multiply '
  408. 'high and an int16 to int8 rounding right shift with saturation.'),
  409. Doc('FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8 = 4',
  410. 'Fused operation of an int32 elemwise add, an int32 rounding multiply '
  411. 'high and an int32 to int8 rounding right shift with saturation.'),
  412. Doc('ROUND_SHR_SATURATE_IXxI8xI16 = 5',
  413. 'Compute ``a >> b``, round the result according to lower ``b`` bits of '
  414. '``a``` and make a saturating conversion to int16. Where ``a`` should'
  415. ' be an integer tensor and ``b`` should be an int8 scalar.'),
  416. Doc('QADD = 6', 'Fused elemwise add two quantized int8 with specified'
  417. 'output quantized dtype'),
  418. Doc('QFUSE_ADD_RELU = 7', 'Fused elemwise add two quantized int8 followed'
  419. ' by ReLU and typecvt to specified dtype'),
  420. Doc('QMUL = 8', 'Fused elemwise multiply two quantized int8 with specified'
  421. 'output quantized dtype'),
  422. Doc('QMIN = 9', 'Fused elemwise min two quantized int8 with specified'
  423. 'output quantized dtype'),
  424. Doc('QMAX = 10', 'quantized: max(x, y), with specified output quantized dtype'),
  425. Doc('QSUB = 11', 'quantized: x - y'),
  426. Doc('QTRUE_DIV = 12', 'quantized: x / y'),
  427. Doc('QFUSE_ADD_SIGMOID = 13', 'quantized: sigmoid(x + y)'),
  428. Doc('QFUSE_ADD_TANH = 14', 'quantized: tanh(x + y)'),
  429. Doc('QRELU = 15', 'quantized: x > 0 ? x : 0'),
  430. Doc('QABS = 16', 'quantized: x > 0 ? x : -x'),
  431. Doc('QSIGMOID = 17', 'quantized: sigmoid(x)'),
  432. Doc('QEXP = 18', 'quantized: exp(x)'),
  433. Doc('QTANH = 19', 'quantized: tanh(x)'),
  434. Doc('QFUSE_MUL_ADD3 = 20', 'quantized: x * y + z'),
  435. Doc('QFAST_TANH = 21', 'quantized: fast_tanh(x)'),
  436. Doc('QNEGATE = 22', 'quantized: -x'),
  437. Doc('QACOS = 23', 'quantized: acos(x)'),
  438. Doc('QASIN = 24', 'quantized: asin(x)'),
  439. Doc('QCEIL = 25', 'quantized: ceil(x)'),
  440. Doc('QCOS = 26', 'quantized: cos(x)'),
  441. Doc('QEXPM1 = 27', 'quantized: expm1(x)'),
  442. Doc('QFLOOR = 28', 'quantized: floor(x)'),
  443. Doc('QLOG = 29', 'quantized: log(x)'),
  444. Doc('QLOG1P = 30', 'quantized: log1p(x)'),
  445. Doc('QSIN = 31', 'quantized: sin(x)'),
  446. Doc('QROUND = 32', 'quantized: round(x)'),
  447. Doc('QERF = 33', 'quantized: erf(x)'),
  448. Doc('QERFINV = 34', 'quantized: erfinv(x)'),
  449. Doc('QERFC = 35', 'quantized: erfc(x)'),
  450. Doc('QERFCINV = 36', 'quantized: erfcinv(x)'),
  451. Doc('QABS_GRAD = 37', 'quantized: abs_grad'),
  452. Doc('QFLOOR_DIV = 38', 'quantized floor_div'),
  453. Doc('QMOD = 39', 'quantized mod'),
  454. Doc('QSIGMOID_GRAD = 40', 'quantized sigmoid_grad'),
  455. Doc('QSWITCH_GT0 = 41', 'quantized switch_gt0'),
  456. Doc('QTANH_GRAD = 42', 'quantized tanh_grad'),
  457. Doc('QLT = 43', 'quantized lt'),
  458. Doc('QLEQ = 44', 'quantized leq'),
  459. Doc('QEQ = 45', 'quantized eq'),
  460. Doc('QPOW = 46', 'quantized pow'),
  461. Doc('QLOG_SUM_EXP = 47', 'quantized log_sum_exp'),
  462. Doc('QFAST_TANH_GRAD = 48', 'quantized fast_tanh_grad'),
  463. Doc('QATAN2 = 49', 'quantized atan2'),
  464. Doc('QCOND_LEQ_MOV = 50', 'quantized cond_leq_mov'),
  465. Doc('QH_SWISH = 51', 'quantized h_swish'),
  466. Doc('QFUSE_ADD_H_SWISH = 52', 'quantized h_swish(x+y)'),
  467. Doc('QH_SWISH_GRAD = 53', 'quantized h_swish_grad'),
  468. Doc('FUSE_MUL_ADD3_INT16xF32xF32xF32 = 54',
  469. 'compute ``a * b + c`` requiring that ``a`` be int16 and ``b`` and '
  470. '``c`` float32, and the result is float32.'),
  471. Doc('MUL_INT16xF32xF32 = 55',
  472. 'compute ``a * b `` requiring that ``a`` be int16 and ``b`` float32, '
  473. 'and the result is float32.'),
  474. Doc('FUSE_MUL_ADD3_UINT8xF32xF32xF32 = 56',
  475. 'compute ``a * b + c`` requiring that ``a`` be uint8 and ``b`` and '
  476. '``c`` float32, and the result is float32.'),
  477. Doc('QCOND_LT_MOV = 57', 'quantized cond_lt_mov'),
  478. )
  479. pdef('PowC', 'power with constant exponent').add_fields('float32', 'exp', 0)
  480. (pdef('DctChannelSelect', '2d discrete cosine transform', version=0, is_legacy=True).add_enum_alias('Format', 'ConvolutionV0').
  481. add_enum('FastImpl', 'NONE = 0', 'FIX_32_MASK = 1').add_fields('int32', 'dct_block_size', 8))
  482. (pdef('DctChannelSelect', '2d discrete cosine transform', version=1).add_enum_alias('Format', 'Convolution').
  483. add_enum_alias('FastImpl', 'DctChannelSelectV0').add_fields('int32', 'dct_block_size', 8))
  484. (pdef('MatrixMul', version=0, is_legacy=True).
  485. add_fields('bool', 'transposeA', 'false', 'transposeB', 'false').
  486. add_enum('DataType',
  487. Doc('FLOAT = 0', 'input/output both float32/float16'),
  488. 'INT8x8x16 = 1',
  489. 'INT8x8x32 = 2',
  490. Doc('FLOAT_IO16xC32 = 3', 'input/output both float16, the internal compute is '
  491. 'float32'),
  492. Doc('QUINT8x8x32 = 4', 'input QuantizedAsymm8, output QuantizedS32'),
  493. Doc('QUINT4x4x32 = 5', 'input QuantizedAsymm4, output QuantizedS32'),
  494. name_field='data_type'))
  495. (pdef('MatrixMul', version=1, is_legacy=True).
  496. add_fields('bool', 'transposeA', 'false', 'transposeB', 'false').
  497. add_enum(Doc('ComputeMode', 'Specifies special computation modes, e.g. '
  498. 'different combinations of intermediate result '
  499. 'data types.'),
  500. Doc('DEFAULT = 0', 'No special requirements on the precision of '
  501. 'intermediate results.'),
  502. Doc('FLOAT32 = 1', 'Use Float32 accumulator and intermediate result. '
  503. 'Only supported when input and output is Float16.'),
  504. name_field='compute_mode'))
  505. (pdef('MatrixMul', version=2).
  506. add_fields('bool', 'transposeA', 'false', 'transposeB', 'false').
  507. add_enum_alias('ComputeMode', 'MatrixMulV1', name_field='compute_mode').
  508. add_enum('Format',
  509. Doc('DEFAULT = 0', 'Normal matrix mul: (M, K) x (K, N) = (M, N)'),
  510. Doc('MK4 = 1', 'Split 4 from M and K, better for neon compute:'
  511. '(M/4, K/4, 4(k), 4(m)) x (K/4, N, 4(k)). if transposeA the '
  512. 'layout is (K/4, M/4, 4(k), 4(m)) x (K/4, N, 4(k))'),
  513. Doc('MK8 = 2', 'Split 8 from M and K, better for neon compute:'
  514. '(M/8, K/8, 8(k), 8(m)) x (K/8, N, 8(k)). if transposeA the '
  515. 'layout is (K/8, M/8, 8(k), 8(m)) x (K/8, N, 8(k))'),
  516. Doc('MK4_DOT = 3', 'Split 4 from M and K, better for neon dotprod:'
  517. 'M/4, K/4, 4(m), 4(k)) x (K/4, N, 4(k)). if transposeA the '
  518. 'layout is (K/4, M/4, 4(m), 4(k)) x (K/4, N, 4(k))'),
  519. Doc('N32K4_DOT = 4', 'Split 32 from N and 4 from K, better for neon gevm dotprod:'
  520. 'N/32, K/4, 32(n), 4(k)')
  521. )
  522. )
  523. (pdef('SVD').
  524. add_fields('bool',
  525. Doc('full_matrices',
  526. 'Whether to compute the full-sized u and v or only the leading'
  527. ' min(m, n) singular vectors. Ignored if compute_uv is '
  528. 'false.'),
  529. 'false',
  530. Doc('compute_uv',
  531. 'Whether the left (u) and right (v) singular vectors will be '
  532. 'computed and outputted.'),
  533. 'true'))
  534. (pdef('Reduce', 'legacy reduce', version=0, is_legacy=True).
  535. add_enum('Mode',
  536. 'SUM = 0',
  537. Doc('SUM_SQR = 1', 'sum of x * x for each element x'),
  538. 'PRODUCT = 2', 'MIN = 3', 'MAX = 4').
  539. add_fields('int32',
  540. Doc('axis',
  541. 'axis along which reduction is performed; if -1 is given, '
  542. 'reduce to given target shape (only used in megbrain)'),
  543. -1))
  544. (pdef('Reduce', 'reduce along given axis', version=1, is_legacy=True).
  545. add_enum('Mode',
  546. 'SUM = 0',
  547. Doc('SUM_SQR = 1', 'sum of x * x for each element x'),
  548. 'PRODUCT = 2', 'MIN = 3', 'MAX = 4', 'MEAN = 5').
  549. add_fields('int32',
  550. Doc('axis',
  551. 'axis along which reduction is performed; if -1 is given, '
  552. 'reduce to given target shape (only used in megbrain)'),
  553. -1).
  554. add_enum('DataType',
  555. Doc('DEFAULT = 0',
  556. '''
  557. input/output are the same data type, and the internal computation type would be chosen by the input/output dtypes and the reduction mode.
  558. Currently, ```DEFAULT``` mode means:
  559. +--------------------+-----------------------------------+-------------------+
  560. | Input/Output DType | Mode | Computation DType |
  561. +====================+===================================+===================+
  562. | FLOAT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT32 |
  563. +--------------------+-----------------------------------+-------------------+
  564. | FLOAT16 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT16 |
  565. +--------------------+-----------------------------------+-------------------+
  566. | INT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT32 |
  567. +--------------------+-----------------------------------+-------------------+
  568. | INT8 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT8 |
  569. +--------------------+-----------------------------------+-------------------+
  570. | QuantizedS8 | MIN/MAX | QuantizedS8 |
  571. +--------------------+-----------------------------------+-------------------+
  572. | QuantizedS8 | MEAN/SUM | QuantizedS32 |
  573. +--------------------+-----------------------------------+-------------------+
  574. | Quantized8Asymm | MIN/MAX | Quantized8Asymm |
  575. +--------------------+-----------------------------------+-------------------+
  576. | Quantized8Asymm | MEAN/SUM | QuantizedS32 |
  577. +--------------------+-----------------------------------+-------------------+
  578. '''
  579. ),
  580. Doc('FLOAT_IO16xC32 = 1', 'Deprecated. This was replaced by '
  581. 'FLOAT_O16xC32, and input\'s dtype decided by actual input tensor.'),
  582. Doc('FLOAT_O32xC32 = 2', 'compute/output both are float32'),
  583. Doc('FLOAT_O16xC32 = 3', 'compute are float32, output float16'),
  584. Doc('QUINT_I8xO32 = 4', 'input quint8, compute and output are qint32'),
  585. Doc('QINT_I8xO32 = 5', 'input qint8, compute and output are qint32'),
  586. name_field='data_type'))
  587. (pdef('Reduce', 'reduce along given axis', version=2).
  588. add_enum('Mode',
  589. 'SUM = 0',
  590. Doc('SUM_SQR = 1', 'sum of x * x for each element x'),
  591. 'PRODUCT = 2', 'MIN = 3', 'MAX = 4', 'MEAN = 5').
  592. add_fields('int32',
  593. Doc('axis',
  594. 'axis along which reduction is performed; if INT_MAX is given, '
  595. 'reduce to given target shape (only used in megbrain)'),
  596. (1<<31)-1).
  597. add_enum('DataType',
  598. Doc('DEFAULT = 0',
  599. '''
  600. input/output are the same data type, and the internal computation type would be chosen by the input/output dtypes and the reduction mode.
  601. Currently, ```DEFAULT``` mode means:
  602. +--------------------+-----------------------------------+-------------------+
  603. | Input/Output DType | Mode | Computation DType |
  604. +====================+===================================+===================+
  605. | FLOAT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT32 |
  606. +--------------------+-----------------------------------+-------------------+
  607. | FLOAT16 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT16 |
  608. +--------------------+-----------------------------------+-------------------+
  609. | INT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT32 |
  610. +--------------------+-----------------------------------+-------------------+
  611. | INT8 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT8 |
  612. +--------------------+-----------------------------------+-------------------+
  613. | QuantizedS8 | MIN/MAX | QuantizedS8 |
  614. +--------------------+-----------------------------------+-------------------+
  615. | QuantizedS8 | MEAN/SUM | QuantizedS32 |
  616. +--------------------+-----------------------------------+-------------------+
  617. | Quantized8Asymm | MIN/MAX | Quantized8Asymm |
  618. +--------------------+-----------------------------------+-------------------+
  619. | Quantized8Asymm | MEAN/SUM | QuantizedS32 |
  620. +--------------------+-----------------------------------+-------------------+
  621. '''
  622. ),
  623. Doc('FLOAT_IO16xC32 = 1', 'Deprecated. This was replaced by '
  624. 'FLOAT_O16xC32, and input\'s dtype decided by actual input tensor.'),
  625. Doc('FLOAT_O32xC32 = 2', 'compute/output both are float32'),
  626. Doc('FLOAT_O16xC32 = 3', 'compute are float32, output float16'),
  627. Doc('QUINT_I8xO32 = 4', 'input quint8, compute and output are qint32'),
  628. Doc('QINT_I8xO32 = 5', 'input qint8, compute and output are qint32'),
  629. name_field='data_type'))
  630. (pdef('Cumsum', 'calculate accumulated sum along given axis', version=0, is_legacy=True).
  631. add_fields('int32',
  632. Doc('axis',
  633. 'axis along which cumsum is performed'),
  634. -1).
  635. add_fields('bool',
  636. Doc('exclusive',
  637. 'whether the current element is taken into account'),
  638. 'true').
  639. add_fields('bool',
  640. Doc('reverse',
  641. 'whether the cumsum is forward or backward'),
  642. 'false'))
  643. (pdef('Cumsum', 'calculate accumulated sum along given axis', version=1).
  644. add_fields('int32',
  645. Doc('axis',
  646. 'axis along which cumsum is performed, default with INT_MAX'),
  647. (1<<31)-1).
  648. add_fields('bool',
  649. Doc('exclusive',
  650. 'whether the current element is taken into account'),
  651. 'true').
  652. add_fields('bool',
  653. Doc('reverse',
  654. 'whether the cumsum is forward or backward'),
  655. 'false'))
  656. (pdef('CondTake').
  657. add_enum('Mode',
  658. Doc('EQ = 0', 'take if ``abs(data-val)<eps``'),
  659. Doc('NEQ = 1', 'take if ``abs(data-val)>=eps``'),
  660. Doc('LT = 2', 'take if ``data<val``'),
  661. Doc('LEQ = 3', 'take if ``data<=val``'),
  662. Doc('GT = 4', 'take if ``data>val``'),
  663. Doc('GEQ = 5', 'take if ``data>=val``')).
  664. add_fields('float32',
  665. Doc('val', 'the value to be compared with; note that for integer '
  666. 'data, val is also converted to int'), 0).
  667. add_fields('float32', Doc('eps', 'used for float equality comparison'),
  668. 1e-6))
  669. pdef('Argsort').add_enum('Order', 'ASCENDING = 0', 'DESCENDING = 1')
  670. (pdef('IndexingRemap').
  671. add_fields('bool',
  672. Doc('is_non_overlapping',
  673. 'Whether no two dst element maps to the same src element. '
  674. 'Enabling this option can accelerate gradient operator since'
  675. ' atomic adding operations could be avoided.'),
  676. 'false'))
  677. pdef('Sleep').add_fields('float32', Doc('time', 'time to sleep in seconds'), 0)
  678. (pdef('Linspace').
  679. add_fields('bool',
  680. Doc('endpoint',
  681. 'Whether stop is included in the generated tensor'),
  682. 'true'))
  683. (pdef('LinspaceFull').
  684. add_fields('float64',
  685. Doc('start', 'The first val.'),
  686. 0).
  687. add_fields('float64',
  688. Doc('stop', 'The last val.'),
  689. 1).
  690. add_fields('bool',
  691. Doc('endpoint',
  692. 'Whether stop is included in the generated tensor'),
  693. 'true'))
  694. (pdef('Eye').
  695. add_fields(
  696. 'int32',
  697. Doc('k', 'Index of the diagonal: 0 (the default) refers to the main '
  698. 'diagonal, a positive value refers to an upper diagonal, and a '
  699. 'negative value to a lower diagonal.'),
  700. 0).
  701. add_fields(
  702. 'dtype', Doc('dtype', 'data type of output value'),
  703. 'DTypeEnum::Float32'))
  704. (pdef('Diag').
  705. add_fields(
  706. 'int32',
  707. Doc('k', 'Index of the diagonal: 0 (the default) refers to the main '
  708. 'diagonal, a positive value refers to an upper diagonal, and a '
  709. 'negative value to a lower diagonal.'),
  710. 0))
  711. (pdef('UniformRNG', version=0, is_legacy=True).
  712. add_fields('uint64', 'seed', 0))
  713. (pdef('UniformRNG', version=1).
  714. add_fields('uint64', 'seed', 0).
  715. add_fields(
  716. 'dtype', Doc('dtype', 'The dtype of output Tensor. Only support Float32.'),
  717. 'DTypeEnum::Float32'))
  718. (pdef('GaussianRNG', version=0, is_legacy=True).
  719. add_fields('uint64', 'seed', 0).
  720. add_fields('float32', 'mean', 0, 'std', 1))
  721. (pdef('GaussianRNG', version=1).
  722. add_fields('uint64', 'seed', 0).
  723. add_fields('float32', 'mean', 0, 'std', 1).
  724. add_fields(
  725. 'dtype', Doc('dtype', 'The dtype of output Tensor. Only support Float32.'),
  726. 'DTypeEnum::Float32'))
  727. (pdef('GammaRNG').
  728. add_fields('uint64', 'seed', 0))
  729. (pdef('BetaRNG').
  730. add_fields('uint64', 'seed', 0))
  731. (pdef('PoissonRNG').
  732. add_fields('uint64', 'seed', 0))
  733. (pdef('PermutationRNG').
  734. add_fields('uint64', 'seed', 0).
  735. add_fields(
  736. 'dtype', Doc('dtype', 'The dtype of output Tensor. Int32, Int16 and '
  737. 'Float32 are supported.'),
  738. 'DTypeEnum::Int32'))
  739. (pdef('ShuffleRNG').
  740. add_fields('uint64', 'seed', 0))
  741. (pdef('Flip').
  742. add_fields('bool', 'vertical', 'false', 'horizontal', 'false'))
  743. (pdef('Rotate')
  744. .add_fields('bool', 'clockwise', 'true'))
  745. (pdef('ROICopy')
  746. .add_fields('uint32', 'row_from', 0, 'row_to', 0, 'col_from', 0, 'col_to', 0))
  747. (pdef('CvtColor')
  748. .add_enum('Mode', 'RGB2GRAY = 0', 'RGB2YUV = 1', 'YUV2RGB = 2', 'GRAY2RGB = 3', 'RGBA2RGB = 4',
  749. 'RGBA2BGR = 5', 'RGBA2GRAY = 6', 'RGB2BGR = 7', 'BGR2GRAY = 8', 'BGR2RGB = 9',
  750. Doc('YUV2GRAY_NV21 = 10', 'For historical reasons, referred to as YCC by opencv'),
  751. 'YUV2RGB_NV21 = 11', 'YUV2BGR_NV21 = 12', 'YUV2GRAY_NV12 = 13', 'YUV2RGB_NV12 = 14',
  752. 'YUV2BGR_NV12 = 15', 'YUV2GRAY_YV12 = 16', 'YUV2RGB_YV12 = 17', 'YUV2BGR_YV12 = 18',
  753. 'YUV2GRAY_YU12 = 19', 'YUV2RGB_YU12 = 20', 'YUV2BGR_YU12 = 21',
  754. 'YCrCb2RGB = 22', 'YCrCb2BGR = 23',
  755. Doc('BT601_YUV2RGB_NV21 = 24', 'BT601 yuv format, referred to as YUV by opencv'),
  756. 'BT601_YUV2BGR_NV21 = 25', 'BT601_YUV2RGB_NV12 = 26', 'BT601_YUV2BGR_NV12 = 27',
  757. 'BT601_YUV2RGB_YV12 = 28', 'BT601_YUV2BGR_YV12 = 29', 'BT601_YUV2RGB_YU12 = 30',
  758. 'BT601_YUV2BGR_YU12 = 31',
  759. member_alias=[('YUV2GRAY_NV21', 'BT601_YUV2GRAY_NV21'),
  760. ('YUV2GRAY_NV12', 'BT601_YUV2GRAY_NV12'),
  761. ('YUV2GRAY_YV12', 'BT601_YUV2GRAY_YV12'),
  762. ('YUV2GRAY_YU12', 'BT601_YUV2GRAY_YU12')],
  763. name_field = 'mode'))
  764. (pdef('WarpAffine', version=0, is_legacy=True)
  765. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  766. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  767. .add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f'))
  768. (pdef('WarpAffine', version=1, is_legacy=True)
  769. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  770. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  771. .add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f')
  772. .add_enum_alias('Format', 'ConvolutionV0', default=1))
  773. (pdef('WarpAffine', version=2)
  774. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  775. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  776. .add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f')
  777. .add_enum_alias('Format', 'Convolution', default=1))
  778. (pdef('GaussianBlur')
  779. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  780. .add_fields('uint32', 'kernel_height', 0, 'kernel_width', 0)
  781. .add_fields('float32','sigma_x', '0.f', 'sigma_y', '0.f'))
  782. (pdef('Resize', version=0, is_legacy=True)
  783. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode'))
  784. (pdef('Resize', version=1, is_legacy=True)
  785. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  786. .add_enum_alias('Format', 'ConvolutionV0', default=1))
  787. (pdef('Resize', version=2)
  788. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  789. .add_enum_alias('Format', 'Convolution', default=1))
  790. (pdef('Remap', version=0,is_legacy=True)
  791. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  792. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_type')
  793. .add_enum_alias('Format', 'ConvolutionV0', default=1)
  794. .add_fields('float32', 'scalar', '0.f'))
  795. (pdef('Remap', version=1)
  796. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  797. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_type')
  798. .add_enum_alias('Format', 'Convolution', default=1)
  799. .add_fields('float32', 'scalar', '0.f'))
  800. (pdef('Convolution3D').
  801. add_enum('Mode', 'CROSS_CORRELATION = 0', 'CONVOLUTION = 1').
  802. add_fields(
  803. 'uint32',
  804. Doc('pad_d', 'padding on one side on the first dimension'), 0,
  805. Doc('pad_h', 'padding on one side on the second dimension'), 0,
  806. Doc('pad_w', 'padding on one side on the third dimension'), 0,
  807. Doc('stride_d', 'kernel stride on the first dimension'), 1,
  808. Doc('stride_h', 'kernel stride on the second dimension'), 1,
  809. Doc('stride_w', 'kernel stride on the third dimension'), 1,
  810. Doc('dilate_d', 'dilation (i.e. size of each zero-padded kernel block) '
  811. 'on the first dimension'), 1,
  812. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  813. 'on the second dimension'), 1,
  814. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  815. 'on the third dimension'), 1
  816. ).
  817. add_enum('Sparse',
  818. Doc('DENSE = 0', 'dense convolution: filter shape should be '
  819. '[oc, ic, spatial...] if format is NCDHW, '
  820. '[oc, spatial..., ic] if format is NDHWC'),
  821. Doc('GROUP = 1', 'group convolution: filter shape should be '
  822. '[group, oc_per_group, ic_per_group, spatial...] if format is NCDHW, '
  823. '[group, oc_per_group, spatial..., ic_per_group] if format is NDHWC')
  824. ).
  825. add_enum('DataType',
  826. Doc('FLOAT = 0', 'input/output both float32/float16'),
  827. Doc('FLOAT_IO16xC32 = 1', 'input/output both float16, the internal '
  828. 'compute is float32'),
  829. name_field='data_type').
  830. add_enum('Format', 'NCDHW = 0', 'NDHWC = 1')
  831. )
  832. (pdef('Conv3DBias').
  833. add_enum('NonlineMode', 'IDENTITY = 0', 'RELU = 1', 'SIGMOID = 2').
  834. add_enum_alias('Mode', 'Convolution3D').
  835. add_fields('uint32', 'pad_d', 0, 'pad_h', 0, 'pad_w', 0,
  836. 'stride_d', 1, 'stride_h', 1, 'stride_w', 0))
  837. (pdef('SeparableConv3D').
  838. add_enum_alias('Mode', 'Convolution3D').
  839. add_enum('BorderMode', 'BORDER_REPLICATE = 0', 'BORDER_REFLECT = 1',
  840. 'BORDER_REFLECT_101 = 2','BORDER_WRAP = 3',
  841. 'BORDER_CONSTANT = 4', 'BORDER_TRANSPARENT = 5','BORDER_ISOLATED = 6').
  842. add_fields('bool', 'is_symm_kernel', 'true').
  843. add_fields('uint32', 'pad_d', 0, 'pad_h', 0, 'pad_w', 0,
  844. 'stride_d', 0, 'stride_h', 1, 'stride_w', 1,
  845. 'ksize_d', 0, 'ksize_h', 3, 'ksize_w', 3,
  846. 'anchor_d', 0, 'anchor_h', 1, 'anchor_w', 1))
  847. (pdef('TopK').
  848. add_enum(
  849. 'Mode',
  850. Doc('KTH_ONLY = 0', "only the value of the k'th element would be computed"),
  851. Doc('VALUE_IDX_NOSORT = 1',
  852. 'all the top-k values and corresponding indices would be computed; '
  853. 'no order is guaranteed'),
  854. Doc('VALUE_IDX_SORTED = 2',
  855. 'all the top-k values and corresponding indices sorted'))
  856. )
  857. RELAYOUT_FORMAT_MODE_DOC = """
  858. Relayout mode.
  859. **Naming conventions**
  860. 1. ``A_B`` means change from layout format ``A`` to ``B``.
  861. 2. ``INTER_WEIGHT_xx`` means relayout the weight for faster processing by
  862. :attr:`Convolution.Format.NHWCD4` convolutions.
  863. 3. A suffix of ``I`` means ``Image2DPack4TensorFormat`` tensor format is used
  864. for faster processing on GPUs.
  865. **Layout definitions**
  866. * ``NCHW`` layout: ``{N, C, H, W}``
  867. * ``NHWC`` layout: ``{N, H, W, C}``
  868. * ``NHWCD4`` layout: ``{N, H, (C + 3) / 4, W, 4}``
  869. * ``NHWCD4I`` layout: with ``align_axis = 2``
  870. * ``NCHW4`` layout: ``{N, C/4, H, W, 4}``
  871. * ``NCHW88`` layout: ``{N, C/8, H, W, 8}``
  872. * ``CHWN4`` layout: ``{C/4, H, W, N, 4}``
  873. * ``NCHW64`` layout: ``{N, C/64, H, W, 64}``
  874. **Float weight transformation definitions**
  875. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  876. | Sparsity Type | Input Layout | Input Req | Output Layout | Axis |
  877. +===============+=================================+====================+======================================+======+
  878. | DENSE | ``{OC, IC, FH, FW}`` | ``OC % 4 == 0`` | ``{OC/4, FH, FW, IC, 4}`` | 3 |
  879. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  880. | GROUP | ``{GROUP, OCPG, ICPG, FH, FW}`` | ``OCPG % 4 == 0`` | ``{GROUP, OCPG/4, FH, FW, ICPG, 4}`` | 4 |
  881. | | | ``ICPG % 4 == 0`` | | |
  882. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  883. | CHAN | ``{GROUP, 1, 1, FH, FW}`` | ``GROUP % 4 == 0`` | ``{GROUP / 4, 1, FH ,FW, 4}`` | 1 |
  884. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  885. **Float weight transformation nchw88 definitions**
  886. +---------------+---------------------------------+--------------------+--------------------------------------+
  887. | Sparsity Type | Input Layout | Input Req | Output Layout |
  888. +===============+=================================+====================+======================================+
  889. | DENSE | ``{OC, IC, FH, FW}`` | ``OC % 8 == 0`` |``{OC/8, IC/8 ,FH, FW, 8(IC), 8(OC)}``|
  890. | | | ``IC % 8 == 0`` | |
  891. +---------------+---------------------------------+--------------------+--------------------------------------+
  892. | GROUP | ``{GROUP, OCPG, ICPG, FH, FW}`` | ``OCPG % 8 == 0`` | ``{GROUP, OCPG/8, ICPG/8 FH, FW, |
  893. | | | ``ICPG % 8 == 0`` | 8(ICPG), 8(OCPG)} `` |
  894. +---------------+---------------------------------+--------------------+--------------------------------------+
  895. | CHAN | ``{GROUP, 1, 1, FH, FW}`` | ``GROUP % 8 == 0`` | ``{GROUP / 8, 1, FH ,FW, 8}`` |
  896. +---------------+---------------------------------+--------------------+--------------------------------------+
  897. **Int8(DOT) weight transformation definitions**
  898. +---------------+---------------------------------+--------------------+------------------------------------------+------+
  899. | Sparsity Type | Input Layout | Input Req | Output Layout | Axis |
  900. +===============+=================================+====================+==========================================+======+
  901. | DENSE | ``{OC, IC, FH, FW}`` | ``OC % 4 == 0`` | ``{OC/4, FH, FW, IC/4, 4, 4}` | 3 |
  902. +---------------+---------------------------------+--------------------+------------------------------------------+------+
  903. | GROUP | ``{GROUP, OCPG, ICPG, FH, FW}`` | ``OCPG % 4 == 0`` | ``{GROUP, OCPG/4, FH, FW, ICPG/4, 4, 4}``| 4 |
  904. | | | ``ICPG % 4 == 0`` | | |
  905. +---------------+---------------------------------+--------------------+------------------------------------------+------+
  906. Note: the axis column means the corresponding ``align_axis`` for image format
  907. when the ``I`` suffix is present.
  908. Note: NCHW_NCHW4_WEIGHT will auto pad oc and ic, you should remove oc in later opr by seting group and oc param with NCHW4_NCHW
  909. """
  910. (pdef('RelayoutFormat', 'Change the tensor layout format', version=0, is_legacy=True).
  911. add_enum(
  912. Doc('Mode', RELAYOUT_FORMAT_MODE_DOC),
  913. 'NHWC_NHWCD4 = 0',
  914. 'NHWCD4_NHWC = 1',
  915. 'NHWC_NHWCD4I = 2',
  916. 'NCHW_NHWCD4 = 3',
  917. 'NCHW_NHWCD4I = 4',
  918. 'NHWCD4I_NCHW = 5',
  919. 'NHWCD4_NCHW = 6',
  920. 'INTER_WEIGHT_DENSE = 7',
  921. 'INTER_WEIGHT_DENSEI = 8',
  922. 'INTER_WEIGHT_GROUP = 9',
  923. 'INTER_WEIGHT_GROUPI = 10',
  924. 'INTER_WEIGHT_CHAN = 11',
  925. 'INTER_WEIGHT_CHANI = 12',
  926. 'INTER_WEIGHT_DENSEI_DOT = 13',
  927. 'INTER_WEIGHT_GROUPI_DOT = 14',
  928. 'NCHW4_CHWN4 = 15',
  929. 'CHWN4_NCHW4 = 16',
  930. 'NCHW_NCHW88_CONV_DENSE_WEIGHT = 17',
  931. 'NCHW_NCHW88_CONV_CHAN_WEIGHT = 18',
  932. 'NCHW_NCHW88_CONV_GROUP_WEIGHT = 19',
  933. 'NCHW_NCHW88 = 20',
  934. 'NCHW88_NCHW = 21',
  935. 'NCHW_NCHW4_IC_SMALL = 22',
  936. 'NCHW_NCHW4_IC_SMALL_CONV_DENSE_WEIGHT = 23',
  937. 'NCHW_NCHW4 = 24',
  938. 'NCHW4_NCHW = 25',
  939. 'NCHW_NCHW4_WEIGHT = 26',
  940. 'NCHW_NCHW64 = 27',
  941. 'NCHW64_NCHW = 28',
  942. 'NCHW_NHWC = 29',
  943. 'NHWC_NCHW = 30',
  944. 'NHWCD4I_NHWC = 31',
  945. )
  946. )
  947. (pdef('RelayoutFormat', 'Change the tensor layout format', version=1).
  948. add_enum_alias('Mode', 'RelayoutFormatV0').
  949. add_fields('uint32', 'oc', '0').
  950. add_fields('uint32', 'group', '1')
  951. )
  952. (pdef('SeparableFilter', version=0, is_legacy=True).
  953. add_enum_alias('Format', 'ConvolutionV0').
  954. add_enum_alias('BorderMode', 'WarpPerspectiveV1').
  955. add_fields('bool', 'is_symm_kernel', 'true').
  956. add_fields('uint32', 'ksize_h', 3, 'ksize_w', 3, 'anchor_h', 1, 'anchor_w', 1))
  957. (pdef('SeparableFilter', version=1).
  958. add_enum_alias('Format', 'Convolution').
  959. add_enum_alias('BorderMode', 'WarpPerspectiveV1').
  960. add_fields('bool', 'is_symm_kernel', 'true').
  961. add_fields('uint32', 'ksize_h', 3, 'ksize_w', 3, 'anchor_h', 1, 'anchor_w', 1))
  962. (pdef('LocalShare', 'Local share convolution',version=0, is_legacy=True).
  963. add_enum_alias('Mode', 'ConvolutionV0').
  964. add_fields(
  965. 'uint32',
  966. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  967. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  968. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  969. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  970. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  971. 'on the second dimension'), 1,
  972. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  973. 'on the second dimension'), 1,
  974. Doc('spatial_groups_h', 'spatial groups on the first dimension'), 1,
  975. Doc('spatial_groups_w', 'spatial groups on the second dimension'), 1
  976. ).
  977. add_enum_alias('Sparse', 'ConvolutionV0').
  978. add_enum_alias('Format', 'ConvolutionV0').
  979. add_enum_alias('ComputeMode', 'ConvolutionV1')
  980. )
  981. (pdef('LocalShare', 'Local share convolution', version=1).
  982. add_enum_alias('Mode', 'ConvolutionV0').
  983. add_fields(
  984. 'uint32',
  985. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  986. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  987. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  988. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  989. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  990. 'on the second dimension'), 1,
  991. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  992. 'on the second dimension'), 1,
  993. Doc('spatial_groups_h', 'spatial groups on the first dimension'), 1,
  994. Doc('spatial_groups_w', 'spatial groups on the second dimension'), 1
  995. ).
  996. add_enum_alias('Sparse', 'ConvolutionV0').
  997. add_enum_alias('Format', 'Convolution').
  998. add_enum_alias('ComputeMode', 'ConvolutionV1')
  999. )
  1000. (pdef('ROIAlign',version=0,is_legacy=True).
  1001. add_enum('Mode', 'MAX = 0', 'AVERAGE = 1', name_field='mode').
  1002. add_enum_alias('Format', 'ConvolutionV0').
  1003. add_fields('float32', 'spatial_scale', '1.0').
  1004. add_fields('float32', 'offset', '0.0').
  1005. add_fields('uint32',
  1006. 'pooled_height', '1',
  1007. 'pooled_width', '1',
  1008. 'sample_height', '2',
  1009. 'sample_width', '2')
  1010. )
  1011. (pdef('ROIAlign', version=1).
  1012. add_enum_alias('Mode', 'ROIAlignV0', name_field='mode').
  1013. add_enum_alias('Format', 'Convolution').
  1014. add_fields('float32', 'spatial_scale', '1.0').
  1015. add_fields('float32', 'offset', '0.0').
  1016. add_fields('uint32',
  1017. 'pooled_height', '1',
  1018. 'pooled_width', '1',
  1019. 'sample_height', '2',
  1020. 'sample_width', '2')
  1021. )
  1022. (pdef('Correlation').
  1023. add_enum_alias('Format', 'ConvolutionV0').
  1024. add_fields('uint32', 'kernel_size', '1').
  1025. add_fields('uint32', 'max_displacement', '1').
  1026. add_fields('uint32', 'stride1', '1').
  1027. add_fields('uint32', 'stride2', '1').
  1028. add_fields('uint32', 'pad_size', '0').
  1029. add_fields('bool', 'is_multiply', 'true')
  1030. )
  1031. (pdef('DeformablePSROIPooling').
  1032. add_fields('bool', 'no_trans', 'true').
  1033. add_fields('float32', 'spatial_scale', 1,
  1034. 'trans_std', 1).
  1035. add_fields('uint32',
  1036. Doc('pooled_h', 'height of pooling output'), 1,
  1037. Doc('pooled_w', 'width of pooling output'), 1,
  1038. Doc('part_size', 'size of each deformable part'), 1,
  1039. Doc('sample_per_part', 'sample count of each bbox'), 1))
  1040. (pdef('BatchConvBias', 'Batch convolution (unshare weights on the batch dimension)',version=0,is_legacy=True).
  1041. add_enum_alias('NonlineMode', 'ConvBiasV0').
  1042. add_enum_alias('Mode', 'ConvolutionV0').
  1043. add_fields(
  1044. 'uint32',
  1045. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  1046. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  1047. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  1048. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  1049. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  1050. 'on the second dimension'), 1,
  1051. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  1052. 'on the second dimension'), 1,
  1053. ).
  1054. add_enum_alias('Sparse', 'ConvolutionV0').
  1055. add_enum_alias('Format', 'ConvolutionV0').
  1056. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field="compute_mode")
  1057. )
  1058. (pdef('BatchConvBias', 'Batch convolution (unshare weights on the batch dimension)',version=1).
  1059. add_enum_alias('NonlineMode', 'ConvBiasV0').
  1060. add_enum_alias('Mode', 'ConvolutionV0').
  1061. add_fields(
  1062. 'uint32',
  1063. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  1064. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  1065. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  1066. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  1067. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  1068. 'on the second dimension'), 1,
  1069. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  1070. 'on the second dimension'), 1,
  1071. ).
  1072. add_enum_alias('Sparse', 'ConvolutionV0').
  1073. add_enum_alias('Format', 'Convolution').
  1074. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field="compute_mode")
  1075. )
  1076. (pdef('FakeQuant').
  1077. add_fields('int32','qmin','-2147483648').
  1078. add_fields('int32','qmax','2147483647')
  1079. )
  1080. (pdef('TQT').
  1081. add_fields('int32', 'qmin', '-2147483648').
  1082. add_fields('int32', 'qmax', '2147483647')
  1083. )
  1084. (pdef('LSQ').
  1085. add_fields('int32', 'qmin', '-2147483648').
  1086. add_fields('int32', 'qmax', '2147483647')
  1087. )
  1088. pdef('Fill').add_fields('float32', 'value', '0')
  1089. pdef('CheckNonFinite').add_fields('float32', 'scale', '1.0')
  1090. PADDING_MODES = [Doc('REPLICATE = 0', 'aaaaaa|abcdefgh|hhhhhhh'),
  1091. Doc('REFLECT = 1', 'fedcba|abcdefgh|hgfedcb'),
  1092. Doc('CONSTANT = 2', 'iiiiii|abcdefgh|iiiiiii')]
  1093. (pdef('Padding').
  1094. add_fields('uint32', Doc('front_offset_dim0','offset in dim 0'), 0).
  1095. add_fields('uint32', Doc('front_offset_dim1','offset in dim 1'), 0).
  1096. add_fields('uint32', Doc('front_offset_dim2','offset in dim 2'), 0).
  1097. add_fields('uint32', Doc('front_offset_dim3','offset in dim 3'), 0).
  1098. add_fields('uint32', Doc('front_offset_dim4','offset in dim 4'), 0).
  1099. add_fields('uint32', Doc('front_offset_dim5','offset in dim 5'), 0).
  1100. add_fields('uint32', Doc('front_offset_dim6','offset in dim 6'), 0).
  1101. add_fields('uint32', Doc('back_offset_dim0', 'back offset in dim0'), 0).
  1102. add_fields('uint32', Doc('back_offset_dim1', 'back offset in dim1'), 0).
  1103. add_fields('uint32', Doc('back_offset_dim2', 'back offset in dim2'), 0).
  1104. add_fields('uint32', Doc('back_offset_dim3', 'back offset in dim3'), 0).
  1105. add_fields('uint32', Doc('back_offset_dim4', 'back offset in dim4'), 0).
  1106. add_fields('uint32', Doc('back_offset_dim5', 'back offset in dim5'), 0).
  1107. add_fields('uint32', Doc('back_offset_dim6', 'back offset in dim6'), 0).
  1108. add_fields('float32', Doc('padding_val','param of padding opr'), 0).
  1109. add_enum('PaddingMode', *PADDING_MODES,
  1110. name_field='padding_mode', default=2,
  1111. member_alias=[(i, 'PADDING_{}'.format(i)) for i in PADDING_MODES]
  1112. )
  1113. )
  1114. (pdef('LayerNorm')
  1115. .add_fields('bool', 'affine', 'true')
  1116. .add_fields('float32', 'eps', '1e-5f')
  1117. .add_fields('uint64', 'normalized_dim', '1')
  1118. .add_fields('uint64', 'normalized_size', '1')
  1119. )
  1120. (pdef('Dropout')
  1121. .add_fields('float32', 'drop_prob', '0')
  1122. .add_fields('uint64', 'seed', '0')
  1123. )
  1124. (pdef('RNNCell').
  1125. add_enum('NonlineMode', 'IDENTITY = 0', 'RELU = 1', 'TANH = 2')
  1126. )
  1127. (pdef('RNN').
  1128. add_fields('uint32', Doc('num_layers', 'Number of recurrent layers'), '1').
  1129. add_fields('bool', Doc('bidirectional', 'If becomes a bidirectional RNN'), 'false').
  1130. add_fields('bool', Doc('bias', 'If the layer use bias weights b_ih and b_hh'), 'true').
  1131. add_fields('uint32', Doc('hidden_size', 'The number of features in the hidden state'), '128').
  1132. add_fields('float32', Doc('dropout', 'If introduce a Dropout layer on the outputs of each RNN layer'), '0.f').
  1133. add_enum_alias('NonlineMode', 'RNNCell').
  1134. add_enum_alias('FwdMode', 'BN', name_field='fwd_mode')
  1135. )
  1136. (pdef('LSTM').
  1137. add_fields('uint32', Doc('num_layers', 'Number of recurrent layers'), '1').
  1138. add_fields('bool', Doc('bidirectional', 'If becomes a bidirectional LSTM'), 'false').
  1139. add_fields('bool', Doc('bias', 'If the layer use bias weights b_ih and b_hh'), 'true').
  1140. add_fields('uint32', Doc('hidden_size', 'The number of features in the hidden state'), '128').
  1141. add_fields('uint32', Doc('proj_size', 'If use LSTM with projections of corresponding size'), '0').
  1142. add_fields('float32', Doc('dropout', 'If introduce a Dropout layer on the outputs of each LSTM layer'), '0.f').
  1143. add_enum_alias('FwdMode', 'BN', name_field='fwd_mode')
  1144. )
  1145. (pdef('LAMBUpdate').
  1146. add_fields('float32', Doc('beta_1', 'beta_1 paramter of lamb'), '1.f').
  1147. add_fields('float32', Doc('beta_2', 'beta_2 paramter of lamb'), '1.f').
  1148. add_fields('float32', Doc('step', 'training step'), '1.f').
  1149. add_fields('float32', Doc('lr', 'learning rate'), '1.f').
  1150. add_fields('float32', Doc('weight_decay', 'weight decay to adjust learning rate'), '1.f').
  1151. add_fields('float32', Doc('eps', 'eps to multi'), '1.f').
  1152. add_fields('bool', Doc('bias_correction', 'whether correct bias'), 'true').
  1153. add_fields('bool', Doc('always_adapt', 'apply adaptive lr to 0.0'), 'false')
  1154. )