Skip to content

Commit 23c1dce

Browse files
committed
[UI] Add explore at stage button
With it IR can be printed individually after a stage in the custom pipeline.
1 parent 98143f4 commit 23c1dce

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

src/app/page.js

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ export default function PyTorchTritonExplorer() {
137137
const [editFlags, setEditFlags] = useState("");
138138
const [editModalVisible, setEditModalVisible] = useState(false);
139139
const [layout, setLayout] = useState("vertical");
140+
const [exploreStage, setExploreStage] = useState({
141+
windowId: null,
142+
stageIdx: null,
143+
});
140144

141145
const isTriton = selectedLanguage === "triton";
142146
const isPytorch = selectedLanguage === "pytorch";
@@ -346,7 +350,19 @@ export default function PyTorchTritonExplorer() {
346350
}));
347351
};
348352

353+
function filterToStage(fullDump, stageIdx) {
354+
const slices = fullDump.split(/===== /).slice(1);
355+
const block = slices[stageIdx + 1];
356+
if (!block) {
357+
// out-of-range - fallback to dump after each stage
358+
return fullDump;
359+
}
360+
const lines = block.split("\n");
361+
return lines.slice(1).join("\n").trim();
362+
}
363+
349364
const generateIR = async (id) => {
365+
const exploring = exploreStage.windowId === id;
350366
updateActiveSource((s) => ({
351367
...s,
352368
irWindows: s.irWindows.map((w) =>
@@ -386,7 +402,7 @@ export default function PyTorchTritonExplorer() {
386402
.filter((p) => p.tool === "user-tool")
387403
.map((p) => p.flags)
388404
.join(" && "),
389-
dump_after_each_opt: irWin.dumpAfterEachOpt,
405+
dump_after_each_opt: exploring ? true : irWin.dumpAfterEachOpt,
390406
};
391407

392408
const response = await fetch(
@@ -1023,6 +1039,23 @@ export default function PyTorchTritonExplorer() {
10231039
{preview}
10241040
</span>
10251041
</span>
1042+
{/*Explore‐at‐this‐stage*/}
1043+
<button
1044+
onClick={() => {
1045+
setExploreStage({
1046+
windowId: irWin.id,
1047+
stageIdx: i,
1048+
});
1049+
generateIR(irWin.id);
1050+
}}
1051+
style={{
1052+
marginLeft: 4,
1053+
padding: "2px 6px",
1054+
cursor: "pointer",
1055+
}}
1056+
>
1057+
🔍
1058+
</button>
10261059
</React.Fragment>
10271060
);
10281061
})}
@@ -1081,6 +1114,28 @@ export default function PyTorchTritonExplorer() {
10811114
? "✓ Print IR after opts"
10821115
: "Print IR after opts"}
10831116
</button>
1117+
{/*Reset explore-mode*/}
1118+
{exploreStage.windowId === irWin.id && (
1119+
<button
1120+
onClick={() =>
1121+
setExploreStage({
1122+
windowId: null,
1123+
stageIdx: null,
1124+
})
1125+
}
1126+
style={{
1127+
flex: 1,
1128+
padding: "4px",
1129+
backgroundColor: "#ccc",
1130+
border: "none",
1131+
borderRadius: "5px",
1132+
fontWeight: "bold",
1133+
cursor: "pointer",
1134+
}}
1135+
>
1136+
Reset Explore At Stage
1137+
</button>
1138+
)}
10841139
</div>
10851140
<div
10861141
style={{
@@ -1092,7 +1147,14 @@ export default function PyTorchTritonExplorer() {
10921147
<Editor
10931148
height="100%"
10941149
language="mlir"
1095-
value={irWin.output}
1150+
value={
1151+
exploreStage.windowId === irWin.id
1152+
? filterToStage(
1153+
irWin.output,
1154+
exploreStage.stageIdx,
1155+
)
1156+
: irWin.output
1157+
}
10961158
onChange={() => {}}
10971159
theme="mlirTheme"
10981160
options={{ readOnly: true }}

0 commit comments

Comments
 (0)