-
Notifications
You must be signed in to change notification settings - Fork 315
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
Substitute zdnn calls for stick/unstick late, after most ZLow optimizations are performed #2812
Merged
AlexandreEichenberger
merged 46 commits into
onnx:main
from
AlexandreEichenberger:opt-su-v5-3-late
May 9, 2024
Merged
Changes from 43 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
939c53e
first version, can generate an op but it vanishes in the canonicalize…
AlexandreEichenberger 4df21b9
update
AlexandreEichenberger 7f239bd
prefetch are now guarded
AlexandreEichenberger b6016fb
version that works
AlexandreEichenberger 01ba9a6
merge
AlexandreEichenberger 727db44
remove test code
AlexandreEichenberger 5a1c8cf
remove test code
AlexandreEichenberger 475bf26
format
AlexandreEichenberger b8414cc
initial
AlexandreEichenberger 0dab0c1
update
AlexandreEichenberger 581c5bf
first version
AlexandreEichenberger 56bf221
try prefetch before simd conversion
AlexandreEichenberger 768c6c5
added prefetch of input
AlexandreEichenberger 768a4ec
added prefetch of input as read
AlexandreEichenberger ed3fa42
prefetch fix
AlexandreEichenberger ee72930
loop ahead
AlexandreEichenberger 1761c5e
version with older prefetch scheme
AlexandreEichenberger ba0d183
gen prefetch like zDNN
AlexandreEichenberger 1b18ecf
settled on prefetch like zDNN with N=M=1, dist=0, locality=1
AlexandreEichenberger 8e1f487
prefetch without dist for unstick
AlexandreEichenberger 66ee7bc
added stick without buffer
AlexandreEichenberger b46f7d6
added prefetch to no buffer
AlexandreEichenberger e9dcc4e
manually unrolled
AlexandreEichenberger 06bd764
fix prefetch error
AlexandreEichenberger a993510
multi prefetch
AlexandreEichenberger b5546e7
update
AlexandreEichenberger f847139
update
AlexandreEichenberger bca7aa5
removed trivial reshape
AlexandreEichenberger bd1b392
no buffer unstick, partial impl
AlexandreEichenberger c05c98f
handling partial blocks
AlexandreEichenberger 6d1c3ed
unrolled
AlexandreEichenberger 83c6d3c
added prefetch
AlexandreEichenberger 35d642f
fixed issue with dyn shape
AlexandreEichenberger 9e7dc95
reverted simple prefetch computation
AlexandreEichenberger 35f1511
cleaned up version with no buffers
AlexandreEichenberger 3dfc49e
update
AlexandreEichenberger 15022f0
initial
AlexandreEichenberger 7a65395
first try to gen code
AlexandreEichenberger 234fc65
disable parallel
AlexandreEichenberger df11f6a
added parallel back
AlexandreEichenberger c2692cf
removed all but the late expansion of stick/unsick
AlexandreEichenberger 4335049
format
AlexandreEichenberger 945f873
spelling
AlexandreEichenberger ed37a4e
response to comments
AlexandreEichenberger adedee8
Merge branch 'main' into opt-su-v5-3-late
AlexandreEichenberger 3ae8ac5
Merge branch 'main' into opt-su-v5-3-late
AlexandreEichenberger 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
#include "src/Dialect/ONNX/ElementsAttr/WideNum.hpp" | ||
#include "src/Dialect/ONNX/ONNXDimAnalysis.hpp" | ||
#include "src/Dialect/ONNX/ONNXOps.hpp" | ||
#include "src/Dialect/ONNX/ONNXOps/OpHelper.hpp" | ||
#include "src/Dialect/ONNX/ONNXOps/ShapeHelper.hpp" | ||
#include "src/Dialect/ONNX/OnnxElementsAttrBuilder.hpp" | ||
#include "src/Support/TypeUtilities.hpp" | ||
|
@@ -467,6 +468,31 @@ class AddSubWithRHSZeroExpandPattern : public OpRewritePattern<OP_TYPE> { | |
} | ||
}; | ||
|
||
class RemoveReshapeWithIdentityPattern | ||
: public OpRewritePattern<ONNXReshapeOp> { | ||
public: | ||
using OpRewritePattern<ONNXReshapeOp>::OpRewritePattern; | ||
|
||
DimAnalysis *dimAnalysis; | ||
|
||
RemoveReshapeWithIdentityPattern( | ||
MLIRContext *context, DimAnalysis *dimAnalysis) | ||
: OpRewritePattern<ONNXReshapeOp>(context, 1001), | ||
dimAnalysis(dimAnalysis) {} | ||
|
||
LogicalResult matchAndRewrite( | ||
ONNXReshapeOp reshapeOp, PatternRewriter &rewriter) const override { | ||
if (!isIdentityReshape(reshapeOp, dimAnalysis)) | ||
return failure(); | ||
|
||
// Rewrite | ||
Operation *op = reshapeOp.getOperation(); | ||
Value data = reshapeOp.getData(); | ||
rewriter.replaceOp(op, data); | ||
return success(); | ||
} | ||
}; | ||
|
||
//===----------------------------------------------------------------------===// | ||
// Rewrite ONNX ops to ZHigh ops and ONNX ops for ZHigh. | ||
//===----------------------------------------------------------------------===// | ||
|
@@ -482,6 +508,8 @@ void getRewriteONNXForZHighPatterns( | |
patterns.getContext(), dimAnalysis); | ||
patterns.insert<AddSubWithRHSZeroExpandPattern<ONNXSubOp>>( | ||
patterns.getContext(), dimAnalysis); | ||
patterns.insert<RemoveReshapeWithIdentityPattern>( | ||
patterns.getContext(), dimAnalysis); | ||
} | ||
|
||
void getRewriteONNXForZHighDynamicallyLegal( | ||
|
@@ -643,6 +671,15 @@ void getRewriteONNXForZHighDynamicallyLegal( | |
return isSuitableForZDNN<ONNXConvOp>(op) || | ||
!canInferencePadsForNNPAConv(op); | ||
}); | ||
#if 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you will remove this in the final version. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tx |
||
addDynamicallyLegalOpFor<ONNXReshapeOp>(target, dimAnalysis, | ||
[](ONNXReshapeOp op, const DimAnalysis *dimAnalysis) { | ||
// Get rid of identity reshape here, as it impacts stick/unstick. | ||
// So all reshape are legal, unless it is an identity reshape, in which | ||
// case there is a rule here to remove it. | ||
return !isIdentityReshape(op, dimAnalysis); | ||
}); | ||
#endif | ||
} | ||
|
||
struct RewriteONNXForZHighPass | ||
|
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.
It's clever to do it here. Thanks!