diff --git a/pyphism/phism_runner/runner.py b/pyphism/phism_runner/runner.py index 85a05d54385..2c8493b0ea5 100644 --- a/pyphism/phism_runner/runner.py +++ b/pyphism/phism_runner/runner.py @@ -278,6 +278,7 @@ def polygeist_compile_c( ): """Compile C/C++ code to MLIR using mlir-clang.""" src_file, self.cur_file = self.cur_file, self.cur_file.replace(suffix, ".mlir") + log_file = src_file.replace(suffix, ".log") self.run_command(cmd=f'sed -i "s/static//g" {src_file}', shell=True) self.run_command( @@ -304,6 +305,7 @@ def polygeist_compile_c( + (flags if flags else []) ), stdout=open(self.cur_file, "w"), + stderr=open(log_file, "w"), shell=True, env=self.env, ) diff --git a/scripts/rosetta.py b/scripts/rosetta.py index 3809b0e2025..77a1deb0743 100755 --- a/scripts/rosetta.py +++ b/scripts/rosetta.py @@ -1,17 +1,44 @@ #!/usr/bin/env python3 import argparse +import functools +import logging import os import shutil +from multiprocessing import Pool +from typing import Tuple from pyphism.phism_runner.options import PhismRunnerOptions from pyphism.phism_runner.runner import PhismRunner from pyphism.utils.helper import get_logger -logger = get_logger("rosetta") +def process(p: Tuple[str, str], vitis_hls_root: str): + root, source_file = p + top_func = source_file.split(".")[0] + options = PhismRunnerOptions( + key="{}-{}".format(root.split("/")[-1], source_file.split(".")[0]), + source_file=os.path.join(root, source_file), + source_dir=root, + work_dir=root, + sanity_check=False, + top_func=top_func, + ) + runner = PhismRunner(options=options) + runner.set_cur_file() + runner.polygeist_compile_c( + flags=[ + "-I", + os.path.abspath(root), + "-I", + f"{vitis_hls_root}/include", + f"--function=*", + ], + suffix=".cpp", + ) -def check_polygeist(work_dir: str, vitis_hls_root: str): + +def check_polygeist(work_dir: str, vitis_hls_root: str, logger: logging.Logger): """""" worklist = [] for root, _, files in os.walk(work_dir): @@ -26,28 +53,8 @@ def check_polygeist(work_dir: str, vitis_hls_root: str): worklist.append((root, source_file)) worklist = set(worklist) - for root, source_file in worklist: - top_func = source_file.split(".")[0] - options = PhismRunnerOptions( - key="{}-{}".format(root.split("/")[-1], source_file.split(".")[0]), - source_file=os.path.join(root, source_file), - source_dir=root, - work_dir=root, - sanity_check=False, - top_func=top_func, - ) - runner = PhismRunner(options=options) - runner.set_cur_file() - runner.polygeist_compile_c( - flags=[ - "-I", - os.path.abspath(root), - "-I", - f"{vitis_hls_root}/include", - f"--function={top_func}", - ], - suffix=".cpp", - ) + with Pool(len(worklist)) as p: + p.map(functools.partial(process, vitis_hls_root=vitis_hls_root), worklist) def main(): @@ -59,7 +66,9 @@ def main(): shutil.copytree(args.source_dir, args.work_dir, dirs_exist_ok=True) - check_polygeist(args.work_dir, vitis_hls_root=args.vitis_hls_root) + logger = get_logger("rosetta", os.path.join(args.work_dir, "phism.log")) + + check_polygeist(args.work_dir, vitis_hls_root=args.vitis_hls_root, logger=logger) if __name__ == "__main__":