Skip to content

Commit

Permalink
update mlonmcu integration
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Nov 17, 2024
1 parent 7f6fcd8 commit ecaeb61
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Integration/MLonMCU/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Further the script use Python3.8 and assumes that the Virtualenv package is inst
Now setup MLonMCU and all its dependencies:

```
./setup_mlonmcu.sh --enable-tflm --enable-tvm --enable-spike
./setup_mlonmcu.sh --enable-tflm --enable-tvm --enable-spike --enable-vext --enable-gcc --enable-llvm
```

## Usage
Expand Down
13 changes: 7 additions & 6 deletions Integration/MLonMCU/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ export VENV_DIR=$SCRIPT_DIR/venv

# MLonMCU
# export MLONMCU_REF=3ec39b1881535d7a0727b5afd6b78d816b556b73
export MLONMCU_REF=main
# export MLONMCU_REF=main
export MLONMCU_REF=develop
# export MLIF_REF=c7b0e7364c232666ebd5a17476181e3ff9a71d70
export MLIF_REF=main

# TFLM
# export TFLM_REF=47f77ab6876f66a2d5e4b7f0266e374b4260181e
export TFLM_REF=main
export TFLM_REF=8eb6b23de4470d6a8da3131650d6a67514dfa130
export ENABLE_TFLM=0

# TVM
Expand Down Expand Up @@ -54,10 +55,10 @@ export ENABLE_ETISS=0
export LOCAL_GCC=1
export LOCAL_LLVM=1
export ENABLE_DEFAULT=1
export ENABLE_PEXT=1
export ENABLE_VEXT=1
export ENABLE_GCC=1
export ENABLE_LLVM=1
export ENABLE_PEXT=0
export ENABLE_VEXT=0
export ENABLE_GCC=0
export ENABLE_LLVM=0

