Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 1 | import os |
| 2 | |
Jared Smolens | 2a76ad2 | 2021-03-04 11:18:54 -0800 | [diff] [blame] | 3 | # Copyright (c) 2020-2021, ARM Limited. |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import json |
| 18 | import shlex |
| 19 | import subprocess |
| 20 | from tosa_test_runner import TosaTestRunner, run_sh_command |
| 21 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 22 | |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 23 | class TosaRefRunner(TosaTestRunner): |
| 24 | def __init__(self, args, runnerArgs, testDir): |
| 25 | super().__init__(args, runnerArgs, testDir) |
| 26 | |
| 27 | def runModel(self): |
| 28 | # Build up the TOSA reference command line |
| 29 | # Uses arguments from the argParser args, not the runnerArgs |
| 30 | args = self.args |
| 31 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 32 | ref_cmd = [ |
| 33 | args.ref_model_path, |
| 34 | "-Csubgraph_file={}".format(self.testDesc["tosa_file"]), |
| 35 | "-Csubgraph_dir={}".format(self.testDir), |
| 36 | "-Cinput_dir={}".format(self.testDir), |
| 37 | "-Coutput_dir={}".format(self.testDir), |
| 38 | "-Coutput_tensor_prefix=ref-", # Naming agreement with TosaSerializer |
| 39 | ] |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 40 | |
| 41 | # Build up input tensor_name/filename list |
| 42 | inputTensors = [] |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 43 | for i in range(len(self.testDesc["ifm_placeholder"])): |
| 44 | inputTensors.append( |
| 45 | "{}:{}".format( |
| 46 | self.testDesc["ifm_placeholder"][i], self.testDesc["ifm_file"][i] |
| 47 | ) |
| 48 | ) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 49 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 50 | ref_cmd.append("-Cinput_tensor={}".format(",".join(inputTensors))) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 51 | |
| 52 | if args.ref_debug: |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 53 | ref_cmd.extend(["-dALL", "-l{}".format(args.ref_debug)]) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 54 | |
| 55 | if args.ref_intermediates: |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 56 | ref_cmd.extend(["-Ddump_intermediates=1"]) |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 57 | |
Kevin Cheng | 550ccc5 | 2021-03-03 11:21:43 -0800 | [diff] [blame] | 58 | expectedFailure = self.testDesc["expected_failure"] |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 59 | |
| 60 | try: |
| 61 | run_sh_command(self.args, ref_cmd) |
| 62 | if expectedFailure: |
| 63 | result = TosaTestRunner.Result.UNEXPECTED_PASS |
| 64 | else: |
| 65 | result = TosaTestRunner.Result.EXPECTED_PASS |
| 66 | except Exception as e: |
| 67 | if expectedFailure: |
| 68 | result = TosaTestRunner.Result.EXPECTED_FAILURE |
| 69 | else: |
Jared Smolens | 2a76ad2 | 2021-03-04 11:18:54 -0800 | [diff] [blame] | 70 | result = TosaTestRunner.Result.UNEXPECTED_FAILURE |
Eric Kunze | e5e2676 | 2020-10-13 16:11:07 -0700 | [diff] [blame] | 71 | |
| 72 | return result |