Commit 8ac2022
Add
Summary:
Pull Request resolved: #5835
X-link: https://github.com/facebookresearch/FBGEMM/pull/2758
On ROCm, replace the single-element gradient accumulation loop in `compute_grad_sum` with a cascading block-size unrolling scheme (`PROCESS_BLOCK` with block sizes 8/4/2/1) that processes multiple segment elements per iteration. Each block manually unrolls the per-element `SHFL_SYNC` metadata broadcasts and `Vec4TAcc` gradient loads, so several independent `grad_output` loads are issued before accumulation. This increases instruction-level parallelism, hides global-memory latency across the block, and reduces loop/branch overhead. The 8-wide block is gated on `sizeof(grad_t) <= 2` (fp16) to bound register pressure.
`compute_grad_sum` lives in the shared `embedding_backward_split_device_kernel_template.cuh`, which is `#include`d by both the CTA and warp backward kernels, so both benefit. The CTA kernel processes long, high-collision segments (many loop iterations to amortize the unrolling over) and gains the most; the warp kernel processes short segments and sees a smaller but consistent gain. The NVIDIA code path is unchanged. The helper macros are gated on `not gen_once` (they are only used by `compute_grad_sum`) and `#undef`'d after use, so they never leak into downstream translation units.
Benchmarks on MI350 (fp32 weights/output, `rowwise_adagrad`, no flag), backward kernel time in us, positive = faster.
## TBE sweep over T, D, B
Backward CTA kernel:
```
T D B baseline optimized speedup
1 8 2048 103 60 +42.4%
1 8 4096 201 113 +43.8%
1 8 131072 527 299 +43.3%
1 128 2048 844 67 +92.1%
1 128 4096 1195 124 +89.6%
1 128 131072 697 402 +42.4%
1 256 2048 n/a 67 (*)
1 256 4096 259 126 +51.3%
1 256 131072 834 725 +13.1%
1 512 2048 339 76 +77.5%
1 512 4096 375 163 +56.6%
1 512 131072 1435 1427 +0.6%
1 1024 2048 398 172 +56.9%
1 1024 4096 828 341 +58.9%
1 1024 131072 2942 3092 -5.1%
10 8 2048 367 71 +80.6%
10 8 4096 1466 145 +90.1%
10 8 131072 4835 2404 +50.3%
10 128 2048 605 89 +85.2%
10 128 4096 5(*) 184 (*)
10 128 131072 6323 3694 +41.6%
10 256 2048 207 106 +48.9%
10 256 4096 431 228 +47.0%
10 256 131072 8241 7047 +14.5%
10 512 2048 252 178 +29.2%
10 512 4096 540 383 +29.0%
10 512 131072 17449 14523 +16.8%
```
Backward warp kernel:
```
T D B baseline optimized speedup
1 8 2048 48 43 +10.4%
1 8 4096 75 70 +6.0%
1 8 131072 1353 1196 +11.6%
1 128 2048 544 47 +91.4%
1 128 4096 284 78 +72.6%
1 128 131072 1457 1398 +4.0%
1 256 2048 n/a 49 (*)
1 256 4096 95 86 +9.2%
1 256 131072 1772 1688 +4.7%
1 512 2048 76 65 +14.3%
1 512 4096 134 119 +11.1%
1 512 131072 2462 2353 +4.4%
1 1024 2048 146 119 +18.5%
1 1024 4096 254 219 +14.0%
1 1024 131072 4412 4242 +3.9%
10 8 2048 899 349 +61.2%
10 8 4096 696 666 +4.3%
10 8 131072 12261 11890 +3.0%
10 128 2048 4461 423 +90.5%
10 128 4096 2069 773 +62.7%
10 128 131072 15498 15427 +0.5%
10 256 2048 513 492 +4.1%
10 256 4096 921 892 +3.1%
10 256 131072 23360 17836 +23.6%
10 512 2048 686 648 +5.5%
10 512 4096 1236 1183 +4.3%
10 512 131072 25658 29404 -14.6%
```
## bench_list (representative production mixed-D configs)
Backward CTA kernel:
```
bench T Ds baseline optimized speedup
bench_103 2 8 18 15 +18.1%
bench_0 10 128 488 140 +71.3%
bench_2 14 12/24/128 256 138 +46.3%
bench_1 18 20/128 400 142 +64.6%
bench_27 22 20/24/128 311 154 +50.4%
TOTAL 1474 588 +60.1%
```
Backward warp kernel:
```
bench T Ds baseline optimized speedup
bench_103 2 8 57 51 +9.8%
bench_0 10 128 364 252 +30.6%
bench_2 14 12/24/128 236 237 -0.5%
bench_1 18 20/128 173 167 +3.5%
bench_27 22 20/24/128 276 270 +2.2%
TOTAL 1106 978 +11.6%
```
## VBE (variable batch size, by alpha skew)
```
kernel a baseline optimized speedup
CTA 1 4 4 -0.1%
CTA 1.15 299 130 +56.6%
warp 1 126 129 -2.4%
warp 1.15 65 58 +11.5%
```
(*) Two CTA sweep baseline cells are measurement artifacts on this run and have no meaningful speedup: `T=1 D=256 B=2048` has no baseline sample, and `T=10 D=128 B=4096` recorded a spurious 5us baseline. The few negative outliers (e.g. CTA `T=1 D=1024 B=131072`, warp `T=10 D=512 B=131072`, VBE `a=1`) are within the cross-run measurement noise observed on this setup; `a=1` VBE is ~4us where noise dominates. CTA gains are largest for high-collision configs (long segments); warp gains are smaller but broadly positive.
Reviewed By: q10
Differential Revision: D107551685
fbshipit-source-id: d46d46a3c1357ca662d1baf91d648ba024d4da50PROCESS_BLOCK macro for grad accumulation loop unrolling (#5835)1 parent a48a374 commit 8ac2022
1 file changed
Lines changed: 136 additions & 1 deletion
Lines changed: 136 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 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 | + | |
| 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 | + | |
17 | 114 | | |
18 | 115 | | |
19 | 116 | | |
| |||
141 | 238 | | |
142 | 239 | | |
143 | 240 | | |
144 | | - | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
145 | 279 | | |
146 | 280 | | |
147 | 281 | | |
| |||
180 | 314 | | |
181 | 315 | | |
182 | 316 | | |
| 317 | + | |
183 | 318 | | |
184 | 319 | | |
185 | 320 | | |
| |||
0 commit comments