Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 1 | # Copyright © 2020 Arm Ltd. All rights reserved. |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | import os |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | import pyarmnn as ann |
| 8 | |
| 9 | |
| 10 | class MockIProfiler: |
| 11 | def __init__(self, json_string): |
| 12 | self._profile_json = json_string |
| 13 | |
| 14 | def as_json(self): |
| 15 | return self._profile_json |
| 16 | |
| 17 | |
| 18 | @pytest.fixture() |
| 19 | def mock_profiler(shared_data_folder): |
| 20 | path_to_file = os.path.join(shared_data_folder, 'mock_profile_out.json') |
| 21 | with open(path_to_file, 'r') as file: |
| 22 | profiler_output = file.read() |
| 23 | return MockIProfiler(profiler_output) |
| 24 | |
| 25 | |
| 26 | def test_inference_exec(mock_profiler): |
Nina Drozd | 63b234c | 2020-05-15 17:54:19 +0100 | [diff] [blame] | 27 | profiling_data_obj = ann.get_profiling_data(mock_profiler) |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 28 | |
| 29 | assert (len(profiling_data_obj.inference_data) > 0) |
| 30 | assert (len(profiling_data_obj.per_workload_execution_data) > 0) |
| 31 | |
| 32 | # Check each total execution time |
| 33 | assert (profiling_data_obj.inference_data["execution_time"] == [1.1, 2.2, 3.3, 4.4, 5.5, 6.6]) |
| 34 | assert (profiling_data_obj.inference_data["time_unit"] == "us") |
| 35 | |
| 36 | |
| 37 | @pytest.mark.parametrize("exec_times, unit, backend, workload", [([2, 2, |
| 38 | 2, 2, |
| 39 | 2, 2], |
| 40 | 'us', |
| 41 | 'CpuRef', |
| 42 | 'RefSomeMock1dWorkload_Execute_#5'), |
| 43 | ([2, 2, |
| 44 | 2, 2, |
| 45 | 2, 2], |
| 46 | 'us', |
| 47 | 'CpuAcc', |
| 48 | 'NeonSomeMock2Workload_Execute_#6'), |
| 49 | ([2, 2, |
| 50 | 2, 2, |
| 51 | 2, 2], |
| 52 | 'us', |
| 53 | 'GpuAcc', |
| 54 | 'ClSomeMock3dWorkload_Execute_#7'), |
| 55 | ([2, 2, |
| 56 | 2, 2, |
| 57 | 2, 2], |
| 58 | 'us', |
| 59 | 'EthosNAcc', |
| 60 | 'EthosNSomeMock4dWorkload_Execute_#8') |
| 61 | ]) |
| 62 | def test_profiler_workloads(mock_profiler, exec_times, unit, backend, workload): |
Nina Drozd | 63b234c | 2020-05-15 17:54:19 +0100 | [diff] [blame] | 63 | profiling_data_obj = ann.get_profiling_data(mock_profiler) |
Richard Burton | dc0c6ed | 2020-04-08 16:39:05 +0100 | [diff] [blame] | 64 | |
| 65 | work_load_exec = profiling_data_obj.per_workload_execution_data[workload] |
| 66 | assert work_load_exec["execution_time"] == exec_times |
| 67 | assert work_load_exec["time_unit"] == unit |
Nina Drozd | 63b234c | 2020-05-15 17:54:19 +0100 | [diff] [blame] | 68 | assert work_load_exec["backend"] == backend |