Skip to content

Commit 4ac235b

Browse files
authored
Remove unused aievec dialect ops (#1279)
We can add these back as/when we need them, from mlir-aie
1 parent f50ca97 commit 4ac235b

File tree

7 files changed

+4
-483
lines changed

7 files changed

+4
-483
lines changed

compiler/plugins/target/AMD-AIE/aievec/AIEVecOps.cpp

Lines changed: 0 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -420,191 +420,6 @@ LogicalResult ShuffleOp::verify() {
420420
return success();
421421
}
422422

423-
//===----------------------------------------------------------------------===//
424-
// MulElemOp and FMAElemOp
425-
//===----------------------------------------------------------------------===//
426-
427-
// MulElemOp and FMAElemOp are structurally similar, except that FMAElem op
428-
// has few extra fields (accumulator, bool flag to indicate if it is fmsub,
429-
// etc.). We create some specializations to print those fields specifically for
430-
// FMAElemOp and MULElemOp.
431-
432-
// Print the accumulator
433-
template <typename T>
434-
void printAccumulator(OpAsmPrinter &p, T op);
435-
template <>
436-
inline void printAccumulator(OpAsmPrinter &p, aievec::FMAElemOp op) {
437-
p << ", " << op.getAcc();
438-
}
439-
template <>
440-
inline void printAccumulator(OpAsmPrinter &p, aievec::MulElemOp op) {}
441-
442-
// Mark fmsub indicator as elided if the FMAElem op is not fmsub
443-
template <typename T>
444-
void elideFMSubAttr(T op, SmallVector<StringRef, 4> &elidedAttrs);
445-
template <>
446-
inline void elideFMSubAttr(aievec::FMAElemOp op,
447-
SmallVector<StringRef, 4> &elidedAttrs) {
448-
if (!op.getFmsub()) elidedAttrs.push_back(op.getSubAttrName());
449-
}
450-
451-
template <>
452-
inline void elideFMSubAttr(aievec::MulElemOp op,
453-
SmallVector<StringRef, 4> &elidedAttrs) {}
454-
455-
// Print out MulElem and FMAElem op.
456-
template <typename T>
457-
static void printMulFMAElemOp(OpAsmPrinter &p, T op) {
458-
// Print the left operand
459-
p << " " << op.getLhs();
460-
// Print the right operand
461-
p << ", " << op.getRhs();
462-
// For fma op, print the accumulator
463-
printAccumulator(p, op);
464-
465-
// Print the attributes, but don't print attributes that are empty strings
466-
SmallVector<StringRef, 4> elidedAttrs;
467-
for (int idx = 0; idx < 2; ++idx) {
468-
elideFMSubAttr(op, elidedAttrs);
469-
}
470-
p.printOptionalAttrDict(op->getAttrs(), elidedAttrs);
471-
472-
// And now print the types
473-
p << " : " << op.getLhs().getType() << ", " << op.getRhs().getType();
474-
p << ", " << op.getResult().getType();
475-
}
476-
477-
void MulElemOp::print(OpAsmPrinter &p) {
478-
printMulFMAElemOp<aievec::MulElemOp>(p, *this);
479-
}
480-
481-
void aievec::FMAElemOp::print(OpAsmPrinter &p) {
482-
printMulFMAElemOp<aievec::FMAElemOp>(p, *this);
483-
}
484-
485-
// Verify MulElem and FMAElem op.
486-
template <typename T>
487-
LogicalResult verifyMulFMAElemOp(T op) {
488-
// Verify the types
489-
auto lhsType = llvm::dyn_cast<VectorType>(op.getLhs().getType());
490-
auto rhsType = llvm::dyn_cast<VectorType>(op.getRhs().getType());
491-
492-
if (!lhsType || !rhsType) return op.emitError("requires vector type");
493-
494-
auto resultType = llvm::dyn_cast<VectorType>(op.getResult().getType());
495-
496-
if (!resultType) return op.emitError("requires vector type");
497-
498-
// Additional checks for FMAElem op
499-
// Get the width of the underlying scalars of all the vectors
500-
Type ltype = lhsType.getElementType();
501-
Type rtype = rhsType.getElementType();
502-
Type atype = resultType.getElementType();
503-
unsigned ltypeWidth = ltype.getIntOrFloatBitWidth();
504-
unsigned rtypeWidth = rtype.getIntOrFloatBitWidth();
505-
unsigned atypeWidth = atype.getIntOrFloatBitWidth();
506-
507-
// Checks on the number of lanes
508-
unsigned rhsLanes = getVectorLaneSize(rhsType);
509-
unsigned lhsLanes = getVectorLaneSize(lhsType);
510-
511-
// lane size must match
512-
if (lhsLanes != rhsLanes) {
513-
return op.emitError(
514-
"The number of lanes in lhs operand "
515-
"must be the same as rhs operand");
516-
}
517-
518-
// lhs and rhs vector's element type must match
519-
if (ltype != rtype)
520-
return op.emitError(
521-
"The element type of lhs and rhs "
522-
"operand vectors must match");
523-
524-
// The integer datatype of accumulator must always be greater width
525-
if (isa<IntegerType>(atype)) {
526-
if (!isa<IntegerType>(ltype))
527-
return op.emitError("Integer result must have integer operands");
528-
529-
if (ltypeWidth >= atypeWidth || rtypeWidth >= atypeWidth)
530-
return op.emitError(
531-
"the element type of accumulator must have "
532-
"wider width than that of the operand vectors");
533-
} else if (isa<FloatType>(atype)) {
534-
if (!isa<FloatType>(ltype))
535-
return op.emitError(
536-
"Floating point result must have "
537-
"floating point operands");
538-
}
539-
540-
return success();
541-
}
542-
543-
LogicalResult aievec::MulElemOp::verify() {
544-
return verifyMulFMAElemOp<aievec::MulElemOp>(*this);
545-
}
546-
547-
LogicalResult aievec::FMAElemOp::verify() {
548-
return verifyMulFMAElemOp<aievec::FMAElemOp>(*this);
549-
}
550-
551-
// Parse MulElem and FMAElem op.
552-
ParseResult parseMulFMAElemOp(OpAsmParser &parser, OperationState &result,
553-
bool isFMAElemOp = true) {
554-
llvm::SMLoc typesLoc;
555-
SmallVector<Type, 3> types;
556-
OpAsmParser::UnresolvedOperand lhs, rhs, acc;
557-
558-
// Parse the lhs and rhs
559-
if (parser.parseOperand(lhs) || parser.parseComma() ||
560-
parser.parseOperand(rhs))
561-
return failure();
562-
563-
// Parse the acc for FMA op
564-
if (isFMAElemOp) {
565-
if (parser.parseComma() || parser.parseOperand(acc)) return failure();
566-
}
567-
568-
// Parse all the attributes and types
569-
if (parser.parseOptionalAttrDict(result.attributes) ||
570-
parser.getCurrentLocation(&typesLoc) || parser.parseColonTypeList(types))
571-
return failure();
572-
573-
// Assert that there are three types: lhs, rhs, and acc
574-
if (types.size() != 3)
575-
return parser.emitError(typesLoc, "requires three types");
576-
577-
// Some verification
578-
VectorType lhsType = llvm::dyn_cast<VectorType>(types[0]);
579-
if (!lhsType) return parser.emitError(typesLoc, "requires vector type");
580-
VectorType rhsType = llvm::dyn_cast<VectorType>(types[1]);
581-
if (!rhsType) return parser.emitError(typesLoc, "requires vector type");
582-
583-
// Int ops use the accumulator while float ops use normal vector registers
584-
VectorType accType = llvm::dyn_cast<VectorType>(types[2]);
585-
if (!accType) return parser.emitError(typesLoc, "requires vector type");
586-
587-
// Populate the lhs and rhs operands, and result
588-
if (parser.resolveOperand(lhs, lhsType, result.operands) ||
589-
parser.resolveOperand(rhs, rhsType, result.operands))
590-
return failure();
591-
592-
// Populate acc operand for FMA op
593-
if (isFMAElemOp) {
594-
if (parser.resolveOperand(acc, accType, result.operands)) return failure();
595-
}
596-
597-
return parser.addTypeToList(accType, result.types);
598-
}
599-
600-
ParseResult MulElemOp::parse(OpAsmParser &parser, OperationState &result) {
601-
return parseMulFMAElemOp(parser, result, false);
602-
}
603-
604-
ParseResult FMAElemOp::parse(OpAsmParser &parser, OperationState &result) {
605-
return parseMulFMAElemOp(parser, result, true);
606-
}
607-
608423
//===----------------------------------------------------------------------===//
609424
// ExtOp
610425
//===----------------------------------------------------------------------===//

compiler/plugins/target/AMD-AIE/aievec/AIEVecOps.td

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -318,60 +318,4 @@ def AIEVec_ShuffleOp : AIEVec_Op<"shuffle",
318318
let hasVerifier = 1;
319319
}
320320

