tum-ei-eda / seal5

Seal5 - Semi-automated LLVM Support for RISC-V Extensions including Autovectorization
https://tum-ei-eda.github.io/seal5/
Apache License 2.0
11 stars 6 forks source link

Add Tranform Python API / Allow calling transforms/backends directly via python (without subprocess) #54

Open PhilippvK opened 6 months ago

PhilippvK commented 6 months ago

Since the transforms and backends are included in the Seal5 Python codebase anyways, it might be reasonable to call them directly from python instead of opening up a subprocess running python -m seal5.transform.name .... If we decide to support using the Python API we should make sure that we have an consistent Inferface. (Python API and CLI of each transform should be feature-compatible and common args for all transforms (log level, ...) should be defined only one)

This change would also be welcome for https://github.com/tum-ei-eda/M2-ISA-R, so i will think about upstreaming it there as well.

To get started, we should define new abstract classes Seal5Frontend, Seal5Transform, and Seal5Backend for introducing such API.

TODOs:

PhilippvK commented 6 months ago

Addition: every pass/transform should be configurable via the Seal5Settings

PhilippvK commented 4 months ago

The details about the new API is still to be decided. I propose to roughly follow these steps:

  1. Split each transforms main() into get_parser() and run(args), allowing sys.argv to be overridden by Python. This allows us to call the transforms from within Python with minimal changes to the passes. The full cmdline is generated manually in the pass functions.
  2. Wrap each transform in a Python class, i.e. seal5.transform.infer_types.InferTypes. The features remain untouched.
  3. Introduce a Python-first configuration approach for each transform, argparse/cmdline support ist generated automatically based on these configs. The config (as well as input/output files) is passed to the transforms as a dict.
  4. Rewrite transforms to share as much common code as possible by streamlining the logging options, parallelism levels and handling of metrics.

Step 1. (& 2.) can be implemented effortlessly, which allows us to eliminate the debugging related issues raised in https://github.com/tum-ei-eda/seal5/issues/64#issuecomment-2081996631. We can also benchmark the Python-based approach vs. the original cmdline-only based one in terms of runtime.

Caveats: