-
Notifications
You must be signed in to change notification settings - Fork 17
[Transform][Tiling] Add deep tile support for matmul #90
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
373d10c
add deep tile pass for matmul and tests
zhczhong 8ec246b
Enhance upstream utility and merge all parallel into one forall
zhczhong 90c2b4b
add easy builder support
zhczhong c0c5749
Init C buffer with easy builder
zhczhong c4b777c
support partial reduction
zhczhong b98100b
support bf16 cast fuse
zhczhong 66a986b
replace generic op with named op
zhczhong 56624bb
support 2Dx4D/5D case
zhczhong b950edb
support fusing cast to the innermost loop
zhczhong dc9a1a4
enhance config
zhczhong 9c9ff10
rebase to the latest llvm
zhczhong 162466e
fix deepTileMatmul
zhczhong b138713
tune config
zhczhong 8c7d155
add merge forall pass
zhczhong df1c683
polish code
zhczhong af8aad6
support dlti
zhczhong 24198fb
fix comments
zhczhong 9f294ea
format code
zhczhong 3c5567f
replace sysDesc with target info
zhczhong a205731
deprecated tileToForallUsingTileSize
zhczhong ccd02f2
use expand/collapse_shape to do rank alter
zhczhong 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
//===-- MatmulConfigAnalysis.h - the analysis for matmul config -*- C++ -*-===// | ||
// | ||
// This file is 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 MLIR_ANALYSIS_MATMULCONFIGANALYSIS_H | ||
#define MLIR_ANALYSIS_MATMULCONFIGANALYSIS_H | ||
|
||
#include "gc/Dialect/Linalgx/LinalgxOps.h" | ||
#include "mlir/Dialect/DLTI/DLTI.h" | ||
#include "mlir/Dialect/Linalg/IR/Linalg.h" | ||
#include "mlir/Interfaces/DataLayoutInterfaces.h" | ||
|
||
namespace mlir { | ||
namespace gc { | ||
|
||
using namespace mlir; | ||
|
||
// The configuration for matmul tiling | ||
// TODO: support batch matmul | ||
struct MatmulConfig { | ||
// The number of threads distributed to M, N, K | ||
uint32_t MThreads, NThreads, KThreads; | ||
// The outer block size for M, N, K which will be used to decide the loop tile | ||
// size in single thread | ||
uint32_t MBlock, NBlock, KBlock; | ||
// The innermost block size for M, N, K which will be directly converted to | ||
// brgemm. | ||
uint32_t innerMostMBlock, innerMostNBlock, innerMostKBlock; | ||
}; | ||
|
||
enum DimType { Batch, M, N, K }; | ||
|
||
// Extract the index of the given DimType in the DimType list | ||
inline SmallVector<unsigned> extractDimTypeIdx(ArrayRef<DimType> tyList, | ||
DimType ty) { | ||
SmallVector<unsigned> idxList; | ||
for (auto [idx, type] : llvm::enumerate(tyList)) { | ||
if (type == ty) { | ||
idxList.push_back(idx); | ||
} | ||
} | ||
return idxList; | ||
} | ||
|
||
// Get the operand dim type for every operand for the given linalg op | ||
inline FailureOr<SmallVector<SmallVector<DimType>>> | ||
getOprandDimType(linalg::LinalgOp &linalgOp) { | ||
zhczhong marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// TODO: replace the linalgx op with generic op | ||
if (llvm::isa<linalg::MatmulOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::M, DimType::K}, | ||
SmallVector<DimType>{DimType::K, DimType::N}, | ||
SmallVector<DimType>{DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalgx::Mm2DVnniOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::M, DimType::K}, | ||
SmallVector<DimType>{DimType::N, DimType::K, DimType::K, DimType::N, | ||
DimType::K}, | ||
SmallVector<DimType>{DimType::M, DimType::N, DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalgx::Mm4DVnniOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::M, DimType::K, DimType::M, DimType::K}, | ||
SmallVector<DimType>{DimType::N, DimType::K, DimType::K, DimType::N, | ||
DimType::K}, | ||
SmallVector<DimType>{DimType::M, DimType::N, DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalg::BatchMatmulOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::Batch, DimType::M, DimType::K}, | ||
SmallVector<DimType>{DimType::Batch, DimType::K, DimType::N}, | ||
SmallVector<DimType>{DimType::Batch, DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalg::MatmulTransposeAOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::K, DimType::M}, | ||
SmallVector<DimType>{DimType::K, DimType::N}, | ||
SmallVector<DimType>{DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalg::MatmulTransposeBOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::M, DimType::K}, | ||
SmallVector<DimType>{DimType::N, DimType::K}, | ||
SmallVector<DimType>{DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalg::BatchMatmulTransposeAOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::Batch, DimType::K, DimType::M}, | ||
SmallVector<DimType>{DimType::Batch, DimType::K, DimType::N}, | ||
SmallVector<DimType>{DimType::Batch, DimType::M, DimType::N}}; | ||
} else if (llvm::isa<linalg::BatchMatmulTransposeBOp>(linalgOp)) { | ||
return SmallVector<SmallVector<DimType>>{ | ||
SmallVector<DimType>{DimType::Batch, DimType::M, DimType::K}, | ||
SmallVector<DimType>{DimType::Batch, DimType::N, DimType::K}, | ||
SmallVector<DimType>{DimType::Batch, DimType::M, DimType::N}}; | ||
} | ||
return failure(); | ||
} | ||
|
||
// The analysis to extract the matmul configuration from the given linalg op | ||
struct MatmulConfigAnalysis { | ||
public: | ||
explicit MatmulConfigAnalysis(Operation *root); | ||
MatmulConfig getConfig() { return config; } | ||
|
||
private: | ||
MatmulConfig config; | ||
}; | ||
|
||
} // namespace gc | ||
} // namespace mlir | ||
|
||
#endif |
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.