Skip to content

[IR Container] Phase 2.3 Basic shared ptr#5960

Draft
mdavis36 wants to merge 1 commit intomd/fusion-stmt-regfrom
md/phase2-shared-ptr
Draft

[IR Container] Phase 2.3 Basic shared ptr#5960
mdavis36 wants to merge 1 commit intomd/fusion-stmt-regfrom
md/phase2-shared-ptr

Conversation

@mdavis36
Copy link
Collaborator

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). Disable parallel compilation during the shared_ptr transition.

@mdavis36
Copy link
Collaborator Author

!test

@github-actions
Copy link

github-actions bot commented Feb 12, 2026

Review updated until commit f8ff364

Description

  • Transition Fusion::ir_container_ from unique_ptr to shared_ptr for container sharing

  • Add Fusion tracking API to IrContainer (addFusion/removeFusion/transferFusion/sharingCount)

  • Remove IrContainer::parent_ since 1:1 relationship no longer holds

  • Disable parallel compilation during shared_ptr transition with kPhase2DisableParallelCompile flag

Changes walkthrough

Relevant files
Enhancement
fusion.cpp
Transition Fusion to shared_ptr IrContainer                           

csrc/fusion.cpp

  • Change ir_container_ from unique_ptr to shared_ptr
  • Remove parent_ pointer updates in swap function
  • Update constructor to use addFusion(this) and make_shared
  • Update destructor to call removeFusion(this)
  • Update IrCloner copy call to pass dest_fusion parameter
  • Update inContainer check to use sharing_fusions_ instead of parent_
  • +8/-10   
    container.cpp
    Add Fusion tracking infrastructure to IrContainer               

    csrc/ir/container.cpp

  • Remove parent_ member variable and swap updates
  • Update copy function to accept dest_fusion parameter
  • Add new Fusion tracking API methods
    (addFusion/removeFusion/transferFusion/sharingCount/hasMultipleFusions/sharingFusions)
  • Update inContainer to check sharing_fusions_ instead of parent_
  • +31/-5   
    fusion.h
    Update Fusion header for shared_ptr transition                     

    csrc/fusion.h

  • Change ir_container_ member from unique_ptr to shared_ptr
  • Add ir_container_ptr() method to access shared_ptr
  • +5/-2     
    container.h
    Update IrContainer header for shared_ptr and tracking       

    csrc/ir/container.h

  • Remove parent_ member variable
  • Update copy function signature to accept dest_fusion parameter
  • Add Fusion tracking API declarations
  • +11/-9   
    Configuration changes
    fusion_kernel_runtime.cpp
    Disable parallel compilation during shared_ptr transition

    csrc/runtime/fusion_kernel_runtime.cpp

  • Add kPhase2DisableParallelCompile constant set to true
  • Use constant to disable parallel compilation in compileFusionParallel
  • Use constant to disable parallel compilation in error handling
  • +7/-2     

    PR Reviewer Guide

    Here are some key observations to aid the review process:

    🧪 PR contains tests
    ⚡ Recommended focus areas for review
    Memory Management Safety

    The transition from unique_ptr to shared_ptr requires careful validation of ownership semantics. The removeFusion call in the destructor needs to be verified to prevent dangling references and ensure proper cleanup when multiple fusions share the same container.

    Fusion::~Fusion() {
      clear();
      if (ir_container_) {
        ir_container_->removeFusion(this);
      }
    }
    Container Sharing Logic

    The new sharing_fusions_ tracking mechanism needs validation to ensure it correctly handles fusion addition, removal, and transfer operations. The hasMultipleFusions() and sharingCount() functions should be tested with various fusion sharing scenarios.

    void IrContainer::addFusion(Fusion* fusion) {
      sharing_fusions_.insert(fusion);
    }
    
    void IrContainer::removeFusion(Fusion* fusion) {
      sharing_fusions_.erase(fusion);
    }
    
    void IrContainer::transferFusion(Fusion* from, Fusion* to) {
      sharing_fusions_.erase(from);
      sharing_fusions_.insert(to);
    }
    
    size_t IrContainer::sharingCount() const {
      return sharing_fusions_.size();
    }
    
    bool IrContainer::hasMultipleFusions() const {
      return sharing_fusions_.size() > 1;
    }
    
    const std::unordered_set<Fusion*>& IrContainer::sharingFusions() const {
      return sharing_fusions_;
    }
    Performance Impact

    The kPhase2DisableParallelCompile flag disables parallel compilation which may significantly impact performance. This should be temporary, but the PR should include performance benchmarks or at least acknowledge the performance regression during this transition phase.

    // TODO: Remove when std::shared_mutex is added to IrContainer.
    constexpr bool kPhase2DisableParallelCompile = true;

    @mdavis36 mdavis36 force-pushed the md/phase2-shared-ptr branch from 3a199c8 to 53e5045 Compare February 12, 2026 22:09
    @mdavis36 mdavis36 changed the title [WIP] phase2 basic shared ptr [IR Container] Phase2 Basic shared ptr Feb 12, 2026
    @mdavis36 mdavis36 changed the title [IR Container] Phase2 Basic shared ptr [IR Container] Phase 2.3 Basic shared ptr Feb 18, 2026
    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.
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    1 participant