aboutsummaryrefslogtreecommitdiff
path: root/verif/runner
diff options
context:
space:
mode:
authorJeremy Johnson <jeremy.johnson@arm.com>2023-10-09 16:31:13 +0100
committerJeremy Johnson <jeremy.johnson@arm.com>2023-10-16 15:08:36 +0100
commit65ba809d7a8b4ddd0a51f6c76ad0afc5f417de07 (patch)
tree249926aeeccfb0dac60f27967e5d01001adc5e33 /verif/runner
parent9c2fe6e129e4d176c3e14f172b92efe985af7c78 (diff)
downloadreference_model-65ba809d7a8b4ddd0a51f6c76ad0afc5f417de07.tar.gz
Data generator library python interface added
Added support for using generate library in tosa_verif_build_tests and tosa_verif_run_tests tosa tool scripts. Reduced scope of compliance test creation and verification to the supported type of FP32. Fix missing virtual destructor warning in generate_dot_product.h and add config file for generate library. Simple pytests included to check python interface. Signed-off-by: Jeremy Johnson <jeremy.johnson@arm.com> Change-Id: I6cdad9b00660d6ddc8bd07fdea813937fb48626a
Diffstat (limited to 'verif/runner')
-rw-r--r--verif/runner/tosa_test_runner.py30
-rw-r--r--verif/runner/tosa_verif_run_tests.py71
2 files changed, 59 insertions, 42 deletions
diff --git a/verif/runner/tosa_test_runner.py b/verif/runner/tosa_test_runner.py
index b348f50..984b2d9 100644
--- a/verif/runner/tosa_test_runner.py
+++ b/verif/runner/tosa_test_runner.py
@@ -10,7 +10,9 @@ from checker.color_print import print_color
from checker.color_print import set_print_in_color
from checker.tosa_result_checker import set_print_result
from checker.tosa_result_checker import test_check
+from generator.datagenerator import GenerateLibrary
from json2fbbin import json2fbbin
+from json2numpy import json2numpy
from runner.tosa_test_presets import TOSA_REFCOMPLIANCE_RUNNER
@@ -71,6 +73,7 @@ class TosaTestRunner:
self.testDirPath = testDirPath
self.testName = self.testDirPath.name
self.verify_lib_path = args.verify_lib_path
+ self.generate_lib_path = args.generate_lib_path
set_print_in_color(not args.no_color)
# Stop the result checker printing anything - we will do it
@@ -135,6 +138,33 @@ class TosaTestRunner:
return True, "non-{} profile".format(self.args.profile)
return False, ""
+ def _ready_file(self, dataFile, jsonOnly=False):
+ """Convert/create any data file that is missing."""
+ dataPath = self.testDirPath / dataFile
+ if not dataPath.is_file():
+ jsonPath = dataPath.with_suffix(".json")
+ if jsonPath.is_file():
+ # Data files stored as JSON
+ if self.args.verbose:
+ print(f"Readying data file: {dataPath}")
+ json2numpy.json_to_npy(jsonPath)
+ elif not jsonOnly:
+ # Use data generator for all data files
+ if self.args.verbose:
+ print("Readying all data input files")
+ dgl = GenerateLibrary(self.generate_lib_path)
+ dgl.set_config(self.testDesc)
+ dgl.write_numpy_files(self.testDirPath)
+
+ def readyDataFiles(self):
+ """Check that the data files have been created/converted."""
+ for dataFile in self.testDesc["ifm_file"]:
+ self._ready_file(dataFile)
+ # Convert expected result if any
+ if "expected_result_file" in self.testDesc:
+ for dataFile in self.testDesc["expected_result_file"]:
+ self._ready_file(dataFile, jsonOnly=True)
+
def runTestGraph(self):
"""Override with function that calls system under test."""
pass
diff --git a/verif/runner/tosa_verif_run_tests.py b/verif/runner/tosa_verif_run_tests.py
index 54cb7b2..d2aae22 100644
--- a/verif/runner/tosa_verif_run_tests.py
+++ b/verif/runner/tosa_verif_run_tests.py
@@ -13,7 +13,7 @@ from pathlib import Path
import conformance.model_files as cmf
import runner.tosa_test_presets as ttp
-from json2numpy import json2numpy
+from generator.datagenerator import GenerateError
from runner.tosa_test_runner import TosaTestInvalid
from runner.tosa_test_runner import TosaTestRunner
from xunit import xunit
@@ -52,6 +52,15 @@ def parseArgs(argv):
help="Path to TOSA reference model executable",
)
parser.add_argument(
+ "--generate-lib-path",
+ dest="generate_lib_path",
+ type=Path,
+ help=(
+ "Path to TOSA generate library. Defaults to "
+ "the library in the directory of `ref-model-path`"
+ ),
+ )
+ parser.add_argument(
"--verify-lib-path",
dest="verify_lib_path",
type=Path,
@@ -177,22 +186,6 @@ def parseArgs(argv):
return args
-EXCLUSION_PREFIX = ["test", "model", "desc"]
-
-
-def convert2Numpy(test_path):
- """Convert all the JSON numpy files back into binary numpy."""
- jsons = test_path.glob("*.json")
- for j in jsons:
- for exclude in EXCLUSION_PREFIX:
- if j.name.startswith(exclude):
- j = None
- break
- if j:
- # debug print(f"Converting {json}")
- json2numpy.json_to_npy(j)
-
-
def workerThread(task_queue, runnerList, complianceRunner, args, result_queue):
"""Worker thread that runs the next test from the queue."""
complianceRunnerList = runnerList.copy()
@@ -222,7 +215,6 @@ def workerThread(task_queue, runnerList, complianceRunner, args, result_queue):
currentRunners = runnerList
msg = ""
- converted = False
for runnerModule, runnerArgs in currentRunners:
try:
start_time = datetime.now()
@@ -232,39 +224,30 @@ def workerThread(task_queue, runnerList, complianceRunner, args, result_queue):
skip, reason = runner.skipTest()
if skip:
- msg = "Skipping {} test".format(reason)
- print("{} {}".format(msg, test_path))
+ msg = f"Skipping {reason} test"
+ print(f"{msg} {test_path}")
rc = TosaTestRunner.Result.SKIPPED
else:
- # Convert JSON data files into numpy format on first pass
- if not converted:
- convert2Numpy(test_path)
- converted = True
-
if args.verbose:
- print(
- "Running runner {} with test {}".format(
- runnerName, test_path
- )
- )
+ print(f"Running runner {runnerName} with test {test_path}")
+ try:
+ # Convert or generate the required data files
+ runner.readyDataFiles()
+ except Exception as e:
+ msg = f"Failed to ready test files error: {e}"
+ raise e
+
try:
grc, gmsg = runner.runTestGraph()
rc, msg = runner.testResult(grc, gmsg)
except Exception as e:
- msg = "System Under Test error: {}".format(e)
- print(msg)
- print(
- "".join(
- traceback.format_exception(
- etype=type(e), value=e, tb=e.__traceback__
- )
- )
- )
- rc = TosaTestRunner.Result.INTERNAL_ERROR
+ msg = f"System Under Test error: {e}"
+ raise e
except Exception as e:
- msg = "Internal error: {}".format(e)
+ if not msg:
+ msg = f"Internal error: {e}"
print(msg)
- if not isinstance(e, TosaTestInvalid):
+ if not isinstance(e, (TosaTestInvalid, GenerateError)):
# Show stack trace on unexpected exceptions
print(
"".join(
@@ -374,6 +357,10 @@ def main(argv=None):
args.ref_model_path = cmf.find_tosa_file(
cmf.TosaFileType.REF_MODEL, Path("reference_model"), False
)
+ if args.generate_lib_path is None:
+ args.generate_lib_path = cmf.find_tosa_file(
+ cmf.TosaFileType.GENERATE_LIBRARY, args.ref_model_path
+ )
if args.verify_lib_path is None:
args.verify_lib_path = cmf.find_tosa_file(
cmf.TosaFileType.VERIFY_LIBRARY, args.ref_model_path