321-
def AIEVec_MulElemOp:
322-
AIEVec_Op<"mul_elem", [
323-
Pure,
324-
SameTypeOperands,
325-
SameOperandsShape,
326-
SameOperandsAndResultShape,
327-
isOperandResultTypePairValidForAIE2MulElem<"lhs", "rhs", "result">
328-
]>,
329-
Arguments<(ins
330-
VectorOfLengthAndType<[16, 32], [I8, I16, I32, BF16, F32]>:$lhs,
331-
VectorOfLengthAndType<[16, 32], [I8, I16, I32, BF16, F32]>:$rhs)>,
332-
Results<(outs
333-
VectorOfLengthAndType<[16, 32], [I32, I64, F32]>:$result)> {
334-
let summary = "AIE2 vector element-wise multiply";
335-
let description = [{
336-
AMD-specific multiply operation that multiplies two 1-D vectors in the same channel.
337-
The vector sizes are at least 512 bits.
338-
`$result = `$lhs * $rhs`.
339-
Currently, the following are the supported type combinations:
340-
lhs | rhs | Accumulator
341-
:------------------:|:------------------:|:-----------------:
342-
`vector<32xi8>` | `vector<32xi8>` | `vector<32xi32>`
343-
`vector<32xi16>` | `vector<32xi16>` | `vector<32xi32>`
344-
`vector<16xi32>` | `vector<16xi32>` | `vector<16xi64>`
345-
`vector<16xbf16>` | `vector<16xbf16>` | `vector<16xf32>`
346-
`vector<16xf32>` | `vector<16xf32>` | `vector<16xf32>`'
347-
}];
348-
}
349-
350-
def AIEVec_FMAElemOp :
351-
AIEVec_Op<"mac_elem", [
352-
Pure
353-
]>,
354-
Arguments<(ins AnyVectorOfNonZeroRank:$lhs, AnyVectorOfNonZeroRank:$rhs, AnyVectorOfNonZeroRank:$acc,
355-
DefaultValuedAttr<BoolAttr, "false">:$fmsub)>,
356-
Results<(outs AnyVectorOfNonZeroRank:$result)> {
357-
let summary = "AIE2 element-wise vector fused multiply-add";
358-
let description = [{
359-
AMD-specific multiply-add operation. It multiplies two 1-D vectors in the same channel,
360-
and adds the result to an accumulator.
361-
`$result = `$lhs * $rhs + $acc`.
362-
Note: the same operator can be used as fmsub operator by setting the
363-
'fmsub' bool to true.
364-
}];
365-
let builders = [
366-
OpBuilder<(ins "mlir::Value":$lhs, "mlir::Value":$rhs, "mlir::Value":$acc,
367-
"bool":$fmsub),
368-
[{build($_builder, $_state, acc.getType(), lhs, rhs, acc,
369-
fmsub);}]>
370-
];
371-
let extraClassDeclaration = [{
372-
// Get the attribute names
373-
llvm::StringRef getSubAttrName() { return "fmsub"; }
374-
}];
375-
}
376-
377321
#endif // AIEVEC_OPS

