Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions python/python_direct/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ Notes
- This output is not returned from the fusion.
- The same value can be registered as a regular output, so it is returned from
the fusion.
)")
.def(
"print",
[](Fusion& f) {
// Send debug messages to stringstream
std::stringstream ss;
DebugStreamGuard dsg(ss);

f.print(ss);
return ss.str();
},
R"(
Return a string representing the expressions in the fusion.

Returns
-------
str
The fusion intermediate representation (IR) as a string.
)")
.def(
"print_math",
Expand Down
28 changes: 28 additions & 0 deletions tests/python/direct/test_python_direct.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@ def test_fusion_definition_print():
tv2 = fd.ops.add(tv0, tv1)
fd.add_output(tv2)

# Test fusion representation
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"""
assert fd.fusion.print() == full_prescheduled_fusion_definition

# Test fusion math representation
prescheduled_fusion_definition = """Inputs:
T0_g_float[iS0{2}, iS1{4}, iS2{8}]
Expand Down
Loading