Skip to content

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 53e5045

Description

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

  • Replace parent_ pointer with sharing_fusions_ set for multi-Fusion container support

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

  • Disable parallel compilation during shared_ptr transition with kPhase2DisableParallelCompile

Changes walkthrough

Relevant files
Enhancement
fusion.cpp
Update Fusion class for shared_ptr IrContainer                     

csrc/fusion.cpp

  • Change ir_container_ from unique_ptr to shared_ptr
  • Remove parent_ pointer updates in swap function
  • Update copy constructor to pass dest_fusion parameter
  • Use addFusion in constructor, removeFusion in destructor
  • Minor formatting improvements
  • +8/-10   
    container.cpp
    Implement shared container with Fusion tracking                   

    csrc/ir/container.cpp

  • Remove parent_ member from swap function
  • Update copy function to use dest_fusion instead of parent()
  • Replace parent_ checks with sharing_fusions_ in inContainer
  • Add Fusion tracking API implementation
  • Replace parent_ with sharing_fusions_ unordered_set
  • +31/-5   
    fusion.h
    Update Fusion header for shared_ptr                                           

    csrc/fusion.h

  • Change ir_container_ from unique_ptr to shared_ptr
  • Add ir_container_ptr() method for shared_ptr access
  • Update comments for new ownership model
  • +5/-2     
    container.h
    Update IrContainer header for shared ownership                     

    csrc/ir/container.h

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

    csrc/runtime/fusion_kernel_runtime.cpp

  • Add kPhase2DisableParallelCompile constant set to true
  • Update parallel compilation checks to use the new constant
  • +7/-2     

    PR Reviewer Guide

    Here are some key observations to aid the review process:

    🧪 No relevant tests
    ⚡ Recommended focus areas for review
    Missing Error Handling

    In the destructor, the code calls ir_container_->removeFusion(this) without checking if ir_container_ is null. While there's a null check, the error message suggests this should never happen, but defensive programming would be safer.

    if (ir_container_) {
      ir_container_->removeFusion(this);
    }
    Potential Race Condition

    The new fusion tracking methods (addFusion, removeFusion, transferFusion) modify the sharing_fusions_ set, but there's no synchronization mechanism visible. If multiple threads could access these methods concurrently, this could lead to race conditions.

    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_;
    }
    Hardcoded Flag

    The kPhase2DisableParallelCompile flag is hardcoded to true with a TODO comment to remove when std::shared_mutex is added. This should be made configurable or have a clear timeline for removal to avoid accidentally leaving parallel compilation disabled in production.

    constexpr bool kPhase2DisableParallelCompile = true;

    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.
    @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
    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