Skip to content

Commit

Permalink
Merge pull request #107 from xdslproject/parametrize-collapse-and-tiles
Browse files Browse the repository at this point in the history
compiler: Parametrize collapse and tiles
  • Loading branch information
georgebisbas authored Jul 1, 2024
2 parents 65127f4 + e43eef3 commit ee1326e
Show file tree
Hide file tree
Showing 5 changed files with 439 additions and 6 deletions.
2 changes: 1 addition & 1 deletion devito/ir/xdsl_iet/cluster_to_ssa.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def build_time_loop(
)

# Name the 'time' step iterator
assert step_dim.root.name is 'time'
assert step_dim.root.name == 'time'
loop.body.block.args[0].name_hint = step_dim.root.name
# Store for later reference
self.symbol_values[step_dim.root.name] = loop.body.block.args[0]
Expand Down
33 changes: 28 additions & 5 deletions devito/xdsl_core/xdsl_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

class XdslnoopOperator(Cpu64OperatorMixin, CoreOperator):

# This operator needs more testing as we currently compare the starting
# initial generated code against the advanced one
_Target = CTarget

@classmethod
Expand Down Expand Up @@ -400,7 +402,9 @@ def _jit_compile(self):
mlir_pipeline = generate_MLIR_CPU_PIPELINE()

if is_omp:
mlir_pipeline = generate_MLIR_OPENMP_PIPELINE()
# We collapse as many loops as we tile
kwargs = {'num_loops': to_tile}
mlir_pipeline = generate_MLIR_OPENMP_PIPELINE(kwargs)

if is_mpi:
shape, _ = self.mpi_shape
Expand Down Expand Up @@ -442,9 +446,9 @@ def _jit_compile(self):
cflags += ' -lmpi '
cc = "mpicc -cc=clang"
if is_omp:
cflags += " -fopenmp "
cflags += " -fopenmp"
if is_gpu:
cflags += " -lmlir_cuda_runtime "
cflags += " -lmlir_cuda_runtime"

cflags += " -shared "

Expand Down Expand Up @@ -552,7 +556,9 @@ def generate_MLIR_CPU_noop_PIPELINE():
return generate_mlir_pipeline(passes)


def generate_MLIR_OPENMP_PIPELINE():
def generate_MLIR_OPENMP_PIPELINE(kwargs):
num_loops = kwargs.get('num_loops')

return generate_pipeline([
generate_mlir_pipeline([
"canonicalize",
Expand All @@ -572,7 +578,7 @@ def generate_MLIR_OPENMP_PIPELINE():
# "canonicalize",
# "cse",
]),
"convert-scf-to-openmp{collapse=1}",
f"convert-scf-to-openmp{{{generate_collapse_arg(num_loops)}}}",
generate_mlir_pipeline([
"finalize-memref-to-llvm",
"convert-scf-to-cf"
Expand Down Expand Up @@ -652,9 +658,26 @@ def generate_tiling_arg(nb_tiled_dims: int):
"""
if nb_tiled_dims < 1:
return 'parallel-loop-tile-sizes=0'

# TOFIX: 64 is hardcoded, should be a parameter
# TOFIX: Zero is also hardcoded, should be a parameter
return "parallel-loop-tile-sizes=" + ",".join(["64"]*nb_tiled_dims) + ",0"


def generate_collapse_arg(num_loops: int):
"""
Generate the number of loops that will be collapsed
Resort to 1 if no number of loops is provided
"""

if num_loops < 1:
num_loops = 1

ret_arg = "collapse=" + "".join(str(num_loops)) # noqa

return ret_arg


def get_arg_names_from_module(op):
return [
str_attr.name_hint for str_attr in op.body.block.ops.first.body.block.args # noqa
Expand Down
Loading

0 comments on commit ee1326e

Please sign in to comment.