Commit 4ccf31f
Share one foreach_axis/sum_axes pair between the CPU and GPU operators
The axis loop was written two ways: the CPU operators called
`unrolled_foreach(axis_vals(op))` inline at five sites, each repeating the
`@inline` annotation and a comment explaining it, while the CUDA extension had
its own `sum_over_axes` plus a bare `unrolled_foreach(axis_vals(op))` in the
shared-memory fills. Both now go through `foreach_axis` and `sum_axes`, defined
once next to `axis_vals`, so the axis-tuple plumbing and the reason the per-axis
accumulators are kept separate are stated in one place.
The `@inline` stays in each closure body rather than moving into the helpers:
only a method, not an anonymous function, can carry it, and forcing the inline
from inside the helper -- by wrapping `f` in another closure to annotate its
call site -- reintroduces the per-slab heap allocation it exists to prevent (I
measured every operator kernel allocating again). The helpers' docstring now
carries that explanation, along with the matching note about `@inbounds`.
Verified: CPU results bitwise unchanged (74/74 expressions) with allocations
back at zero for all 14 benchmark kernels; GPU results bitwise identical for all
70 supported expressions. Tests pass on both devices.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0148rCSSVswyipJTZjqpEUMd1 parent 8804cf0 commit 4ccf31f
3 files changed
Lines changed: 59 additions & 28 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
| |||
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
94 | | - | |
| 95 | + | |
| 96 | + | |
95 | 97 | | |
96 | 98 | | |
97 | 99 | | |
| |||
124 | 126 | | |
125 | 127 | | |
126 | 128 | | |
127 | | - | |
| 129 | + | |
| 130 | + | |
128 | 131 | | |
129 | 132 | | |
130 | 133 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
194 | 195 | | |
195 | 196 | | |
196 | 197 | | |
197 | | - | |
198 | | - | |
199 | | - | |
| 198 | + | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
| |||
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | 245 | | |
249 | 246 | | |
250 | 247 | | |
| |||
260 | 257 | | |
261 | 258 | | |
262 | 259 | | |
263 | | - | |
| 260 | + | |
| 261 | + | |
264 | 262 | | |
265 | 263 | | |
266 | 264 | | |
| |||
283 | 281 | | |
284 | 282 | | |
285 | 283 | | |
286 | | - | |
| 284 | + | |
| 285 | + | |
287 | 286 | | |
288 | 287 | | |
289 | 288 | | |
| |||
347 | 346 | | |
348 | 347 | | |
349 | 348 | | |
350 | | - | |
| 349 | + | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
670 | 671 | | |
671 | 672 | | |
672 | 673 | | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
677 | 679 | | |
678 | 680 | | |
679 | 681 | | |
| |||
691 | 693 | | |
692 | 694 | | |
693 | 695 | | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
694 | 722 | | |
695 | 723 | | |
696 | 724 | | |
| |||
819 | 847 | | |
820 | 848 | | |
821 | 849 | | |
822 | | - | |
823 | | - | |
| 850 | + | |
| 851 | + | |
824 | 852 | | |
825 | 853 | | |
826 | 854 | | |
| |||
958 | 986 | | |
959 | 987 | | |
960 | 988 | | |
961 | | - | |
962 | | - | |
| 989 | + | |
| 990 | + | |
963 | 991 | | |
964 | 992 | | |
965 | 993 | | |
| |||
970 | 998 | | |
971 | 999 | | |
972 | 1000 | | |
973 | | - | |
974 | | - | |
| 1001 | + | |
| 1002 | + | |
975 | 1003 | | |
976 | 1004 | | |
977 | 1005 | | |
| |||
1046 | 1074 | | |
1047 | 1075 | | |
1048 | 1076 | | |
1049 | | - | |
1050 | | - | |
| 1077 | + | |
| 1078 | + | |
1051 | 1079 | | |
1052 | 1080 | | |
1053 | 1081 | | |
| |||
1195 | 1223 | | |
1196 | 1224 | | |
1197 | 1225 | | |
1198 | | - | |
1199 | | - | |
| 1226 | + | |
| 1227 | + | |
1200 | 1228 | | |
1201 | 1229 | | |
1202 | 1230 | | |
| |||
0 commit comments