Repository navigation
Commit e875b0f
authored
PDX fast path for spatial
Summary:
A float `mean` over the spatial dims of a channels-last tensor,
`x[N,H,W,C].mean((1,2))` (global average pooling), runs `mean.out`
through NNLib's `xa_nn_mean_f32_f32`. For this reduction (dims {1,2} of
an `[N,H,W,C]` tensor) NNLib uses a strided generic loop that costs ~10
cycles per element, which makes it a hotspot in networks that pool this
way.
Add `mean_nhwc_spatial_simd` in front of the NNLib call. For a float
`[N,H,W,C]` tensor reduced over dims {1,2} (negative dims accepted, any
`keepdim`), it zeroes the output row for each batch element, adds every
position row into it with `PDX_ADD_MXF32` (four channels per vector,
positions in order), then divides by the position count with
`PDX_DIV_MXF32`. The per-channel summation order is the sequential
position order, and the division is an exact IEEE division.
PDX vector accesses must be 16-byte aligned on Fusion G3 (an unaligned
access raises `LoadStoreAlignmentCause`), so the fast path is only taken
when both buffers are 16-byte aligned and `C % 4 == 0`; every other case
falls through to the existing NNLib / portable paths unchanged.
On a Fusion G3 core, `mean.out` on these shapes is ~13x faster, with
unchanged output.
Differential Revision: D127346731mean.out of channels-last tensors (#24164)1 parent 10b5018 commit e875b0f
1 file changed
Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
62 | 128 | | |
63 | 129 | | |
64 | 130 | | |
| |||
100 | 166 | | |
101 | 167 | | |
102 | 168 | | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
103 | 173 | | |
104 | 174 | | |
105 | 175 | | |
| |||
0 commit comments