-
Notifications
You must be signed in to change notification settings - Fork 605
Add onnx GridSample support for border padding mode #3819
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
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bbf652c
[TorchToLinalg][GridSample] Add support for border padding mode
Ax9D d76d2b6
[TorchToLinalg][GridSample] Add lit test for border padding
Ax9D 1e09ab2
[OnnxToTorch][GridSample] Add support for border padding mode
Ax9D 3ae0446
[OnnxToTorch][GridSample] Add lit test for border padding mode
Ax9D 3395df8
Simplify paddingMode lowering
Ax9D 797f74d
Merge branch 'llvm:main' into grid_sampler
Ax9D 3ffa1f6
Merge branch 'llvm:main' into grid_sampler
Ax9D 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2587,10 +2587,30 @@ class ConvertAtenGridSamplerOp : public OpConversionPattern<AtenGridSamplerOp> { | |
return res; | ||
}; | ||
|
||
auto lambdaBorder = [&](OpBuilder &b, Location loc, Value x, | ||
Value SizeSubOne) -> Value { | ||
Value xMaxZero = b.create<arith::MaximumFOp>(loc, x, zeroFloat); | ||
return b.create<arith::MinimumFOp>(loc, xMaxZero, SizeSubOne); | ||
}; | ||
|
||
auto lambdaPadding = [&](OpBuilder &b, Location loc, int64_t paddingMode, | ||
Value x, Value SizeSubOne) -> Value { | ||
// Border | ||
if (paddingMode == 1) { | ||
return lambdaBorder(b, loc, x, SizeSubOne); | ||
} | ||
|
||
return x; | ||
}; | ||
|
||
auto resultType = cast<RankedTensorType>( | ||
getTypeConverter()->convertType(op.getResult().getType())); | ||
Value alignCorners = adaptor.getAlignCorners(); | ||
Value interMode = adaptor.getInterpolationMode(); | ||
|
||
int64_t paddingModeInt; | ||
matchPattern(op.getPaddingMode(), m_TorchConstantInt(&paddingModeInt)); | ||
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. Why not put this inside an if and return failure? |
||
|
||
SmallVector<Value> dynamicSizes{}; | ||
if (resultType.isDynamicDim(0)) | ||
dynamicSizes.push_back(rewriter.create<tensor::DimOp>(loc, input, 0)); | ||
|
@@ -2618,10 +2638,14 @@ class ConvertAtenGridSamplerOp : public OpConversionPattern<AtenGridSamplerOp> { | |
Value gplus1 = b.create<arith::AddFOp>(loc, gr1, oneFloat); | ||
Value gPlusMul0 = b.create<arith::MulFOp>(loc, gplus0, innerDim0e); | ||
Value gPlusMul1 = b.create<arith::MulFOp>(loc, gplus1, innerDim1e); | ||
Value result0 = | ||
Value unnorm0 = | ||
b.create<arith::AddFOp>(loc, gPlusMul0, gr0HalfSelect); | ||
Value result1 = | ||
Value unnorm1 = | ||
b.create<arith::AddFOp>(loc, gPlusMul1, gr1HalfSelect); | ||
Value result0 = | ||
lambdaPadding(b, loc, paddingModeInt, unnorm0, innerDim0d); | ||
Value result1 = | ||
lambdaPadding(b, loc, paddingModeInt, unnorm1, innerDim1d); | ||
Value checkLowerBound0 = b.create<arith::CmpFOp>( | ||
loc, arith::CmpFPredicate::OLT, result0, zeroFloat); | ||
Value checkLowerBound1 = b.create<arith::CmpFOp>( | ||
|
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.
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.
SizeSubOne ->
sizeSubOne