This PR merges the `triton-mlir` branch, in which we have been quietly rewriting the Triton backend from scratch to increase maintainability, stability and ultimately performance. Changes to the runtime are minimal, and this new version aims to remain backward-compatible with the previous commit. The legacy backend is now officially deprecated, but can still be accessed via the `legacy-backend` tag. Co-authored-by: Keren Zhou <kerenzhou@openai.com> Co-authored-by: Yan Chunwei <yanchunwei@outlook.com> Co-authored-by: goostavz <109190422+goostavz@users.noreply.github.com> Co-authored-by: Shintaro Iwasaki <siwasaki@fb.com> Co-authored-by: Yan Da <dyanab@connect.ust.hk> Co-authored-by: Jun Yang <yangjunpro@gmail.com> Co-authored-by: Ian Bearman <ianb@microsoft.com> Co-authored-by: Jason Ansel <jansel@jansel.net> Co-authored-by: Qingyi Liu <qingyil@nvidia.com> Co-authored-by: ben-zhang-609 <110140741+ben-zhang-609@users.noreply.github.com> Co-authored-by: Chenggang Zhao <lyricz@yeah.net> Co-authored-by: ben-zhang-609 <benzh609@gmail.com> Co-authored-by: dongdongl <dongdongl@nvidia.com>
49 lines
1.9 KiB
TableGen
49 lines
1.9 KiB
TableGen
#ifndef TRITON_PATTERNS
|
|
#define TRITON_PATTERNS
|
|
|
|
include "mlir/Dialect/StandardOps/IR/Ops.td"
|
|
include "mlir/Dialect/Arithmetic/IR/ArithmeticOps.td"
|
|
include "triton/Dialect/Triton/IR/TritonOps.td"
|
|
|
|
|
|
// AddIOp(DotOp(a, b, c), d) and c==0 => DotOp(a, b, d)
|
|
// AddFOp(DotOp(a, b, c), d) and c==0 => DotOp(a, b, d)
|
|
|
|
// AddIOp(d, DotOp(a, b, c)) and c==0 => DotOp(a, b, d)
|
|
// AddFOp(d, DotOp(a, b, c)) and c==0 => DotOp(a, b, d)
|
|
def CombineDotAddIPattern : Pat<
|
|
(Arith_AddIOp $d, (TT_DotOp:$res $a, $b, $c, $allowTF32)),
|
|
(TT_DotOp $a, $b, $d, $allowTF32),
|
|
[(Constraint<CPred<"isZero($0)">> $c)]>;
|
|
def CombineDotAddFPattern : Pat<
|
|
(Arith_AddFOp $d, (TT_DotOp:$res $a, $b, $c, $allowTF32)),
|
|
(TT_DotOp $a, $b, $d, $allowTF32),
|
|
[(Constraint<CPred<"isZero($0)">> $c)]>;
|
|
|
|
def CombineDotAddIRevPattern : Pat<
|
|
(Arith_AddIOp (TT_DotOp:$res $a, $b, $c, $allowTF32), $d),
|
|
(TT_DotOp $a, $b, $d, $allowTF32),
|
|
[(Constraint<CPred<"isZero($0)">> $c)]>;
|
|
def CombineDotAddFRevPattern : Pat<
|
|
(Arith_AddFOp (TT_DotOp:$res $a, $b, $c, $allowTF32), $d),
|
|
(TT_DotOp $a, $b, $d, $allowTF32),
|
|
[(Constraint<CPred<"isZero($0)">> $c)]>;
|
|
|
|
// TODO: this fails for addptr(addptr(ptr, i32), i64)
|
|
// Commented out until fixed
|
|
// addptr(addptr(%ptr, %idx0), %idx1) => addptr(%ptr, AddI(%idx0, %idx1))
|
|
// Note: leave (sub %c0, %c0) canceling to ArithmeticDialect
|
|
// (ref: ArithmeticCanonicalization.td)
|
|
// def CombineAddPtrPattern : Pat<
|
|
// (TT_AddPtrOp (TT_AddPtrOp $ptr, $idx0), $idx1),
|
|
// (TT_AddPtrOp $ptr, (Arith_AddIOp $idx0, $idx1))>;
|
|
|
|
// broadcast(cst) => cst
|
|
def getConstantValue : NativeCodeCall<"getConstantValue($_builder, $0, $1)">;
|
|
def CombineBroadcastConstantPattern : Pat<
|
|
(TT_BroadcastOp:$bcast_res (Arith_ConstantOp $value)),
|
|
(Arith_ConstantOp (getConstantValue $value, $bcast_res)),
|
|
[(Constraint<CPred<"isBroadcastConstantCombinable($0)">> $value)]>;
|
|
|
|
#endif
|