File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2020from xtc .backends .mlir .MlirCompilerPasses import (
2121 MlirProgramInsertTransformPass ,
2222 MlirProgramApplyTransformPass ,
23- MlirProgramApplyPasses ,
23+ apply_bufferization_passes ,
2424)
2525
2626from 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
Original file line number Diff line number Diff line change 2626 OpResult ,
2727)
2828from mlir .passmanager import PassManager
29+ import platform
2930
3031# Import SDist if available
3132try :
@@ -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+ )
You can’t perform that action at this time.
0 commit comments