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

[aievec] Adding type constraints for aievec::mul_elem operation #1514

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
32 changes: 26 additions & 6 deletions include/aie/Dialect/AIEVec/IR/AIEVecOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,40 @@ def AIEVec_MulOp:
}

def AIEVec_MulElemOp:
AIEVec_Op<"mul_elem", [
Pure
]>,
Arguments<(ins AnyVector:$lhs, AnyVector:$rhs)>,
Results<(outs AnyVector:$result)> {
AIEVec_Op<"mul_elem", [
Pure,
SameTypeOperands,
SameOperandsShape,
IsValidAccTypeForAIE2MulElem<"lhs", "rhs", "result">
]>,
Arguments<(ins
VectorOfLengthAndType<[16, 32, 64], [I8, I16, I32, BF16, F32]>:$lhs,
VectorOfLengthAndType<[16, 32, 64], [I8, I16, I32, BF16, F32]>:$rhs)>,
Results<(outs
VectorOfLengthAndType<[16, 32], [I8, I16, I32, I64, BF16, F32]>:$result)> {
let summary = "AIE-ML vector element-wise multiply";
let description = [{
AMD-specific multiply operation that multiplies two 1-D vectors in the same channel.
The vector sizes are at least 512 bits.
`$result = `$lhs * $rhs`.
Currently, the following are the supported type combinations:
lhs | rhs | Accumulator
:------------------:|:------------------:|:-----------------:
`vector<32xi8>` | `vector<32xi8>` | `vector<32xi8>`
`vector<32xi8>` | `vector<32xi8>` | `vector<32xi32>`
`vector<64xi8>` | `vector<64xi8>` | `vector<32xi32>`
`vector<32xi16>` | `vector<32xi16>` | `vector<32xi16>`
`vector<32xi16>` | `vector<32xi16>` | `vector<32xi32>`
`vector<32xi16>` | `vector<32xi16>` | `vector<16xi64>`
`vector<16xi32>` | `vector<16xi32>` | `vector<16xi32>`
`vector<16xi32>` | `vector<16xi32>` | `vector<16xi64>`
`vector<16xbf16>` | `vector<16xbf16>` | `vector<16xbf16>`
`vector<16xbf16>` | `vector<16xbf16>` | `vector<16xf32>`
`vector<16xf32>` | `vector<16xf32>` | `vector<16xf32>`'
muradq-amd marked this conversation as resolved.
Show resolved Hide resolved
}];
let builders = [
OpBuilder<(ins "mlir::Value":$lhs, "mlir::Value":$rhs, "mlir::Type":$accType),
muradq-amd marked this conversation as resolved.
Show resolved Hide resolved
[{build($_builder, $_state, accType, lhs, rhs);}]>
[{build($_builder, $_state, accType, lhs, rhs);}]>
];
}

Expand Down
13 changes: 13 additions & 0 deletions include/aie/Dialect/AIEVec/IR/AIEVecTypeConstraints.td
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,17 @@ class IsValidAIE2MatMulShapeAndType<string lhs, string rhs, string acc> :
rhs, VectorOfShapeAndType<[8, 4], BF16>,
acc, VectorOfShapeAndType<[4, 4], F32>>]>>;

class hasAnyTypeOf<string name, list<Type> vaildTypes> :
SubstLeaves<"$_self", ElementType<name>.result, AnyTypeOf<vaildTypes>.predicate>;
muradq-amd marked this conversation as resolved.
Show resolved Hide resolved

class IsValidAccTypeForAIE2MulElem<string lhs, string rhs, string acc> :
PredOpTrait<lhs # " x " # rhs # " = " # acc # " is a valid AIE2 " #
muradq-amd marked this conversation as resolved.
Show resolved Hide resolved
"element-wise multiply and accumulate op",
Or<[
And <[hasAnyTypeOf<lhs, [I8 ]>, hasAnyTypeOf<acc, [I8, I32]>]>,
And <[hasAnyTypeOf<lhs, [I16]>, hasAnyTypeOf<acc, [I16, I32, I64]>]>,
And <[hasAnyTypeOf<lhs, [I32]>, hasAnyTypeOf<acc, [I32, I64]>]>,
And <[hasAnyTypeOf<lhs, [BF16]>, hasAnyTypeOf<acc, [BF16, F32]>]>,
And <[hasAnyTypeOf<lhs, [F32]>, hasAnyTypeOf<acc, [F32]>]>
muradq-amd marked this conversation as resolved.
Show resolved Hide resolved
]>>;
#endif
Loading