Skip to content
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

feat: add 'reflection' padding_mode and 'nearest' and 'cubic' mode in xten_nn.grid_sample. #115

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/Dialect/XTenNN/IR/XTenNNOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,11 +608,11 @@ static std::string getOpInvalidModeOption(ArrayRef<const char *> subOptions,

LogicalResult amd::xten_nn::GridSampleOp::verify() {

constexpr std::array mode{"bilinear"};
constexpr std::array mode{"bilinear", "nearest", "cubic"};
if (getMode() > mode.size() - 1) {
return emitOpError(getOpInvalidModeOption(mode, getModeAttrName()));
}
constexpr std::array paddingMode{"zeros", "border"};
constexpr std::array paddingMode{"zeros", "border", "reflection"};
if (getPaddingMode() > paddingMode.size() - 1) {
return emitOpError(
getOpInvalidModeOption(paddingMode, getPaddingModeAttrName()));
Expand Down
15 changes: 7 additions & 8 deletions test/Dialect/XTenNN/grid_sample.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,17 @@ func.func @test_grid_sample_valid3(%arg0: tensor<1x3x1152x1344xf32>, %arg1: tens
return %0 : tensor<*xf32>
}

// -----

func.func @test_grid_sample_no_padding_mode(%arg0: tensor<1x3x1152x1344xf32>, %arg1: tensor<1x1152x1344x2xf32>) -> tensor<*xf32> {
// expected-error@+1 {{Valid values for 'padding_mode' option are: 'zeros'(0), 'border'(1)}}
func.func @test_grid_sample_reflection(%arg0: tensor<1x3x1152x1344xf32>, %arg1: tensor<1x1152x1344x2xf32>) -> tensor<*xf32> {
%0 = "xten_nn.grid_sample"(%arg0, %arg1) {align_corners = 1 : i64, mode = 0 : i64, padding_mode = 2 : i64} : (tensor<1x3x1152x1344xf32>, tensor<1x1152x1344x2xf32>) -> tensor<*xf32>
return %0 : tensor<*xf32>
}

// -----

func.func @test_grid_sample_interpolate_mode(%arg0: tensor<1x3x1152x1344xf32>, %arg1: tensor<1x1152x1344x2xf32>) -> tensor<*xf32> {
// expected-error@+1 {{Valid values for 'mode' option are: 'bilinear'(0)}}
func.func @test_grid_sample_interpolate_nearest(%arg0: tensor<1x3x1152x1344xf32>, %arg1: tensor<1x1152x1344x2xf32>) -> tensor<*xf32> {
%0 = "xten_nn.grid_sample"(%arg0, %arg1) {align_corners = 1 : i64, mode = 1 : i64, padding_mode = 1 : i64} : (tensor<1x3x1152x1344xf32>, tensor<1x1152x1344x2xf32>) -> tensor<*xf32>
return %0 : tensor<*xf32>
}

func.func @test_grid_sample_interpolate_cubic(%arg0: tensor<1x3x1152x1344xf32>, %arg1: tensor<1x1152x1344x2xf32>) -> tensor<*xf32> {
%0 = "xten_nn.grid_sample"(%arg0, %arg1) {align_corners = 1 : i64, mode = 2 : i64, padding_mode = 1 : i64} : (tensor<1x3x1152x1344xf32>, tensor<1x1152x1344x2xf32>) -> tensor<*xf32>
return %0 : tensor<*xf32>
}