Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Pipelines cleanup #30

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions devito/operator/xdsl_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
from devito.types import Evaluable, TimeFunction
from devito.types.mlir_types import ptr_of, f32

from mpi4py import MPI

from xdsl.printer import Printer

__all__ = ['XDSLOperator']
Expand All @@ -48,9 +46,11 @@

CFLAGS = "-O3 -march=native -mtune=native -lmlir_c_runner_utils"

MLIR_CPU_PIPELINE = '"builtin.module(canonicalize, cse, loop-invariant-code-motion, canonicalize, cse, loop-invariant-code-motion,cse,canonicalize,fold-memref-alias-ops,expand-strided-metadata, loop-invariant-code-motion,lower-affine,convert-scf-to-cf,convert-math-to-llvm,convert-func-to-llvm{use-bare-ptr-memref-call-conv},finalize-memref-to-llvm,canonicalize,cse)"'
MLIR_OPENMP_PIPELINE = '"builtin.module(canonicalize, cse, loop-invariant-code-motion, canonicalize, cse, loop-invariant-code-motion,cse,canonicalize,fold-memref-alias-ops,expand-strided-metadata, loop-invariant-code-motion,lower-affine,finalize-memref-to-llvm,loop-invariant-code-motion,canonicalize,cse,convert-scf-to-openmp,finalize-memref-to-llvm,convert-scf-to-cf,convert-func-to-llvm{use-bare-ptr-memref-call-conv},convert-openmp-to-llvm,convert-math-to-llvm,reconcile-unrealized-casts,canonicalize,cse)"'
# gpu-launch-sink-index-computations seemed to have no impact

def MLIR_CPU_PIPELINE(openmp: bool):
return ('"builtin.module(canonicalize, cse, loop-invariant-code-motion, fold-memref-alias-ops, loop-invariant-code-motion, lower-affine, finalize-memref-to-llvm, loop-invariant-code-motion, canonicalize, cse, '
f'{"convert-scf-to-openmp, " if openmp else ""}'
'finalize-memref-to-llvm, convert-scf-to-cf, convert-func-to-llvm{use-bare-ptr-memref-call-conv}, convert-openmp-to-llvm, convert-math-to-llvm, reconcile-unrealized-casts, canonicalize, cse)"')
MLIR_GPU_PIPELINE = lambda block_sizes: f'"builtin.module(test-math-algebraic-simplification,scf-parallel-loop-tiling{{parallel-loop-tile-sizes={block_sizes}}},func.func(gpu-map-parallel-loops),convert-parallel-loops-to-gpu,lower-affine, canonicalize,cse, fold-memref-alias-ops, gpu-launch-sink-index-computations, gpu-kernel-outlining, canonicalize{{region-simplify}},cse,fold-memref-alias-ops,expand-strided-metadata,lower-affine,canonicalize,cse,func.func(gpu-async-region),canonicalize,cse,convert-arith-to-llvm{{index-bitwidth=64}},convert-scf-to-cf,convert-cf-to-llvm{{index-bitwidth=64}},canonicalize,cse,convert-func-to-llvm{{use-bare-ptr-memref-call-conv}},gpu.module(convert-gpu-to-nvvm,reconcile-unrealized-casts,canonicalize,gpu-to-cubin),gpu-to-llvm,canonicalize,cse)"'

XDSL_CPU_PIPELINE = lambda nb_tiled_dims: f'"stencil-shape-inference,convert-stencil-to-ll-mlir{{tile-sizes={",".join(["64"]*nb_tiled_dims)}}},printf-to-llvm"'
Expand Down Expand Up @@ -100,9 +100,10 @@ def _jit_compile(self):
#ccode = transform_devito_xdsl_string(self)
#self.ccode = ccode
with self._profiler.timer_on('jit-compile'):
is_mpi = MPI.Is_initialized()
is_mpi = self._options['mpi']
# TODO This one is less clear from what I see in self._options..
is_gpu = os.environ.get("DEVITO_PLATFORM", None) == 'nvidiaX'
is_omp = os.environ.get("DEVITO_LANGUAGE", None) == 'openmp'
is_omp = self._options['openmp']

if is_mpi and is_gpu:
raise RuntimeError("Cannot run MPI+GPU for now!")
Expand All @@ -121,13 +122,11 @@ def _jit_compile(self):
to_tile = len(list(filter(lambda s : str(s) in ["x", "y", "z"], self.dimensions)))-1

xdsl_pipeline = XDSL_CPU_PIPELINE(to_tile)
mlir_pipeline = MLIR_CPU_PIPELINE

block_sizes: list[int] = [min(target, self._jit_kernel_constants.get(f"{dim}_size", 1)) for target, dim in zip([32, 4, 8], ["x", "y", "z"])]
block_sizes = ','.join(str(bs) for bs in block_sizes)

if is_omp:
mlir_pipeline = MLIR_OPENMP_PIPELINE
mlir_pipeline = MLIR_CPU_PIPELINE(is_omp)

if is_mpi:
shape, mpi_rank = self.mpi_shape
Expand Down
Loading