-
Notifications
You must be signed in to change notification settings - Fork 608
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
Support default configs for BATCH_MATMUL_* in MaterializeEncoding pass #14762
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
33 changes: 33 additions & 0 deletions
33
...rnal-projects/iree-dialects/include/iree-dialects/Dialect/LinalgExt/Utils/EncodingUtils.h
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2023 The IREE Authors | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#ifndef IREE_DIALECTS_DIALECT_LINALGEXT_UTILS_ENCODING_UTILS_H_ | ||
#define IREE_DIALECTS_DIALECT_LINALGEXT_UTILS_ENCODING_UTILS_H_ | ||
|
||
#include "iree-dialects/Dialect/LinalgExt/IR/LinalgExtOps.h" | ||
#include "iree-dialects/Dialect/LinalgExt/Utils/Utils.h" | ||
|
||
namespace mlir { | ||
namespace iree_compiler { | ||
namespace IREE { | ||
namespace LinalgExt { | ||
|
||
struct MatmulTileParams { | ||
int64_t M = 1; | ||
int64_t K = 1; | ||
int64_t N = 1; | ||
}; | ||
|
||
MaterializeEncodingInfo | ||
chooseEncodingInfoForMatmul(EncodingUser user, EncodingRole role, | ||
MatmulTileParams tileParams); | ||
|
||
} // namespace LinalgExt | ||
} // namespace IREE | ||
} // namespace iree_compiler | ||
} // namespace mlir | ||
|
||
#endif // IREE_DIALECTS_DIALECT_LINALGEXT_UTILS_ENCODING_UTILS_H_ |
This file contains 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
This file contains 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
This file contains 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
63 changes: 63 additions & 0 deletions
63
llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/Utils/EncodingUtils.cpp
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// Copyright 2023 The IREE Authors | ||
// | ||
// Licensed under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
||
#include "iree-dialects/Dialect/LinalgExt/Utils/EncodingUtils.h" | ||
|
||
namespace mlir { | ||
namespace iree_compiler { | ||
namespace IREE { | ||
namespace LinalgExt { | ||
|
||
MaterializeEncodingInfo | ||
chooseEncodingInfoForMatmul(EncodingUser user, EncodingRole role, | ||
MatmulTileParams tileParams) { | ||
// Start dim of the MxK (LHS), KxN (RHS), or MxN (RESULT) 2D matrix. | ||
int64_t matmulDimBase = 0; | ||
switch (user) { | ||
case EncodingUser::BATCH_MATMUL_F32F32F32: | ||
case EncodingUser::BATCH_MATMUL_F16F16F32: | ||
case EncodingUser::BATCH_MATMUL_F16F16F16: | ||
case EncodingUser::BATCH_MATMUL_BF16BF16F32: | ||
case EncodingUser::BATCH_MATMUL_BF16BF16BF16: | ||
case EncodingUser::BATCH_MATMUL_I8I8I32: | ||
matmulDimBase = 1; | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
MaterializeEncodingInfo encodingInfo; | ||
encodingInfo.innerDimsPos = {matmulDimBase, matmulDimBase + 1}; | ||
switch (role) { | ||
case (EncodingRole::LHS): { | ||
encodingInfo.innerTileSizes = {tileParams.M, tileParams.K}; | ||
break; | ||
} | ||
case (EncodingRole::RHS): { | ||
encodingInfo.innerTileSizes = {tileParams.N, tileParams.K}; | ||
encodingInfo.innerDimsPos = {matmulDimBase + 1, matmulDimBase}; | ||
encodingInfo.outerDimsPerm = | ||
llvm::to_vector(llvm::seq<int64_t>(0, matmulDimBase)); | ||
encodingInfo.outerDimsPerm.push_back(matmulDimBase + 1); | ||
encodingInfo.outerDimsPerm.push_back(matmulDimBase); | ||
break; | ||
} | ||
case (EncodingRole::RESULT): { | ||
encodingInfo.innerTileSizes = {tileParams.M, tileParams.N}; | ||
break; | ||
} | ||
default: { | ||
assert(false); | ||
return {}; | ||
} | ||
} | ||
return encodingInfo; | ||
} | ||
|
||
} // namespace LinalgExt | ||
} // namespace IREE | ||
} // namespace iree_compiler | ||
} // namespace mlir |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to add this code in to
LinalgExt/Utils/Utils.h
, butLinalgExt/Utils/Utils.h
is used inLinalgExt/IR/LinalgExtOps.cpp
. And we need to use linalg_ext ops, which results in cyclic library dependencies.I'm not sure what the better way is to solve this. Here I simply creates a separate utils library.
If I put this code into
LinalgExt/Utils/Utils.h
and addIREELinalgExtDialect
to the dependencies ofIREELinalgExtUtils
, I'll get the error:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHy does
Utils
needsIR
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new code added here needs
IREE::LinalgExt::EncodingUser
, which is defined inLinalgExt/IR/LinalgExtOps.h
. So if we add the code intoLinalgExt/Utils/Utils.h
instead, IIUC IREELinalgExtUtils will have a dependency to IREELinalgExtDialect.On the other hand, LinalgExtOps.cpp is using
getDimValue
andcomputeInterchangeFromDimPos
defined inUtils.cpp
, so it currently has a dependecy to IREELinalgExtUtilshttps://github.com/openxla/iree/blob/5142828f9d6fb761c98900e45f4e398c6da9af6d/llvm-external-projects/iree-dialects/lib/Dialect/LinalgExt/IR/CMakeLists.txt#L12-L13
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, here I'm trying to move
chooseEncodingInfoForMatmul
from IREE codegen into LinalgExt so we can reuse the same logic to choose tiling and permutations for materialization based on LinExt::EncodingUser.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've seen similar issues in MLIR repo. I think the solution is that
*IR
should not depends on*Util
. The common methods are moved to*IR.h
in upstream, and we can probably follow the convention. Dependency issue looks fine to me, and we can refactor it later.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MaheshRavishankar Kindly ping : ) Do you have further comments on this PR?