-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[MLIR] Folding unpack and pack sequence in data layout propagation from padded domain #138332
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -298,20 +298,56 @@ getOrCreatePackedViewOfOperand(OpBuilder &b, Location loc, PackInfo packInfo, | |
| return std::make_tuple(packedOperand, indexingMap); | ||
| } | ||
|
|
||
| static bool isGenericOutsNotUsed(linalg::GenericOp genericOp) { | ||
| int numDpsOuts = genericOp.getNumDpsInits(); | ||
| for (int i = 0; i < numDpsOuts; ++i) { | ||
| Block *block = genericOp.getBody(); | ||
| int numBlockArgs = block->getNumArguments(); | ||
| int matchingInitArgIndex = numBlockArgs - numDpsOuts + i; | ||
| return block->getArgument(matchingInitArgIndex).use_empty(); | ||
| } | ||
| return true; | ||
| } | ||
|
|
||
| /// Pack a genericOp and return it. | ||
| static GenericOp packGenericOp(RewriterBase &rewriter, GenericOp genericOp, | ||
| Value dest, AffineMap packedOutIndexingMap, | ||
| const PackInfo &packInfo) { | ||
| Location loc = genericOp.getLoc(); | ||
| SmallVector<Value> inputOperands; | ||
| SmallVector<Value> inputOperandsFromUnpackedSource; | ||
| SmallVector<AffineMap> indexingMaps; | ||
|
|
||
| // Note: canUnpackPackFold needs to also guarantee the generic body | ||
| // doesn't have gather semantics. Since such scenarios has been | ||
| // rejected by both BubbleUpPackOpThroughGenericOp and | ||
| // PushDownUnPackOpThroughGenericOp, we can safely assume | ||
| // canUnpackPackFold is as long as init is not used. | ||
| bool canUnpackPackFold = isGenericOutsNotUsed(genericOp); | ||
|
||
| for (OpOperand *inputOperand : genericOp.getDpsInputOperands()) { | ||
| auto [packedOperand, packedIndexingMap] = getOrCreatePackedViewOfOperand( | ||
| rewriter, loc, packInfo, genericOp, inputOperand); | ||
|
|
||
| if (auto unpackOp = inputOperand->get().getDefiningOp<linalg::UnPackOp>()) { | ||
| inputOperandsFromUnpackedSource.push_back(unpackOp.getSource()); | ||
| } else { | ||
| inputOperandsFromUnpackedSource.push_back(packedOperand); | ||
| } | ||
|
|
||
| inputOperands.push_back(packedOperand); | ||
| indexingMaps.push_back(packedIndexingMap); | ||
| } | ||
|
|
||
| // If The pack and unpack op can be folded: | ||
jerryyin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // 1) use unpack op source op for operand to fold unpack -> pack sequence | ||
| // 2) init tensor of the generic op can be replaced by the new tensor.empty | ||
| // as the generic out. | ||
jerryyin marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (canUnpackPackFold) { | ||
| inputOperands = inputOperandsFromUnpackedSource; | ||
| if (auto destPack = dest.getDefiningOp<linalg::PackOp>()) | ||
| dest = destPack.getDest(); | ||
| } | ||
|
|
||
| int64_t numInnerLoops = packInfo.getNumTiledLoops(); | ||
| SmallVector<utils::IteratorType> iterTypes = | ||
| genericOp.getIteratorTypesArray(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.