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

TosaToLinalg: Support unsigned tosa.max_pool2d (FXML-4556) #172

Merged

Conversation

mgehre-amd
Copy link
Collaborator

@mgehre-amd mgehre-amd commented Apr 30, 2024

This PR allows to lower unsigned tosa.max_pool2d to linalg.

// CHECK-LABEL: @max_pool_ui8
func.func @max_pool_ui8(%arg0: tensor<1x6x34x62xui8>) -> tensor<1x4x32x62xui8> {
  // CHECK: builtin.unrealized_conversion_cast {{.*}} : tensor<1x6x34x62xui8> to tensor<1x6x34x62xi8>
  // CHECK: arith.constant 0
  // CHECK: linalg.pooling_nhwc_max_unsigned {{.*}} : (tensor<1x4x32x62xi8>) -> tensor<1x4x32x62xi8>
  // CHECK: builtin.unrealized_conversion_cast {{.*}} : tensor<1x4x32x62xi8> to tensor<1x4x32x62xui8>
  %0 = tosa.max_pool2d %arg0 {pad = array<i64: 0, 0, 0, 0>, kernel = array<i64: 3, 3>, stride = array<i64: 1, 1>} : (tensor<1x6x34x62xui8>) -> tensor<1x4x32x62xui8>
  return %0 : tensor<1x4x32x62xui8>
}

It does this by

  1. Moving the type converter from mlir/lib/Conversion/TosaToLinalg/TosaToLinalgPass.cpp into populateTosaToLinalgTypeConversion
  2. Adding materializations to the type converter using UnrealizedConversionCastOp
  3. Converting the MaxPool2dConverter from OpRewriterPattern to OpConversion Pattern
  4. Adjusting the padding value to the the minimum unsigned value when the max_pool is unsigned
  5. Lowering to linalg.pooling_nhwc_max_unsigned (which uses arith.maxui) when the max_pool is unsigned

@mgehre-amd mgehre-amd requested review from TinaAMD and josel-amd April 30, 2024 08:41
@mgehre-amd mgehre-amd force-pushed the matthias.tosa_to_linalg_unsigned_maxpool branch from 3066e45 to 418d0cd Compare April 30, 2024 08:56
Copy link
Collaborator

@josel-amd josel-amd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mgehre-amd mgehre-amd removed the request for review from TinaAMD May 3, 2024 08:14
Copy link
Collaborator

@cferry-AMD cferry-AMD left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Let's see what upstream folks think for the interface; I'd prefer the approach proposed here but there may be a use case that needs it changed.

@mgehre-amd mgehre-amd merged commit 55b8b59 into feature/fused-ops May 3, 2024
3 checks passed
@mgehre-amd mgehre-amd deleted the matthias.tosa_to_linalg_unsigned_maxpool branch May 3, 2024 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants