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.

ops.td 7.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /**
  2. * \file src/core/include/megbrain/ir/ops.td
  3. * MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
  4. *
  5. * Copyright (c) 2014-2021 Megvii Inc. All rights reserved.
  6. *
  7. * Unless required by applicable law or agreed to in writing,
  8. * software distributed under the License is distributed on an
  9. * "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or
  10. * implied.
  11. */
  12. #ifndef MGB_OPS
  13. #define MGB_OPS
  14. include "base.td"
  15. include "param_defs.td"
  16. include "mlir/Interfaces/SideEffectInterfaces.td"
  17. def Elemwise : MgbHashableOp<"Elemwise", [ElemwiseParam], [NoSideEffect]> {
  18. let inputs = (ins Variadic<AnyType>:$input);
  19. let results = (outs AnyType);
  20. let usingModeName = 1;
  21. }
  22. def Reduce: MgbHashableOp<"Reduce", [ReduceParam]>;
  23. def TypeCvt: MgbHashableOp<"TypeCvt", [], [NoSideEffect]> {
  24. let inputs = (ins AnyType:$inputs);
  25. let extraArguments = (ins
  26. TypeAttr:$idtype,
  27. MgbDTypeAttr:$dtype
  28. );
  29. let results = (outs AnyType);
  30. }
  31. def MatrixInverse: MgbHashableOp<"MatrixInverse", [EmptyParam]>;
  32. def MatrixMul: MgbHashableOp<"MatrixMul", [MatrixMulParam, ExecutionPolicyParamBase<"policy">]>;
  33. def BatchedMatrixMul: MgbHashableOp<"BatchedMatmul", [MatrixMulParam, ExecutionPolicyParamBase<"policy">]>;
  34. def Dot: MgbHashableOp<"Dot", [EmptyParam]>;
  35. def SVD: MgbHashableOp<"SVD", [SVDParam]>;
  36. def Convolution : MgbHashableOp<"Convolution", [ConvolutionParam, ExecutionPolicyParamBase<"policy">]>;
  37. def ConvolutionBackwardData: MgbHashableOp<"ConvolutionBackwardData", [ConvolutionParam, ExecutionPolicyParamBase<"policy">]>;
  38. def DeformableConv : MgbHashableOp<"DeformableConv", [ConvolutionParam, ExecutionPolicyParamBase<"policy">]>;
  39. def GroupLocal: MgbHashableOp<"GroupLocal", [ConvolutionParam]>;
  40. def Pooling: MgbHashableOp<"Pooling", [PoolingParam]>;
  41. def AdaptivePooling : MgbHashableOp<"AdaptivePooling", [AdaptivePoolingParam]>;
  42. def ROIPooling: MgbHashableOp<"ROIPooling", [ROIPoolingParam]>;
  43. def DeformablePSROIPooling : MgbHashableOp<"DeformablePSROIPooling", [DeformablePSROIPoolingParam]>;
  44. def ConvBias : MgbHashableOp<"ConvBias", [ConvBiasParam, ExecutionPolicyParamBase<"policy">]> {
  45. let extraArguments = (ins
  46. MgbDTypeAttr:$dtype
  47. );
  48. }
  49. def BatchConvBias : MgbHashableOp<"BatchConvBias", [BatchConvBiasParam, ExecutionPolicyParamBase<"policy">]> {
  50. let extraArguments = (ins
  51. MgbDTypeAttr:$dtype
  52. );
  53. }
  54. def BatchNorm : MgbHashableOp<"BatchNorm", [BNParam]>;
  55. def ROIAlign: MgbHashableOp<"ROIAlign", [ROIAlignParam]>;
  56. def WarpPerspective: MgbHashableOp<"WarpPerspective", [WarpPerspectiveParam]>;
  57. def WarpAffine: MgbHashableOp<"WarpAffine", [WarpAffineParam]>;
  58. def Remap: MgbHashableOp<"Remap", [RemapParam]>;
  59. def Resize: MgbHashableOp<"Resize", [ResizeParam]>;
  60. def IndexingOneHot: MgbHashableOp<"IndexingOneHot", [AxisParam]>;
  61. def IndexingSetOneHot: MgbHashableOp<"IndexingSetOneHot", [AxisParam]>;
  62. def Copy: MgbHashableOp<"Copy"> {
  63. let extraArguments = (ins
  64. MgbCompNodeAttr:$comp_node
  65. );
  66. }
  67. def Argsort: MgbHashableOp<"Argsort", [ArgsortParam]>;
  68. def Argmax : MgbHashableOp<"Argmax", [AxisParam]>;
  69. def Argmin : MgbHashableOp<"Argmin", [AxisParam]>;
  70. def CondTake : MgbHashableOp<"CondTake">;
  71. def TopK: MgbHashableOp<"TopK", [TopKParam]>;
  72. def NvOf: MgbHashableOp<"NvOf", [NvOfParam]>;
  73. def UniformRNG: MgbHashableOp<"UniformRNG", [UniformRNGParam]> {
  74. let hashFunction = [{return mgb::hash($_self.dyn_typeinfo());}];
  75. let cmpFunction = [{return true;}];
  76. }
  77. def GaussianRNG: MgbHashableOp<"GaussianRNG", [GaussianRNGParam]> {
  78. let hashFunction = [{
  79. return mgb::hash_pair_combine(
  80. mgb::hash($_self.dyn_typeinfo()),
  81. mgb::hash_pair_combine(mgb::hash($_self.mean), mgb::hash($_self.std)));
  82. }];
  83. let cmpFunction = [{return $0.mean == $1.mean && $0.std == $1.std;}];
  84. }
  85. def Linspace: MgbHashableOp<"Linspace", [LinspaceParam]> {
  86. let extraArguments = (ins
  87. MgbCompNodeAttr:$comp_node
  88. );
  89. }
  90. def Eye: MgbHashableOp<"Eye", [EyeParam]> {
  91. let extraArguments = (ins
  92. MgbCompNodeAttr:$comp_node
  93. );
  94. }
  95. def GetVarShape : MgbHashableOp<"GetVarShape", [OptionalAxisV1Param]>;
  96. def Concat: MgbHashableOp<"Concat", [AxisParam]> {
  97. let extraArguments = (ins
  98. MgbCompNodeAttr:$comp_node
  99. );
  100. }
  101. def Broadcast : MgbHashableOp<"Broadcast", [EmptyParam]>;
  102. def Identity: MgbHashableOp<"Identity">;
  103. def CollectiveComm : MgbHashableOp<"CollectiveComm", [CollectiveCommParam]> {
  104. let extraArguments = (ins
  105. MgbStringAttr:$key,
  106. MgbUI32Attr:$nr_devices,
  107. MgbUI32Attr:$rank,
  108. MgbBoolAttr:$is_root,
  109. MgbBoolAttr:$local_grad,
  110. MgbStringAttr:$addr,
  111. MgbUI32Attr:$port,
  112. MgbDTypeAttr:$dtype,
  113. MgbStringAttr:$backend,
  114. MgbStringAttr:$comp_node
  115. );
  116. }
  117. def RemoteSend : MgbHashableOp<"RemoteSend"> {
  118. let extraArguments = (ins
  119. MgbStringAttr:$key,
  120. MgbStringAttr:$addr,
  121. MgbUI32Attr:$port,
  122. MgbUI32Attr:$rank_to
  123. );
  124. }
  125. def RemoteRecv : MgbHashableOp<"RemoteRecv"> {
  126. let extraArguments = (ins
  127. MgbStringAttr:$key,
  128. MgbStringAttr:$addr,
  129. MgbUI32Attr:$port,
  130. MgbUI32Attr:$rank_from,
  131. MgbCompNodeAttr:$cn,
  132. MgbTensorShapeAttr:$shape,
  133. MgbDTypeAttr:$dtype
  134. );
  135. }
  136. def NMSKeep : MgbHashableOp<"NMSKeep"> {
  137. let extraArguments = (ins
  138. MgbF32Attr:$iou_thresh,
  139. MgbUI32Attr:$max_output
  140. );
  141. }
  142. def ParamPackSplit : MgbHashableOp<"ParamPackSplit"> {
  143. let extraArguments = (ins
  144. MgbArrayAttr<MgbI32Attr>:$offsets,
  145. MgbArrayAttr<MgbArrayAttr<MgbSizeTAddr>>:$shapes
  146. );
  147. }
  148. def ParamPackConcat : MgbHashableOp<"ParamPackConcat"> {
  149. let extraArguments = (ins
  150. MgbArrayAttr<MgbI32Attr>:$offsets
  151. );
  152. }
  153. def Dimshuffle: MgbHashableOp<"Dimshuffle"> {
  154. let inputs = (ins AnyMemRef:$input);
  155. let extraArguments = (ins MgbArrayAttr<MgbI32Attr>:$pattern);
  156. let results = (outs AnyMemRef);
  157. }
  158. def Reshape: MgbHashableOp<"Reshape", [OptionalAxisV1Param]>;
  159. // TODO: merge Add/Remove Axis into AxisAddRemove as megbrain?
  160. def AddAxis: MgbHashableOp<"AddAxis"> {
  161. let extraArguments = (ins
  162. MgbArrayAttr<MgbI32Attr>:$axis
  163. );
  164. }
  165. def RemoveAxis: MgbHashableOp<"RemoveAxis"> {
  166. let extraArguments = (ins
  167. MgbArrayAttr<MgbI32Attr>:$axis
  168. );
  169. }
  170. class FancyIndexingBase<string name>: MgbHashableOp<name> {
  171. let extraArguments = (ins
  172. MgbArrayAttr<MgbTupleAttr<
  173. [MgbI8Attr, MgbBoolAttr, MgbBoolAttr, MgbBoolAttr, MgbBoolAttr]>>:$items
  174. );
  175. }
  176. def Subtensor: FancyIndexingBase<"Subtensor">;
  177. def SetSubtensor: FancyIndexingBase<"SetSubtensor">;
  178. def IncrSubtensor: FancyIndexingBase<"IncrSubtensor">;
  179. def IndexingMultiAxisVec: FancyIndexingBase<"IndexingMultiAxisVec">;
  180. def IndexingSetMultiAxisVec: FancyIndexingBase<"IndexingSetMultiAxisVec">;
  181. def IndexingIncrMultiAxisVec: FancyIndexingBase<"IndexingIncrMultiAxisVec">;
  182. def MeshIndexing: FancyIndexingBase<"MeshIndexing">;
  183. def IncrMeshIndexing: FancyIndexingBase<"IncrMeshIndexing">;
  184. def SetMeshIndexing: FancyIndexingBase<"SetMeshIndexing">;
  185. def BatchedMeshIndexing: FancyIndexingBase<"BatchedMeshIndexing">;
  186. def BatchedIncrMeshIndexing: FancyIndexingBase<"BatchedIncrMeshIndexing">;
  187. def BatchedSetMeshIndexing: FancyIndexingBase<"BatchedSetMeshIndexing">;
  188. def FakeQuant: MgbHashableOp<"FakeQuant", [FakeQuantParam]>;
  189. def AssertEqual: MgbHashableOp<"AssertEqual",[AssertEqualParam]>;
  190. def TQT: MgbHashableOp<"TQT", [TQTParam]>;
  191. def ElemwiseMultiType: MgbHashableOp<"ElemwiseMultiType", [ElemwiseMultiTypeParam]> {
  192. let extraArguments = (ins
  193. MgbDTypeAttr:$dtype
  194. );
  195. let usingModeName = 1;
  196. }
  197. def InplaceAdd: MgbHashableOp<"InplaceAdd", [EmptyParam]>;
  198. def TensorRTRuntime: MgbHashableOp<"TensorRTRuntime"> {
  199. let extraArguments = (ins
  200. MgbStringAttr:$buf,
  201. MgbSizeTAddr:$buf_size
  202. );
  203. }
  204. def CvtColor: MgbHashableOp<"CvtColor", [CvtColorParam]>;
  205. #endif // MGB_OPS

MegEngine 安装包中集成了使用 GPU 运行代码所需的 CUDA 环境,不用区分 CPU 和 GPU 版。 如果想要运行 GPU 程序,请确保机器本身配有 GPU 硬件设备并安装好驱动。 如果你想体验在云端 GPU 算力平台进行深度学习开发的感觉,欢迎访问 MegStudio 平台