Publishing 2019 R2 content (#223)
[platform/upstream/dldt.git] / inference-engine / src / vpu / graph_transformer / src / utils / perf_report.cpp
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #include <vpu/utils/perf_report.hpp>
6
7 #include <vector>
8 #include <string>
9 #include <map>
10
11 namespace vpu {
12
13 std::map<std::string, ie::InferenceEngineProfileInfo> parsePerformanceReport(
14         const std::vector<StageMetaInfo>& stagesMeta,
15         const float* deviceTimings,
16         int deviceTimingsCount,
17         PerfReport perfReport,
18         bool printReceiveTensorTime) {
19     IE_ASSERT(deviceTimings != nullptr);
20     IE_ASSERT(deviceTimingsCount > 0);
21
22     std::map<std::string, ie::InferenceEngineProfileInfo> outPerfMap;
23
24     int timeIndex = 0;
25     int execIndex = 1;
26
27     for (const auto& stageMeta : stagesMeta) {
28         float timeMS = 0;
29         if (stageMeta.status == ie::InferenceEngineProfileInfo::EXECUTED &&
30             timeIndex < deviceTimingsCount) {
31             timeMS = deviceTimings[timeIndex];
32             timeIndex++;
33         }
34
35         if (stageMeta.stageType == "<Receive-Tensor>" &&
36             !printReceiveTensorTime) {
37             continue;
38         }
39
40         ie::InferenceEngineProfileInfo profInfo = {};
41
42         profInfo.status = stageMeta.status;
43
44         profInfo.cpu_uSec = 0;
45         profInfo.realTime_uSec = static_cast<long long int>(timeMS * 1000);
46
47         stageMeta.layerType.copy(profInfo.layer_type, sizeof(profInfo.layer_type) / sizeof(profInfo.layer_type[0]), 0);
48         stageMeta.stageType.copy(profInfo.exec_type, sizeof(profInfo.exec_type) / sizeof(profInfo.exec_type[0]), 0);
49
50         if (stageMeta.stageType == "<Receive-Tensor>") {
51             profInfo.execution_index = 0;
52         } else if (stageMeta.status == ie::InferenceEngineProfileInfo::EXECUTED) {
53             profInfo.execution_index = execIndex;
54             execIndex++;
55         }
56
57         if (perfReport == PerfReport::PerStage) {
58             outPerfMap[stageMeta.stageName] = profInfo;
59         } else if (perfReport == PerfReport::PerLayer) {
60             auto it = outPerfMap.find(stageMeta.layerName);
61             if (it == outPerfMap.end()) {
62                 outPerfMap[stageMeta.layerName] = profInfo;
63             } else {
64                 auto& prevProfInfo = it->second;
65
66                 if (profInfo.status == ie::InferenceEngineProfileInfo::EXECUTED) {
67                     prevProfInfo.status = ie::InferenceEngineProfileInfo::EXECUTED;
68                 }
69
70                 prevProfInfo.cpu_uSec += profInfo.cpu_uSec;
71                 prevProfInfo.realTime_uSec += profInfo.realTime_uSec;
72             }
73         }
74     }
75
76     return outPerfMap;
77 }
78
79 }  // namespace vpu