portable: add fast path for contiguous innermost-dim reduction in amax.out and amin.out (#21142)
### Motivation
`sum.IntList_out`, `mean.out`, and `var_mean.correction_out`
special-case the contiguous, single innermost-dim reduction shape with a
direct pointer loop instead of the generic `ReduceOverDimListPlan`,
which recomputes a stride-based starting index per output element via
`get_init_index` (#18789, #18790, #18791). `amax.out` and `amin.out` do
not have this fast path.
### Tests
No new tests were added. The existing tests already cover both fast and
generic paths.
`sum`'s (#18789), `mean`'s (#18790), and `var_mean`'s (#18791) fast-path
PRs had no test changes either.
| Test | Shape | `dim` | Fast path? | Dtypes covered |
| --- | --- | --- | --- | --- |
| `AllRealInputOutputPasses` | `{2,3,4}` | `{2}` (innermost) | Yes |
`ET_FORALL_REALHBBF16_TYPES` (incl. `Bool`, `Half`, `BFloat16`) |
| `AllRealInputOutputPasses` | `{2,3,4}` | `{-2}` (not innermost) | No,
fallback | same |
| `AllRealInputOutputPasses` | `{2,3,4}` | `{0,1}` (multi-dim) | No,
fallback | same |
| `AllRealInputOutputPasses` | `{2,2,4}` | null / empty | No, fallback |
same |
| `InfinityAndNANTest` | `{2,3,4}` | `{-1}` (innermost) | Yes |
`ET_FORALL_FLOATHBF16_TYPES` |
Same coverage in both `op_amax_test.cpp` and `op_amin_test.cpp`.
```
$ ninja -C cmake-out-bench portable_kernels_test -j16
[6/6] Linking CXX executable kernels/test/portable_kernels_test
$ ./cmake-out-bench/kernels/test/portable_kernels_test
[==========] Running 1625 tests from 190 test suites.
[ PASSED ] 1521 tests.
# 0 FAILED, 209 SKIPPED (pre-existing DISABLED/Aten-only tests, unrelated to this change)
$ ./cmake-out-bench/kernels/test/portable_kernels_test --gtest_filter="OpAmaxOutTest.*:OpAminOutTest.*"
[==========] 10 tests from 2 test suites ran.
[ PASSED ] 10 tests.
$ lintrunner -a kernels/portable/cpu/op_amax.cpp kernels/portable/cpu/op_amin.cpp
ok No lint issues.
```
cc @larryliu0820 @manuelcandales
Signed-off-by: Youngsik Yang <vacu9708@gmail.com> Y
Youngsik Yang committed
6cd7ecd9a3cfb0edb00cfbe7688c9ab72dd071d6
Parent: ff0f92e
Committed by GitHub <noreply@github.com>
on 7/24/2026, 6:57:05 PM