diff --git a/mlonmcu/target/_target.py b/mlonmcu/target/_target.py index 336eb0ae0..50b766f01 100644 --- a/mlonmcu/target/_target.py +++ b/mlonmcu/target/_target.py @@ -25,6 +25,7 @@ AraRtlTarget, CV32E40PTarget, VicunaTarget, + CanMvK230SSHTarget, ) from .arm import Corstone300Target from .host_x86 import HostX86Target @@ -59,3 +60,4 @@ def get_targets(): register_target("ara_rtl", AraRtlTarget) register_target("cv32e40p", CV32E40PTarget) register_target("vicuna", VicunaTarget) +register_target("canmv_k230_ssh", CanMvK230SSHTarget) diff --git a/mlonmcu/target/riscv/__init__.py b/mlonmcu/target/riscv/__init__.py index e030356b6..7905ba5b0 100644 --- a/mlonmcu/target/riscv/__init__.py +++ b/mlonmcu/target/riscv/__init__.py @@ -9,6 +9,7 @@ from .ara_rtl import AraRtlTarget from .cv32e40p import CV32E40PTarget from .vicuna import VicunaTarget +from .canmv_k230_ssh import CanMvK230SSHTarget __all__ = [ "EtissPulpinoTarget", diff --git a/mlonmcu/target/riscv/canmv_k230_ssh.py b/mlonmcu/target/riscv/canmv_k230_ssh.py new file mode 100644 index 000000000..375b94500 --- /dev/null +++ b/mlonmcu/target/riscv/canmv_k230_ssh.py @@ -0,0 +1,116 @@ +# +# Copyright (c) 2022 TUM Department of Electrical and Computer Engineering. +# +# This file is part of MLonMCU. +# See https://github.com/tum-ei-eda/mlonmcu.git for further info. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +"""MLonMCU Spike Target definitions""" + +import os +import time +# from pathlib import Path + +from mlonmcu.logging import get_logger +from mlonmcu.setup.utils import execute +from mlonmcu.target.common import cli +from mlonmcu.target.metrics import Metrics +from mlonmcu.target.ssh_target import SSHTarget +from mlonmcu.target.bench import add_bench_metrics +from .riscv_vext_target import RVVTarget + +logger = get_logger() + + +class CanMvK230SSHTarget(SSHTarget, RVVTarget): + """TODO.""" + + FEATURES = SSHTarget.FEATURES | RVVTarget.FEATURES + + DEFAULTS = { + **SSHTarget.DEFAULTS, + **RVVTarget.DEFAULTS, + "xlen": 64, + "vlen": 128, + } + REQUIRED = SSHTarget.REQUIRED | RVVTarget.REQUIRED + + def __init__(self, name="canmv_k230_ssh", features=None, config=None): + super().__init__(name, features=features, config=config) + + def exec(self, program, *args, cwd=os.getcwd(), handle_exit=None, **kwargs): + """Use target to execute a executable with given arguments""" + + if self.enable_vext: + assert self.vlen == 128, "CanMV K230 only supports VLEN=128" + + if self.timeout_sec > 0: + raise NotImplementedError + + output = self.exec_via_ssh(program, *args, **kwargs) + if handle_exit: + exit_code = handle_exit(0, out=output) + print("exit_code", exit_code) + assert exit_code == 0 + return output + + def parse_stdout(self, out, metrics, exit_code=0): + add_bench_metrics(out, metrics, exit_code != 0, target_name=self.name) + + def get_metrics(self, elf, directory, *args, handle_exit=None): + out = "" + + def _handle_exit(code, out=None): + print("_handle_exit (k230)", code) + assert out is not None + temp = self.parse_exit(out) + # TODO: before or after? + if temp is None: + temp = code + if handle_exit is not None: + temp = handle_exit(temp, out=out) + return temp + + start_time = time.time() + if self.print_outputs: + out = self.exec(elf, *args, cwd=directory, live=True, handle_exit=_handle_exit) + else: + out = self.exec( + elf, *args, cwd=directory, live=False, print_func=lambda *args, **kwargs: None, handle_exit=_handle_exit + ) + # TODO: do something with out? + end_time = time.time() + diff = end_time - start_time + # size instead of readelf? + + # TODO: get exit code + exit_code = 0 + metrics = Metrics() + self.parse_stdout(out, metrics, exit_code=exit_code) + + if metrics.has("Simulated Instructions"): + sim_insns = metrics.get("Simulated Instructions") + if diff > 0: + metrics.add("MIPS", (sim_insns / diff) / 1e6, True) + + return metrics, out, [] + + def get_platform_defs(self, platform): + ret = {} + ret.update(RVVTarget.get_platform_defs(self, platform)) + return ret + + +if __name__ == "__main__": + cli(target=CanMvK230SSHTarget) diff --git a/requirements.txt b/requirements.txt index 643fe595a..fe52f5a93 100644 --- a/requirements.txt +++ b/requirements.txt @@ -21,3 +21,6 @@ psutil # Sessions tqdm filelock + +# SSH +paramiko # TODO: make optional diff --git a/resources/templates/k230.yml.j2 b/resources/templates/k230.yml.j2 new file mode 100644 index 000000000..61d1f1345 --- /dev/null +++ b/resources/templates/k230.yml.j2 @@ -0,0 +1,284 @@ +--- +# The MLONMCU_HOME is filled in automatically when creating the environment +home: "{{ home_dir }}" +logging: + level: DEBUG + to_file: false + rotate: false +cleanup: + auto: true + keep: 50 +# Default locations for certain directoriescan be changed here +# Non-absolute paths will always be threated relative to the MLONMCU_HOME +paths: + # Where the dependencies are downloaded and installed + deps: deps + # If logging to file is used keep logs in this directory + logs: logs + # Location where reports and artifacts are written to + results: results + # Directory where custom extensions can be integrated + plugins: plugins + # Directory for intermediate build products, should be located on a large enough drive + temp: temp + # A collection of models which will be used to look for models + # The paths will be checked in the order defined here stopping at the first match + # Non-existant paths will be skipped without throwing an error + models: + - "{{ home_dir }}/models" + - "{{ config_dir }}/models" +# Here default clone_urls +repos: + tensorflow: + url: "https://github.com/tensorflow/tflite-micro.git" + ref: 93d4b1ccc6e0d1a9062acb1d79f21505daf9d940 + tvm: + url: "https://github.com/apache/tvm.git" + # ref: de6d8067754d746d88262c530b5241b5577b9aae + ref: a9fcac1a47f4b57c1d9d828c7ed1d77452b02cc5 + options: + recursive: true + tvm_extensions: + url: "https://github.com/tum-ei-eda/tvm_extensions.git" + ref: 859bbc89519b610d8adcdba0869d8b087887aabd + muriscvnn: + url: "https://github.com/tum-ei-eda/muriscv-nn.git" + ref: 71800396c2a07202265a8f92c85c33845a369494 # TODO: tag release + etiss: + url: "https://github.com/tum-ei-eda/etiss.git" + ref: 739573d5f12798074bc7d375a46c005f23f59f67 # develop, 23.01.2024 + spike: + url: "https://github.com/riscv-software-src/riscv-isa-sim.git" + ref: 0bc176b3fca43560b9e8586cdbc41cfde073e17a + spikepk: + url: "https://github.com/riscv-software-src/riscv-pk.git" + ref: 7e9b671c0415dfd7b562ac934feb9380075d4aa2 + cmsis: + # url: "https://github.com/PhilippvK/CMSIS_5.git" + url: "https://github.com/ARM-software/CMSIS_5.git" + ref: a75f01746df18bb5b929dfb8dc6c9407fac3a0f3 + # ref: a75f01746df18bb5b929dfb8dc6c9407fac3a0f3 + cmsisnn: + # url: "https://github.com/PhilippvK/CMSIS-NN.git" + url: "https://github.com/ARM-software/CMSIS-NN.git" + # ref: 35ce20560794ddc9e6d87006cad7a3bc665f8319 # v4.0.0 + portability patch + ref: 040da18234b597867bd54d736ca4ceae545b2853 + mlif: + url: "https://github.com/tum-ei-eda/mlonmcu-sw.git" + ref: 0380fec7d7e3959aeedd14aa7fb58729dd4fed16 + espidf: + url: "https://github.com/espressif/esp-idf.git" + ref: release/v4.4 # TODO: v5.2 + options: + recursive: true + microtvm_etiss: + url: "https://github.com/PhilippvK/microtvm-etiss-template.git" + ref: b1e53bdae24bb35e53d7cdad2917a9090f7fa933 + microtvm_spike: + url: "https://github.com/PhilippvK/microtvm-spike-template.git" + ref: ffba460345f5b8682e2a6cb315699ff872c6221e + zephyr: + url: "https://github.com/zephyrproject-rtos/zephyr.git" + ref: v3.2.0 + tflite_pack: + url: "https://github.com/tum-ei-eda/tflite-pack.git" + ref: 2d31cafc941d3889b042af9c0a72b5f768ac4606 + layergen: + url: "https://github.com/PhilippvK/ml-layer-gen.git" + ref: 8d27988fe3a50838521e7c7fb42193da717c5830 + dtc: + url: "https://github.com/dgibson/dtc.git" + ref: main +# Here all supported frameworks with their specific features are defined +# Optionally disable unwanted or incomatible backends or features here +# The configured defaults are used if no backend was specified in the command line options +frameworks: + default: tvm + tflm: + enabled: true + backends: + default: tflmi + tflmi: + enabled: true + features: + debug_arena: true + features: + muriscvnn: true + cmsisnn: false + tvm: + enabled: true + backends: + default: tvmaot + tvmrt: + enabled: true + features: + debug_arena: true + disable_legalize: false + autotuned: true + moiopt: true + tvmaot: + enabled: true + features: + debug_arena: true + unpacked_api: true + usmp: true + disable_legalize: false + autotuned: true + moiopt: true + tvmaotplus: + enabled: true + features: + debug_arena: true + disable_legalize: false + autotuned: true + moiopt: true + tvmllvm: + enabled: true + features: + # unpacked_api: true + disable_legalize: false + autotuned: true + moiopt: true + features: + cmsisnnbyoc: false + muriscvnnbyoc: false +# Some frontends are experimental and therefore disabled here +# Features like packing are only available in certain environments +frontends: + tflite: + enabled: true + features: + validate: true + visualize: true + split_layers: false + relay: + enabled: true + features: + relayviz: true + packed: + enabled: false + features: + packing: true + packed: true + onnx: + enabled: true + pb: + enabled: true + paddle: + enabled: true + layergen: + enabled: true + # TODO: saved_model (TF->TFLITE), ipynb (IPYNB->?) +# Some targets/platforms support multiple toolchains +toolchains: + gcc: true + llvm: true +# Platform extend the number of supported targets +platforms: + mlif: + enabled: true + features: + debug: true + validate: true + benchmark: true + espidf: + enabled: false + features: + debug: true + zephyr: + enabled: false + features: + debug: true + tvm: + enabled: true + features: + benchmark: true + tvm_rpc: true + autotune: true + tvm_profile: true + microtvm: + enabled: true + features: [] + # validate: true +# List of supported targets in the environment +targets: + default: etiss_pulpino + etiss_pulpino: + enabled: true + features: + gdbserver: true + etissdbg: true + trace: true + log_instrs: true + # vext: true + # pext: true + etiss: + enabled: true + features: + gdbserver: true + etissdbg: true + trace: true + log_instrs: true + # vext: true + # pext: true + host_x86: + enabled: true + features: + gdbserver: true + spike: + enabled: true + features: + vext: false + pext: false + cachesim: true + log_instrs: true + ovpsim: + enabled: false + features: + vext: false + pext: false + log_instrs: true + corstone300: + enabled: false + features: + ethosu: false + arm_mvei: true + arm_dsp: true + riscv_qemu: + enabled: true + features: + vext: false + microtvm_host: + enabled: true + microtvm_spike: + enabled: true + microtvm_zephyr: + enabled: false + microtvm_arduino: + enabled: false + microtvm_etiss: + enabled: true + microtvm_espidf: + enabled: false + tvm_cpu: + enabled: true +postprocesses: + use: + # - detailed_cycles + # - average_cycles + # - filter_cols + # - features2cols + # - config2cols + # - bytes2kb + # - visualize +# This is where further options such as specific versions of dependencies can be set in the furture +vars: + allow_extensions: false + runs_per_stage: true + # tvm.make_tool: "ninja" + riscv_gcc.dl_url: "https://syncandshare.lrz.de/dl/fiWBtDLWz17RBc1Yd4VDW7/GCC/default/2023.11.27/Ubuntu/20.04/rv32gc_ilp32d.tar.xz" + riscv_gcc.dl_url_vext: "https://syncandshare.lrz.de/dl/fiWBtDLWz17RBc1Yd4VDW7/GCC/default/2023.11.27/Ubuntu/20.04/rv32gcv_ilp32d.tar.xz" + riscv_gcc.dl_url_pext: "https://syncandshare.lrz.de/dl/fiWBtDLWz17RBc1Yd4VDW7/GCC/pext/2022.04.28/Ubuntu/20.04/rv32gcp_ilp32d.tar.xz" +flags: + tflmc.exe: + - x86