blob: 9fb7fd8b3d2cf1dd74798d523ffc309452c1a7da [file] [log] [blame]
Richard Burtondc0c6ed2020-04-08 16:39:05 +01001# 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):
Nina Drozdb6390dd2020-05-05 12:16:06 +010027 preferred_backends = [ann.BackendId('CpuRef'), ann.BackendId('CpuAcc'),
28 ann.BackendId('GpuAcc'), ann.BackendId('EthosNAcc')]
29 profiling_data_obj = ann.get_profiling_data(mock_profiler, preferred_backends)
Richard Burtondc0c6ed2020-04-08 16:39:05 +010030
31 assert (len(profiling_data_obj.inference_data) > 0)
32 assert (len(profiling_data_obj.per_workload_execution_data) > 0)
33
34 # Check each total execution time
35 assert (profiling_data_obj.inference_data["execution_time"] == [1.1, 2.2, 3.3, 4.4, 5.5, 6.6])
36 assert (profiling_data_obj.inference_data["time_unit"] == "us")
37
38
39@pytest.mark.parametrize("exec_times, unit, backend, workload", [([2, 2,
40 2, 2,
41 2, 2],
42 'us',
43 'CpuRef',
44 'RefSomeMock1dWorkload_Execute_#5'),
45 ([2, 2,
46 2, 2,
47 2, 2],
48 'us',
49 'CpuAcc',
50 'NeonSomeMock2Workload_Execute_#6'),
51 ([2, 2,
52 2, 2,
53 2, 2],
54 'us',
55 'GpuAcc',
56 'ClSomeMock3dWorkload_Execute_#7'),
57 ([2, 2,
58 2, 2,
59 2, 2],
60 'us',
61 'EthosNAcc',
62 'EthosNSomeMock4dWorkload_Execute_#8')
63 ])
64def test_profiler_workloads(mock_profiler, exec_times, unit, backend, workload):
Nina Drozdb6390dd2020-05-05 12:16:06 +010065 preferred_backends = [ann.BackendId('CpuRef'), ann.BackendId('CpuAcc'),
66 ann.BackendId('GpuAcc'), ann.BackendId('EthosNAcc')]
67 profiling_data_obj = ann.get_profiling_data(mock_profiler, preferred_backends)
Richard Burtondc0c6ed2020-04-08 16:39:05 +010068
69 work_load_exec = profiling_data_obj.per_workload_execution_data[workload]
70 assert work_load_exec["execution_time"] == exec_times
71 assert work_load_exec["time_unit"] == unit
72 assert work_load_exec["backend"] == backend