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

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