Skip to content

Commit 7b2309a

Browse files
committed
Move location and give more helpful output
1 parent ed5f224 commit 7b2309a

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "ingress/KernelBench/KernelBench"]
2+
path = ingress/KernelBench/KernelBench
3+
url = https://github.com/ScalingIntelligence/KernelBench.git

ingress/KernelBench/KernelBench

Submodule KernelBench added at 018c599

ingress/Torch-MLIR/convert-kernel-bench-to-mlir.py renamed to ingress/KernelBench/convert-kernel-bench-to-mlir.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
#!/usr/bin/env python3
22

3+
import sys
34
from pathlib import Path
45

56
from mlir import ir, passmanager
67
from lighthouse.ingress import torch as torch_ingress
78

89

910
kernels_as_pytorch_folder = Path(__file__).parent / "KernelBench" / "KernelBench"
11+
12+
if not (kernels_as_pytorch_folder.exists() and kernels_as_pytorch_folder.is_dir()):
13+
print(
14+
"ERROR: KernelBench repo not found.\n"
15+
"NOTE: Pull in dependency with: git submodule update "
16+
+ str(kernels_as_pytorch_folder.parent.relative_to(Path.cwd()))
17+
+ "",
18+
file=sys.stderr,
19+
)
20+
sys.exit(1)
21+
22+
1023
kernels_as_pytorch_level1 = kernels_as_pytorch_folder / "level1"
1124
kernels_as_pytorch_level2 = kernels_as_pytorch_folder / "level2"
1225

@@ -105,6 +118,7 @@
105118
pm = passmanager.PassManager(context=ctx)
106119
pm.add("linalg-specialize-generic-ops")
107120

121+
print("Output directory:", kernels_as_mlir_folder)
108122
for pytorch_level, mlir_level in (
109123
(kernels_as_pytorch_level1, kernels_as_mlir_level1),
110124
(kernels_as_pytorch_level2, kernels_as_mlir_level2),
@@ -133,16 +147,14 @@
133147
mlir_kernel = torch_ingress.import_from_file(
134148
kernel_pytorch_file, ir_context=ctx
135149
)
150+
assert isinstance(mlir_kernel, ir.Module)
136151

137-
before_clean_up = "//" + str(mlir_kernel)[:-1].replace("\n", "\n//") + "\n"
138152
try:
139153
pm.run(mlir_kernel.operation) # cleanup
140154
except Exception as e:
141-
print(f"Error: got the following error cleaning up {kernel_name}")
155+
print(f"Error: got the following error cleaning up '{kernel_name}'")
142156
raise e
143157

144158
with kernel_as_mlir_path.open("w") as f:
145-
print("// Torch-MLIR output:", file=f)
146-
print(before_clean_up, file=f)
147-
print("// MLIR output after clean-up:", file=f)
159+
print("// MLIR output after conversion and clean-up:", file=f)
148160
print(mlir_kernel, file=f)

0 commit comments

Comments
 (0)