aboutsummaryrefslogtreecommitdiff
path: root/verif/conformance/model_files.py
blob: 5447f08d71e980c95e0ab5463af2c798b40c432e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# Copyright (c) 2023, ARM Limited.
# SPDX-License-Identifier: Apache-2.0
"""Locate model files helper functions."""
from enum import IntEnum
from pathlib import Path

DEFAULT_REF_MODEL_SCHEMA_PATH = Path("thirdparty/serialization_lib/schema")
DEFAULT_REF_MODEL_BUILD_FLATC_PATH = Path(
    "thirdparty/serialization_lib/third_party/flatbuffers"
)
DEFAULT_REF_MODEL_BUILD_EXE_PATH = Path("reference_model")
DEFAULT_BUILD_DIR = Path("build")


class TosaFileType(IntEnum):
    """TOSA file types."""

    REF_MODEL = 0
    SCHEMA = 1
    FLATC = 2
    VERIFY_LIBRARY = 3
    GENERATE_LIBRARY = 4


TOSA_FILE_TYPE_TO_DETAILS = {
    TosaFileType.REF_MODEL: {
        "name": "tosa_reference_model",
        "location": DEFAULT_REF_MODEL_BUILD_EXE_PATH,
        "build": True,
    },
    TosaFileType.SCHEMA: {
        "name": "tosa.fbs",
        "location": DEFAULT_REF_MODEL_SCHEMA_PATH,
        "build": False,
    },
    TosaFileType.FLATC: {
        "name": "flatc",
        "location": DEFAULT_REF_MODEL_BUILD_FLATC_PATH,
        "build": True,
    },
    TosaFileType.VERIFY_LIBRARY: {
        "name": "libtosa_reference_verify_lib.so",
        "location": DEFAULT_REF_MODEL_BUILD_EXE_PATH,
        "build": True,
    },
    TosaFileType.GENERATE_LIBRARY: {
        "name": "libtosa_reference_generate_lib.so",
        "location": DEFAULT_REF_MODEL_BUILD_EXE_PATH,
        "build": True,
    },
}


def find_tosa_file(file_type, ref_model_path, path_is_ref_model_exe=True):
    """Return the possible path to the required tosa file type."""
    name = TOSA_FILE_TYPE_TO_DETAILS[file_type]["name"]
    location = TOSA_FILE_TYPE_TO_DETAILS[file_type]["location"]
    build = TOSA_FILE_TYPE_TO_DETAILS[file_type]["build"]

    if path_is_ref_model_exe:
        # Given a path to the reference_model executable

        # Special case - return what we have been given!
        if file_type == TosaFileType.REF_MODEL:
            return ref_model_path

        try:
            if build:
                # Look in build directory
                search_path = ref_model_path.parents[1]
            else:
                # Look in reference_model directory
                search_path = ref_model_path.parents[2]
        except IndexError:
            search_path = ref_model_path.parent
    else:
        # Given a path to the reference_model directory
        if build:
            search_path = ref_model_path / DEFAULT_BUILD_DIR
        else:
            search_path = ref_model_path

    search_path = search_path / location / name

    return search_path