Commit 6cd7ecd
authored
portable: add fast path for contiguous innermost-dim reduction in amax.out and amin.out (pytorch#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` (pytorch#18789, pytorch#18790, pytorch#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 (pytorch#18789), `mean`'s (pytorch#18790), and `var_mean`'s (pytorch#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>1 parent ff0f92e commit 6cd7ecd
2 files changed
Lines changed: 60 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
52 | 80 | | |
53 | 81 | | |
54 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
47 | | - | |
48 | 46 | | |
49 | 47 | | |
50 | 48 | | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
51 | 79 | | |
52 | 80 | | |
53 | 81 | | |
| |||
0 commit comments