Commit db76610
committed
Numba: no-dup vectorization promise for distinct-index inc-scatter
Fusing a value-compute into an `inc`-scatter normally scalarizes the whole loop:
the read-modify-write on out[idx[i]] is a possible cross-iteration dependency the
LoopVectorizer can't rule out. When the indices are statically known to be distinct
there is no such dependency, so we promise it to LLVM with an access group on every
loop memory op plus `llvm.loop.parallel_accesses` on the latch -- the value-compute
then vectorizes (LLVM scalarizes only the indexed stores, which AVX2 has no scatter for).
- FuseIndexedElemwise gates the promise on `_has_unique_indices` (a constant with unique
entries, or a `unique_indices` assumption), only for `inc` (`set` already vectorizes),
recording it as a 4th `indexed_outputs` field that flows into the cache key.
- make_loop_call emits a `distinct !{}` access group (a small MDValue subclass, since
llvmlite can't emit distinct nodes and a uniqued !{} crashes the verifier) and tags
the indexed RMW load/store, the index loads, and the input loads -- every memory op
must join the group or LLVM's isAnnotatedParallel rejects the loop.
Builds on the scratch-slot store redirection (prior commit). Validated: arithmetic
value-compute goes 0 -> 3 packed ops with the promise; results unchanged with/without it.
The transcendental win composes once a vector math library is wired (orthogonal veclib work).1 parent 4e47539 commit db76610
4 files changed
Lines changed: 177 additions & 21 deletions
File tree
- pytensor
- link/numba/dispatch
- tensor/rewriting
- tests/link/numba
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
794 | 794 | | |
795 | 795 | | |
796 | 796 | | |
797 | | - | |
| 797 | + | |
798 | 798 | | |
799 | 799 | | |
800 | 800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
25 | 26 | | |
26 | 27 | | |
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 | + | |
28 | 54 | | |
29 | 55 | | |
30 | 56 | | |
| |||
108 | 134 | | |
109 | 135 | | |
110 | 136 | | |
111 | | - | |
112 | | - | |
| 137 | + | |
| 138 | + | |
113 | 139 | | |
114 | 140 | | |
115 | 141 | | |
| |||
150 | 176 | | |
151 | 177 | | |
152 | 178 | | |
153 | | - | |
| 179 | + | |
154 | 180 | | |
155 | 181 | | |
156 | 182 | | |
| |||
444 | 470 | | |
445 | 471 | | |
446 | 472 | | |
| 473 | + | |
447 | 474 | | |
448 | 475 | | |
449 | 476 | | |
| |||
475 | 502 | | |
476 | 503 | | |
477 | 504 | | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
478 | 513 | | |
479 | 514 | | |
480 | 515 | | |
| |||
541 | 576 | | |
542 | 577 | | |
543 | 578 | | |
| 579 | + | |
| 580 | + | |
544 | 581 | | |
545 | 582 | | |
546 | 583 | | |
| |||
646 | 683 | | |
647 | 684 | | |
648 | 685 | | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
649 | 691 | | |
650 | 692 | | |
651 | 693 | | |
| |||
752 | 794 | | |
753 | 795 | | |
754 | 796 | | |
| 797 | + | |
| 798 | + | |
755 | 799 | | |
756 | 800 | | |
757 | 801 | | |
| |||
787 | 831 | | |
788 | 832 | | |
789 | 833 | | |
790 | | - | |
791 | | - | |
792 | | - | |
793 | | - | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
| 842 | + | |
| 843 | + | |
| 844 | + | |
| 845 | + | |
| 846 | + | |
| 847 | + | |
| 848 | + | |
| 849 | + | |
| 850 | + | |
| 851 | + | |
794 | 852 | | |
795 | 853 | | |
796 | 854 | | |
| |||
916 | 974 | | |
917 | 975 | | |
918 | 976 | | |
919 | | - | |
| 977 | + | |
920 | 978 | | |
921 | 979 | | |
922 | 980 | | |
| |||
976 | 1034 | | |
977 | 1035 | | |
978 | 1036 | | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
979 | 1045 | | |
980 | 1046 | | |
981 | 1047 | | |
| |||
1159 | 1225 | | |
1160 | 1226 | | |
1161 | 1227 | | |
| 1228 | + | |
1162 | 1229 | | |
1163 | 1230 | | |
1164 | 1231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
| |||
240 | 241 | | |
241 | 242 | | |
242 | 243 | | |
243 | | - | |
| 244 | + | |
244 | 245 | | |
245 | 246 | | |
246 | 247 | | |
247 | 248 | | |
248 | 249 | | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
249 | 254 | | |
250 | 255 | | |
251 | 256 | | |
252 | | - | |
| 257 | + | |
253 | 258 | | |
254 | 259 | | |
255 | 260 | | |
| |||
301 | 306 | | |
302 | 307 | | |
303 | 308 | | |
304 | | - | |
| 309 | + | |
305 | 310 | | |
306 | 311 | | |
307 | 312 | | |
| |||
721 | 726 | | |
722 | 727 | | |
723 | 728 | | |
724 | | - | |
725 | | - | |
726 | | - | |
727 | | - | |
728 | | - | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
729 | 736 | | |
730 | | - | |
731 | | - | |
732 | | - | |
733 | | - | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
734 | 745 | | |
735 | 746 | | |
736 | 747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
571 | 572 | | |
572 | 573 | | |
573 | 574 | | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
574 | 652 | | |
575 | 653 | | |
576 | 654 | | |
| |||
0 commit comments