Commit 3f69ed4
authored
[TIR] Finer predicate handling in cross-thread reduction (#15374)
This PR fixes the predicate handling logic of the cross-thread
reduction lowering pass.
For the cross-thread reduction write-back block, prior to this PR, its
predicate is the conjunction of `t == 0` for each reduction thread dim
of the cross-thread reduction. This is problematic when the write-back
buffer is stored in local memory, where each thread is supposed to
have a copy of the final value, while the final value is only stored
by the first thread. In this PR, the predicate is changed to be the
conjunction of the clauses from the two parts:
* the clause of the original reduction block's predicate which contains
spatial loop var,
* `t == 0` for each reduction thread dim **only when the write-back
buffer is global or shared**.
So the first part ensures that the write-back will not go out of bound,
and the second part ensures that when the write-back buffer is local,
every thread gets a value and when the write-back buffer is non-local,
only one thread writes the value out.
Meanwhile, this PR fixes the cross-thread broadcasting detection with
the awareness of the storage scope of the write buffer of the
broadcasting block. Specifically, for each consumer block of a buffer
produced by cross-thread reduction under the same kernel (i.e., same
set of `blockIdx`) of the cross-thread reduction block, when the
write buffer of this consumer block is in local memory, we do not treat
it as broadcasting, and will not add a predicate to it. Otherwise,
we will add the predicate according to the broadcasting handling
introduced by #15192.1 parent e4af302 commit 3f69ed4
File tree
2 files changed
+237
-18
lines changed- src/tir/transforms
- tests/python/unittest
2 files changed
+237
-18
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
426 | 426 | | |
427 | 427 | | |
428 | 428 | | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
429 | 433 | | |
430 | | - | |
431 | | - | |
432 | | - | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
433 | 468 | | |
434 | 469 | | |
| 470 | + | |
435 | 471 | | |
436 | 472 | | |
437 | 473 | | |
| |||
498 | 534 | | |
499 | 535 | | |
500 | 536 | | |
501 | | - | |
502 | | - | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
503 | 543 | | |
504 | 544 | | |
505 | | - | |
506 | | - | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
| 557 | + | |
| 558 | + | |
| 559 | + | |
| 560 | + | |
| 561 | + | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
507 | 568 | | |
508 | 569 | | |
509 | 570 | | |
510 | | - | |
| 571 | + | |
511 | 572 | | |
512 | 573 | | |
513 | | - | |
514 | 574 | | |
515 | | - | |
| 575 | + | |
516 | 576 | | |
517 | 577 | | |
518 | 578 | | |
| |||
582 | 642 | | |
583 | 643 | | |
584 | 644 | | |
| 645 | + | |
| 646 | + | |
585 | 647 | | |
586 | 648 | | |
587 | 649 | | |
588 | 650 | | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
589 | 664 | | |
590 | 665 | | |
591 | | - | |
| 666 | + | |
592 | 667 | | |
593 | 668 | | |
594 | 669 | | |
| |||
631 | 706 | | |
632 | 707 | | |
633 | 708 | | |
634 | | - | |
635 | | - | |
636 | 709 | | |
637 | 710 | | |
638 | 711 | | |
| |||
649 | 722 | | |
650 | 723 | | |
651 | 724 | | |
652 | | - | |
| 725 | + | |
653 | 726 | | |
654 | 727 | | |
655 | 728 | | |
| |||
716 | 789 | | |
717 | 790 | | |
718 | 791 | | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
719 | 807 | | |
720 | 808 | | |
721 | 809 | | |
| |||
792 | 880 | | |
793 | 881 | | |
794 | 882 | | |
795 | | - | |
796 | | - | |
| 883 | + | |
| 884 | + | |
797 | 885 | | |
798 | 886 | | |
799 | 887 | | |
| |||
Lines changed: 133 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
496 | 496 | | |
497 | 497 | | |
498 | 498 | | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
499 | 557 | | |
500 | 558 | | |
501 | 559 | | |
| |||
1315 | 1373 | | |
1316 | 1374 | | |
1317 | 1375 | | |
1318 | | - | |
1319 | 1376 | | |
1320 | 1377 | | |
1321 | 1378 | | |
| |||
1428 | 1485 | | |
1429 | 1486 | | |
1430 | 1487 | | |
1431 | | - | |
| 1488 | + | |
1432 | 1489 | | |
1433 | 1490 | | |
1434 | 1491 | | |
| |||
1442 | 1499 | | |
1443 | 1500 | | |
1444 | 1501 | | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
| 1551 | + | |
| 1552 | + | |
| 1553 | + | |
| 1554 | + | |
| 1555 | + | |
| 1556 | + | |
| 1557 | + | |
| 1558 | + | |
| 1559 | + | |
| 1560 | + | |
| 1561 | + | |
| 1562 | + | |
| 1563 | + | |
| 1564 | + | |
| 1565 | + | |
| 1566 | + | |
| 1567 | + | |
1445 | 1568 | | |
1446 | 1569 | | |
1447 | 1570 | | |
| |||
1472 | 1595 | | |
1473 | 1596 | | |
1474 | 1597 | | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
1475 | 1602 | | |
1476 | 1603 | | |
1477 | 1604 | | |
| |||
1534 | 1661 | | |
1535 | 1662 | | |
1536 | 1663 | | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
1537 | 1668 | | |
1538 | 1669 | | |
1539 | 1670 | | |
| |||
0 commit comments