Stencil global to local
stencil_global_to_local
ChangeStoreOpSizes
dataclass
Bases: RewritePattern
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
strategy: dmp.DomainDecompositionStrategy
instance-attribute
__init__(strategy: dmp.DomainDecompositionStrategy) -> None
match_and_rewrite(op: stencil.StoreOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | |
AddHaloExchangeOps
dataclass
Bases: RewritePattern
This rewrite adds a stencil.halo_exchange after each stencil.load op
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
strategy: dmp.DomainDecompositionStrategy
instance-attribute
__init__(strategy: dmp.DomainDecompositionStrategy) -> None
match_and_rewrite(op: stencil.LoadOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
55 56 57 58 59 60 61 62 63 64 | |
LowerHaloExchangeToMpi
dataclass
Bases: RewritePattern
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
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 | |
init: bool
instance-attribute
debug_prints: bool = False
class-attribute
instance-attribute
__init__(init: bool, debug_prints: bool = False) -> None
match_and_rewrite(op: dmp.SwapOp, rewriter: PatternRewriter)
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | |
MpiLoopInvariantCodeMotion
THIS IS NOT A REWRITE PATTERN!
This is a two-stage rewrite that modifies operations in a manner that is incompatible with the PatternRewriter!
It implements a custom rewrite_module() method directly on the class.
This rewrite moves all memref.allo, mpi.comm.rank, mpi.allocate and mpi.unwrap_memref ops and moves them "up" until it hits a func.func, and then places them before the op they appear in.
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
413 414 415 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 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 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 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 | |
seen_ops: set[Operation] = set()
instance-attribute
has_init: set[func.FuncOp] = set()
instance-attribute
__init__()
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
431 432 433 | |
rewrite(op: memref.AllocOp | mpi.CommRankOp | mpi.AllocateTypeOp | mpi.UnwrapMemRefOp | mpi.InitOp, rewriter: Rewriter)
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
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 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | |
get_matcher(worklist: list[memref.AllocOp | mpi.CommRankOp | mpi.AllocateTypeOp | mpi.UnwrapMemRefOp | mpi.InitOp]) -> Callable[[Operation], None]
Returns a match() function that adds methods to a worklist if they satisfy some criteria.
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 | |
rewrite_module(op: builtin.ModuleOp)
Apply the rewrite to a module.
We do a two-stage rewrite because we are modifying
the operations we loop on them, which would throw of op.walk.
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |
DmpDecompositionPass
dataclass
Bases: ModulePass, ABC
Represents a pass that takes a strategy as input
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
582 583 584 585 586 | |
__init__() -> None
DistributeStencilPass
dataclass
Bases: DmpDecompositionPass
Decompose a stencil to apply to a local domain.
This pass applies stencil shape inference!
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
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 | |
name = 'distribute-stencil'
class-attribute
instance-attribute
STRATEGIES: dict[str, type[dmp.GridSlice2dAttr | dmp.GridSlice3dAttr]] = {'2d-grid': dmp.GridSlice2dAttr, '3d-grid': dmp.GridSlice3dAttr}
class-attribute
slices: tuple[int, ...]
instance-attribute
Number of slices to decompose the input into
strategy: str
instance-attribute
Name of the decomposition strategy to use, see STRATEGIES property for options
restrict_domain: bool = True
class-attribute
instance-attribute
Apply the domain restriction (i.e. change the stencil.apply to operate on the local domain. If false, it assumes that the generated code is already local)
__init__(slices: tuple[int, ...], strategy: str, restrict_domain: bool = True) -> None
apply(ctx: Context, op: builtin.ModuleOp) -> None
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
DmpToMpiPass
dataclass
Bases: ModulePass
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 | |
name = 'dmp-to-mpi'
class-attribute
instance-attribute
mpi_init: bool = True
class-attribute
instance-attribute
generate_debug_prints: bool = False
class-attribute
instance-attribute
__init__(mpi_init: bool = True, generate_debug_prints: bool = False) -> None
apply(ctx: Context, op: builtin.ModuleOp) -> None
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
646 647 648 649 650 651 652 653 654 655 656 657 | |
generate_mpi_calls_for(source: SSAValue, exchanges: list[dmp.ExchangeDeclarationAttr], dtype: Attribute, grid: dmp.RankTopoAttr, emit_init: bool = True, emit_debug: bool = False) -> Iterable[Operation]
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
generate_memcpy(field: SSAValue, ex: dmp.ExchangeDeclarationAttr, buffer: SSAValue, receive: bool = False) -> list[Operation]
This function generates a memcpy routine to copy over the parts
specified by the field from field into buffer.
If receive=True, it instead copy from buffer into the parts of
field as specified by ex
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 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 | |
can_loop_invariant_code_move(op: Operation)
This function walks the def-use chain up to see if all the args are "constant enough" to move outside the loop.
This check is very conservative, but that means it definitely works!
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 | |
collect_args_recursive(op: Operation) -> Iterable[Operation]
Collect the def-use chain "upwards" of an operation. Check with can_loop_invariant_code_move prior to using this!
Source code in xdsl/transforms/experimental/dmp/stencil_global_to_local.py
571 572 573 574 575 576 577 578 579 | |