Skip to content

Commit

Permalink
Insert necessary boilerplate. stencil lowerings doesn't handle it.
Browse files Browse the repository at this point in the history
  • Loading branch information
PapyChacal committed Jul 28, 2023
1 parent 6de1971 commit 4702dfb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
19 changes: 18 additions & 1 deletion devito/ir/ietxdsl/cluster_to_ssa.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ------------- devito import -------------#

from sympy import Add, Expr, Float, Indexed, Integer, Mod, Mul, Pow, Symbol
from xdsl.dialects import arith, builtin, func, memref, scf, stencil
from xdsl.dialects import arith, builtin, func, memref, scf, stencil, gpu
from xdsl.dialects.experimental import dmp, math
from xdsl.ir import Attribute, Block, Operation, OpResult, Region, SSAValue
from typing import Any
Expand Down Expand Up @@ -479,8 +479,25 @@ def match_and_rewrite(self, op: iet_ssa.LoadSymbolic, rewriter: PatternRewriter,
if symb_name not in args:
body = parent.body.blocks[0]
args[symb_name] = body.insert_arg(op.result.type, len(body.args))
# GPU STUFF

arg = args[symb_name]
shapetype = arg.type
if isinstance(shapetype, stencil.FieldType):
memref_type = memref.MemRefType.from_element_type_and_shape(shapetype.get_element_type(), shapetype.get_shape())
alloc = gpu.AllocOp(memref.MemRefType.from_element_type_and_shape(shapetype.get_element_type(), shapetype.get_shape()))
outcast = builtin.UnrealizedConversionCastOp.get(alloc, shapetype)
# arg.replace_by(outcast.results[0])
args[symb_name] = outcast.results[0]
incast = builtin.UnrealizedConversionCastOp.get(arg, memref_type)
copy = gpu.MemcpyOp(source=incast, destination=alloc)
body.insert_ops_before([alloc, outcast, incast, copy], body.ops.first)
print(arg)
print(arg.uses)
print(parent)

op.result.replace_by(args[symb_name])

rewriter.erase_matched_op()
parent.update_function_type()
# attach information on parameter names to func
Expand Down
6 changes: 3 additions & 3 deletions devito/operator/xdsl_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@
# gpu-launch-sink-index-computations seemed to have no impact
MLIR_GPU_PIPELINE = '"builtin.module(test-math-algebraic-simplification,scf-parallel-loop-tiling{parallel-loop-tile-sizes=128,1,1},func.func(gpu-map-parallel-loops),convert-parallel-loops-to-gpu,fold-memref-alias-ops,expand-strided-metadata,lower-affine,gpu-kernel-outlining,canonicalize,cse,convert-arith-to-llvm{index-bitwidth=64},finalize-memref-to-llvm{index-bitwidth=64},convert-scf-to-cf,convert-cf-to-llvm{index-bitwidth=64},canonicalize,cse,gpu.module(convert-gpu-to-nvvm,reconcile-unrealized-casts,canonicalize,gpu-to-cubin),gpu-to-llvm,canonicalize,cse)"'

XDSL_CPU_PIPELINE = "stencil-shape-inference,convert-stencil-to-ll-mlir,printf-to-llvm"
XDSL_GPU_PIPELINE = "stencil-shape-inference,convert-stencil-to-ll-mlir{target=gpu},printf-to-llvm"
XDSL_MPI_PIPELINE = lambda decomp: f'"dmp-decompose-2d{decomp},convert-stencil-to-ll-mlir,dmp-to-mpi{{mpi_init=false}},lower-mpi,printf-to-llvm"'
XDSL_CPU_PIPELINE = "stencil-shape-inference,convert-stencil-to-ll-mlir,reconcile-unrealized-casts,printf-to-llvm"
XDSL_GPU_PIPELINE = "stencil-shape-inference,convert-stencil-to-ll-mlir{target=gpu},reconcile-unrealized-casts,printf-to-llvm"
XDSL_MPI_PIPELINE = lambda decomp: f'"dmp-decompose-2d{decomp},convert-stencil-to-ll-mlir,reconcile-unrealized-casts,dmp-to-mpi{{mpi_init=false}},lower-mpi,printf-to-llvm"'


class XDSLOperator(Operator):
Expand Down

0 comments on commit 4702dfb

Please sign in to comment.