-
Notifications
You must be signed in to change notification settings - Fork 817
[Codegen] Add LowerStructuralPCFPass #22915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: users/qedawkins/pcf-transforms-fuse-writes
Are you sure you want to change the base?
[Codegen] Add LowerStructuralPCFPass #22915
Conversation
MaheshRavishankar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without reviewing this yet. I dont think we should be using scf.execute_region at all. Can you say whats the reason for this?
I am open to alternatives, but that's pretty much the exact op I need here. I have and need to execute its region without breaking up the parent block (because we haven't lowered scf to cf yet). This is kinda exactly what |
|
Wait, doesn't that make |
| - `pcf.generic` -> `scf.execute_region` with worker IDs from scope | ||
| - `pcf.loop` -> serialized `scf.forall` with iteration bounds from count operands | ||
| - `pcf.return` -> `scf.yield` (in generic) or `scf.forall.in_parallel` (in loop) | ||
| - `pcf.branch_cond_return` -> `cf.cond_br` to a return block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... why do we need cf here? Couldn't we have if or switch or such?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. That's why.
... Is it just me, or should this conditional branch in PCF be something more like a switch-type op that takes multiple regions to choose between? That means we aren't mixing structured and unstructured control flow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regions are limited because either we get no implicit capture within regions at the same scope, or we switch into a finer scope, in which case that's just reinventing one of the already existing switch ops. I'll admit that I haven't landed on a super strong use case for pcf.branch_cond_return yet, but I haven't implemented the use case I had in mind for it yet, so we will see. I am willing to remove it if prompted but in it's current state it does "work" :P.
if you have something like you cannot inline the body of the execute region because scf.for requires a single block body. So the solution is to use the execute_region to hold the region and then lower both at the same time. |
kuhar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic looks good to me, I'll leave the exact lowering to scf for others to decide
compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/LowerStructuralPCF.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/LowerStructuralPCF.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/LowerStructuralPCF.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/LowerStructuralPCF.cpp
Outdated
Show resolved
Hide resolved
compiler/src/iree/compiler/Codegen/Dialect/PCF/Transforms/LowerStructuralPCF.cpp
Show resolved
Hide resolved
7c630ab to
b061486
Compare
Adds the LowerStructuralPCFPass which lowers structural PCF operations to their SCF equivalents: - pcf.generic is lowered to scf.execute_region - pcf.loop is lowered to scf.forall - pcf.branch_cond_return is lowered to cf.cond_br The pass uses the scope attribute on each operation to determine how to generate worker IDs and counts for the lowered operations. Synchronization barriers are inserted when sync_on_return is set. Also adds loadStructuralLoweringDependentDialects to PCFConversionDialectInterface, allowing external dialects to register dependent dialects needed during lowering.
6a255ec to
867ec68
Compare
Adds the LowerStructuralPCFPass which lowers structural PCF operations to SCF:
The pass uses the scope attribute on each operation to determine how to generate worker IDs and counts for the lowered operations. Synchronization barriers are inserted when sync_on_return is set.
Also adds loadStructuralLoweringDependentDialects to PCFConversionDialectInterface, allowing external dialects to register dependent dialects needed during lowering.