diff options
author | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2023-02-02 14:02:05 +0000 |
---|---|---|
committer | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2023-02-10 13:45:18 +0000 |
commit | 7a661257b6adad0c8f53e32b42ced56a1e7d952f (patch) | |
tree | 938ad8578c5b9edc0573e810ce64ce0a5bda3d8c /src/mlia/cli/helpers.py | |
parent | 50271dee0a84bfc481ce798184f07b5b0b4bc64d (diff) | |
download | mlia-7a661257b6adad0c8f53e32b42ced56a1e7d952f.tar.gz |
MLIA-769 Expand use of target/backend registries
- Use the target/backend registries to avoid hard-coded names.
- Cache target profiles to avoid re-loading them
Change-Id: I474b7c9ef23894e1d8a3ea06d13a37652054c62e
Diffstat (limited to 'src/mlia/cli/helpers.py')
-rw-r--r-- | src/mlia/cli/helpers.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/mlia/cli/helpers.py b/src/mlia/cli/helpers.py index ac64581..576670b 100644 --- a/src/mlia/cli/helpers.py +++ b/src/mlia/cli/helpers.py @@ -1,14 +1,19 @@ # SPDX-FileCopyrightText: Copyright 2022-2023, Arm Limited and/or its affiliates. # SPDX-License-Identifier: Apache-2.0 -"""Module for various helper classes.""" +"""Module for various helpers.""" from __future__ import annotations +from pathlib import Path +from shutil import copy from typing import Any +from typing import cast from mlia.cli.options import get_target_profile_opts from mlia.core.helpers import ActionResolver from mlia.nn.tensorflow.optimizations.select import OptimizationSettings from mlia.nn.tensorflow.utils import is_keras_model +from mlia.target.config import get_builtin_profile_path +from mlia.target.config import is_builtin_profile from mlia.utils.types import is_list_of @@ -108,3 +113,20 @@ class CLIActionResolver(ActionResolver): model_path = self.args.get("model") return model_path, device_opts + + +def copy_profile_file_to_output_dir( + target_profile: str | Path, output_dir: str | Path +) -> bool: + """Copy the target profile file to the output directory.""" + profile_file_path = ( + get_builtin_profile_path(cast(str, target_profile)) + if is_builtin_profile(target_profile) + else Path(target_profile) + ) + output_file_path = f"{output_dir}/{profile_file_path.stem}.toml" + try: + copy(profile_file_path, output_file_path) + return True + except OSError as err: + raise RuntimeError("Failed to copy profile file:", err.strerror) from err |