Skip to content

Commit

Permalink
add support for openasip example models
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippvK committed Sep 30, 2024
1 parent c7599df commit 7495fad
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mlonmcu/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
MathisFrontend,
MibenchFrontend,
LayerGenFrontend,
OpenASIPFrontend,
)

SUPPORTED_FRONTENDS = {
Expand All @@ -51,6 +52,7 @@
"mathis": MathisFrontend,
"mibench": MibenchFrontend,
"layergen": LayerGenFrontend,
"openasip": OpenASIPFrontend,
} # TODO: use registry instead

__all__ = [
Expand Down
48 changes: 48 additions & 0 deletions mlonmcu/models/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
DhrystoneProgram,
MathisProgram,
MibenchProgram,
OpenASIPProgram,
)
from mlonmcu.models.lookup import lookup_models
from mlonmcu.feature.type import FeatureType
Expand Down Expand Up @@ -2094,3 +2095,50 @@ def helper(args):
artifact = Artifact(f"{name}.{ext}", raw=raw, fmt=ArtifactFormat.RAW, flags=["model"])
artifacts[name] = [artifact]
return artifacts, {}


class OpenASIPFrontend(SimpleFrontend):

def __init__(self, features=None, config=None):
super().__init__(
"openasip",
ModelFormats.NONE,
features=features,
config=config,
)

@property
def supported_names(self):
return [
"sha256",
"aes",
"crc",
]

# @property
# def skip_backend(self):
# return True

def lookup_models(self, names, config=None, context=None):
ret = []
for name in names:
name = name.replace("openasip/", "")
if name in self.supported_names:
hint = OpenASIPProgram(
name,
alt=f"openasip/{name}",
config=config,
)
ret.append(hint)
return ret

def generate(self, model) -> Tuple[dict, dict]:
artifacts = [Artifact("dummy_model", raw=bytes(), fmt=ArtifactFormat.RAW, flags=["model", "dummy"])]

return {"default": artifacts}, {}

def get_platform_config(self, platform):
ret = {}
if platform == "mlif":
ret["template"] = "openasip"
return ret
18 changes: 18 additions & 0 deletions mlonmcu/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,3 +413,21 @@ def get_platform_defs(self, platform):
if platform == "mlif":
ret["DHRYSTONE_ITERATIONS"] = 10000
return ret


class OpenASIPProgram(Program):
DEFAULTS = {
"crc_mode": "both",
}

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

def get_platform_defs(self, platform):
ret = {}
if platform == "mlif":
ret["OPENASIP_BENCHMARK"] = self.name
if self.name == "crc":
ret["OPENASIP_CRC_MODE"] = self.crc_mode
return ret

0 comments on commit 7495fad

Please sign in to comment.