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