Stencil bufferize
stencil_bufferize
¶
ApplyBufferizePattern
¶
Bases: RewritePattern
Naive partial stencil.apply bufferization.
Just replace all temp arguments with the field result of a stencil.buffer on them, meaning "The buffer those value are allocated to".
Example:
%out = stencil.apply(%0 = %in : !stencil.temp<[0,32]xf64>) -> (!stencil.temp<[0,32]>xf64) {
// [...]
}
%in_buf = stencil.buffer %in : !stencil.temp<[0,32]xf64> -> !stencil.field<[0,32]xf64>
stencil.apply(%0 = %in_buf : !stencil.field<[0,32]>xf64) outs (%out_buf : !stencil.field<[0,32]>xf64) {
// [...]
}
Source code in xdsl/transforms/stencil_bufferize.py
match_and_rewrite(op: ApplyOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
LoadBufferFoldPattern
¶
Bases: RewritePattern
Fold a reference-semantic stencil.buffer of a stencil.load to the underlying
field if safe.
Example:
%temp = stencil.load %field : !stencil.field<[-2,34]> -> !stencil.temp<[0,32]>
// [... No changes on %field]
%temp_f = stencil.buffer %temp : !stencil.temp<[0,32]> -> !stencil.field<[0,32]>
// [... No changes on %field]
// Last use of temp_f
Source code in xdsl/transforms/stencil_bufferize.py
match_and_rewrite(op: BufferOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
ApplyStoreFoldPattern
¶
Bases: RewritePattern
Fold stores of applys result
Example:
%temp = stencil.apply() -> (!stencil.temp<[0,32]>) {
// [...]
}
// [... %dest not read]
stencil.store %temp to %dest (<[0], [32]>) : !stencil.temp<[0,32]> to !stencil.field<[-2,34]>
Source code in xdsl/transforms/stencil_bufferize.py
229 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 | |
is_dest_safe(apply: ApplyOp, store: StoreOp) -> bool
staticmethod
¶
Source code in xdsl/transforms/stencil_bufferize.py
match_and_rewrite(op: ApplyOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
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 | |
UpdateApplyArgs
dataclass
¶
Bases: RewritePattern
Stencil bufferization will often replace a temporary apply's argument with a wider one. This pattern simply updates block arguments accordingly.
Source code in xdsl/transforms/stencil_bufferize.py
__init__() -> None
¶
match_and_rewrite(op: ApplyOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
BufferAlloc
dataclass
¶
Bases: RewritePattern
Replace a value semantic stencil.buffer by a load from an allocated field, after
a store of the input values on it.
This matches the orginal dialect's lowering for this operation.
Example:
yields:%alloc = stencil.alloc : !stencil.field<[0,32]>xf64
// [...]
// This should be folded in the above computation
stencil.store %in to %alloc (<[0], [32]>) : !stencil.temp<[0,32]> to !stencil.field<[0,32]>
// This should be folded in the below computation
%forward = stencil.load %alloc : !stencil.field<[0,32]>xf64 -> !stencil.temp<[0,32]>
// [...]
Source code in xdsl/transforms/stencil_bufferize.py
__init__() -> None
¶
match_and_rewrite(op: BufferOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
CombineStoreFold
dataclass
¶
Bases: RewritePattern
A stored combine result is folded into stores of the matching operand in the destination field.
Example:
%res1, %res2 = stencil.combine 1 at 11 lower = (%0 : !stencil.temp<[0,16]xf64>) upper = (%1 : !stencil.temp<[16,32]xf64>) lowerext = (%2 : !stencil.temp<[0,16]xf64>): !stencil.temp<[0,32]xf64>, !stencil.temp<[0,32]xf64>
stencil.store %res1 to %dest1 (<[0], [32]>) : !stencil.temp<[0,32]xf64> to !stencil.field<[-2,34]xf64>
stencil.store %res2 to %dest2 (<[0], [32]>) : !stencil.temp<[0,32]xf64> to !stencil.field<[-2,34]xf64>
stencil.store %0 to %dest1 (<[0], [16]>) : !stencil.temp<[0,16]xf64> to !stencil.field<[-2,34]xf64>
stencil.store %1 to %dest1 (<[16], [32]>) : !stencil.temp<[16,32]xf64> to !stencil.field<[-2,34]xf64>
stencil.store %2 to %dest2 (<[0], [16]>) : !stencil.temp<[0,16]xf64> to !stencil.field<[-2,34]xf64>
Source code in xdsl/transforms/stencil_bufferize.py
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 | |
__init__() -> None
¶
match_and_rewrite(op: CombineOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
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 | |
SwapBufferize
¶
Bases: RewritePattern
Bufferize a dmp.swap operation.
NB: This should most likely consider a shared pass following canonicalize and shape-inference.
Source code in xdsl/transforms/stencil_bufferize.py
match_and_rewrite(op: SwapOp, rewriter: PatternRewriter)
¶
Source code in xdsl/transforms/stencil_bufferize.py
StencilBufferize
dataclass
¶
Bases: ModulePass
Bufferize the stencil dialect, i.e., try to fold all loads, sotres, buffer and combines, and to output stencils working directly on buffers (fields) with hopefully few allocations.
Source code in xdsl/transforms/stencil_bufferize.py
name = 'stencil-bufferize'
class-attribute
instance-attribute
¶
__init__() -> None
¶
apply(ctx: Context, op: builtin.ModuleOp) -> None
¶
Source code in xdsl/transforms/stencil_bufferize.py
field_from_temp(temp: TempType[_TypeElement]) -> FieldType[_TypeElement]
¶
might_effect(operation: Operation, effects: set[MemoryEffectKind], value: SSAValue) -> bool
¶
Return True if the operation might have any of the given effects on the given value.
Source code in xdsl/transforms/stencil_bufferize.py
walk_from(a: Operation) -> Generator[Operation, Any, None]
¶
Walk through all operations recursively inside a or its block.
walk_from_to(a: Operation, b: Operation, *, inclusive: bool = False)
¶
Walk through all operations recursively inside a or its block, until b is met, if ever.
Source code in xdsl/transforms/stencil_bufferize.py
is_inplace(apply: ApplyOp, field: SSAValue)
¶
Check if the passed stencil.apply has any non-zero offset access to the passed
stencil.field.