Skip to content

Conversation

@rdspring1
Copy link
Collaborator

@rdspring1 rdspring1 commented Oct 31, 2025

This PR creates a check to determine if two separate Fusion objects have the same definition. This check is unlike existing equality IR checks the enforce that the object must be exactly the same. This second part of creating an LRU Cache for direct bindings.

sameDefinition details

Val::sameDefinition checks the Val's definition. Expr::sameDefinition checks the Expr's input arguments.
Fusion::sameDefinition starts from each output and traverses the entire Fusion DAG. Unlike the legacy TensorRecord check,
TensorView::sameDefinition directly compares the logical and allocation domain, which handles non-trival operations like
preprocessGroupedMatmulInputSf.

Differences between Val::sameAs and Val::sameDefinition

  • Val::sameVal contains common code for Val::sameAs and Val::sameDefinition
  • sameAs determines if a Statement has the exact same result as the other value.
  • For sameAs, two values without definition nor value are not equal. This is used in concretization.
    In addition, if either Val has a non-deterministic definition, then the Vals are not the same.
  • sameDefinition determines if a two values will create the same fusion definition.
  • Symbolic values and NaNs are considered the same. Also, the value's integer name is checked to ensure argument order.

Differences between Expr::sameAs and Expr::sameDefinition

  • Expr::sameDefinition skips the isDeterministic.

PR Stack

@rdspring1 rdspring1 added the Direct Bindings Python extension with direct mapping to NvFuser CPP objects. label Oct 31, 2025
@github-actions
Copy link

github-actions bot commented Oct 31, 2025

Review updated until commit 9f6ee7c

Description

  • Implement sameDefinition for Fusion to compare structural equivalence

  • Add sameDefinition methods across IR nodes: Val, Expr, IterDomain, etc.

  • Support alias and symbolic value handling in definition equality checks

  • Introduce comprehensive tests for fusion definition equality


Changes walkthrough 📝

Relevant files
Enhancement
8 files
fusion.cpp
Add Fusion::sameDefinition for structural comparison         
+46/-0   
base_nodes.cpp
Implement Val::sameVal and sameDefinition methods               
+90/-28 
nodes.cpp
Add sameDefinition for IterDomain and TensorDomain             
+93/-39 
tensor_view.cpp
Implement TensorView::sameDefinition override                       
+15/-0   
fusion.h
Declare Fusion::sameDefinition method                                       
+3/-0     
base_nodes.h
Declare sameDefinition and sameVal in Val and Expr             
+15/-0   
interface_nodes.h
Declare TensorView::sameDefinition override                           
+2/-0     
internal_base_nodes.h
Declare sameDefinition for IterDomain and TensorDomain     
+4/-0     
Tests
1 files
test_fusion_hash.cpp
Add tests for Fusion sameDefinition and hashing                   
+93/-0   

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
⚡ Recommended focus areas for review

Input Order Sensitivity

The sameDefinition function in Fusion checks inputs and outputs by index, implying order sensitivity. This may lead to false negatives when comparing functionally equivalent fusions with reordered inputs/outputs. Consider whether definition equality should be order-independent.

if (inputs().size() != other.inputs().size()) {
  return false;
}
if (outputs().size() != other.outputs().size()) {
  return false;
NaN Handling in sameDefinition

The sameDefinition method handles NaN values specially for double types, but this logic may need to be extended to other floating-point types (e.g., float) for consistency. Consider whether this NaN equality logic should be applied more broadly.

if (value_.is<double>() && std::isnan(value_.as<double>()) &&
    std::isnan(other_val->value_.as<double>())) {
  return true;
Complex Allocation Domain Check

The strideOrder method returns empty for complex allocation domains, which affects how tensor domains are compared in sameDefinition. This special case should be validated to ensure it doesn't lead to incorrect equality determinations between tensor domains that should be considered different.

bool is_complex_allocation = std::all_of(
    allocation_domain_.begin(), allocation_domain_.end(), [](IterDomain* id) {
      return id->extent()->definition() != nullptr;
    });
if (is_complex_allocation) {
  return {};
}

@rdspring1 rdspring1 marked this pull request as draft October 31, 2025 02:32
@rdspring1 rdspring1 force-pushed the equality_fusion branch 3 times, most recently from 0c6874f to 91324c6 Compare November 4, 2025 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Direct Bindings Python extension with direct mapping to NvFuser CPP objects.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants