Skip to content

Commit 10ee3c9

Browse files
authored
Don't use window as variable name. (#6)
This allows to use the global `window` variable to e.g. get the host we're on -> don't hardcode localhost.
2 parents 2b2ec65 + 81ad23d commit 10ee3c9

File tree

2 files changed

+42
-40
lines changed

2 files changed

+42
-40
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
!.yarn/releases
1111
!.yarn/versions
1212

13+
mlir_venv
14+
1315
# python temps
1416
__pycache__/
1517

src/app/page.js

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -303,42 +303,42 @@ export default function PyTorchTritonExplorer() {
303303
prev.map((w) => (w.id === id ? { ...w, loading: true } : w))
304304
);
305305

306-
const window = irWindows.find((w) => w.id === id);
307-
if (!window) return;
306+
const irWin = irWindows.find((w) => w.id === id);
307+
if (!irWin) return;
308308

309309
const body = {
310310
code,
311-
ir_type: window.selectedIR,
311+
ir_type: irWin.selectedIR,
312312
selected_language: selectedLanguage,
313313
custom_pipeline: [],
314-
torch_mlir_opt: window.pipeline
314+
torch_mlir_opt: irWin.pipeline
315315
.filter((p) => p.tool === "torch-mlir-opt")
316316
.map((p) => p.flags)
317317
.join(" && "),
318-
mlir_opt: window.pipeline
318+
mlir_opt: irWin.pipeline
319319
.filter((p) => p.tool === "mlir-opt")
320320
.map((p) => p.flags)
321321
.join(" && "),
322-
mlir_translate: window.pipeline
322+
mlir_translate: irWin.pipeline
323323
.filter((p) => p.tool === "mlir-translate")
324324
.map((p) => p.flags)
325325
.join(" && "),
326-
llvm_opt: window.pipeline
326+
llvm_opt: irWin.pipeline
327327
.filter((p) => p.tool === "opt")
328328
.map((p) => p.flags)
329329
.join(" && "),
330-
llc: window.pipeline
330+
llc: irWin.pipeline
331331
.filter((p) => p.tool === "llc")
332332
.map((p) => p.flags)
333333
.join(" && "),
334-
user_tool: window.pipeline
334+
user_tool: irWin.pipeline
335335
.filter((p) => p.tool === "user-tool")
336336
.map((p) => p.flags)
337337
.join(" && "),
338-
dump_after_each_opt: window.dumpAfterEachOpt,
338+
dump_after_each_opt: irWin.dumpAfterEachOpt,
339339
};
340340

