[IR Container] Phase 2.3 Basic shared ptr#5960
[IR Container] Phase 2.3 Basic shared ptr#5960mdavis36 wants to merge 1 commit intomd/fusion-stmt-regfrom
Conversation
|
!test |
|
Review updated until commit f8ff364 Description
|
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Enhancement |
| ||||||||
| Configuration changes |
|
PR Reviewer Guide
Here are some key observations to aid the review process:
| 🧪 PR contains tests |
| ⚡ Recommended focus areas for review |
Memory Management Safety
|
Test failures
-
(Low, 1)
Minor numerical mismatch in Thunder vs Torch instance_norm nvFuser CUDA testTest Name A100 Source thunder.tests.test_ops.test_core_vs_torch_consistency_instance_norm_nvfuser_cuda_thunder.dtypes.float32 ❌
3a199c8 to
53e5045
Compare
Change Fusion::ir_container_ from unique_ptr to shared_ptr to enable future container sharing between Fusions. Add Fusion tracking API to IrContainer (addFusion/removeFusion/transferFusion/sharingCount). Remove IrContainer::parent_ since the 1:1 relationship no longer holds. Disable parallel compilation during the shared_ptr transition.
074c814 to
54cd0fe
Compare
53e5045 to
f8ff364
Compare
|
!test |
Greptile SummaryThis PR replaces
Confidence Score: 4/5
Important Files Changed
Class Diagram%%{init: {'theme': 'neutral'}}%%
classDiagram
class IrContainer {
-unordered_set~Fusion*~ sharing_fusions_
-deque~unique_ptr~Val~~ vals_up_
-deque~unique_ptr~Expr~~ exprs_up_
+addFusion(Fusion*)
+removeFusion(Fusion*)
+transferFusion(Fusion*, Fusion*)
+sharingCount() size_t
+hasMultipleFusions() bool
+sharingFusions() unordered_set~Fusion*~
#copy(IrContainer*, IrContainer*, Fusion*) IrCloner
#swap(IrContainer, IrContainer)
}
class Fusion {
-shared_ptr~IrContainer~ ir_container_
#ir_container() IrContainer*
#ir_container_ptr() shared_ptr~IrContainer~
+Fusion()
+~Fusion()
+swap(Fusion, Fusion)
+copy(Fusion*, Fusion*) IrCloner
}
class Statement {
-Fusion* ir_container_
+container() Fusion*
+fusion() Fusion*
}
Fusion "1..*" --> "1" IrContainer : shared_ptr
Statement "*" --> "1" Fusion : raw pointer
IrContainer "1" --> "1..*" Fusion : sharing_fusions_
Last reviewed commit: f8ff364 |
Additional Comments (1)
These comments reference "parent backpointers" and say "each Fusion owns a different IrContainer", both of which are artifacts of the old |
Summary
Replace
unique_ptr<IrContainer>withshared_ptr<IrContainer>in Fusion and add the container-side registration API that tracks which Fusions share a given container.This is the foundational change of Phase 2. The pointer type change alone has no behavioral impact — single-Fusion containers behave identically under
shared_ptr. The tracking infrastructure (sharing_fusions_,addFusion/removeFusion) lays the groundwork for all subsequent tasks.Parallel compilation is disabled in-code via
kPhase2DisableParallelCompile = trueas a precaution during the transition. This ensures CI runs serial compilation for later PRs without requiring environment variables. Parallel compilation is restored in #5971 .Relationship to Phase 2
This is the core type change that enables the shared container model:
Without this change, no subsequent Phase 2 work (per-Fusion tracking, shared-container copy/move, thread safety) is possible. The tracking API is the mechanism that makes container sharing safe — it allows the container to know its consumers, enabling correct cleanup when Fusions are destroyed.
CI Risk
Low. For single-Fusion containers (all existing usage),
shared_ptris behaviorally identical tounique_ptr. No accessor paths change. Parallel compilation is serialized by the in-code constant.