Skip to content

Commit 58ffe40

Browse files
committed
tensor-dialect: changed to pass mac tests, moved bufferize pass
1 parent 3759374 commit 58ffe40

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

src/xtc/backends/mlir/MlirCompiler.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from xtc.backends.mlir.MlirCompilerPasses import (
2121
MlirProgramInsertTransformPass,
2222
MlirProgramApplyTransformPass,
23-
MlirProgramApplyPasses,
23+
apply_bufferization_passes,
2424
)
2525

2626
from xtc.backends.mlir.MlirTarget import (
@@ -151,18 +151,11 @@ def mlir_apply_transform_pass(self) -> None:
151151
self.dump_ir("IR Dump After transform")
152152

153153
def mlir_apply_tensor_lowering_pass(self) -> None:
154-
apply_transform_pass = MlirProgramApplyPasses(
155-
mlir_program=self._mlir_program,
156-
)
157154
if self._config.print_bufferization_ir:
158155
self.dump_ir("IR Dump Before Tensor Lowering")
159-
apply_transform_pass.run(
160-
[
161-
"eliminate-empty-tensors", # causes ops to write directly to out buffer
162-
"one-shot-bufferize{bufferize-function-boundaries=1 function-boundary-type-conversion=identity-layout-map buffer-alignment=256}",
163-
"func.func(promote-buffers-to-stack)",
164-
]
165-
)
156+
157+
apply_bufferization_passes(self._mlir_program)
158+
166159
if self._config.print_bufferization_ir:
167160
self.dump_ir("IR Dump After Tensor Lowering")
168161

src/xtc/backends/mlir/MlirCompilerPasses.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
OpResult,
2727
)
2828
from mlir.passmanager import PassManager
29+
import platform
2930

3031
# Import SDist if available
3132
try:
@@ -549,3 +550,22 @@ def run(self, pass_names: list[str]) -> None:
549550
for name in pass_names:
550551
pm.add(name) # type: ignore # no attribute add
551552
pm.run(self._mlir_program.mlir_module.operation)
553+
554+
555+
def apply_bufferization_passes(mlir_program: RawMlirProgram):
556+
apply_passes = MlirProgramApplyPasses(mlir_program)
557+
bufferize_options = [
558+
"bufferize-function-boundaries=1",
559+
"function-boundary-type-conversion=identity-layout-map",
560+
"buffer-alignment=256",
561+
]
562+
# needed for now because macos mlir version needs to be updated
563+
if platform.system() != "Darwin":
564+
bufferize_options.append("buffer-alignment=256")
565+
apply_passes.run(
566+
[
567+
"eliminate-empty-tensors", # causes ops to write directly to out buffer
568+
f"one-shot-bufferize{{{' '.join(bufferize_options)}}}",
569+
"func.func(promote-buffers-to-stack)",
570+
]
571+
)

0 commit comments

Comments
 (0)