blob: 57f32e80ac73fe095a0d17cfc4f30c417a7e66e6 [file] [log] [blame]
Matthew Bentham245d64c2019-12-02 12:59:43 +00001# Copyright © 2019 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, '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"] == [16035243.953000, 16096248.590000, 16138614.290000,
34 16140544.388000, 16228118.274000, 16543585.760000])
35 assert (profiling_data_obj.inference_data["time_unit"] == "us")
36
37
38@pytest.mark.parametrize("exec_times, unit, backend, workload", [([1233915.166, 1221125.149,
39 1228359.494, 1235065.662,
40 1244369.694, 1240633.922],
41 'us',
42 'CpuRef',
43 'RefConvolution2dWorkload_Execute_#25'),
44 ([270.64, 256.379,
45 269.664, 259.449,
46 266.65, 277.05],
47 'us',
48 'CpuAcc',
49 'NeonActivationWorkload_Execute_#70'),
50 ([715.474, 729.23,
51 711.325, 729.151,
52 741.231, 729.702],
53 'us',
54 'GpuAcc',
55 'ClConvolution2dWorkload_Execute_#80')
56 ])
57def test_profiler_workloads(mock_profiler, exec_times, unit, backend, workload):
58 profiling_data_obj = ann.get_profiling_data(mock_profiler)
59
60 work_load_exec = profiling_data_obj.per_workload_execution_data[workload]
61 assert work_load_exec["execution_time"] == exec_times
62 assert work_load_exec["time_unit"] == unit
63 assert work_load_exec["backend"] == backend