Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpose parameter in matmul/linear op #1750

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions include/ttmlir/Dialect/TTIR/IR/TTIROps.td
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,9 @@ def TTIR_LinearOp : TTIR_DPSOp<"linear"> {
let arguments = (ins AnyRankedTensor:$a,
AnyRankedTensor:$b,
Optional<AnyRankedTensor>:$bias,
AnyRankedTensor:$output);
AnyRankedTensor:$output,
DefaultValuedAttr<BoolAttr, "false">:$transpose_a,
DefaultValuedAttr<BoolAttr, "false">:$transpose_b);

let results = (outs AnyRankedTensor:$result);

Expand All @@ -1314,6 +1316,8 @@ def TTIR_LinearOp : TTIR_DPSOp<"linear"> {
}];

let hasVerifier = 1;

let hasCanonicalizer = 1;
}

// ANCHOR: adding_an_op_matmul_ttir
Expand All @@ -1325,7 +1329,9 @@ def TTIR_MatmulOp : TTIR_DPSOp<"matmul"> {

let arguments = (ins AnyRankedTensor:$a,
AnyRankedTensor:$b,
AnyRankedTensor:$output);
AnyRankedTensor:$output,
DefaultValuedAttr<BoolAttr, "false">:$transpose_a,
DefaultValuedAttr<BoolAttr, "false">:$transpose_b);

let results = (outs AnyRankedTensor:$result);

Expand All @@ -1334,6 +1340,8 @@ def TTIR_MatmulOp : TTIR_DPSOp<"matmul"> {
}];

let hasVerifier = 1;

let hasCanonicalizer = 1;
}
// ANCHOR_END: adding_an_op_matmul_ttir

Expand Down
10 changes: 8 additions & 2 deletions include/ttmlir/Dialect/TTNN/IR/TTNNOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,10 @@ def TTNN_LinearOp : TTNN_NamedDPSOp<"linear"> {
let arguments = (ins AnyRankedTensor:$a,
AnyRankedTensor:$b,
Optional<AnyRankedTensor>:$bias,
AnyRankedTensor:$output);
AnyRankedTensor:$output,
DefaultValuedAttr<BoolAttr, "false">:$transpose_a,
DefaultValuedAttr<BoolAttr, "false">:$transpose_b);

let results = (outs AnyRankedTensor:$result);

let extraClassDeclaration = [{
Expand All @@ -815,7 +818,10 @@ def TTNN_MatmulOp : TTNN_NamedDPSOp<"matmul",
> {
let arguments = (ins AnyRankedTensor:$a,
AnyRankedTensor:$b,
AnyRankedTensor:$output);
AnyRankedTensor:$output,
DefaultValuedAttr<BoolAttr, "false">:$transpose_a,
DefaultValuedAttr<BoolAttr, "false">:$transpose_b);

let results = (outs AnyRankedTensor:$result);

let extraClassDeclaration = [{
Expand Down
13 changes: 9 additions & 4 deletions include/ttmlir/Target/TTNN/program.fbs
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,22 @@ table SliceOp {
}

table LinearOp {
in0: tt.target.TensorRef;
in1: tt.target.TensorRef;
a: tt.target.TensorRef;
b: tt.target.TensorRef;
bias: tt.target.TensorRef;
out: tt.target.TensorRef;
transpose_a: bool;
transpose_b: bool;
}

// ANCHOR: adding_an_op_matmul_fbs
table MatmulOp {
in0: tt.target.TensorRef;
in1: tt.target.TensorRef;
a: tt.target.TensorRef;
b: tt.target.TensorRef;
out: tt.target.TensorRef;
transpose_a: bool;
transpose_b: bool;

}
// ANCHOR_END: adding_an_op_matmul_fbs

Expand Down
6 changes: 4 additions & 2 deletions lib/Conversion/TTIRToTTNN/TTIRToTTNN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,8 @@ class LinearOpConversionPattern : public OpConversionPattern<ttir::LinearOp> {
ConversionPatternRewriter &rewriter) const override {
rewriter.replaceOpWithNewOp<ttnn::LinearOp>(
op, this->getTypeConverter()->convertType(op.getType()), adaptor.getA(),
adaptor.getB(), adaptor.getBias(), adaptor.getOutput());
adaptor.getB(), adaptor.getBias(), adaptor.getOutput(),
adaptor.getTransposeA(), adaptor.getTransposeB());
return success();
}
};
Expand All @@ -785,7 +786,8 @@ class MatmulOpConversionPattern : public OpConversionPattern<ttir::MatmulOp> {
ConversionPatternRewriter &rewriter) const override {
rewriter.replaceOpWithNewOp<ttnn::MatmulOp>(
op, this->getTypeConverter()->convertType(op.getType()), adaptor.getA(),
adaptor.getB(), adaptor.getOutput());
adaptor.getB(), adaptor.getOutput(), adaptor.getTransposeA(),
adaptor.getTransposeB());
return success();
}
};
Expand Down
Loading
Loading