ie_icnn_net_reader.h
Go to the documentation of this file.
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 "details/ie_no_copy.hpp"
15 #include "ie_api.h"
16 #include "ie_blob.h"
17 #include "ie_common.h"
18 #include "ie_icnn_network.hpp"
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
32  * reader instance.
33  * @param filepath The full path to the .xml file of the IR
34  * @param resp Response message
35  * @return Result code
36  */
37  virtual StatusCode ReadNetwork(const char* filepath, ResponseDesc* resp) noexcept = 0;
38 
39  /**
40  * @brief Parses the topology part of the IR (.xml) given the xml as a buffer
41  * This method can be called once only to read network. If you need to read another network instance then create new
42  * reader instance.
43  * @param model Pointer to a char array with the IR
44  * @param resp Response message
45  * @param size Size of the char array in bytes
46  * @return Result code
47  */
48  virtual StatusCode ReadNetwork(const void* model, size_t size, ResponseDesc* resp) noexcept = 0;
49 
50  /**
51  * @brief Sets the weights buffer (.bin part) from the IR.
52  * Weights Blob must always be of bytes - the casting to precision is done per-layer to support mixed
53  * networks and to ease of use.
54  * This method can be called more than once to reflect updates in the .bin.
55  * @param weights Blob of bytes that holds all the IR binary data
56  * @param resp Response message
57  * @return Result code
58  */
59  virtual StatusCode SetWeights(const TBlob<uint8_t>::Ptr& weights, ResponseDesc* resp) noexcept = 0;
60 
61  /**
62  * @brief Loads and sets the weights buffer directly from the IR .bin file.
63  * This method can be called more than once to reflect updates in the .bin.
64  * @param filepath Full path to the .bin file
65  * @param resp Response message
66  * @return Result code
67  */
68  virtual StatusCode ReadWeights(const char* filepath, ResponseDesc* resp) noexcept = 0;
69 
70  /**
71  * @brief Returns a pointer to the built network
72  * @param resp Response message
73  */
74  virtual ICNNNetwork* getNetwork(ResponseDesc* resp) noexcept = 0;
75 
76  /**
77  * @brief Retrieves the last building status
78  * @param resp Response message
79  */
80  virtual bool isParseSuccess(ResponseDesc* resp) noexcept = 0;
81 
82  /**
83  * @brief Retrieves the last building failure message if failed
84  * @param resp Response message
85  * @return StatusCode that indicates the network status
86  */
87  virtual StatusCode getDescription(ResponseDesc* resp) noexcept = 0;
88 
89  /**
90  * @brief Gets network name
91  * @param name Pointer to preallocated buffer that receives network name
92  * @param len Length of the preallocated buffer, network name will be trimmed by this lenght
93  * @param resp Response message
94  * @return Result code
95  */
96  virtual StatusCode getName(char* name, size_t len, ResponseDesc* resp) noexcept = 0;
97 
98  /**
99  * @brief Returns a version of IR
100  * @param resp Response message
101  * @return IR version number: 1 or 2
102  */
103  virtual int getVersion(ResponseDesc* resp) noexcept = 0;
104 };
105 
106 /**
107  * @brief Creates a CNNNetReader instance
108  * @return An object that implements the ICNNNetReader interface
109  */
110 INFERENCE_ENGINE_API(ICNNNetReader*) CreateCNNNetReader() noexcept;
111 } // namespace InferenceEngine
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
virtual StatusCode ReadNetwork(const char *filepath, ResponseDesc *resp) noexcept=0
Parses the topology part of the IR (.xml) This method can be called once only to read network...
virtual bool isParseSuccess(ResponseDesc *resp) noexcept=0
Retrieves the last building status.
A header file for Blob and generic TBlob<>
virtual StatusCode SetWeights(const TBlob< uint8_t >::Ptr &weights, ResponseDesc *resp) noexcept=0
Sets the weights buffer (.bin part) from the IR. Weights Blob must always be of bytes - the casting t...
This is a header file for the ICNNNetwork class.
virtual StatusCode ReadWeights(const char *filepath, ResponseDesc *resp) noexcept=0
Loads and sets the weights buffer directly from the IR .bin file. This method can be called more than...
This class is the main interface to build and parse a network from a given IR.
Definition: ie_icnn_net_reader.h:27
ICNNNetReader * CreateCNNNetReader() noexcept
Creates a CNNNetReader instance.
Represents detailed information for an error.
Definition: ie_common.h:235
std::shared_ptr< TBlob< T >> Ptr
Smart Pointer to this TBlob object.
Definition: ie_blob.h:358
StatusCode
This enum contains codes for all possible return values of the interface functions.
Definition: ie_common.h:212
virtual StatusCode getName(char *name, size_t len, ResponseDesc *resp) noexcept=0
Gets network name.
This is the main interface to describe the NN topology.
Definition: ie_icnn_network.hpp:41
The macro defines a symbol import/export mechanism essential for Microsoft Windows(R) OS...
header file for no_copy class
virtual StatusCode getDescription(ResponseDesc *resp) noexcept=0
Retrieves the last building failure message if failed.
virtual ICNNNetwork * getNetwork(ResponseDesc *resp) noexcept=0
Returns a pointer to the built network.
This is a header file with common inference engine definitions.
virtual int getVersion(ResponseDesc *resp) noexcept=0
Returns a version of IR.