Skip to content

Conversation

@kevinstephano
Copy link
Collaborator

I found this useful when trying to understanding the printing of the ID-Model in the test_tutorial.py file.

@github-actions
Copy link

github-actions bot commented Oct 14, 2025

Review updated until commit e3388d0

Description

  • Add print() method to Fusion for full pre-scheduled IR output

  • Include test validating FusionDefinition IR string representation

  • Expose debug-level fusion IR as returnable string in Python

  • Verify printed IR matches expected pre-scheduled structure


Changes walkthrough 📝

Relevant files
Enhancement
runtime.cpp
Add Fusion.print() to expose pre-scheduled IR in Python   

python/python_direct/runtime.cpp

  • Added print method to Fusion class in Python bindings
  • Uses DebugStreamGuard and f.print(ss) to capture IR
  • Returns full pre-scheduled fusion IR as a Python string
  • Complements existing print_math method
  • +18/-0   
    Tests
    test_python_direct.py
    Test FusionDefinition.print() string representation           

    tests/python/direct/test_python_direct.py

  • Added test for fd.fusion.print() output
  • Defined expected full pre-scheduled IR string
  • Asserted printed IR matches expected format
  • Verified inputs, outputs, kernel, and TransformPrinter sections
  • +28/-0   

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🧪 PR contains tests
    ⚡ Recommended focus areas for review

    Potential Performance Overhead

    The use of DebugStreamGuard in the print method may introduce unnecessary overhead, as it is typically meant for debug logging rather than regular string serialization. Consider whether this guard is needed for the intended use case of printing the fusion IR.

    std::stringstream ss;
    DebugStreamGuard dsg(ss);
    String Equality with Formatting Sensitivity

    The test relies on exact string matching including whitespace and newlines, which may lead to fragile tests if formatting changes in the future. Consider using a more robust comparison method that ignores insignificant formatting differences.

        full_prescheduled_fusion_definition = """Inputs:
      T0_g_float[iS0{2}, iS1{4}, iS2{8}]
      T1_g_float[iS3{2}, iS4{4}, iS5{8}]
    Outputs:
      T2_g_float[iS6{2}, iS7{4}, iS8{8}]
    
    %kernel {
    T2_g_float[iS6{2}, iS7{4}, iS8{8}]
       = T0_g_float[iS0{2}, iS1{4}, iS2{8}]
       + T1_g_float[iS3{2}, iS4{4}, iS5{8}];
    
    TransformPrinter :
    T0_g_float[iS0{2}, iS1{4}, iS2{8}]
     logical domain : (iS0{2}, iS1{4}, iS2{8})
     contiguity: f f f
     loop domain : (iS0{2}, iS1{4}, iS2{8})
    T1_g_float[iS3{2}, iS4{4}, iS5{8}]
     logical domain : (iS3{2}, iS4{4}, iS5{8})
     contiguity: f f f
     loop domain : (iS3{2}, iS4{4}, iS5{8})
    T2_g_float[iS6{2}, iS7{4}, iS8{8}]
     logical domain : (iS6{2}, iS7{4}, iS8{8})
     contiguity: t t t
     loop domain : (iS6{2}, iS7{4}, iS8{8})
    } // %kernel\n"""

    @kevinstephano
    Copy link
    Collaborator Author

    !test

    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.

    2 participants