# LLVM
# Not supported
10 changes: 9 additions & 1 deletion Integration/MLonMCU/environment.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,21 @@ vars:
# toolchain
{% if enable_gcc | int %}
{% if local_gcc | int %}
# riscv_gcc.name: "riscv64-unknown-elf"
riscv_gcc.name: "riscv32-unknown-elf"
riscv_gcc_rv32.name: "riscv32-unknown-elf"
riscv_gcc_rv64.name: "riscv64-unknown-elf"
riscv_gcc.install_dir_default: "{{ home_dir }}/../../../Toolchain/rv32gc"
riscv_gcc_rv32.install_dir_default: "{{ home_dir }}/../../../Toolchain/rv32gc"
riscv_gcc_rv64.install_dir_default: "{{ home_dir }}/../../../Toolchain/rv64gc"
{% if enable_vext | int %}
riscv_gcc.install_dir_vext: "{{ home_dir }}/../../../Toolchain/rv32gcv"
riscv_gcc_rv32.install_dir_vext: "{{ home_dir }}/../../../Toolchain/rv32gcv"
riscv_gcc_rv64.install_dir_vext: "{{ home_dir }}/../../../Toolchain/rv64gcv"
{% endif %}
{% if enable_pext | int %}
riscv_gcc.install_dir_pext: "{{ home_dir }}/../../../Toolchain/rv32gcp"
riscv_gcc_rv32.install_dir_pext: "{{ home_dir }}/../../../Toolchain/rv32gcp"
riscv_gcc_rv64.install_dir_pext: "{{ home_dir }}/../../../Toolchain/rv64gcp"
{% endif %}
{% endif %}
{% endif %}
Expand Down
90 changes: 78 additions & 12 deletions Integration/MLonMCU/gen_muriscnn_benchmarks.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ def post_session(self, report):
)
if "config_tvmaot.desired_layout" in df.columns:
df["Layout"] = df["config_tvmaot.desired_layout"].fillna("NHWC")
if "config_tvmaotplus.desired_layout" in df.columns:
df["Layout"] = df["config_tvmaotplus.desired_layout"].fillna("NHWC")
if "config_tvmrt.desired_layout" in df.columns:
df["Layout"] = df["config_tvmrt.desired_layout"].fillna("NHWC")
if "config_tvmllvm.desired_layout" in df.columns:
df["Layout"] = df["config_tvmllvm.desired_layout"].fillna("NHWC")
df["AutoVectorize"] = df.apply(
lambda row: (
"Loop+SLP"
Expand Down Expand Up @@ -104,7 +110,13 @@ def post_session(self, report):
# ),
# axis=1,
# )
df["Arch"] = df["config_spike.final_arch"].apply(lambda x: x.upper()) # TODO: generalize!
if "config_spike.final_arch" not in df.columns:
df["config_spike.final_arch"] = None
if "config_spike_rv32.final_arch" not in df.columns:
df["config_spike_rv32.final_arch"] = None
if "config_spike_rv64.final_arch" not in df.columns:
df["config_spike_rv64.final_arch"] = None
df["Arch"] = df["config_spike.final_arch"].combine_first(df["config_spike_rv32.final_arch"].combine_first(df["config_spike_rv64.final_arch"])).apply(lambda x: x.upper()) # TODO: generalize!

Check failure on line 119 in Integration/MLonMCU/gen_muriscnn_benchmarks.py

View workflow job for this annotation

GitHub Actions / Flake8

Integration/MLonMCU/gen_muriscnn_benchmarks.py#L119

Line too long (198 > 120 characters) (E501)
del df["Backend"]
report.post_df = df

Expand All @@ -113,6 +125,8 @@ def post_session(self, report):

RISCV_TARGETS = [
"spike",
"spike_rv32",
"spike_rv64",
"ovpsim",
"etiss_pulpino",
]
Expand All @@ -124,10 +138,10 @@ def post_session(self, report):
TARGETS = RISCV_TARGETS + OTHER_TARGETS


AUTOTUNED_TARGETS = ["spike", "ovpsim", "etiss_pulpino"]
AUTOTUNED_TARGETS = ["spike", "spike_rv32", "ovpsim", "etiss_pulpino"]

DEFAULT_TARGETS = [
"spike",
"spike_rv32",
# "host_x86",
# "etiss_pulpino",
"corstone300",
Expand All @@ -138,11 +152,13 @@ def post_session(self, report):
BACKENDS = [
"tflmi",
"tvmaot",
# TODO: tvmllvm, tvmaotplus
"tvmaotplus",
"tvmllvm",
"tvmllvm",
]
DEFAULT_BACKENDS = [
"tflmi",
"tvmaot",
"tvmaotplus",
]

FEATURES = [
Expand All @@ -168,7 +184,7 @@ def post_session(self, report):

TUNING_RECORDS = os.path.join(
os.path.dirname(os.path.abspath(__file__)),
"riscv_cpu_v0.01.log.best",
"riscv_cpu_v0.01.log.best", # TODO: replace?
)


Expand Down Expand Up @@ -202,6 +218,16 @@ def get_target_features(
*([*MURISCVNN_SCALAR, *MURISCVNN_VEXT, *MURISCVNN_PEXT] if enable_muriscvnn else []),
*([*CMSISNN_SCALAR] if enable_cmsisnn else []),
],
"spike_rv32": [
*([*DEFAULT_SCALAR, *DEFAULT_VEXT, *DEFAULT_PEXT] if enable_default else []),
*([*MURISCVNN_SCALAR, *MURISCVNN_VEXT, *MURISCVNN_PEXT] if enable_muriscvnn else []),
*([*CMSISNN_SCALAR] if enable_cmsisnn else []),
],
"spike_rv64": [
*([*DEFAULT_SCALAR, *DEFAULT_VEXT, *DEFAULT_PEXT] if enable_default else []),
*([*MURISCVNN_SCALAR, *MURISCVNN_VEXT, *MURISCVNN_PEXT] if enable_muriscvnn else []),
*([*CMSISNN_SCALAR] if enable_cmsisnn else []),
],
"ovpsim": [
*([*DEFAULT_SCALAR, *DEFAULT_VEXT, *DEFAULT_PEXT] if enable_default else []),
*([*MURISCVNN_SCALAR, *MURISCVNN_VEXT, *MURISCVNN_PEXT] if enable_muriscvnn else []),
Expand Down Expand Up @@ -243,6 +269,8 @@ def get_target_features(

TARGET_ARCH = {
"spike": "riscv",
"spike_rv32": "riscv",
"spike_rv64": "riscv",
"ovpsim": "riscv",
"x86": "x86",
"etiss_pulpino": "riscv",
Expand All @@ -252,13 +280,19 @@ def get_target_features(
BACKEND_DEFAULT_FEATURES = {
"tflmi": [],
"tvmaot": ["unpacked_api", "usmp"],
"tvmaotplus": [],
"tvmrt": [],
"tvmllvm": [],
}


def get_backend_features(backend, target, enable_autotuned=False):
BACKEND_FEATURES = {
"tflmi": [[]],
"tvmaot": [[], *([["autotuned"]] if enable_autotuned and target in AUTOTUNED_TARGETS else [])],
"tvmaotplus": [[], *([["autotuned"]] if enable_autotuned and target in AUTOTUNED_TARGETS else [])],
"tvmrt": [[], *([["autotuned"]] if enable_autotuned and target in AUTOTUNED_TARGETS else [])],
"tvmllvm": [[], *([["autotuned"]] if enable_autotuned and target in AUTOTUNED_TARGETS else [])],
}
return BACKEND_FEATURES[backend]

Expand All @@ -274,9 +308,33 @@ def get_backend_config(backend, features, enable_autotuned=False):
else []
),
],
"tvmaotplus": [
*([{}] if "muriscvnn" in features or "cmsisnn" in features else []),
*(
[{"tvmaotplus.desired_layout": "NCHW"}, {"tvmaotplus.desired_layout": "NHWC"}]
if "muriscvnn" not in features and "cmsisnn" not in features
else []
),
],
"tvmrt": [
*([{}] if "muriscvnn" in features or "cmsisnn" in features else []),
*(
[{"tvmrt.desired_layout": "NCHW"}, {"tvmrt.desired_layout": "NHWC"}]
if "muriscvnn" not in features and "cmsisnn" not in features
else []
),
],
"tvmllvm": [
*([{}] if "muriscvnn" in features or "cmsisnn" in features else []),
*(
[{"tvmllvm.desired_layout": "NCHW"}, {"tvmllvm.desired_layout": "NHWC"}]
if "muriscvnn" not in features and "cmsisnn" not in features
else []
),
],
}
ret = BACKEND_FEATURES[backend]
if enable_autotuned and backend == "tvmaot":
if enable_autotuned and backend in ["tvmaot", "tvmaotplus", "tvmrt", "tvmllvm"]:
for cfg in ret:
cfg.update({"autotuned.results_file": TUNING_RECORDS})
return ret
Expand All @@ -295,6 +353,9 @@ def get_backend_config(backend, features, enable_autotuned=False):
BACKEND_DEFAULT_CONFIG = {
"tflmi": {},
"tvmaot": {"usmp.algorithm": "hill_climb"},
"tvmaotplus": {"usmp.algorithm": "hill_climb"},
"tvmrt": {},
"tvmllvm": {}
}

VLENS = [64, 128, 256, 512, 1024, 2048, 4096, 8192]
Expand Down Expand Up @@ -377,8 +438,13 @@ def get_backend_config(backend, features, enable_autotuned=False):
],
"rename_cols.mapping": {
"config_spike.vlen": "VLEN",
"config_spike_rv32.vlen": "VLEN",
"config_spike_rv64.vlen": "VLEN",
"config_ovpsim.vlen": "VLEN",
"config_tvmaot.desired_layout": "Layout",
"config_tvmaotplus.desired_layout": "Layout",
"config_tvmrt.desired_layout": "Layout",
"config_tvmllvm.desired_layout": "Layout",
"config_mlif.toolchain": "Toolchain",
# "config_auto_vectorize.loop": "Loop",
# "config_auto_vectorize.slp": "SLP",
Expand Down Expand Up @@ -408,7 +474,7 @@ def gen_features(backend, features, validate=False, auto_vectorize=False):
ret.extend(BACKEND_DEFAULT_FEATURES[backend])
if validate:
ret += VALIDATE_FEATURES
if backend == "tvmaot":
if backend in ["tvmaot", "tvmaotplus", "tvmrt", "tvmllvm"]:
# Rename muriscvnn -> muriscvnnbyoc etc.
for feature in features:
if "muriscvnn" in feature:
Expand Down Expand Up @@ -456,13 +522,13 @@ def gen_config(
assert "vext" not in features
assert vlen == 0
if "muriscvnn" in features or "muriscvnnbyoc" in features:
if backend == "tvmaot":
if backend in ["tvmaot", "tvmaotplus", "tvmrt", "tvmllvm"]:
ret["muriscvnnbyoc.mcpu"] = "cortex-m33"
if "vext" in features:
if use_vext != 0:
assert "pext" not in features
if "muriscvnn" in features or "muriscvnnbyoc" in features:
if backend == "tvmaot":
if backend in ["tvmaot", "tvmaotplus", "tvmrt", "tvmllvm"]:
ret["muriscvnnbyoc.mcpu"] = "cortex-m55"
# if not scalar_default_only or "muriscvnn" in features or "muriscvnnbyoc" in features:
ret["vext.vlen"] = vlen
Expand All @@ -474,7 +540,7 @@ def gen_config(
# else:
# assert vlen == 0
if "cmsisnnbyoc" in features:
assert backend == "tvmaot"
assert backend in ["tvmaot", "tvmaotplus", "tvmrt", "tvmllvm"]
if "arm_mvei" in features:
ret["cmsisnnbyoc.mcpu"] = "cortex-m55"
elif "arm_dsp" in features:
Expand Down Expand Up @@ -546,7 +612,7 @@ def benchmark(args):
if (
"cmsisnn" not in target_features
and "muriscvnn" not in target_features
and backend == "tvmaot"
and backend in ["tvmaot", "tvmaotplus", "tvmrt", "tvmllvm"]
):
enable_autotuned = True
for backend_features in get_backend_features(
Expand Down

0 comments on commit ecaeb61

Please sign in to comment.