Skip to content

Commit

Permalink
Make xDSL flow use a temp .mlir file just like the usual temp .c file.
Browse files Browse the repository at this point in the history
Output compile command.
  • Loading branch information
PapyChacal committed Jul 20, 2023
1 parent 335b5f5 commit e9c76a7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions devito/operator/xdsl_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ def _jit_compile(self):
print("JIT Backdoor: loading xdsl file from: " + backdoor)
with open(backdoor, 'r') as f:
module_str = f.read()

source_name = os.path.splitext(self._tf.name)[0] + ".mlir"
source_file = open(source_name, "w")
source_file.write(module_str)
source_file.close()
# compile IR using xdsl-opt | mlir-opt | mlir-translate | clang
try:
cflags = CFLAGS
Expand All @@ -154,15 +157,14 @@ def _jit_compile(self):
# TODO More detailed error handling manually,
# instead of relying on a bash-only feature.
cmd = 'set -eo pipefail; '\
f'xdsl-opt -p {xdsl_pipeline} |' \
f'xdsl-opt {source_name} -p {xdsl_pipeline} |' \
f'mlir-opt -p {mlir_pipeline} | ' \
f'mlir-translate --mlir-to-llvmir | ' \
f'{cc} {cflags} -shared -o {self._tf.name} {self._interop_tf.name} -xir -'

print(cmd)
res = subprocess.run(
cmd,
shell=True,
input=module_str,
text=True,
capture_output=True,
executable="/bin/bash"
Expand All @@ -181,7 +183,7 @@ def _jit_compile(self):
elapsed = self._profiler.py_timers['jit-compile']

perf("XDSLOperator `%s` jit-compiled `%s` in %.2f s with `mlir-opt`" %
(self.name, self._tf.name, elapsed))
(self.name, source_name, elapsed))

@property
def _soname(self):
Expand Down

0 comments on commit e9c76a7

Please sign in to comment.