Commit fcbd7ea
committed
auto: whole-batch GPU bias so matmul-heavy blocks don't thrash devices
The per-op auto threshold is greedy: it places each op in isolation, so a
transformer block's small projection gemms (seq*d*d, below the matmul
threshold) stay on the CPU while its one large FFN gemm goes to the GPU. The
block then thrashes CPU<->GPU and every hand-off is a blocking flush.
graph::run_ now sums M*N*K over every dot in an evaluation batch and, when the
block as a whole earns the GPU (batch_matmul_bias_threshold_, types.h), pins
the whole batch to the GPU via a thread_local flag read by gpu_mode_. Ops with
no GPU kernel still fall back per-op, so results are unchanged; only device
placement shifts. The flag is scoped to the run_ call by an RAII guard.
Calibrated on the pipelined transformer bench (position-rotated, per-config
min, M1 Pro): the Metal threshold sits between d768's ~7e8 attention batch
(pinning it is a net loss) and d1024's ~1.2e9 attention batch (pinning it is a
large win). auto d_model=1024 drops 8.73 -> 5.51 ms/iter (gpu 4.90); d512 stays
on the CPU. env TL_BATCH_MATMUL_BIAS re-calibrates per target.1 parent a756625 commit fcbd7ea
2 files changed
Lines changed: 58 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
191 | 197 | | |
192 | 198 | | |
193 | 199 | | |
| |||
1381 | 1387 | | |
1382 | 1388 | | |
1383 | 1389 | | |
| 1390 | + | |
1384 | 1391 | | |
1385 | 1392 | | |
1386 | 1393 | | |
| |||
1756 | 1763 | | |
1757 | 1764 | | |
1758 | 1765 | | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
1759 | 1784 | | |
1760 | 1785 | | |
1761 | 1786 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
120 | 121 | | |
121 | 122 | | |
122 | 123 | | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
123 | 156 | | |
0 commit comments