-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[mlir][vector] Refactor VectorUnrollOpInterface ops. (NFC) #166462
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
Open
amd-eochoalo
wants to merge
8
commits into
llvm:main
Choose a base branch
from
amd-eochoalo:eochoa/2025-11-04/refactoring
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[mlir][vector] Refactor VectorUnrollOpInterface ops. (NFC) #166462
amd-eochoalo
wants to merge
8
commits into
llvm:main
from
amd-eochoalo:eochoa/2025-11-04/refactoring
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-mlir-vector @llvm/pr-subscribers-mlir Author: Erick Ochoa Lopez (amd-eochoalo) ChangesWhile looking into unrolling I found that the description of the getShapeForUnroll function was wrong and that some operations use the default implementation of this interface but still implement their own. Full diff: https://github.com/llvm/llvm-project/pull/166462.diff 3 Files Affected:
diff --git a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
index 6e15b1e7df606..ba110ce3e5f22 100644
--- a/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
+++ b/mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
@@ -360,7 +360,7 @@ def Vector_MultiDimReductionOp :
def Vector_BroadcastOp :
Vector_Op<"broadcast", [Pure,
- DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
+ DeclareOpInterfaceMethods<VectorUnrollOpInterface>,
DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>,
PredOpTrait<"source operand and result have same element type",
TCresVTEtIsSameAsOpBase<0, 0>>]>,
@@ -731,7 +731,7 @@ def Vector_ExtractOp :
def Vector_FMAOp :
Op<Vector_Dialect, "fma", [
Pure, AllTypesMatch<["lhs", "rhs", "acc", "result"]>,
- DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>
+ DeclareOpInterfaceMethods<VectorUnrollOpInterface>
] # ElementwiseMappable.traits>,
Arguments<(ins VectorOfAnyRankOf<[AnyFloat]>:$lhs,
VectorOfAnyRankOf<[AnyFloat]>:$rhs,
@@ -1244,7 +1244,7 @@ def Vector_ExtractStridedSliceOp :
def Vector_TransferReadOp :
Vector_Op<"transfer_read", [
DeclareOpInterfaceMethods<VectorTransferOpInterface>,
- DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
+ DeclareOpInterfaceMethods<VectorUnrollOpInterface>,
DeclareOpInterfaceMethods<MaskableOpInterface>,
DeclareOpInterfaceMethods<MemoryEffectsOpInterface>,
DeclareOpInterfaceMethods<ConditionallySpeculatable>,
@@ -1652,7 +1652,7 @@ def Vector_TransferWriteOp :
}
def Vector_LoadOp : Vector_Op<"load", [
- DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
+ DeclareOpInterfaceMethods<VectorUnrollOpInterface>,
DeclareOpInterfaceMethods<MemorySpaceCastConsumerOpInterface>
]> {
let summary = "reads an n-D slice of memory into an n-D vector";
@@ -2048,7 +2048,7 @@ def Vector_GatherOp :
Vector_Op<"gather", [
DeclareOpInterfaceMethods<MaskableOpInterface>,
DeclareOpInterfaceMethods<MemorySpaceCastConsumerOpInterface>,
- DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>
+ DeclareOpInterfaceMethods<VectorUnrollOpInterface>
]>,
Arguments<(ins Arg<TensorOrMemRef<[AnyType]>, "", [MemRead]>:$base,
Variadic<Index>:$offsets,
@@ -2739,7 +2739,7 @@ def Vector_MaskOp : Vector_Op<"mask", [
def Vector_TransposeOp :
Vector_Op<"transpose", [Pure,
DeclareOpInterfaceMethods<InferIntRangeInterface, ["inferResultRanges"]>,
- DeclareOpInterfaceMethods<VectorUnrollOpInterface, ["getShapeForUnroll"]>,
+ DeclareOpInterfaceMethods<VectorUnrollOpInterface>,
PredOpTrait<"operand and result have same element type",
TCresVTEtIsSameAsOpBase<0, 0>>]> {
let summary = "vector transpose operation";
diff --git a/mlir/include/mlir/Interfaces/VectorInterfaces.td b/mlir/include/mlir/Interfaces/VectorInterfaces.td
index 6838c16fdf0fe..1223f5c0704ab 100644
--- a/mlir/include/mlir/Interfaces/VectorInterfaces.td
+++ b/mlir/include/mlir/Interfaces/VectorInterfaces.td
@@ -24,9 +24,8 @@ def VectorUnrollOpInterface : OpInterface<"VectorUnrollOpInterface"> {
let methods = [
InterfaceMethod<
/*desc=*/[{
- Return the shape ratio of unrolling to the target vector shape
- `targetShape`. Return `std::nullopt` if the op cannot be unrolled to the
- target vector shape.
+ Return the shape of the vector of this operation, which may be used to decide unrolling factors.
+ Return std::nullopt if the op is not applicable for unrolling.
}],
/*retTy=*/"::std::optional<::llvm::SmallVector<int64_t, 4>>",
/*methodName=*/"getShapeForUnroll",
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index daef0ba02100a..b030b060c6ba0 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -2374,14 +2374,6 @@ static void populateFromInt64AttrArray(ArrayAttr arrayAttr,
results.push_back(llvm::cast<IntegerAttr>(attr).getInt());
}
-//===----------------------------------------------------------------------===//
-// FmaOp
-//===----------------------------------------------------------------------===//
-
-std::optional<SmallVector<int64_t, 4>> FMAOp::getShapeForUnroll() {
- return llvm::to_vector<4>(getVectorType().getShape());
-}
-
//===----------------------------------------------------------------------===//
// ToElementsOp
//===----------------------------------------------------------------------===//
@@ -2782,10 +2774,6 @@ void BroadcastOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
setResultRanges(getResult(), argRanges.front());
}
-std::optional<SmallVector<int64_t, 4>> BroadcastOp::getShapeForUnroll() {
- return llvm::to_vector<4>(getResultVectorType().getShape());
-}
-
/// Return the dimensions of the result vector that were formerly ones in the
/// source tensor and thus correspond to "dim-1" broadcasting.
static llvm::SetVector<int64_t>
@@ -5100,10 +5088,6 @@ OpFoldResult TransferReadOp::fold(FoldAdaptor) {
return OpFoldResult();
}
-std::optional<SmallVector<int64_t, 4>> TransferReadOp::getShapeForUnroll() {
- return llvm::to_vector<4>(getVectorType().getShape());
-}
-
void TransferReadOp::getEffects(
SmallVectorImpl<SideEffects::EffectInstance<MemoryEffects::Effect>>
&effects) {
@@ -5778,10 +5762,6 @@ OpFoldResult LoadOp::fold(FoldAdaptor) {
return OpFoldResult();
}
-std::optional<SmallVector<int64_t, 4>> LoadOp::getShapeForUnroll() {
- return llvm::to_vector<4>(getVectorType().getShape());
-}
-
FailureOr<std::optional<SmallVector<Value>>>
LoadOp::bubbleDownCasts(OpBuilder &builder) {
return mlir::detail::bubbleDownInPlaceMemorySpaceCastImpl(getBaseMutable(),
@@ -5986,10 +5966,6 @@ Type GatherOp::getExpectedMaskType() {
vecType.getScalableDims());
}
-std::optional<SmallVector<int64_t, 4>> GatherOp::getShapeForUnroll() {
- return llvm::to_vector<4>(getVectorType().getShape());
-}
-
/// Cheeck if `indexVec` is constant 1D vec of consecutive values [0, 1, 2, ...]
static LogicalResult isZeroBasedContiguousSeq(Value indexVec) {
auto vecType = dyn_cast<VectorType>(indexVec.getType());
@@ -6720,10 +6696,6 @@ LogicalResult vector::TransposeOp::verify() {
return success();
}
-std::optional<SmallVector<int64_t, 4>> TransposeOp::getShapeForUnroll() {
- return llvm::to_vector<4>(getResultVectorType().getShape());
-}
-
void TransposeOp::inferResultRanges(ArrayRef<ConstantIntRanges> argRanges,
SetIntRangeFn setResultRanges) {
setResultRanges(getResult(), argRanges.front());
|
4e92eee to
71e53e7
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While looking into unrolling I found that the description of the getShapeForUnroll function was wrong and that some operations use the default implementation of this interface but still implement their own.
This commit modifies the VectorOp.td file to use the default implementation for getShapeForUnroll for the following ops: