Publishing R3
[platform/upstream/dldt.git] / inference-engine / src / cldnn_engine / debug_options.h
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #pragma once
7
8 #include <vector>
9 #include <iostream>
10 #include <iomanip>
11 #include <string>
12 #include <set>
13 #include <map>
14 #include <algorithm>
15 #include "cpp/ie_cnn_network.h"
16 #include <CPP/memory.hpp>
17 #include <CPP/primitive.hpp>
18 #include <CPP/network.hpp>
19
20 // Debugging options flags
21 // #define _DEBUG_LAYER_CONTENT
22 // #define _DEBUG_LAYER_CONTENT_FULL
23 // #define _DEBUG_LAYER_FORMAT
24 // #define _PLUGIN_PERF_PRINTS
25
26 namespace CLDNNPlugin {
27
28 class DebugOptions {
29 public:
30     bool m_bDebugLayerContent;
31     bool m_bDebugLayerContentIndexed;
32     bool m_bDebugLayerFormat;
33     bool m_bPluginPerfPrints;
34     cldnn::tensor::value_type m_maxPrintSize;
35
36     DebugOptions();
37     void PrintOptions() const;
38     static std::string GetFormatName(cldnn::format::type format);
39     static std::string GetDataTypeName(cldnn::data_types dataType);
40     void PrintInput(const InferenceEngine::TBlob<float>& input) const;
41     void PrintIndexedValue(const cldnn::memory& mem, const cldnn::tensor index) const;
42     static uint32_t CalcLinearIndex(const cldnn::layout& memLayout, const cldnn::tensor index);
43
44     void PrintNetworkOutputs(std::map<cldnn::primitive_id, cldnn::network_output>& outputsMap) const;
45     void DumpSingleOutput(cldnn::primitive_id name, std::map<cldnn::primitive_id, cldnn::network_output>& outputs, bool bSingleFeatureMap = false)const;
46
47     // the functions below will work in release unlike the rest
48     void AddTimedEvent(std::string eventName, std::string startingAt = std::string());
49     void PrintTimedEvents();
50     void ClearTimedEvents();
51
52     void EnableWA(std::string name);
53     void DisableWA(std::string name);
54     bool IsWAActive(std::string name);
55
56     static std::string IELayoutToString(InferenceEngine::Layout layout);
57
58 protected:
59     std::map<std::string, std::chrono::steady_clock::time_point> m_TimedEventTimestamp;
60     std::map<std::string, std::string> m_TimedEventStart;
61     std::set<std::string> m_workaroundNames;
62
63     static float SimpleConvertFP16toFP32(uint16_t u16val);
64
65     template <typename T>
66     static void DumpElementsRaw(cldnn::memory& mem, const std::vector<size_t>& pitches, size_t numElements) {
67 #ifndef NDEBUG
68         auto layout = mem.get_layout();
69         auto ptr = mem.pointer<T>();
70         auto data = ptr.data();  // +offset;
71         auto elements = std::min(layout.count(), numElements);
72         cldnn::status_t status = CLDNN_SUCCESS;
73         for (size_t i = 0; i < elements;) {
74             // size_t linearAddress = ... // todo calc linear with pitches
75             std::cout << std::setprecision(10)
76                       << ((layout.data_type == cldnn::data_types::f32) ? data[i] : cldnn_half_to_float(uint16_t(data[i]), &status))
77                       << ", ";
78             i++;
79             for (auto& pitch : pitches) {
80                 if ((i % pitch) == 0) {
81                     std::cout << std::endl;
82                 }
83             }
84         }
85 #endif  // NDEBUG
86     }
87 };
88
89 };  // namespace CLDNNPlugin