Lower mpi
lower_mpi
MpiLibraryInfo
dataclass
This object is meant to capture characteristics of a specific MPI implementations.
It holds magic values, sizes of structs, field offsets and much more.
We need these as we currently cannot load these library headers into the programs we want to lower, therefore we need to generate our own external stubs and load magic values directly.
This way of doing it is inherently fragile, but we don't know of any better way. We plan to include a C file that automagically extracts all this information from MPI headers. You can see the current C file used in this PR: https://github.com/xdslproject/xdsl/pull/526 You can see the status of OpenMPI support here: https://github.com/xdslproject/xdsl/issues/523
These defaults have been extracted from MPICH 3.3a2. We would highly suggest running the mpi-info.c file yourself with your version of the library!
Source code in xdsl/transforms/lower_mpi.py
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 | |
MPI_Datatype_size: int = 4
class-attribute
instance-attribute
MPI_CHAR: int = 1275068673
class-attribute
instance-attribute
MPI_SIGNED_CHAR: int = 1275068696
class-attribute
instance-attribute
MPI_UNSIGNED_CHAR: int = 1275068674
class-attribute
instance-attribute
MPI_BYTE: int = 1275068685
class-attribute
instance-attribute
MPI_WCHAR: int = 1275069454
class-attribute
instance-attribute
MPI_SHORT: int = 1275068931
class-attribute
instance-attribute
MPI_UNSIGNED_SHORT: int = 1275068932
class-attribute
instance-attribute
MPI_INT: int = 1275069445
class-attribute
instance-attribute
MPI_UNSIGNED: int = 1275069446
class-attribute
instance-attribute
MPI_LONG: int = 1275070471
class-attribute
instance-attribute
MPI_UNSIGNED_LONG: int = 1275070472
class-attribute
instance-attribute
MPI_FLOAT: int = 1275069450
class-attribute
instance-attribute
MPI_DOUBLE: int = 1275070475
class-attribute
instance-attribute
MPI_LONG_DOUBLE: int = 1275072524
class-attribute
instance-attribute
MPI_LONG_LONG_INT: int = 1275070473
class-attribute
instance-attribute
MPI_UNSIGNED_LONG_LONG: int = 1275070489
class-attribute
instance-attribute
MPI_LONG_LONG: int = 1275070473
class-attribute
instance-attribute
MPI_Op_size: int = 4
class-attribute
instance-attribute
MPI_MAX: int = 1476395009
class-attribute
instance-attribute
MPI_MIN: int = 1476395010
class-attribute
instance-attribute
MPI_SUM: int = 1476395011
class-attribute
instance-attribute
MPI_PROD: int = 1476395012
class-attribute
instance-attribute
MPI_LAND: int = 1476395013
class-attribute
instance-attribute
MPI_BAND: int = 1476395014
class-attribute
instance-attribute
MPI_LOR: int = 1476395015
class-attribute
instance-attribute
MPI_BOR: int = 1476395016
class-attribute
instance-attribute
MPI_LXOR: int = 1476395017
class-attribute
instance-attribute
MPI_BXOR: int = 1476395018
class-attribute
instance-attribute
MPI_MINLOC: int = 1476395019
class-attribute
instance-attribute
MPI_MAXLOC: int = 1476395020
class-attribute
instance-attribute
MPI_REPLACE: int = 1476395021
class-attribute
instance-attribute
MPI_NO_OP: int = 1476395022
class-attribute
instance-attribute
MPI_Comm_size: int = 4
class-attribute
instance-attribute
MPI_COMM_WORLD: int = 1140850688
class-attribute
instance-attribute
MPI_COMM_SELF: int = 1140850689
class-attribute
instance-attribute
MPI_Request_size: int = 4
class-attribute
instance-attribute
MPI_REQUEST_NULL = 738197504
class-attribute
instance-attribute
MPI_Status_size: int = 20
class-attribute
instance-attribute
MPI_STATUS_IGNORE: int = 1
class-attribute
instance-attribute
MPI_STATUSES_IGNORE: int = 1
class-attribute
instance-attribute
MPI_Status_field_MPI_SOURCE: int = 8
class-attribute
instance-attribute
MPI_Status_field_MPI_TAG: int = 12
class-attribute
instance-attribute
MPI_Status_field_MPI_ERROR: int = 16
class-attribute
instance-attribute
MPI_IN_PLACE: int = -1
class-attribute
instance-attribute
__init__(MPI_Datatype_size: int = 4, MPI_CHAR: int = 1275068673, MPI_SIGNED_CHAR: int = 1275068696, MPI_UNSIGNED_CHAR: int = 1275068674, MPI_BYTE: int = 1275068685, MPI_WCHAR: int = 1275069454, MPI_SHORT: int = 1275068931, MPI_UNSIGNED_SHORT: int = 1275068932, MPI_INT: int = 1275069445, MPI_UNSIGNED: int = 1275069446, MPI_LONG: int = 1275070471, MPI_UNSIGNED_LONG: int = 1275070472, MPI_FLOAT: int = 1275069450, MPI_DOUBLE: int = 1275070475, MPI_LONG_DOUBLE: int = 1275072524, MPI_LONG_LONG_INT: int = 1275070473, MPI_UNSIGNED_LONG_LONG: int = 1275070489, MPI_LONG_LONG: int = 1275070473, MPI_Op_size: int = 4, MPI_MAX: int = 1476395009, MPI_MIN: int = 1476395010, MPI_SUM: int = 1476395011, MPI_PROD: int = 1476395012, MPI_LAND: int = 1476395013, MPI_BAND: int = 1476395014, MPI_LOR: int = 1476395015, MPI_BOR: int = 1476395016, MPI_LXOR: int = 1476395017, MPI_BXOR: int = 1476395018, MPI_MINLOC: int = 1476395019, MPI_MAXLOC: int = 1476395020, MPI_REPLACE: int = 1476395021, MPI_NO_OP: int = 1476395022, MPI_Comm_size: int = 4, MPI_COMM_WORLD: int = 1140850688, MPI_COMM_SELF: int = 1140850689, MPI_Request_size: int = 4, MPI_Status_size: int = 20, MPI_STATUS_IGNORE: int = 1, MPI_STATUSES_IGNORE: int = 1, MPI_Status_field_MPI_SOURCE: int = 8, MPI_Status_field_MPI_TAG: int = 12, MPI_Status_field_MPI_ERROR: int = 16, MPI_IN_PLACE: int = -1) -> None
LowerMpiInit
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
321 322 323 324 325 326 327 328 329 330 331 332 333 | |
match_and_rewrite(op: mpi.InitOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
322 323 324 | |
lower(op: mpi.InitOp) -> tuple[list[Operation], list[SSAValue | None]]
We currently don't model any argument passing to MPI_Init() and pass two nullptrs.
Source code in xdsl/transforms/lower_mpi.py
326 327 328 329 330 331 332 333 | |
LowerMpiFinalize
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 | |
match_and_rewrite(op: mpi.FinalizeOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
337 338 339 | |
lower(op: mpi.FinalizeOp) -> tuple[list[Operation], list[SSAValue | None]]
Relatively straight forward lowering of mpi.finalize operation.
Source code in xdsl/transforms/lower_mpi.py
341 342 343 344 345 346 347 348 349 | |
LowerMpiWait
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
352 353 354 355 356 357 358 359 360 361 362 363 364 365 | |
match_and_rewrite(op: mpi.WaitOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
353 354 355 | |
lower(op: mpi.WaitOp) -> tuple[list[Operation], list[SSAValue | None]]
Relatively straight forward lowering of mpi.wait operation.
Source code in xdsl/transforms/lower_mpi.py
357 358 359 360 361 362 363 364 365 | |
LowerMpiWaitall
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
match_and_rewrite(op: mpi.WaitallOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
369 370 371 | |
lower(op: mpi.WaitallOp) -> tuple[list[Operation], list[SSAValue | None]]
Relatively straight forward lowering of mpi.waitall operation.
Source code in xdsl/transforms/lower_mpi.py
373 374 375 376 377 378 379 380 381 382 | |
LowerMpiReduce
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
match_and_rewrite(op: mpi.ReduceOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
386 387 388 | |
lower(op: mpi.ReduceOp) -> tuple[list[Operation], list[SSAValue | None]]
Lowers the MPI Reduce operation
Source code in xdsl/transforms/lower_mpi.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
LowerMpiAllreduce
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 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 | |
match_and_rewrite(op: mpi.AllreduceOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
417 418 419 | |
lower(op: mpi.AllreduceOp) -> tuple[list[Operation], list[SSAValue | None]]
Lowers the MPI Allreduce operation
Source code in xdsl/transforms/lower_mpi.py
421 422 423 424 425 426 427 428 429 430 431 432 433 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 | |
LowerMpiBcast
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
match_and_rewrite(op: mpi.BcastOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
464 465 466 | |
lower(op: mpi.BcastOp) -> tuple[list[Operation], list[SSAValue | None]]
Lowers the MPI Bcast operation
Source code in xdsl/transforms/lower_mpi.py
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
LowerMpiIsend
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
match_and_rewrite(op: mpi.IsendOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
486 487 488 | |
lower(op: mpi.IsendOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.isend
int MPI_Isend(const void buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request request)
Source code in xdsl/transforms/lower_mpi.py
490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 | |
LowerMpiIrecv
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
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 | |
match_and_rewrite(op: mpi.IrecvOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
519 520 521 | |
lower(op: mpi.IrecvOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.irecv operations
int MPI_Irecv(void buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Request request)
Source code in xdsl/transforms/lower_mpi.py
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 | |
LowerMpiSend
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
match_and_rewrite(op: mpi.SendOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
552 553 554 | |
lower(op: mpi.SendOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.send operations
MPI_Send signature:
int MPI_Send(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
Source code in xdsl/transforms/lower_mpi.py
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 | |
LowerMpiRecv
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
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 | |
match_and_rewrite(op: mpi.RecvOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
579 580 581 | |
lower(op: mpi.RecvOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.recv operations
MPI_Recv signature:
int MPI_Recv(void buf, int count, MPI_Datatype datatype, int source, int tag, MPI_Comm comm, MPI_Status status)
Source code in xdsl/transforms/lower_mpi.py
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 | |
LowerMpiUnwrapMemRefOp
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
match_and_rewrite(op: mpi.UnwrapMemRefOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
619 620 621 | |
lower(op: mpi.UnwrapMemRefOp) -> tuple[list[Operation], list[SSAValue | None]]
Source code in xdsl/transforms/lower_mpi.py
623 624 625 626 627 628 629 630 631 632 633 634 635 | |
LowerMpiGetDtype
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
638 639 640 641 642 643 644 645 646 647 648 | |
match_and_rewrite(op: mpi.GetDtypeOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
639 640 641 | |
lower(op: mpi.GetDtypeOp) -> tuple[list[Operation], list[SSAValue | None]]
Source code in xdsl/transforms/lower_mpi.py
643 644 645 646 647 648 | |
LowerMpiAllocateType
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 | |
match_and_rewrite(op: mpi.AllocateTypeOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
652 653 654 | |
lower(op: mpi.AllocateTypeOp) -> tuple[list[Operation], list[SSAValue | None]]
Allocation operation, allocates the required memory as an LLVM pointer
Source code in xdsl/transforms/lower_mpi.py
656 657 658 659 660 661 662 663 664 665 | |
LowerMpiVectorGet
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
match_and_rewrite(op: mpi.VectorGetOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
669 670 671 | |
lower(op: mpi.VectorGetOp) -> tuple[list[Operation], list[SSAValue | None]]
This lowers the get array at index MPI operation in the dialect. Converts the pointer to an integer and then increments this to find the correct location before going back to a pointer and setting this as the result
Source code in xdsl/transforms/lower_mpi.py
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
LowerMpiCommRank
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
match_and_rewrite(op: mpi.CommRankOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
698 699 700 | |
lower(op: mpi.CommRankOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.comm.rank operation
int MPI_Comm_rank(MPI_Comm comm, int *rank)
Source code in xdsl/transforms/lower_mpi.py
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 | |
LowerMpiCommSize
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
match_and_rewrite(op: mpi.CommSizeOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
722 723 724 | |
lower(op: mpi.CommSizeOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.comm.size operation
int MPI_Comm_size(MPI_Comm comm, int *size)
Source code in xdsl/transforms/lower_mpi.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 | |
LowerNullRequestOp
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 | |
match_and_rewrite(op: mpi.NullRequestOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
777 778 779 | |
lower(op: mpi.NullRequestOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.comm.size operation
int MPI_Comm_size(MPI_Comm comm, int *size)
Source code in xdsl/transforms/lower_mpi.py
781 782 783 784 785 786 787 788 789 790 791 792 793 | |
LowerMpiGatherOp
dataclass
Bases: _MPIToLLVMRewriteBase
Source code in xdsl/transforms/lower_mpi.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
match_and_rewrite(op: mpi.GatherOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/lower_mpi.py
797 798 799 | |
lower(op: mpi.GatherOp) -> tuple[list[Operation], list[SSAValue | None]]
This method lowers mpi.gather operation.
int MPI_Gather(const void sendbuf, int sendcount, MPI_Datatype sendtype, void recvbuf, int recvcount, MPI_Datatype recvtype, int root, MPI_Comm comm)
Source code in xdsl/transforms/lower_mpi.py
801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 | |
LowerMPIPass
dataclass
Bases: ModulePass
Source code in xdsl/transforms/lower_mpi.py
832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | |
name = 'lower-mpi'
class-attribute
instance-attribute
__init__() -> None
apply(ctx: Context, op: builtin.ModuleOp) -> None
Source code in xdsl/transforms/lower_mpi.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 | |
add_external_func_defs(module: builtin.ModuleOp)
This rewriter adds all external function definitions for MPI calls to the module.
It does so by first walking the whole module to discover MPI_ calls. Then
it inserts a func.Func.external() op with the correct types at the end of the module.
Make sure to apply this in a separate pass after the lowerings, otherwise this will match first and find no inserted MPI calls.
Source code in xdsl/transforms/lower_mpi.py
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 | |