Skip to content

Commit

Permalink
Merge pull request #100 from tum-ei-eda/feature-microtvm-gvsoc-template
Browse files Browse the repository at this point in the history
[WIP] implement microtvm_gvsoc target
  • Loading branch information
PhilippvK authored Sep 9, 2024
2 parents 3d6e678 + aefd537 commit 0254467
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 0 deletions.
97 changes: 97 additions & 0 deletions mlonmcu/platform/microtvm/microtvm_gvsoc_target.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#
# 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.
#
from pathlib import Path

from mlonmcu.target.target import Target

from mlonmcu.logging import get_logger

from .microtvm_template_target import TemplateMicroTvmPlatformTarget

logger = get_logger()


class GVSocMicroTvmPlatformTarget(TemplateMicroTvmPlatformTarget):
# FEATURES = TemplateMicroTvmPlatformTarget.FEATURES + ["xpulp"]
FEATURES = TemplateMicroTvmPlatformTarget.FEATURES

DEFAULTS = {
**TemplateMicroTvmPlatformTarget.DEFAULTS,
# "verbose": True,
"compiler": "gcc",
"project_type": "host_driven",
# "xpulp_version": None, # None means that xpulp extension is not used,
# "model": "pulp",
}
REQUIRED = Target.REQUIRED + [
"gvsoc.exe",
"pulp_freertos.support_dir",
"pulp_freertos.config_dir",
"pulp_freertos.install_dir",
"microtvm_gvsoc.template",
"hannah_tvm.src_dir",
]

def __init__(self, name=None, features=None, config=None):
super().__init__(name=name, features=features, config=config)
self.template_path = self.microtvm_gvsoc_template
# TODO: integrate into TVM build config
self.option_names = [
# "verbose",
"project_type",
"compiler",
]

@property
def microtvm_gvsoc_template(self):
return Path(self.config["microtvm_gvsoc.template"])

@property
def hannah_tvm_src_dir(self):
return Path(self.config["hannah_tvm.src_dir"])

@property
def compiler(self):
return self.config["compiler"]

def get_project_options(self):
ret = super().get_project_options()
# TODO
ret.update(
{
# "gvsoc_exe": str(self.gvsoc_exe),
}
)
return ret

def update_environment(self, env):
super().update_environment(env)
p = env.get("PYTHONPATH", "")
env["PYTHONPATH"] = f"{self.hannah_tvm_src_dir}:{p}"

# TODO
# if "PATH" in env:
# env["PATH"] = str(self.riscv_gcc_install_dir / "bin") + ":" + env["PATH"]
# else:
# env["PATH"] = str(self.riscv_gcc_install_dir / "bin")

def get_backend_config(self, backend):
ret = {}
# TODO
return ret
2 changes: 2 additions & 0 deletions mlonmcu/platform/microtvm/microtvm_target.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .microtvm_host_target import HostMicroTvmPlatformTarget
from .microtvm_etiss_target import EtissMicroTvmPlatformTarget
from .microtvm_spike_target import SpikeMicroTvmPlatformTarget
from .microtvm_gvsoc_target import GVSocMicroTvmPlatformTarget
from .microtvm_corev_ovpsim_target import CoreVOVPSimMicroTvmPlatformTarget
from .microtvm_mlonmcu_target import MlonmcuMicroTvmPlatformTarget

Expand Down Expand Up @@ -61,6 +62,7 @@ def get_microtvm_platform_targets():
register_microtvm_platform_target("microtvm_etiss", EtissMicroTvmPlatformTarget)
register_microtvm_platform_target("microtvm_espidf", EspidfMicroTvmPlatformTarget)
register_microtvm_platform_target("microtvm_spike", SpikeMicroTvmPlatformTarget)
register_microtvm_platform_target("microtvm_gvsoc", GVSocMicroTvmPlatformTarget)
register_microtvm_platform_target("microtvm_corev_ovpsim", CoreVOVPSimMicroTvmPlatformTarget)
register_microtvm_platform_target("microtvm_mlonmcu", MlonmcuMicroTvmPlatformTarget)

Expand Down
2 changes: 2 additions & 0 deletions mlonmcu/setup/gen_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
["matplotlib", "pyserial", "pyusb"],
),
),
("microtvm_gvsoc", ("Requirements for microtvm_gvsoc target", ["hydra-core"])),
# Provide support for moiopt.
("moiopt", ("Requirements for moiopt", ["ortools"])),
# Provide support for onnx.
Expand Down Expand Up @@ -223,6 +224,7 @@
("gdbgui", "==0.13.2.0"),
("graphviz", None),
("humanize", None),
("hydra-core", None),
("idf-component-manager", "~=1.0"),
("itsdangerous", "<2.1"),
("jinja2", ">=3.1.3"),
Expand Down
4 changes: 4 additions & 0 deletions mlonmcu/setup/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ def feature_enabled_and_supported(obj, feature):
logger.info("add dependencies for etiss")
break
for config in config_pools:
if "microtvm_gvsoc" in config.name and config.enabled:
for d in requirements["microtvm_gvsoc"][1]:
f.write(f"{d}{os.linesep}")
logger.info("add dependencies for microtvm_gvsoc")
if "gvsoc_pulp" in config.name and config.enabled:
for d in requirements["gvsoc_pulp"][1]:
f.write(f"{d}{os.linesep}")
Expand Down
1 change: 1 addition & 0 deletions mlonmcu/setup/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from .utvmcg import * # noqa: F401, F403
from .zephyr import * # noqa: F401, F403
from .pulp import * # noqa: F401, F403
from .ekut import * # noqa: F401, F403
from .ara import * # noqa: F401, F403
from .verilator import * # noqa: F401, F403
from .ovpsim import * # noqa: F401, F403
Expand Down
55 changes: 55 additions & 0 deletions mlonmcu/setup/tasks/ekut.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#
# 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.
#
"""Definition of tasks used to dynamically install MLonMCU dependencies"""

import multiprocessing

from mlonmcu.setup.task import TaskType
from mlonmcu.context.context import MlonMcuContext
from mlonmcu.setup import utils
from mlonmcu.logging import get_logger

from .common import get_task_factory

logger = get_logger()
Tasks = get_task_factory()

##############
# hannah-tvm #
##############


def _validate_hannah_tvm(context: MlonMcuContext, params=None):
return context.environment.has_target("microtvm_gvsoc")


@Tasks.provides(["hannah_tvm.src_dir", "microtvm_gvsoc.template"])
@Tasks.validate(_validate_hannah_tvm)
@Tasks.register(category=TaskType.TARGET)
def clone_hannah_tvm(
context: MlonMcuContext, params=None, rebuild=False, verbose=False, threads=multiprocessing.cpu_count()
):
"""Clone the hannah-tvm repository."""
hannahTvmName = utils.makeDirName("hannah_tvm")
hannahTvmSrcDir = context.environment.paths["deps"].path / "src" / hannahTvmName
if rebuild or not utils.is_populated(hannahTvmSrcDir):
pulpRtosRepo = context.environment.repos["hannah_tvm"]
utils.clone(pulpRtosRepo.url, hannahTvmSrcDir, branch=pulpRtosRepo.ref, refresh=rebuild, recursive=True)
context.cache["hannah_tvm.src_dir"] = hannahTvmSrcDir
context.cache["microtvm_gvsoc.template"] = hannahTvmSrcDir / "template" / "gvsoc"

0 comments on commit 0254467

Please sign in to comment.