-
Notifications
You must be signed in to change notification settings - Fork 74
Fusion / IR Container composition pattern #5688
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: main
Are you sure you want to change the base?
Conversation
Core Architecture Change:
- Changed Fusion from inheritance (class Fusion : public IrContainer)
to composition (class Fusion { std::u
nique_ptr<IrContainer> container_; })
- Added back-reference from IrContainer to owning Fusion via fusion()
method
- All IrContainer public methods forwarded through Fusion
- Added isA<T>() and as<T>() methods to Fusion (no longer inherits
from PolymorphicBase)
|
Review updated until commit f3e849f Description
|
| Relevant files | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Enhancement | 22 files
| ||||||||||||||||||||||||||||||||||||||||||||
| Bug_fix | 1 files
| ||||||||||||||||||||||||||||||||||||||||||||
| Tests | 5 files
| ||||||||||||||||||||||||||||||||||||||||||||
| Additional files |
PR Reviewer Guide
Here are some key observations to aid the review process:
| 🧪 PR contains tests |
| ⚡ Recommended focus areas for review |
Null pointer dereference risk
|
Greptile OverviewGreptile SummaryThis PR refactors Key changes:
Issue identified: Confidence Score: 3/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant User
participant Fusion
participant IrContainer
participant Statement
participant IrBuilder
Note over Fusion,IrContainer: Composition Pattern
User->>Fusion: new Fusion()
Fusion->>IrContainer: create unique_ptr<IrContainer>
IrContainer-->>Fusion: container_
Fusion->>IrContainer: setOwningFusion(this)
IrContainer->>IrContainer: owning_fusion_ = this
Note over User,Statement: Creating IR Nodes
User->>IrBuilder: create<Val>(args...)
IrBuilder->>Fusion: getActiveContainer()
Fusion-->>IrBuilder: container()
IrBuilder->>Val: new Val(passkey, args)
Val->>Statement: ir_container_ = container
IrBuilder->>IrBuilder: registerWithContainer(container, val)
IrBuilder->>IrContainer: fusion()
IrContainer-->>IrBuilder: owning_fusion_
alt Container owned by Fusion
IrBuilder->>Fusion: registerStmt(val)
Fusion->>IrContainer: registerVal(passkey, val)
else Standalone container
IrBuilder->>IrContainer: registerStmt(passkey, val)
end
Note over User,Statement: Type Checking Pattern
User->>Statement: kernel()
Statement->>IrContainer: fusion()
IrContainer-->>Statement: owning_fusion_
Statement->>Fusion: isA<kir::Kernel>()
Fusion-->>Statement: true/false
Statement->>Fusion: as<kir::Kernel>()
Fusion-->>Statement: kernel ptr
Note over Fusion,IrContainer: Swap Operations
User->>Fusion: swap(fusion_a, fusion_b)
Fusion->>Fusion: swap(container_, container_)
Fusion->>IrContainer: setOwningFusion(&fusion_a)
Fusion->>IrContainer: updateAllStatementContainerPointers()
loop For each Val/Expr
IrContainer->>Statement: ir_container_ = this
end
|
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.
24 files reviewed, 1 comment
| kir::Kernel* Statement::kernel() const { | ||
| Fusion* fusion = ir_container_->fusion(); | ||
| NVF_ERROR( | ||
| ir_container_->isA<kir::Kernel>(), | ||
| fusion != nullptr && fusion->isA<kir::Kernel>(), | ||
| "Statement does not belong to a kernel."); | ||
| return ir_container_->as<kir::Kernel>(); | ||
| return fusion->as<kir::Kernel>(); |
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.
logic: Logic error: fusion->isA<kir::Kernel>() will always return false because Kernel inherits from Fusion, not from IrContainer.
Since Kernel extends Fusion, you should check if the fusion itself is a Kernel:
| kir::Kernel* Statement::kernel() const { | |
| Fusion* fusion = ir_container_->fusion(); | |
| NVF_ERROR( | |
| ir_container_->isA<kir::Kernel>(), | |
| fusion != nullptr && fusion->isA<kir::Kernel>(), | |
| "Statement does not belong to a kernel."); | |
| return ir_container_->as<kir::Kernel>(); | |
| return fusion->as<kir::Kernel>(); | |
| kir::Kernel* Statement::kernel() const { | |
| Fusion* fusion = ir_container_->fusion(); | |
| NVF_ERROR( | |
| fusion != nullptr && fusion->isA<kir::Kernel>(), | |
| "Statement does not belong to a kernel."); | |
| return static_cast<kir::Kernel*>(fusion); | |
| } |
Or more simply, since Kernel is a Fusion subclass, use dynamic_cast for type safety.
Major Fix Applied: The core issue was that when we changed Fusion from inheriting IrContainer to using composition, the virtual dispatch for registerExpr was broken. 1. Added Fusion::registerStmt(Statement*) method that dispatches to registerVal or registerExpr 2. Modified IrBuilder::registerWithContainer() to check if the container has an owning Fusion, and if so, call Fusion::registerStmt() instead of directly calling container->registerStmt() 3. This ensures that Fusion::registerExpr is called, which properly sets the definition on output Vals
d504e21 to
f3e849f
Compare
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.
33 files reviewed, no comments
No description provided.