Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / src / mkldnn_plugin / utils / blob_dump.h
1 //
2 // Copyright 2016-2018 Intel Corporation.
3 //
4 // This software and the related documents are Intel copyrighted materials,
5 // and your use of them is governed by the express license under which they
6 // were provided to you (End User License Agreement for the Intel(R) Software
7 // Development Products (Version May 2017)). Unless the License provides
8 // otherwise, you may not use, modify, copy, publish, distribute, disclose or
9 // transmit this software or the related documents without Intel's prior
10 // written permission.
11 //
12 // This software and the related documents are provided as is, with no
13 // express or implied warranties, other than those that are expressly
14 // stated in the License.
15 //
16
17 #pragma once
18
19 #include "ie_blob.h"
20
21 #include <string>
22
23 namespace MKLDNNPlugin {
24
25 /**
26  * Utility class to dump blob contant in plain format.
27  * Every layout information will be lost.
28  *
29  * In case of low precision blob it allow to store
30  * with using scaling factors per channel.
31  * NB! Channel is a second dimension for all blob types.
32  */
33 class BlobDumper {
34     InferenceEngine::Blob::Ptr _blob;
35     InferenceEngine::Blob::Ptr _scales;
36
37 public:
38     BlobDumper() = default;
39     BlobDumper(const BlobDumper&) = default;
40     BlobDumper& operator = (BlobDumper&&) = default;
41
42     explicit BlobDumper(const InferenceEngine::Blob::Ptr blob):_blob(blob) {}
43
44     static BlobDumper read(const std::string &file_path);
45     static BlobDumper read(std::istream &stream);
46
47     void dump(const std::string &file_path);
48     void dump(std::ostream &stream);
49
50     void dumpAsTxt(const std::string file_path);
51     void dumpAsTxt(std::ostream &stream);
52
53     BlobDumper& withScales(InferenceEngine::Blob::Ptr scales);
54     BlobDumper& withoutScales();
55
56     const InferenceEngine::Blob::Ptr& getScales() const;
57
58     InferenceEngine::Blob::Ptr get();
59     InferenceEngine::Blob::Ptr getRealValue();
60 };
61
62 }  // namespace MKLDNNPlugin