1# Copyright © 2020 Arm Ltd. All rights reserved. 2# SPDX-License-Identifier: MIT 3import os 4 5import pytest 6 7import pyarmnn as ann 8 9 10class 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() 19def 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 26def test_inference_exec(mock_profiler): 27 profiling_data_obj = ann.get_profiling_data(mock_profiler) 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 ]) 62def test_profiler_workloads(mock_profiler, exec_times, unit, backend, workload): 63 profiling_data_obj = ann.get_profiling_data(mock_profiler) 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 68 assert work_load_exec["backend"] == backend