Skip to content

Conversation

@Lallapallooza
Copy link
Contributor

Before this patch, the avg_pool2d and avg_pool1d legalizations lacked support for pooling with count_include_pad=True. This patch introduces that support.

@sjarus sjarus requested a review from sahas3 July 16, 2025 06:41
Copy link
Collaborator

@sjarus sjarus left a comment

Choose a reason for hiding this comment

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

Please add an e2e test under projects/pt1/python/torch_mlir_e2e_test/test_suite/pooling.py as well.

// CHECK: %[[VAL_11:.*]] = tosa.const_shape {values = dense<[0, 0, 0, 0, 1, 1, 1, 1]> : tensor<8xindex>} : () -> !tosa.shape<8>
// CHECK: %[[VAL_12:.*]] = "tosa.const"() <{values = dense<0.000000e+00> : tensor<1xf32>}> : () -> tensor<1xf32>
// CHECK: %[[VAL_13:.*]] = tosa.pad %[[VAL_1]], %[[VAL_11]], %[[VAL_12]] : (tensor<1x192x35x35xf32>, !tosa.shape<8>, tensor<1xf32>) -> tensor<1x192x37x37xf32>
// CHECK: %[[VAL_14:.*]] = tosa.transpose %[[VAL_13]] {perms = array<i32: 0, 2, 3, 1>} : (tensor<1x192x37x37xf32>) -> tensor<1x37x37x192xf32>
Copy link
Member

@sahas3 sahas3 Jul 17, 2025

Choose a reason for hiding this comment

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

Thanks for the change.

I think it'll be better to pad after transposing the input data -- the transpose operations for back-to-back pool (or conv -> pool pattern) ops will be optimized out leading to better performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reworked it as you suggested. In newer LLVM, the pad isn't folded into pooling anymore, so we can produce the optimal chain.

@Lallapallooza Lallapallooza marked this pull request as draft July 17, 2025 20:58
@Lallapallooza Lallapallooza force-pushed the tosa_legalize_avgpool branch 2 times, most recently from 2c0cc57 to 79612ae Compare July 17, 2025 21:27
Before this patch, the `avg_pool2d` and `avg_pool1d` legalizations lacked
support for pooling with count_include_pad=True. This patch introduces that support.

Signed-off-by: Vitalii Shutov <[email protected]>
Change-Id: I73fa26a58379e2c021929ade81c983ff91c59667
@Lallapallooza Lallapallooza marked this pull request as ready for review November 11, 2025 16:50
@Lallapallooza Lallapallooza requested a review from sahas3 November 11, 2025 16:52
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