compiler/plugins/target/AMD-AIE/aievec/AIEVecToLLVM.cpp

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -611,66 +611,6 @@ class SRSOpConversion : public mlir::ConvertOpToLLVMPattern<aievec::SRSOp> {
611611
}
612612
};
613613

614-
class FMAElemOpConversion
615-
: public mlir::ConvertOpToLLVMPattern<aievec::FMAElemOp> {
616-
public:
617-
using ConvertOpToLLVMPattern<aievec::FMAElemOp>::ConvertOpToLLVMPattern;
618-
619-
public:
620-
FMAElemOpConversion(LLVMTypeConverter &converter, AMDAIE::AMDAIEDevice device)
621-
: mlir::ConvertOpToLLVMPattern<aievec::FMAElemOp>(converter),
622-
device(device) {}
623-
624-
private:
625-
AMDAIE::AMDAIEDevice device;
626-
627-
LogicalResult matchAndRewrite(
628-
aievec::FMAElemOp fmaOp, OpAdaptor adaptor,
629-
ConversionPatternRewriter &rewriter) const override {
630-
assert(AMDAIE::isAie2(device) && "FMAElemOp currently only supports AIE2.");
631-
auto loc = fmaOp.getLoc();
632-
auto lhs = adaptor.getLhs();
633-
auto rhs = adaptor.getRhs();
634-
auto acc = adaptor.getAcc();
635-
auto lhsTy = cast<VectorType>(lhs.getType());
636-
auto rhsTy = cast<VectorType>(rhs.getType());
637-
auto accTy = cast<VectorType>(acc.getType());
638-
auto flatLhsTy = getFlattenedVectorType(lhsTy);
639-
auto flatRhsTy = getFlattenedVectorType(rhsTy);
640-
auto flatAccTy = getFlattenedVectorType(accTy);
641-
642-
// Flatten operands, if needed
643-
if (lhsTy != flatLhsTy)
644-
lhs = rewriter.create<vector::ShapeCastOp>(loc, flatLhsTy, lhs);
645-
if (rhsTy != flatRhsTy)
646-
rhs = rewriter.create<vector::ShapeCastOp>(loc, flatRhsTy, rhs);
647-
if (accTy != flatAccTy)
648-
acc = rewriter.create<vector::ShapeCastOp>(loc, flatAccTy, acc);
649-
650-
Type i32ty = rewriter.getI32Type();
651-
auto confCst = rewriter.create<LLVM::ConstantOp>(
652-
loc, i32ty,
653-
rewriter.getI32IntegerAttr(DataPathConfiguration(
654-
/*xSigned=*/0, /*ySigned=*/0,
655-
/*aMode=*/2, /*bMode=*/3,
656-
/*cMode=*/1)
657-
.get()));
658-
659-
auto macIntrOp =
660-
forceCastOperandsAndCreateTarget<xllvm::AIEVec2MacConfBF16IntrOp>(
661-
rewriter, loc, {lhs, rhs, acc, confCst});
662-
663-
// Recast/Reshape result
664-
auto resVal =
665-
forceCastValueToType(rewriter, loc, macIntrOp.getResult(), flatAccTy);
666-
if (flatAccTy != accTy)
667-
resVal = rewriter.create<vector::ShapeCastOp>(loc, accTy, resVal);
668-
669-
rewriter.replaceOp(fmaOp, resVal);
670-
return success();
671-
}
672-
};
673-
674614
class MatMulOpConversion
675615
: public mlir::ConvertOpToLLVMPattern<aievec::MatMulOp> {
676616
using ConvertOpToLLVMPattern<aievec::MatMulOp>::ConvertOpToLLVMPattern;
@@ -1043,9 +983,8 @@ struct ConvertAIEVecToLLVMPass
1043983
[&](VectorType type) -> std::optional<Type> { return type; });
1044984

