Skip to content

Cortex-M: Support avg_pool2d ceil_mode lowering#21039

Open
bdemirb wants to merge 3 commits into
pytorch:mainfrom
bdemirb:mletorch-1897-ceil-mode
Open

Cortex-M: Support avg_pool2d ceil_mode lowering#21039
bdemirb wants to merge 3 commits into
pytorch:mainfrom
bdemirb:mletorch-1897-ceil-mode

Conversation

@bdemirb

@bdemirb bdemirb commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

Cortex-M avg_pool2d quantized lowering rejected ceil_mode=True and left the graph on the fallback aten.avg_pool2d path. That preserved correctness but prevented optimized Cortex-M lowering for cases that CMSIS-NN can execute from statically known output shapes.

This patch threads ceil_mode through the cortex_m::quantized_avg_pool2d schema, fake implementation, lowering, and C++ kernel wrapper. The wrapper validates the static output shape against ceil-mode pooling semantics before dispatching to CMSIS-NN.

The avg_pool2d tests now cover optimized ceil_mode lowering, padded ceil_mode, count_include_pad with ceil_mode, non-square multi-channel ceil_mode, and divisor_override fallback behavior.

cc @digantdesai @freddan80 @per @zingo @oscarandersson8218 @mansnils @Sebastian-Larsson @robell @rascani

Cortex-M avg_pool2d quantized lowering rejected ceil_mode=True
and left the graph on the fallback aten.avg_pool2d path. That
preserved correctness but prevented optimized Cortex-M lowering for
cases that CMSIS-NN can execute from statically known output shapes.

This patch threads ceil_mode through the cortex_m::quantized_avg_pool2d
schema, fake implementation, lowering, and C++ kernel wrapper. The
wrapper validates the static output shape against ceil-mode pooling
semantics before dispatching to CMSIS-NN.

The avg_pool2d tests now cover optimized ceil_mode lowering, padded
ceil_mode, count_include_pad with ceil_mode, non-square multi-channel
ceil_mode, and divisor_override fallback behavior.

Signed-off-by: Baris Demir <baris.demir@arm.com>

Change-Id: Ib856e7cc0cc4a29ec6ede7d379b03ef7a98cb12f
@bdemirb
bdemirb requested a review from rascani as a code owner July 20, 2026 10:51
@pytorch-bot

pytorch-bot Bot commented Jul 20, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/21039

Note: Links to docs will display an error until the docs builds have been completed.

✅ You can merge normally! (1 Unrelated Failure)

As of commit 4f88706 with merge base e8c47d7 (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jul 20, 2026
@bdemirb

bdemirb commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot label "partner: arm"

@pytorch-bot pytorch-bot Bot added the partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm label Jul 20, 2026
@bdemirb

bdemirb commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot label "release notes: arm"

@pytorch-bot pytorch-bot Bot added the release notes: arm Changes to the ARM backend delegate label Jul 20, 2026
@rascani
rascani requested a review from AdrianLundell July 20, 2026 21:45
count_include_pad=True,
),
(ramp_tensor(0, 15, (1, 1, 4, 4)),),
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a test case with kernel_size =< stride with count_include_pad & ceil_mode? I think we might wind up with the wrong output size in that case: H=5, kernel=3, stride=3, pad=1, ceil_mode=True, count_include_pad=True

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. partner: arm For backend delegation, kernels, demo, etc. from the 3rd-party partner, Arm release notes: arm Changes to the ARM backend delegate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants