Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / include / ie_icnn_net_reader.h
1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 /**
6  * @brief A header file that provides interface for network reader that is used to build networks from a given IR
7  * @file ie_icnn_net_reader.h
8  */
9 #pragma once
10
11 #include <map>
12 #include <string>
13
14 #include "ie_blob.h"
15 #include "ie_common.h"
16 #include "ie_icnn_network.hpp"
17 #include "details/ie_no_copy.hpp"
18 #include "ie_api.h"
19
20 namespace InferenceEngine {
21 /**
22  * @brief This class is the main interface to build and parse a network from a given IR
23  *
24  * All methods here do not throw exceptions and return a StatusCode and ResponseDesc object.
25  * Alternatively, to use methods that throw exceptions, refer to the CNNNetReader wrapper class.
26  */
27 class ICNNNetReader : public details::IRelease {
28 public:
29     /**
30      * @brief Parses the topology part of the IR (.xml)
31      * This method can be called once only to read network. If you need to read another network instance then create new reader instance.
32      * @param filepath The full path to the .xml file of the IR
33      * @param resp Response message
34      * @return Result code
35      */
36     virtual StatusCode ReadNetwork(const char *filepath, ResponseDesc *resp) noexcept = 0;
37
38     /**
39      * @brief Parses the topology part of the IR (.xml) given the xml as a buffer
40      * This method can be called once only to read network. If you need to read another network instance then create new reader instance.
41      * @param model Pointer to a char array with the IR
42      * @param resp Response message
43      * @param size Size of the char array in bytes
44      * @return Result code
45      */
46     virtual StatusCode ReadNetwork(const void *model, size_t size, ResponseDesc *resp) noexcept = 0;
47
48     /**
49      * @brief Sets the weights buffer (.bin part) from the IR.
50      * Weights Blob must always be of bytes - the casting to precision is done per-layer to support mixed
51      * networks and to ease of use.
52      * This method can be called more than once to reflect updates in the .bin.
53      * @param weights Blob of bytes that holds all the IR binary data
54      * @param resp Response message
55      * @return Result code
56     */
57     virtual StatusCode SetWeights(const TBlob<uint8_t>::Ptr &weights, ResponseDesc *resp) noexcept = 0;
58
59     /**
60      * @brief Loads and sets the weights buffer directly from the IR .bin file.
61      * This method can be called more than once to reflect updates in the .bin.
62      * @param filepath Full path to the .bin file
63      * @param resp Response message
64      * @return Result code
65      */
66     virtual StatusCode ReadWeights(const char *filepath, ResponseDesc *resp) noexcept = 0;
67
68     /**
69      * @brief Returns a pointer to the built network
70      * @param resp Response message
71      */
72     virtual ICNNNetwork *getNetwork(ResponseDesc *resp) noexcept = 0;
73
74     /**
75      * @brief Retrieves the last building status
76      * @param resp Response message
77      */
78     virtual bool isParseSuccess(ResponseDesc *resp) noexcept = 0;
79
80     /**
81      * @brief Retrieves the last building failure message if failed
82      * @param resp Response message
83      * @return StatusCode that indicates the network status
84      */
85     virtual StatusCode getDescription(ResponseDesc *resp) noexcept = 0;
86
87     /**
88      * @brief Gets network name
89      * @param name Pointer to preallocated buffer that receives network name
90      * @param len Length of the preallocated buffer, network name will be trimmed by this lenght
91      * @param resp Response message
92      * @return Result code
93      */
94     virtual StatusCode getName(char *name, size_t len, ResponseDesc *resp) noexcept = 0;
95
96     /**
97      * @brief Returns a version of IR
98      * @param resp Response message
99      * @return IR version number: 1 or 2
100      */
101     virtual int getVersion(ResponseDesc *resp) noexcept = 0;
102 };
103
104 /**
105  * @brief Creates a CNNNetReader instance
106  * @return An object that implements the ICNNNetReader interface
107  */
108 INFERENCE_ENGINE_API(ICNNNetReader*)CreateCNNNetReader() noexcept;
109 }  // namespace InferenceEngine