341-
const response = await fetch("http://localhost:8000/generate_ir", {
341+
const response = await fetch("http://" + window.location.hostname + ":8000/generate_ir", {
342342
method: "POST",
343343
headers: { "Content-Type": "application/json" },
344344
body: JSON.stringify(body),
@@ -511,9 +511,9 @@ export default function PyTorchTritonExplorer() {
511511
</button>
512512
</div>
513513

514-
{irWindows.map((window) => (
514+
{irWindows.map((irWin) => (
515515
<div
516-
key={window.id}
516+
key={irWin.id}
517517
style={{
518518
backgroundColor: "white",
519519
borderRadius: "8px",
@@ -532,10 +532,10 @@ export default function PyTorchTritonExplorer() {
532532
alignItems: "center",
533533
}}
534534
>
535-
<h3>Output {getLabelForIR(window.selectedIR)}</h3>
535+
<h3>Output {getLabelForIR(irWin.selectedIR)}</h3>
536536
<div>
537537
<button
538-
onClick={() => toggleCollapse(window.id)}
538+
onClick={() => toggleCollapse(irWin.id)}
539539
style={{
540540
marginRight: "8px",
541541
padding: "5px",
@@ -545,10 +545,10 @@ export default function PyTorchTritonExplorer() {
545545
cursor: "pointer",
546546
}}
547547
>
548-
{window.collapsed ? "Expand" : "Collapse"}
548+
{irWin.collapsed ? "Expand" : "Collapse"}
549549
</button>
550550
<button
551-
onClick={() => removeWindow(window.id)}
551+
onClick={() => removeWindow(irWin.id)}
552552
style={{
553553
backgroundColor: "#f66",
554554
border: "none",
@@ -562,11 +562,11 @@ export default function PyTorchTritonExplorer() {
562562
</div>
563563
</div>
564564

565-
{!window.collapsed && (
565+
{!irWin.collapsed && (
566566
<>
567567
<select
568-
value={window.selectedIR}
569-
onChange={(e) => handleIRChange(window.id, e)}
568+
value={irWin.selectedIR}
569+
onChange={(e) => handleIRChange(irWin.id, e)}
570570
style={{ marginBottom: "10px" }}
571571
>
572572
{getIROptions().map((opt) => (
@@ -579,7 +579,7 @@ export default function PyTorchTritonExplorer() {
579579
selectedLanguage == "raw_ir") &&
580580
(() => {
581581
const allowTorchMlirOpt = ["torch_script_graph_ir", "torch_mlir", "raw_ir"].includes(
582-
window.selectedIR
582+
irWin.selectedIR
583583
);
584584
const allowMlirOpt = [
585585
"torch_script_graph_ir",
@@ -589,7 +589,7 @@ export default function PyTorchTritonExplorer() {
589589
"stablehlo_mlir",
590590
"llvm_mlir",
591591
"raw_ir",
592-
].includes(window.selectedIR);
592+
].includes(irWin.selectedIR);
593593
const allowMlirTranslate = [
594594
"torch_script_graph_ir",
595595
"torch_mlir",
@@ -598,7 +598,7 @@ export default function PyTorchTritonExplorer() {
598598
"stablehlo_mlir",
599599
"llvm_mlir",
600600
"raw_ir",
601-
].includes(window.selectedIR);
601+
].includes(irWin.selectedIR);
602602
const allowLlvmOpt = true;
603603
const allowLLC = true;
604604
const allowUserTool = true;
@@ -624,7 +624,7 @@ export default function PyTorchTritonExplorer() {
624624
{allowTorchMlirOpt && (
625625
<button
626626
onClick={() =>
627-
handleAddPass(window.id, "torch-mlir-opt")
627+
handleAddPass(irWin.id, "torch-mlir-opt")
628628
}
629629
style={{
630630
padding: "6px 10px",
@@ -644,7 +644,7 @@ export default function PyTorchTritonExplorer() {
644644
)}
645645
{allowMlirOpt && (
646646
<button
647-
onClick={() => handleAddPass(window.id, "mlir-opt")}
647+
onClick={() => handleAddPass(irWin.id, "mlir-opt")}
648648
style={{
649649
padding: "6px 10px",
650650
backgroundColor: "#add8e6",
@@ -664,7 +664,7 @@ export default function PyTorchTritonExplorer() {
664664
{allowMlirTranslate && (
665665
<button
666666
onClick={() =>
667-
handleAddPass(window.id, "mlir-translate")
667+
handleAddPass(irWin.id, "mlir-translate")
668668
}
669669
style={{
670670
padding: "6px 10px",
@@ -684,7 +684,7 @@ export default function PyTorchTritonExplorer() {
684684
)}
685685
{allowLlvmOpt && (
686686
<button
687-
onClick={() => handleAddPass(window.id, "opt")}
687+
onClick={() => handleAddPass(irWin.id, "opt")}
688688
style={{
689689
padding: "6px 10px",
690690
backgroundColor: "#add8e6",
@@ -703,7 +703,7 @@ export default function PyTorchTritonExplorer() {
703703
)}
704704
{allowLLC && (
705705
<button
706-
onClick={() => handleAddPass(window.id, "llc")}
706+
onClick={() => handleAddPass(irWin.id, "llc")}
707707
style={{
708708
padding: "6px 10px",
709709
backgroundColor: "#add8e6",
@@ -723,7 +723,7 @@ export default function PyTorchTritonExplorer() {
723723
{allowUserTool && (
724724
<button
725725
onClick={() =>
726-
handleAddPass(window.id, "user-tool")
726+
handleAddPass(irWin.id, "user-tool")
727727
}
728728
style={{
729729
padding: "6px 10px",
@@ -745,7 +745,7 @@ export default function PyTorchTritonExplorer() {
745745
onClick={() =>
746746
setIrWindows((prev) =>
747747
prev.map((w) =>
748-
w.id === window.id
748+
w.id === irWin.id
749749
? {
750750
...w,
751751
dumpAfterEachOpt: !w.dumpAfterEachOpt,
@@ -756,7 +756,7 @@ export default function PyTorchTritonExplorer() {
756756
}
757757
style={{
758758
padding: "6px 10px",
759-
backgroundColor: window.dumpAfterEachOpt
759+
backgroundColor: irWin.dumpAfterEachOpt
760760
? "#5fa"
761761
: "#ccc",
762762
border: "none",
@@ -769,7 +769,7 @@ export default function PyTorchTritonExplorer() {
769769
flexShrink: 0,
770770
}}
771771
>
772-
{window.dumpAfterEachOpt
772+
{irWin.dumpAfterEachOpt
773773
? "✓ Print IR after opts"
774774
: "Print IR after opts"}
775775
</button>
@@ -779,7 +779,7 @@ export default function PyTorchTritonExplorer() {
779779

780780
{(selectedLanguage === "pytorch" ||
781781
selectedLanguage == "raw_ir") &&
782-
window.pipeline.length > 0 && (
782+
irWin.pipeline.length > 0 && (
783783
<div
784784
style={{
785785
marginBottom: "10px",
@@ -821,9 +821,9 @@ export default function PyTorchTritonExplorer() {
821821
fontWeight: "bold",
822822
}}
823823
>
824-
{getLabelForIR(window.selectedIR)}
824+
{getLabelForIR(irWin.selectedIR)}
825825
</span>
826-
{window.pipeline.map((p, i) => {
826+
{irWin.pipeline.map((p, i) => {
827827
const preview =
828828
p.flags.length <= 25
829829
? p.flags
@@ -837,7 +837,7 @@ export default function PyTorchTritonExplorer() {
837837
</span>
838838
<span
839839
onClick={() =>
840-
handleEditPass(window.id, i, p.tool, p.flags)
840+
handleEditPass(irWin.id, i, p.tool, p.flags)
841841
}
842842
style={{
843843
backgroundColor: "#a5d6a7",
@@ -868,7 +868,7 @@ export default function PyTorchTritonExplorer() {
868868
)}
869869

870870
<button
871-
onClick={() => generateIR(window.id)}
871+
onClick={() => generateIR(irWin.id)}
872872
style={{
873873
marginBottom: "6px",
874874
padding: "4px",
@@ -878,15 +878,15 @@ export default function PyTorchTritonExplorer() {
878878
fontWeight: "bold",
879879
cursor: "pointer",
880880
}}
881-
disabled={window.loading}
881+
disabled={irWin.loading}
882882
>
883-
{window.loading ? "Generating..." : "Generate IR"}
883+
{irWin.loading ? "Generating..." : "Generate IR"}
884884
</button>
885885

886886
<Editor
887887
height="70vh"
888888
language="mlir"
889-
value={window.output}
889+
value={irWin.output}
890890
onChange={() => {}}
891891
theme="mlirTheme"
892892
options={{ readOnly: true }}

0 commit comments

Comments
 (0)