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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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. )
  387. pdef('ElemwiseMultiType').add_enum(
  388. 'Mode',
  389. Doc('FUSE_MUL_ADD3_INT16x32x32x32 = 0',
  390. 'compute ``a * b + c`` requiring that ``a`` be int16 and ``b`` and '
  391. '``c`` int32, and the result is int32. This mode is optimized for '
  392. 'the channel-broadacsted case, i.e. ``a`` has shape (A, B, C) and '
  393. '``b`` and ``c`` have shape (1, C, 1)'),
  394. Doc('FUSE_MUL_ADD3_IXxF32xF32xI8 = 1',
  395. 'compuate ``a * b + c`` where the inputs ``a`` is an integer type '
  396. '``b`` and ``c`` are both ``float32``, the result is '
  397. '``int8``. This is currently only optimized for ``(1, x)`` '
  398. 'broadcast for ``b`` and ``c``. Computation is carried in floating '
  399. 'points and results are rounded towards zero with saturated cast to '
  400. 'int.'),
  401. Doc('ROUND_SHR_SATURATE_IXxI8xI8 = 2',
  402. 'Compute ``a >> b``, round the result according to lower ``b`` bits '
  403. 'of ``a``` and make a saturating conversion to int8. Where ``a`` should'
  404. ' be an integer tensor and ``b`` should be an int8 scalar.'),
  405. Doc('FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT16x16x16x8 = 3',
  406. 'Fused operation of an int16 elemwise add, an int16 rounding multiply '
  407. 'high and an int16 to int8 rounding right shift with saturation.'),
  408. Doc('FUSE_ADD_RMULH_ROUND_SHR_SATURATE_INT32x32x32x8 = 4',
  409. 'Fused operation of an int32 elemwise add, an int32 rounding multiply '
  410. 'high and an int32 to int8 rounding right shift with saturation.'),
  411. Doc('ROUND_SHR_SATURATE_IXxI8xI16 = 5',
  412. 'Compute ``a >> b``, round the result according to lower ``b`` bits of '
  413. '``a``` and make a saturating conversion to int16. Where ``a`` should'
  414. ' be an integer tensor and ``b`` should be an int8 scalar.'),
  415. Doc('QADD = 6', 'Fused elemwise add two quantized int8 with specified'
  416. 'output quantized dtype'),
  417. Doc('QFUSE_ADD_RELU = 7', 'Fused elemwise add two quantized int8 followed'
  418. ' by ReLU and typecvt to specified dtype'),
  419. Doc('QMUL = 8', 'Fused elemwise multiply two quantized int8 with specified'
  420. 'output quantized dtype'),
  421. Doc('QMIN = 9', 'Fused elemwise min two quantized int8 with specified'
  422. 'output quantized dtype'),
  423. Doc('QMAX = 10', 'quantized: max(x, y), with specified output quantized dtype'),
  424. Doc('QSUB = 11', 'quantized: x - y'),
  425. Doc('QTRUE_DIV = 12', 'quantized: x / y'),
  426. Doc('QFUSE_ADD_SIGMOID = 13', 'quantized: sigmoid(x + y)'),
  427. Doc('QFUSE_ADD_TANH = 14', 'quantized: tanh(x + y)'),
  428. Doc('QRELU = 15', 'quantized: x > 0 ? x : 0'),
  429. Doc('QABS = 16', 'quantized: x > 0 ? x : -x'),
  430. Doc('QSIGMOID = 17', 'quantized: sigmoid(x)'),
  431. Doc('QEXP = 18', 'quantized: exp(x)'),
  432. Doc('QTANH = 19', 'quantized: tanh(x)'),
  433. Doc('QFUSE_MUL_ADD3 = 20', 'quantized: x * y + z'),
  434. Doc('QFAST_TANH = 21', 'quantized: fast_tanh(x)'),
  435. Doc('QNEGATE = 22', 'quantized: -x'),
  436. Doc('QACOS = 23', 'quantized: acos(x)'),
  437. Doc('QASIN = 24', 'quantized: asin(x)'),
  438. Doc('QCEIL = 25', 'quantized: ceil(x)'),
  439. Doc('QCOS = 26', 'quantized: cos(x)'),
  440. Doc('QEXPM1 = 27', 'quantized: expm1(x)'),
  441. Doc('QFLOOR = 28', 'quantized: floor(x)'),
  442. Doc('QLOG = 29', 'quantized: log(x)'),
  443. Doc('QLOG1P = 30', 'quantized: log1p(x)'),
  444. Doc('QSIN = 31', 'quantized: sin(x)'),
  445. Doc('QROUND = 32', 'quantized: round(x)'),
  446. Doc('QERF = 33', 'quantized: erf(x)'),
  447. Doc('QERFINV = 34', 'quantized: erfinv(x)'),
  448. Doc('QERFC = 35', 'quantized: erfc(x)'),
  449. Doc('QERFCINV = 36', 'quantized: erfcinv(x)'),
  450. Doc('QABS_GRAD = 37', 'quantized: abs_grad'),
  451. Doc('QFLOOR_DIV = 38', 'quantized floor_div'),
  452. Doc('QMOD = 39', 'quantized mod'),
  453. Doc('QSIGMOID_GRAD = 40', 'quantized sigmoid_grad'),
  454. Doc('QSWITCH_GT0 = 41', 'quantized switch_gt0'),
  455. Doc('QTANH_GRAD = 42', 'quantized tanh_grad'),
  456. Doc('QLT = 43', 'quantized lt'),
  457. Doc('QLEQ = 44', 'quantized leq'),
  458. Doc('QEQ = 45', 'quantized eq'),
  459. Doc('QPOW = 46', 'quantized pow'),
  460. Doc('QLOG_SUM_EXP = 47', 'quantized log_sum_exp'),
  461. Doc('QFAST_TANH_GRAD = 48', 'quantized fast_tanh_grad'),
  462. Doc('QATAN2 = 49', 'quantized atan2'),
  463. Doc('QCOND_LEQ_MOV = 50', 'quantized cond_leq_mov'),
  464. Doc('QH_SWISH = 51', 'quantized h_swish'),
  465. Doc('QFUSE_ADD_H_SWISH = 52', 'quantized h_swish(x+y)'),
  466. Doc('QH_SWISH_GRAD = 53', 'quantized h_swish_grad'),
  467. Doc('FUSE_MUL_ADD3_INT16xF32xF32xF32 = 54',
  468. 'compute ``a * b + c`` requiring that ``a`` be int16 and ``b`` and '
  469. '``c`` float32, and the result is float32.'),
  470. Doc('MUL_INT16xF32xF32 = 55',
  471. 'compute ``a * b `` requiring that ``a`` be int16 and ``b`` float32, '
  472. 'and the result is float32.'),
  473. Doc('FUSE_MUL_ADD3_UINT8xF32xF32xF32 = 56',
  474. 'compute ``a * b + c`` requiring that ``a`` be uint8 and ``b`` and '
  475. '``c`` float32, and the result is float32.')
  476. )
  477. pdef('PowC', 'power with constant exponent').add_fields('float32', 'exp', 0)
  478. (pdef('DctChannelSelect', '2d discrete cosine transform', version=0, is_legacy=True).add_enum_alias('Format', 'ConvolutionV0').
  479. add_enum('FastImpl', 'NONE = 0', 'FIX_32_MASK = 1').add_fields('int32', 'dct_block_size', 8))
  480. (pdef('DctChannelSelect', '2d discrete cosine transform', version=1).add_enum_alias('Format', 'Convolution').
  481. add_enum_alias('FastImpl', 'DctChannelSelectV0').add_fields('int32', 'dct_block_size', 8))
  482. (pdef('MatrixMul', version=0, is_legacy=True).
  483. add_fields('bool', 'transposeA', 'false', 'transposeB', 'false').
  484. add_enum('DataType',
  485. Doc('FLOAT = 0', 'input/output both float32/float16'),
  486. 'INT8x8x16 = 1',
  487. 'INT8x8x32 = 2',
  488. Doc('FLOAT_IO16xC32 = 3', 'input/output both float16, the internal compute is '
  489. 'float32'),
  490. Doc('QUINT8x8x32 = 4', 'input QuantizedAsymm8, output QuantizedS32'),
  491. Doc('QUINT4x4x32 = 5', 'input QuantizedAsymm4, output QuantizedS32'),
  492. name_field='data_type'))
  493. (pdef('MatrixMul', version=1, is_legacy=True).
  494. add_fields('bool', 'transposeA', 'false', 'transposeB', 'false').
  495. add_enum(Doc('ComputeMode', 'Specifies special computation modes, e.g. '
  496. 'different combinations of intermediate result '
  497. 'data types.'),
  498. Doc('DEFAULT = 0', 'No special requirements on the precision of '
  499. 'intermediate results.'),
  500. Doc('FLOAT32 = 1', 'Use Float32 accumulator and intermediate result. '
  501. 'Only supported when input and output is Float16.'),
  502. name_field='compute_mode'))
  503. (pdef('MatrixMul', version=2).
  504. add_fields('bool', 'transposeA', 'false', 'transposeB', 'false').
  505. add_enum_alias('ComputeMode', 'MatrixMulV1', name_field='compute_mode').
  506. add_enum('Format',
  507. Doc('DEFAULT = 0', 'Normal matrix mul: (M, K) x (K, N) = (M, N)'),
  508. Doc('MK4 = 1', 'Split 4 from M and K, better for neon compute:'
  509. '(M/4, K/4, 4(k), 4(m)) x (K/4, N, 4(k)). if transposeA the '
  510. 'layout is (K/4, M/4, 4(k), 4(m)) x (K/4, N, 4(k))'),
  511. Doc('MK8 = 2', 'Split 8 from M and K, better for neon compute:'
  512. '(M/8, K/8, 8(k), 8(m)) x (K/8, N, 8(k)). if transposeA the '
  513. 'layout is (K/8, M/8, 8(k), 8(m)) x (K/8, N, 8(k))'),
  514. Doc('MK4_DOT = 3', 'Split 4 from M and K, better for neon dotprod:'
  515. 'M/4, K/4, 4(m), 4(k)) x (K/4, N, 4(k)). if transposeA the '
  516. 'layout is (K/4, M/4, 4(m), 4(k)) x (K/4, N, 4(k))'),
  517. Doc('N32K4_DOT = 4', 'Split 32 from N and 4 from K, better for neon gevm dotprod:'
  518. 'N/32, K/4, 32(n), 4(k)')
  519. )
  520. )
  521. (pdef('SVD').
  522. add_fields('bool',
  523. Doc('full_matrices',
  524. 'Whether to compute the full-sized u and v or only the leading'
  525. ' min(m, n) singular vectors. Ignored if compute_uv is '
  526. 'false.'),
  527. 'false',
  528. Doc('compute_uv',
  529. 'Whether the left (u) and right (v) singular vectors will be '
  530. 'computed and outputted.'),
  531. 'true'))
  532. (pdef('Reduce', 'legacy reduce', version=0, is_legacy=True).
  533. add_enum('Mode',
  534. 'SUM = 0',
  535. Doc('SUM_SQR = 1', 'sum of x * x for each element x'),
  536. 'PRODUCT = 2', 'MIN = 3', 'MAX = 4').
  537. add_fields('int32',
  538. Doc('axis',
  539. 'axis along which reduction is performed; if -1 is given, '
  540. 'reduce to given target shape (only used in megbrain)'),
  541. -1))
  542. (pdef('Reduce', 'reduce along given axis', version=1, is_legacy=True).
  543. add_enum('Mode',
  544. 'SUM = 0',
  545. Doc('SUM_SQR = 1', 'sum of x * x for each element x'),
  546. 'PRODUCT = 2', 'MIN = 3', 'MAX = 4', 'MEAN = 5').
  547. add_fields('int32',
  548. Doc('axis',
  549. 'axis along which reduction is performed; if -1 is given, '
  550. 'reduce to given target shape (only used in megbrain)'),
  551. -1).
  552. add_enum('DataType',
  553. Doc('DEFAULT = 0',
  554. '''
  555. input/output are the same data type, and the internal computation type would be chosen by the input/output dtypes and the reduction mode.
  556. Currently, ```DEFAULT``` mode means:
  557. +--------------------+-----------------------------------+-------------------+
  558. | Input/Output DType | Mode | Computation DType |
  559. +====================+===================================+===================+
  560. | FLOAT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT32 |
  561. +--------------------+-----------------------------------+-------------------+
  562. | FLOAT16 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT16 |
  563. +--------------------+-----------------------------------+-------------------+
  564. | INT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT32 |
  565. +--------------------+-----------------------------------+-------------------+
  566. | INT8 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT8 |
  567. +--------------------+-----------------------------------+-------------------+
  568. | QuantizedS8 | MIN/MAX | QuantizedS8 |
  569. +--------------------+-----------------------------------+-------------------+
  570. | QuantizedS8 | MEAN/SUM | QuantizedS32 |
  571. +--------------------+-----------------------------------+-------------------+
  572. | Quantized8Asymm | MIN/MAX | Quantized8Asymm |
  573. +--------------------+-----------------------------------+-------------------+
  574. | Quantized8Asymm | MEAN/SUM | QuantizedS32 |
  575. +--------------------+-----------------------------------+-------------------+
  576. '''
  577. ),
  578. Doc('FLOAT_IO16xC32 = 1', 'Deprecated. This was replaced by '
  579. 'FLOAT_O16xC32, and input\'s dtype decided by actual input tensor.'),
  580. Doc('FLOAT_O32xC32 = 2', 'compute/output both are float32'),
  581. Doc('FLOAT_O16xC32 = 3', 'compute are float32, output float16'),
  582. Doc('QUINT_I8xO32 = 4', 'input quint8, compute and output are qint32'),
  583. Doc('QINT_I8xO32 = 5', 'input qint8, compute and output are qint32'),
  584. name_field='data_type'))
  585. (pdef('Reduce', 'reduce along given axis', version=2).
  586. add_enum('Mode',
  587. 'SUM = 0',
  588. Doc('SUM_SQR = 1', 'sum of x * x for each element x'),
  589. 'PRODUCT = 2', 'MIN = 3', 'MAX = 4', 'MEAN = 5').
  590. add_fields('int32',
  591. Doc('axis',
  592. 'axis along which reduction is performed; if INT_MAX is given, '
  593. 'reduce to given target shape (only used in megbrain)'),
  594. (1<<31)-1).
  595. add_enum('DataType',
  596. Doc('DEFAULT = 0',
  597. '''
  598. input/output are the same data type, and the internal computation type would be chosen by the input/output dtypes and the reduction mode.
  599. Currently, ```DEFAULT``` mode means:
  600. +--------------------+-----------------------------------+-------------------+
  601. | Input/Output DType | Mode | Computation DType |
  602. +====================+===================================+===================+
  603. | FLOAT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT32 |
  604. +--------------------+-----------------------------------+-------------------+
  605. | FLOAT16 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | FLOAT16 |
  606. +--------------------+-----------------------------------+-------------------+
  607. | INT32 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT32 |
  608. +--------------------+-----------------------------------+-------------------+
  609. | INT8 | MIN/MAX/MEAN/SUM/SUM_SQR/PRODUCT | INT8 |
  610. +--------------------+-----------------------------------+-------------------+
  611. | QuantizedS8 | MIN/MAX | QuantizedS8 |
  612. +--------------------+-----------------------------------+-------------------+
  613. | QuantizedS8 | MEAN/SUM | QuantizedS32 |
  614. +--------------------+-----------------------------------+-------------------+
  615. | Quantized8Asymm | MIN/MAX | Quantized8Asymm |
  616. +--------------------+-----------------------------------+-------------------+
  617. | Quantized8Asymm | MEAN/SUM | QuantizedS32 |
  618. +--------------------+-----------------------------------+-------------------+
  619. '''
  620. ),
  621. Doc('FLOAT_IO16xC32 = 1', 'Deprecated. This was replaced by '
  622. 'FLOAT_O16xC32, and input\'s dtype decided by actual input tensor.'),
  623. Doc('FLOAT_O32xC32 = 2', 'compute/output both are float32'),
  624. Doc('FLOAT_O16xC32 = 3', 'compute are float32, output float16'),
  625. Doc('QUINT_I8xO32 = 4', 'input quint8, compute and output are qint32'),
  626. Doc('QINT_I8xO32 = 5', 'input qint8, compute and output are qint32'),
  627. name_field='data_type'))
  628. (pdef('Cumsum', 'calculate accumulated sum along given axis', version=0, is_legacy=True).
  629. add_fields('int32',
  630. Doc('axis',
  631. 'axis along which cumsum is performed'),
  632. -1).
  633. add_fields('bool',
  634. Doc('exclusive',
  635. 'whether the current element is taken into account'),
  636. 'true').
  637. add_fields('bool',
  638. Doc('reverse',
  639. 'whether the cumsum is forward or backward'),
  640. 'false'))
  641. (pdef('Cumsum', 'calculate accumulated sum along given axis', version=1).
  642. add_fields('int32',
  643. Doc('axis',
  644. 'axis along which cumsum is performed, default with INT_MAX'),
  645. (1<<31)-1).
  646. add_fields('bool',
  647. Doc('exclusive',
  648. 'whether the current element is taken into account'),
  649. 'true').
  650. add_fields('bool',
  651. Doc('reverse',
  652. 'whether the cumsum is forward or backward'),
  653. 'false'))
  654. (pdef('CondTake').
  655. add_enum('Mode',
  656. Doc('EQ = 0', 'take if ``abs(data-val)<eps``'),
  657. Doc('NEQ = 1', 'take if ``abs(data-val)>=eps``'),
  658. Doc('LT = 2', 'take if ``data<val``'),
  659. Doc('LEQ = 3', 'take if ``data<=val``'),
  660. Doc('GT = 4', 'take if ``data>val``'),
  661. Doc('GEQ = 5', 'take if ``data>=val``')).
  662. add_fields('float32',
  663. Doc('val', 'the value to be compared with; note that for integer '
  664. 'data, val is also converted to int'), 0).
  665. add_fields('float32', Doc('eps', 'used for float equality comparison'),
  666. 1e-6))
  667. pdef('Argsort').add_enum('Order', 'ASCENDING = 0', 'DESCENDING = 1')
  668. (pdef('IndexingRemap').
  669. add_fields('bool',
  670. Doc('is_non_overlapping',
  671. 'Whether no two dst element maps to the same src element. '
  672. 'Enabling this option can accelerate gradient operator since'
  673. ' atomic adding operations could be avoided.'),
  674. 'false'))
  675. pdef('Sleep').add_fields('float32', Doc('time', 'time to sleep in seconds'), 0)
  676. (pdef('Linspace').
  677. add_fields('bool',
  678. Doc('endpoint',
  679. 'Whether stop is included in the generated tensor'),
  680. 'true'))
  681. (pdef('LinspaceFull').
  682. add_fields('float64',
  683. Doc('start', 'The first val.'),
  684. 0).
  685. add_fields('float64',
  686. Doc('stop', 'The last val.'),
  687. 1).
  688. add_fields('bool',
  689. Doc('endpoint',
  690. 'Whether stop is included in the generated tensor'),
  691. 'true'))
  692. (pdef('Eye').
  693. add_fields(
  694. 'int32',
  695. Doc('k', 'Index of the diagonal: 0 (the default) refers to the main '
  696. 'diagonal, a positive value refers to an upper diagonal, and a '
  697. 'negative value to a lower diagonal.'),
  698. 0).
  699. add_fields(
  700. 'dtype', Doc('dtype', 'data type of output value'),
  701. 'DTypeEnum::Float32'))
  702. (pdef('Diag').
  703. add_fields(
  704. 'int32',
  705. Doc('k', 'Index of the diagonal: 0 (the default) refers to the main '
  706. 'diagonal, a positive value refers to an upper diagonal, and a '
  707. 'negative value to a lower diagonal.'),
  708. 0))
  709. (pdef('UniformRNG', version=0, is_legacy=True).
  710. add_fields('uint64', 'seed', 0))
  711. (pdef('UniformRNG', version=1).
  712. add_fields('uint64', 'seed', 0).
  713. add_fields(
  714. 'dtype', Doc('dtype', 'The dtype of output Tensor. Only support Float32.'),
  715. 'DTypeEnum::Float32'))
  716. (pdef('GaussianRNG', version=0, is_legacy=True).
  717. add_fields('uint64', 'seed', 0).
  718. add_fields('float32', 'mean', 0, 'std', 1))
  719. (pdef('GaussianRNG', version=1).
  720. add_fields('uint64', 'seed', 0).
  721. add_fields('float32', 'mean', 0, 'std', 1).
  722. add_fields(
  723. 'dtype', Doc('dtype', 'The dtype of output Tensor. Only support Float32.'),
  724. 'DTypeEnum::Float32'))
  725. (pdef('GammaRNG').
  726. add_fields('uint64', 'seed', 0))
  727. (pdef('BetaRNG').
  728. add_fields('uint64', 'seed', 0))
  729. (pdef('PoissonRNG').
  730. add_fields('uint64', 'seed', 0))
  731. (pdef('PermutationRNG').
  732. add_fields('uint64', 'seed', 0).
  733. add_fields(
  734. 'dtype', Doc('dtype', 'The dtype of output Tensor. Int32, Int16 and '
  735. 'Float32 are supported.'),
  736. 'DTypeEnum::Int32'))
  737. (pdef('ShuffleRNG').
  738. add_fields('uint64', 'seed', 0))
  739. (pdef('Flip').
  740. add_fields('bool', 'vertical', 'false', 'horizontal', 'false'))
  741. (pdef('Rotate')
  742. .add_fields('bool', 'clockwise', 'true'))
  743. (pdef('ROICopy')
  744. .add_fields('uint32', 'row_from', 0, 'row_to', 0, 'col_from', 0, 'col_to', 0))
  745. (pdef('CvtColor')
  746. .add_enum('Mode', 'RGB2GRAY = 0', 'RGB2YUV = 1', 'YUV2RGB = 2', 'GRAY2RGB = 3', 'RGBA2RGB = 4',
  747. 'RGBA2BGR = 5', 'RGBA2GRAY = 6', 'RGB2BGR = 7', 'BGR2GRAY = 8', 'BGR2RGB = 9',
  748. Doc('YUV2GRAY_NV21 = 10', 'For historical reasons, referred to as YCC by opencv'),
  749. 'YUV2RGB_NV21 = 11', 'YUV2BGR_NV21 = 12', 'YUV2GRAY_NV12 = 13', 'YUV2RGB_NV12 = 14',
  750. 'YUV2BGR_NV12 = 15', 'YUV2GRAY_YV12 = 16', 'YUV2RGB_YV12 = 17', 'YUV2BGR_YV12 = 18',
  751. 'YUV2GRAY_YU12 = 19', 'YUV2RGB_YU12 = 20', 'YUV2BGR_YU12 = 21',
  752. 'YCrCb2RGB = 22', 'YCrCb2BGR = 23',
  753. Doc('BT601_YUV2RGB_NV21 = 24', 'BT601 yuv format, referred to as YUV by opencv'),
  754. 'BT601_YUV2BGR_NV21 = 25', 'BT601_YUV2RGB_NV12 = 26', 'BT601_YUV2BGR_NV12 = 27',
  755. 'BT601_YUV2RGB_YV12 = 28', 'BT601_YUV2BGR_YV12 = 29', 'BT601_YUV2RGB_YU12 = 30',
  756. 'BT601_YUV2BGR_YU12 = 31',
  757. member_alias=[('YUV2GRAY_NV21', 'BT601_YUV2GRAY_NV21'),
  758. ('YUV2GRAY_NV12', 'BT601_YUV2GRAY_NV12'),
  759. ('YUV2GRAY_YV12', 'BT601_YUV2GRAY_YV12'),
  760. ('YUV2GRAY_YU12', 'BT601_YUV2GRAY_YU12')],
  761. name_field = 'mode'))
  762. (pdef('WarpAffine', version=0, is_legacy=True)
  763. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  764. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  765. .add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f'))
  766. (pdef('WarpAffine', version=1, is_legacy=True)
  767. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  768. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  769. .add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f')
  770. .add_enum_alias('Format', 'ConvolutionV0', default=1))
  771. (pdef('WarpAffine', version=2)
  772. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  773. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  774. .add_fields('float32', Doc('border_val', 'used for CONSTANT bmode'), '.0f')
  775. .add_enum_alias('Format', 'Convolution', default=1))
  776. (pdef('GaussianBlur')
  777. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_mode')
  778. .add_fields('uint32', 'kernel_height', 0, 'kernel_width', 0)
  779. .add_fields('float32','sigma_x', '0.f', 'sigma_y', '0.f'))
  780. (pdef('Resize', version=0, is_legacy=True)
  781. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode'))
  782. (pdef('Resize', version=1, is_legacy=True)
  783. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  784. .add_enum_alias('Format', 'ConvolutionV0', default=1))
  785. (pdef('Resize', version=2)
  786. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  787. .add_enum_alias('Format', 'Convolution', default=1))
  788. (pdef('Remap', version=0,is_legacy=True)
  789. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  790. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_type')
  791. .add_enum_alias('Format', 'ConvolutionV0', default=1)
  792. .add_fields('float32', 'scalar', '0.f'))
  793. (pdef('Remap', version=1)
  794. .add_enum_alias('InterpolationMode', 'WarpPerspectiveV1', name_field='imode')
  795. .add_enum_alias('BorderMode', 'WarpPerspectiveV1', name_field='border_type')
  796. .add_enum_alias('Format', 'Convolution', default=1)
  797. .add_fields('float32', 'scalar', '0.f'))
  798. (pdef('Convolution3D').
  799. add_enum('Mode', 'CROSS_CORRELATION = 0', 'CONVOLUTION = 1').
  800. add_fields(
  801. 'uint32',
  802. Doc('pad_d', 'padding on one side on the first dimension'), 0,
  803. Doc('pad_h', 'padding on one side on the second dimension'), 0,
  804. Doc('pad_w', 'padding on one side on the third dimension'), 0,
  805. Doc('stride_d', 'kernel stride on the first dimension'), 1,
  806. Doc('stride_h', 'kernel stride on the second dimension'), 1,
  807. Doc('stride_w', 'kernel stride on the third dimension'), 1,
  808. Doc('dilate_d', 'dilation (i.e. size of each zero-padded kernel block) '
  809. 'on the first dimension'), 1,
  810. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  811. 'on the second dimension'), 1,
  812. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  813. 'on the third dimension'), 1
  814. ).
  815. add_enum('Sparse',
  816. Doc('DENSE = 0', 'dense convolution: filter shape should be '
  817. '[oc, ic, spatial...] if format is NCDHW, '
  818. '[oc, spatial..., ic] if format is NDHWC'),
  819. Doc('GROUP = 1', 'group convolution: filter shape should be '
  820. '[group, oc_per_group, ic_per_group, spatial...] if format is NCDHW, '
  821. '[group, oc_per_group, spatial..., ic_per_group] if format is NDHWC')
  822. ).
  823. add_enum('DataType',
  824. Doc('FLOAT = 0', 'input/output both float32/float16'),
  825. Doc('FLOAT_IO16xC32 = 1', 'input/output both float16, the internal '
  826. 'compute is float32'),
  827. name_field='data_type').
  828. add_enum('Format', 'NCDHW = 0', 'NDHWC = 1')
  829. )
  830. (pdef('Conv3DBias').
  831. add_enum('NonlineMode', 'IDENTITY = 0', 'RELU = 1', 'SIGMOID = 2').
  832. add_enum_alias('Mode', 'Convolution3D').
  833. add_fields('uint32', 'pad_d', 0, 'pad_h', 0, 'pad_w', 0,
  834. 'stride_d', 1, 'stride_h', 1, 'stride_w', 0))
  835. (pdef('SeparableConv3D').
  836. add_enum_alias('Mode', 'Convolution3D').
  837. add_enum('BorderMode', 'BORDER_REPLICATE = 0', 'BORDER_REFLECT = 1',
  838. 'BORDER_REFLECT_101 = 2','BORDER_WRAP = 3',
  839. 'BORDER_CONSTANT = 4', 'BORDER_TRANSPARENT = 5','BORDER_ISOLATED = 6').
  840. add_fields('bool', 'is_symm_kernel', 'true').
  841. add_fields('uint32', 'pad_d', 0, 'pad_h', 0, 'pad_w', 0,
  842. 'stride_d', 0, 'stride_h', 1, 'stride_w', 1,
  843. 'ksize_d', 0, 'ksize_h', 3, 'ksize_w', 3,
  844. 'anchor_d', 0, 'anchor_h', 1, 'anchor_w', 1))
  845. (pdef('TopK').
  846. add_enum(
  847. 'Mode',
  848. Doc('KTH_ONLY = 0', "only the value of the k'th element would be computed"),
  849. Doc('VALUE_IDX_NOSORT = 1',
  850. 'all the top-k values and corresponding indices would be computed; '
  851. 'no order is guaranteed'),
  852. Doc('VALUE_IDX_SORTED = 2',
  853. 'all the top-k values and corresponding indices sorted'))
  854. )
  855. RELAYOUT_FORMAT_MODE_DOC = """
  856. Relayout mode.
  857. **Naming conventions**
  858. 1. ``A_B`` means change from layout format ``A`` to ``B``.
  859. 2. ``INTER_WEIGHT_xx`` means relayout the weight for faster processing by
  860. :attr:`Convolution.Format.NHWCD4` convolutions.
  861. 3. A suffix of ``I`` means ``Image2DPack4TensorFormat`` tensor format is used
  862. for faster processing on GPUs.
  863. **Layout definitions**
  864. * ``NCHW`` layout: ``{N, C, H, W}``
  865. * ``NHWC`` layout: ``{N, H, W, C}``
  866. * ``NHWCD4`` layout: ``{N, H, (C + 3) / 4, W, 4}``
  867. * ``NHWCD4I`` layout: with ``align_axis = 2``
  868. * ``NCHW4`` layout: ``{N, C/4, H, W, 4}``
  869. * ``NCHW88`` layout: ``{N, C/8, H, W, 8}``
  870. * ``CHWN4`` layout: ``{C/4, H, W, N, 4}``
  871. * ``NCHW64`` layout: ``{N, C/64, H, W, 64}``
  872. **Float weight transformation definitions**
  873. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  874. | Sparsity Type | Input Layout | Input Req | Output Layout | Axis |
  875. +===============+=================================+====================+======================================+======+
  876. | DENSE | ``{OC, IC, FH, FW}`` | ``OC % 4 == 0`` | ``{OC/4, FH, FW, IC, 4}`` | 3 |
  877. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  878. | GROUP | ``{GROUP, OCPG, ICPG, FH, FW}`` | ``OCPG % 4 == 0`` | ``{GROUP, OCPG/4, FH, FW, ICPG, 4}`` | 4 |
  879. | | | ``ICPG % 4 == 0`` | | |
  880. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  881. | CHAN | ``{GROUP, 1, 1, FH, FW}`` | ``GROUP % 4 == 0`` | ``{GROUP / 4, 1, FH ,FW, 4}`` | 1 |
  882. +---------------+---------------------------------+--------------------+--------------------------------------+------+
  883. **Float weight transformation nchw88 definitions**
  884. +---------------+---------------------------------+--------------------+--------------------------------------+
  885. | Sparsity Type | Input Layout | Input Req | Output Layout |
  886. +===============+=================================+====================+======================================+
  887. | DENSE | ``{OC, IC, FH, FW}`` | ``OC % 8 == 0`` |``{OC/8, IC/8 ,FH, FW, 8(IC), 8(OC)}``|
  888. | | | ``IC % 8 == 0`` | |
  889. +---------------+---------------------------------+--------------------+--------------------------------------+
  890. | GROUP | ``{GROUP, OCPG, ICPG, FH, FW}`` | ``OCPG % 8 == 0`` | ``{GROUP, OCPG/8, ICPG/8 FH, FW, |
  891. | | | ``ICPG % 8 == 0`` | 8(ICPG), 8(OCPG)} `` |
  892. +---------------+---------------------------------+--------------------+--------------------------------------+
  893. | CHAN | ``{GROUP, 1, 1, FH, FW}`` | ``GROUP % 8 == 0`` | ``{GROUP / 8, 1, FH ,FW, 8}`` |
  894. +---------------+---------------------------------+--------------------+--------------------------------------+
  895. **Int8(DOT) weight transformation definitions**
  896. +---------------+---------------------------------+--------------------+------------------------------------------+------+
  897. | Sparsity Type | Input Layout | Input Req | Output Layout | Axis |
  898. +===============+=================================+====================+==========================================+======+
  899. | DENSE | ``{OC, IC, FH, FW}`` | ``OC % 4 == 0`` | ``{OC/4, FH, FW, IC/4, 4, 4}` | 3 |
  900. +---------------+---------------------------------+--------------------+------------------------------------------+------+
  901. | GROUP | ``{GROUP, OCPG, ICPG, FH, FW}`` | ``OCPG % 4 == 0`` | ``{GROUP, OCPG/4, FH, FW, ICPG/4, 4, 4}``| 4 |
  902. | | | ``ICPG % 4 == 0`` | | |
  903. +---------------+---------------------------------+--------------------+------------------------------------------+------+
  904. Note: the axis column means the corresponding ``align_axis`` for image format
  905. when the ``I`` suffix is present.
  906. 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
  907. """
  908. (pdef('RelayoutFormat', 'Change the tensor layout format', version=0, is_legacy=True).
  909. add_enum(
  910. Doc('Mode', RELAYOUT_FORMAT_MODE_DOC),
  911. 'NHWC_NHWCD4 = 0',
  912. 'NHWCD4_NHWC = 1',
  913. 'NHWC_NHWCD4I = 2',
  914. 'NCHW_NHWCD4 = 3',
  915. 'NCHW_NHWCD4I = 4',
  916. 'NHWCD4I_NCHW = 5',
  917. 'NHWCD4_NCHW = 6',
  918. 'INTER_WEIGHT_DENSE = 7',
  919. 'INTER_WEIGHT_DENSEI = 8',
  920. 'INTER_WEIGHT_GROUP = 9',
  921. 'INTER_WEIGHT_GROUPI = 10',
  922. 'INTER_WEIGHT_CHAN = 11',
  923. 'INTER_WEIGHT_CHANI = 12',
  924. 'INTER_WEIGHT_DENSEI_DOT = 13',
  925. 'INTER_WEIGHT_GROUPI_DOT = 14',
  926. 'NCHW4_CHWN4 = 15',
  927. 'CHWN4_NCHW4 = 16',
  928. 'NCHW_NCHW88_CONV_DENSE_WEIGHT = 17',
  929. 'NCHW_NCHW88_CONV_CHAN_WEIGHT = 18',
  930. 'NCHW_NCHW88_CONV_GROUP_WEIGHT = 19',
  931. 'NCHW_NCHW88 = 20',
  932. 'NCHW88_NCHW = 21',
  933. 'NCHW_NCHW4_IC_SMALL = 22',
  934. 'NCHW_NCHW4_IC_SMALL_CONV_DENSE_WEIGHT = 23',
  935. 'NCHW_NCHW4 = 24',
  936. 'NCHW4_NCHW = 25',
  937. 'NCHW_NCHW4_WEIGHT = 26',
  938. 'NCHW_NCHW64 = 27',
  939. 'NCHW64_NCHW = 28',
  940. 'NCHW_NHWC = 29',
  941. 'NHWC_NCHW = 30',
  942. 'NHWCD4I_NHWC = 31',
  943. )
  944. )
  945. (pdef('RelayoutFormat', 'Change the tensor layout format', version=1).
  946. add_enum_alias('Mode', 'RelayoutFormatV0').
  947. add_fields('uint32', 'oc', '0').
  948. add_fields('uint32', 'group', '1')
  949. )
  950. (pdef('SeparableFilter', version=0, is_legacy=True).
  951. add_enum_alias('Format', 'ConvolutionV0').
  952. add_enum_alias('BorderMode', 'WarpPerspectiveV1').
  953. add_fields('bool', 'is_symm_kernel', 'true').
  954. add_fields('uint32', 'ksize_h', 3, 'ksize_w', 3, 'anchor_h', 1, 'anchor_w', 1))
  955. (pdef('SeparableFilter', version=1).
  956. add_enum_alias('Format', 'Convolution').
  957. add_enum_alias('BorderMode', 'WarpPerspectiveV1').
  958. add_fields('bool', 'is_symm_kernel', 'true').
  959. add_fields('uint32', 'ksize_h', 3, 'ksize_w', 3, 'anchor_h', 1, 'anchor_w', 1))
  960. (pdef('LocalShare', 'Local share convolution',version=0, is_legacy=True).
  961. add_enum_alias('Mode', 'ConvolutionV0').
  962. add_fields(
  963. 'uint32',
  964. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  965. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  966. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  967. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  968. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  969. 'on the second dimension'), 1,
  970. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  971. 'on the second dimension'), 1,
  972. Doc('spatial_groups_h', 'spatial groups on the first dimension'), 1,
  973. Doc('spatial_groups_w', 'spatial groups on the second dimension'), 1
  974. ).
  975. add_enum_alias('Sparse', 'ConvolutionV0').
  976. add_enum_alias('Format', 'ConvolutionV0').
  977. add_enum_alias('ComputeMode', 'ConvolutionV1')
  978. )
  979. (pdef('LocalShare', 'Local share convolution', version=1).
  980. add_enum_alias('Mode', 'ConvolutionV0').
  981. add_fields(
  982. 'uint32',
  983. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  984. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  985. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  986. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  987. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  988. 'on the second dimension'), 1,
  989. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  990. 'on the second dimension'), 1,
  991. Doc('spatial_groups_h', 'spatial groups on the first dimension'), 1,
  992. Doc('spatial_groups_w', 'spatial groups on the second dimension'), 1
  993. ).
  994. add_enum_alias('Sparse', 'ConvolutionV0').
  995. add_enum_alias('Format', 'Convolution').
  996. add_enum_alias('ComputeMode', 'ConvolutionV1')
  997. )
  998. (pdef('ROIAlign',version=0,is_legacy=True).
  999. add_enum('Mode', 'MAX = 0', 'AVERAGE = 1', name_field='mode').
  1000. add_enum_alias('Format', 'ConvolutionV0').
  1001. add_fields('float32', 'spatial_scale', '1.0').
  1002. add_fields('float32', 'offset', '0.0').
  1003. add_fields('uint32',
  1004. 'pooled_height', '1',
  1005. 'pooled_width', '1',
  1006. 'sample_height', '2',
  1007. 'sample_width', '2')
  1008. )
  1009. (pdef('ROIAlign', version=1).
  1010. add_enum_alias('Mode', 'ROIAlignV0', name_field='mode').
  1011. add_enum_alias('Format', 'Convolution').
  1012. add_fields('float32', 'spatial_scale', '1.0').
  1013. add_fields('float32', 'offset', '0.0').
  1014. add_fields('uint32',
  1015. 'pooled_height', '1',
  1016. 'pooled_width', '1',
  1017. 'sample_height', '2',
  1018. 'sample_width', '2')
  1019. )
  1020. (pdef('Correlation').
  1021. add_enum_alias('Format', 'ConvolutionV0').
  1022. add_fields('uint32', 'kernel_size', '1').
  1023. add_fields('uint32', 'max_displacement', '1').
  1024. add_fields('uint32', 'stride1', '1').
  1025. add_fields('uint32', 'stride2', '1').
  1026. add_fields('uint32', 'pad_size', '0').
  1027. add_fields('bool', 'is_multiply', 'true')
  1028. )
  1029. (pdef('DeformablePSROIPooling').
  1030. add_fields('bool', 'no_trans', 'true').
  1031. add_fields('float32', 'spatial_scale', 1,
  1032. 'trans_std', 1).
  1033. add_fields('uint32',
  1034. Doc('pooled_h', 'height of pooling output'), 1,
  1035. Doc('pooled_w', 'width of pooling output'), 1,
  1036. Doc('part_size', 'size of each deformable part'), 1,
  1037. Doc('sample_per_part', 'sample count of each bbox'), 1))
  1038. (pdef('BatchConvBias', 'Batch convolution (unshare weights on the batch dimension)',version=0,is_legacy=True).
  1039. add_enum_alias('NonlineMode', 'ConvBiasV0').
  1040. add_enum_alias('Mode', 'ConvolutionV0').
  1041. add_fields(
  1042. 'uint32',
  1043. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  1044. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  1045. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  1046. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  1047. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  1048. 'on the second dimension'), 1,
  1049. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  1050. 'on the second dimension'), 1,
  1051. ).
  1052. add_enum_alias('Sparse', 'ConvolutionV0').
  1053. add_enum_alias('Format', 'ConvolutionV0').
  1054. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field="compute_mode")
  1055. )
  1056. (pdef('BatchConvBias', 'Batch convolution (unshare weights on the batch dimension)',version=1).
  1057. add_enum_alias('NonlineMode', 'ConvBiasV0').
  1058. add_enum_alias('Mode', 'ConvolutionV0').
  1059. add_fields(
  1060. 'uint32',
  1061. Doc('pad_h', 'padding on one side on the first dimension'), 0,
  1062. Doc('pad_w', 'padding on one side on the second dimension'), 0,
  1063. Doc('stride_h', 'kernel stride on the first dimension'), 1,
  1064. Doc('stride_w', 'kernel stride on the second dimension'), 1,
  1065. Doc('dilate_h', 'dilation (i.e. size of each zero-padded kernel block) '
  1066. 'on the second dimension'), 1,
  1067. Doc('dilate_w', 'dilation (i.e. size of each zero-padded kernel block) '
  1068. 'on the second dimension'), 1,
  1069. ).
  1070. add_enum_alias('Sparse', 'ConvolutionV0').
  1071. add_enum_alias('Format', 'Convolution').
  1072. add_enum_alias('ComputeMode', 'ConvolutionV1', name_field="compute_mode")
  1073. )
  1074. (pdef('FakeQuant').
  1075. add_fields('int32','qmin','-2147483648').
  1076. add_fields('int32','qmax','2147483647')
  1077. )
  1078. (pdef('TQT').
  1079. add_fields('int32', 'qmin', '-2147483648').
  1080. add_fields('int32', 'qmax', '2147483647')
  1081. )
  1082. (pdef('LSQ').
  1083. add_fields('int32', 'qmin', '-2147483648').
  1084. add_fields('int32', 'qmax', '2147483647')
  1085. )
  1086. pdef('Fill').add_fields('float32', 'value', '0')
  1087. pdef('CheckNonFinite').add_fields('float32', 'scale', '1.0')
  1088. PADDING_MODES = [Doc('REPLICATE = 0', 'aaaaaa|abcdefgh|hhhhhhh'),
  1089. Doc('REFLECT = 1', 'fedcba|abcdefgh|hgfedcb'),
  1090. Doc('CONSTANT = 2', 'iiiiii|abcdefgh|iiiiiii')]
  1091. (pdef('Padding').
  1092. add_fields('uint32', Doc('front_offset_dim0','offset in dim 0'), 0).
  1093. add_fields('uint32', Doc('front_offset_dim1','offset in dim 1'), 0).
  1094. add_fields('uint32', Doc('front_offset_dim2','offset in dim 2'), 0).
  1095. add_fields('uint32', Doc('front_offset_dim3','offset in dim 3'), 0).
  1096. add_fields('uint32', Doc('front_offset_dim4','offset in dim 4'), 0).
  1097. add_fields('uint32', Doc('front_offset_dim5','offset in dim 5'), 0).
  1098. add_fields('uint32', Doc('front_offset_dim6','offset in dim 6'), 0).
  1099. add_fields('uint32', Doc('back_offset_dim0', 'back offset in dim0'), 0).
  1100. add_fields('uint32', Doc('back_offset_dim1', 'back offset in dim1'), 0).
  1101. add_fields('uint32', Doc('back_offset_dim2', 'back offset in dim2'), 0).
  1102. add_fields('uint32', Doc('back_offset_dim3', 'back offset in dim3'), 0).
  1103. add_fields('uint32', Doc('back_offset_dim4', 'back offset in dim4'), 0).
  1104. add_fields('uint32', Doc('back_offset_dim5', 'back offset in dim5'), 0).
  1105. add_fields('uint32', Doc('back_offset_dim6', 'back offset in dim6'), 0).
  1106. add_fields('float32', Doc('padding_val','param of padding opr'), 0).
  1107. add_enum('PaddingMode', *PADDING_MODES,
  1108. name_field='padding_mode', default=2,
  1109. member_alias=[(i, 'PADDING_{}'.format(i)) for i in PADDING_MODES]
  1110. )
  1111. )
  1112. (pdef('LayerNorm')
  1113. .add_fields('bool', 'affine', 'true')
  1114. .add_fields('float32', 'eps', '1e-5f')
  1115. .add_fields('uint64', 'normalized_dim', '1')
  1116. .add_fields('uint64', 'normalized_size', '1')
  1117. )
  1118. (pdef('Dropout')
  1119. .add_fields('float32', 'drop_prob', '0')
  1120. .add_fields('uint64', 'seed', '0')
  1121. )
  1122. (pdef('RNNCell').
  1123. add_enum('NonlineMode', 'IDENTITY = 0', 'RELU = 1', 'TANH = 2')
  1124. )
  1125. (pdef('RNN').
  1126. add_fields('uint32', Doc('num_layers', 'Number of recurrent layers'), '1').
  1127. add_fields('bool', Doc('bidirectional', 'If becomes a bidirectional RNN'), 'false').
  1128. add_fields('bool', Doc('bias', 'If the layer use bias weights b_ih and b_hh'), 'true').
  1129. add_fields('uint32', Doc('hidden_size', 'The number of features in the hidden state'), '128').
  1130. add_fields('float32', Doc('dropout', 'If introduce a Dropout layer on the outputs of each RNN layer'), '0.f').
  1131. add_enum_alias('NonlineMode', 'RNNCell').
  1132. add_enum_alias('FwdMode', 'BN', name_field='fwd_mode')
  1133. )
  1134. (pdef('LSTM').
  1135. add_fields('uint32', Doc('num_layers', 'Number of recurrent layers'), '1').
  1136. add_fields('bool', Doc('bidirectional', 'If becomes a bidirectional LSTM'), 'false').
  1137. add_fields('bool', Doc('bias', 'If the layer use bias weights b_ih and b_hh'), 'true').
  1138. add_fields('uint32', Doc('hidden_size', 'The number of features in the hidden state'), '128').
  1139. add_fields('uint32', Doc('proj_size', 'If use LSTM with projections of corresponding size'), '0').
  1140. add_fields('float32', Doc('dropout', 'If introduce a Dropout layer on the outputs of each LSTM layer'), '0.f').
  1141. add_enum_alias('FwdMode', 'BN', name_field='fwd_mode')
  1142. )
  1143. (pdef('LAMBUpdate').
  1144. add_fields('float32', Doc('beta_1', 'beta_1 paramter of lamb'), '1.f').
  1145. add_fields('float32', Doc('beta_2', 'beta_2 paramter of lamb'), '1.f').
  1146. add_fields('float32', Doc('step', 'training step'), '1.f').
  1147. add_fields('float32', Doc('lr', 'learning rate'), '1.f').
  1148. add_fields('float32', Doc('weight_decay', 'weight decay to adjust learning rate'), '1.f').
  1149. add_fields('float32', Doc('eps', 'eps to multi'), '1.f').
  1150. add_fields('bool', Doc('bias_correction', 'whether correct bias'), 'true').
  1151. add_fields('bool', Doc('always_adapt', 'apply adaptive lr to 0.0'), 'false')
  1152. )