-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[TOSA] Change PadOp padding to tosa.shape #123133
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 all commits
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 |
---|---|---|
|
@@ -306,7 +306,16 @@ class PadConverter : public OpConversionPattern<tosa::PadOp> { | |
ConversionPatternRewriter &rewriter) const final { | ||
auto loc = padOp.getLoc(); | ||
auto input = padOp.getInput1(); | ||
auto padding = padOp.getPadding(); | ||
|
||
ElementsAttr paddingElems; | ||
if (!matchPattern(padOp.getPadding(), m_Constant(&paddingElems))) { | ||
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. A bit surprised this works, maybe I'm missing something. Should we extract padding in a similar way as below?
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. shape constant value is intended to work properly with matchPattern 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. Thanks, in that case it’s a non-blocking comment, just a suggestion for consistency |
||
return rewriter.notifyMatchFailure( | ||
padOp, "padding must be a static shape value"); | ||
} | ||
llvm::SmallVector<int64_t> paddingVals; | ||
for (auto idx : paddingElems.getValues<IntegerAttr>()) { | ||
paddingVals.push_back(static_cast<int64_t>(idx.getInt())); | ||
} | ||
|
||
ShapedType inputTy = cast<ShapedType>(input.getType()); | ||
Type elementTy = inputTy.getElementType(); | ||
|
@@ -345,18 +354,10 @@ class PadConverter : public OpConversionPattern<tosa::PadOp> { | |
highValues.reserve(rank); | ||
|
||
for (int i = 0; i < rank; i++) { | ||
Value lowIndex = rewriter.create<arith::ConstantIndexOp>(loc, 2 * i); | ||
Value highIndex = rewriter.create<arith::ConstantIndexOp>(loc, 2 * i + 1); | ||
Value lowVal = rewriter.createOrFold<tensor::ExtractOp>( | ||
loc, padding, ValueRange({lowIndex})); | ||
Value highVal = rewriter.createOrFold<tensor::ExtractOp>( | ||
loc, padding, ValueRange({highIndex})); | ||
|
||
lowVal = rewriter.createOrFold<arith::IndexCastOp>( | ||
loc, rewriter.getIndexType(), lowVal); | ||
highVal = rewriter.createOrFold<arith::IndexCastOp>( | ||
loc, rewriter.getIndexType(), highVal); | ||
|
||
Value lowVal = rewriter.create<arith::ConstantOp>( | ||
loc, rewriter.getIndexAttr(paddingVals[2 * i])); | ||
Value highVal = rewriter.create<arith::ConstantOp>( | ||
loc, rewriter.getIndexAttr(paddingVals[2 * i + 1])); | ||
lowValues.push_back(lowVal); | ||
highValues.push_back(highVal); | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.