1045985
patterns.add<UPSOpConversion, SRSOpConversion, FoldAIECastOps,
1046-
FMAElemOpConversion, ShuffleOpConversion, ExtOpConversion,
1047-
ShiftOpConversion, MatMulOpConversion>(converter,
1048-
maybeDevice.value());
986+
ShuffleOpConversion, ExtOpConversion, ShiftOpConversion,
987+
MatMulOpConversion>(converter, maybeDevice.value());
1049988

1050989
LLVMConversionTarget target(getContext());
1051990

compiler/plugins/target/AMD-AIE/aievec/AIEVecTypeConstraints.td

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,4 @@ class VectorTypesMatch<string op1, Type t1,
6666
SubstLeaves<"$_self", VectorType<op2>.result, t2.predicate>,
6767
SubstLeaves<"$_self", VectorType<op3>.result, t3.predicate>]>;
6868

69-
class isOperandResultTypePairValidForAIE2MulElem<string lhs, string rhs, string acc> :
70-
PredOpTrait<acc # " type is a valid accumulator type given the type of the" #
71-
" operands.",
72-
Or<[
73-
And <[ElementTypeIsPred<acc,I32>, ElementTypeIsPred<lhs,I8>]>,
74-
And <[ElementTypeIsPred<acc,I32>, ElementTypeIsPred<lhs,I16>]>,
75-
And <[ElementTypeIsPred<acc,I64>, ElementTypeIsPred<lhs,I32>]>,
76-
And <[ElementTypeIsPred<acc,F32>, ElementTypeIsPred<lhs,BF16>]>,
77-
And <[ElementTypeIsPred<acc,F32>, ElementTypeIsPred<lhs,F32>]>
78-
]>>;
79-
8069
#endif

0 commit comments

Comments
 (0)