You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a6390b4
Browse filesBrowse the repository at this point in the historyBrowse files
Implement the portable kernel for avg_pool1d (#24122)
### Summary
Fixes [#11325](#11325)
ExecuTorch provides a portable average-pooling kernel for 2D inputs but
lacks a portable kernel for `avg_pool1d.out`. This adds one-dimensional
average pooling for batched `(N, C, L)` and unbatched `(C, L)` inputs.
The implementation supports configurable kernel size, stride, padding,
`ceil_mode`, and `count_include_pad`. It handles empty batches and
dynamically resized outputs, with support for Float, Double, Long, Half,
and BFloat16. Half and BFloat16 values accumulate in float.
### Algorithm
```text
Validate input and output shapes, dtypes, layout, and pooling parameters.
Use kernel_size as the stride when stride is omitted.
Calculate the output length.
In ceil mode, discard a final window that starts entirely in right padding.
Resize the output tensor.
For each batch/channel row:
For each output position:
Determine the pooling window and its valid input range.
Sum the valid input values.
If count_include_pad:
Divide by the window size, including applicable padding.
Otherwise:
Divide by the number of valid input values.
Store the result in the output tensor.
```
### File changes
- `kernels/portable/cpu/op_avg_pool1d.cpp`: implements the portable
kernel and parameter validation.
- `kernels/portable/functions.yaml`: registers `avg_pool1d.out`.
- `kernels/test/op_avg_pool1d_test.cpp`: adds 33 tests covering batched
and unbatched inputs, padding, ceil mode, empty batches, dtypes, dynamic
outputs, and invalid arguments.
- `shim_et/xplat/executorch/build/build_variables.bzl` and
`shim_et/xplat/executorch/kernels/portable/op_registration_util.bzl`:
include and register the kernel in the build.
### Test plan
Regenerated bindings and compiled the new kernel and tests against an
existing CMake runtime/GTest cache on Linux:
```sh
GTEST_FILTER='OpAvgPool1DOutTest.*' \
ctest --test-dir cmake-out \
-R '^portable_kernels_test$' \
--output-on-failure
```
Result: portable_kernels_test passed; CTest reported 1/1 test target
passed, 0 failed.
cc @larryliu0820@manuelcandales@JakeStevens@nil-is-all
0 commit comments