ie_compound_blob.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2021 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file for CompoundBlob
7  *
8  * @file ie_compound_blob.h
9  */
10 #pragma once
11 
12 #include <initializer_list>
13 #include <memory>
14 #include <vector>
15 
16 #include "ie_blob.h"
17 
18 namespace InferenceEngine {
19 /**
20  * @brief This class represents a blob that contains other blobs
21  *
22  * Compound blob is a wrapper blob over references to underlying blobs. These blobs should share
23  * some properties and can be grouped into a single entity.
24  */
25 class INFERENCE_ENGINE_API_CLASS(CompoundBlob): public Blob {
26 public:
27  /**
28  * @brief A smart pointer to the CompoundBlob object
29  */
30  using Ptr = std::shared_ptr<CompoundBlob>;
31 
32  /**
33  * @brief A smart pointer to the const CompoundBlob object
34  */
35  using CPtr = std::shared_ptr<const CompoundBlob>;
36 
37  /**
38  * @brief Constructs a compound blob from a vector of blobs
39  *
40  * @param blobs A vector of blobs that is copied to this object
41  */
42  explicit CompoundBlob(const std::vector<Blob::Ptr>& blobs);
43 
44  /**
45  * @brief Constructs a compound blob from a vector of blobs
46  *
47  * @param blobs A vector of blobs that is moved to this object
48  */
49  explicit CompoundBlob(std::vector<Blob::Ptr>&& blobs);
50 
51  /**
52  * @brief Always returns `0`
53  * @return Returns `0`
54  */
55  size_t byteSize() const noexcept override;
56 
57  /**
58  * @brief Always returns `0`
59  * @return Returns `0`
60  */
61  size_t element_size() const noexcept override;
62 
63  /**
64  * @brief No operation is performed. Compound blob does not allocate/deallocate any data
65  */
66  void allocate() noexcept override;
67 
68  /**
69  * @brief No operation is performed. Compound blob does not allocate/deallocate any data
70  * @return Returns `false`
71  */
72  bool deallocate() noexcept override;
73 
74  /**
75  * @brief Always returns an empty LockedMemory object
76  */
77  LockedMemory<void> buffer() noexcept override;
78 
79  /**
80  * @brief Always returns an empty LockedMemory object
81  */
82  LockedMemory<const void> cbuffer() const noexcept override;
83 
84  /**
85  * @brief Returns the number of underlying blobs in the compound blob
86  */
87  size_t size() const noexcept override;
88 
89  /**
90  * @brief Returns an underlying blob at index i
91  *
92  * @param i the index of the underlying Blob object
93  * @return A smart pointer to the underlying Blob object or nullptr in case of an error
94  */
95  virtual Blob::Ptr getBlob(size_t i) const noexcept;
96 
97  Blob::Ptr createROI(const ROI& roi) const override;
98 
99 protected:
100  /**
101  * @brief Constructs a compound blob with specified descriptor
102  *
103  * @param tensorDesc A tensor descriptor for the compound blob
104  */
105  explicit CompoundBlob(const TensorDesc& tensorDesc);
106 
107  /**
108  * @brief Compound blob container for underlying blobs
109  */
110  std::vector<Blob::Ptr> _blobs;
111 
112  /**
113  * @brief Returns nullptr as CompoundBlob is not allocator-based
114  */
115  const std::shared_ptr<IAllocator>& getAllocator() const noexcept override;
116 
117  /**
118  * @brief Returns nullptr as CompoundBlob is not allocator-based
119  */
120  void* getHandle() const noexcept override;
121 };
122 
123 /**
124  * @brief Represents a blob that contains two planes (Y and UV) in NV12 color format
125  */
126 class INFERENCE_ENGINE_API_CLASS(NV12Blob): public CompoundBlob {
127 public:
128  /**
129  * @brief A smart pointer to the NV12Blob object
130  */
131  using Ptr = std::shared_ptr<NV12Blob>;
132 
133  /**
134  * @brief A smart pointer to the const NV12Blob object
135  */
136  using CPtr = std::shared_ptr<const NV12Blob>;
137 
138  /**
139  * @brief Constructs NV12 blob from two planes Y and UV
140  *
141  * @param y Blob object that represents Y plane in NV12 color format
142  * @param uv Blob object that represents UV plane in NV12 color format
143  */
144  NV12Blob(const Blob::Ptr& y, const Blob::Ptr& uv);
145 
146  /**
147  * @brief Constructs NV12 blob from two planes Y and UV
148  *
149  * @param y Blob object that represents Y plane in NV12 color format
150  * @param uv Blob object that represents UV plane in NV12 color format
151  */
153 
154  /**
155  * @brief Returns a shared pointer to Y plane
156  */
157  virtual Blob::Ptr& y() noexcept;
158 
159  /**
160  * @brief Returns a shared pointer to Y plane
161  */
162  virtual const Blob::Ptr& y() const noexcept;
163 
164  /**
165  * @brief Returns a shared pointer to UV plane
166  */
167  virtual Blob::Ptr& uv() noexcept;
168 
169  /**
170  * @brief Returns a shared pointer to UV plane
171  */
172  virtual const Blob::Ptr& uv() const noexcept;
173 
174  Blob::Ptr createROI(const ROI& roi) const override;
175 };
176 
177 /**
178  * @brief Represents a blob that contains three planes (Y,U and V) in I420 color format
179  */
180 class INFERENCE_ENGINE_API_CLASS(I420Blob) : public CompoundBlob {
181 public:
182  /**
183  * @brief A smart pointer to the I420Blob object
184  */
185  using Ptr = std::shared_ptr<I420Blob>;
186 
187  /**
188  * @brief A smart pointer to the const I420Blob object
189  */
190  using CPtr = std::shared_ptr<const I420Blob>;
191 
192  /**
193  * @brief Constructs I420 blob from three planes Y, U and V
194  * @param y Blob object that represents Y plane in I420 color format
195  * @param u Blob object that represents U plane in I420 color format
196  * @param v Blob object that represents V plane in I420 color format
197  */
198  I420Blob(const Blob::Ptr& y, const Blob::Ptr& u, const Blob::Ptr& v);
199 
200  /**
201  * @brief Constructs I420 blob from three planes Y, U and V
202  * @param y Blob object that represents Y plane in I420 color format
203  * @param u Blob object that represents U plane in I420 color format
204  * @param v Blob object that represents V plane in I420 color format
205  */
207 
208  /**
209  * @brief Returns a reference to shared pointer to Y plane
210  *
211  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
212  * the I420Blob object is destroyed.
213  *
214  * @return reference to shared pointer object of Y plane
215  */
216  Blob::Ptr& y() noexcept;
217 
218  /**
219  * @brief Returns a constant reference to shared pointer to Y plane
220  *
221  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
222  * the I420Blob object is destroyed.
223  *
224  * @return constant reference to shared pointer object of Y plane*
225  */
226  const Blob::Ptr& y() const noexcept;
227 
228  /**
229  * @brief Returns a reference to shared pointer to U plane
230  *
231  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
232  * the I420Blob object is destroyed.
233  *
234  * @return reference to shared pointer object of U plane
235  */
236  Blob::Ptr& u() noexcept;
237 
238  /**
239  * @brief Returns a constant reference to shared pointer to U plane
240  *
241  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
242  * the I420Blob object is destroyed.
243  *
244  * @return constant reference to shared pointer object of U plane
245  */
246  const Blob::Ptr& u() const noexcept;
247 
248  /**
249  * @brief Returns a reference to shared pointer to V plane
250  *
251  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
252  * the I420Blob object is destroyed.
253  *
254  * @return reference to shared pointer object of V plane
255  */
256  Blob::Ptr& v() noexcept;
257 
258  /**
259  * @brief Returns a constant reference to shared pointer to V plane
260  *
261  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
262  * the I420Blob object is destroyed.
263  *
264  * @return constant reference to shared pointer object of V plane
265  */
266  const Blob::Ptr& v() const noexcept;
267 
268  Blob::Ptr createROI(const ROI& roi) const override;
269 };
270 
271 /**
272  * @brief This class represents a blob that contains other blobs - one per batch
273  * @details Plugin which supports BatchedBlob input should report BATCHED_BLOB
274  * in the OPTIMIZATION_CAPABILITIES metric.
275  */
276 class INFERENCE_ENGINE_API_CLASS(BatchedBlob) : public CompoundBlob {
277  public:
278  /**
279  * @brief A smart pointer to the BatchedBlob object
280  */
281  using Ptr = std::shared_ptr<BatchedBlob>;
282 
283  /**
284  * @brief A smart pointer to the const BatchedBlob object
285  */
286  using CPtr = std::shared_ptr<const BatchedBlob>;
287 
288  /**
289  * @brief Constructs a batched blob from a vector of blobs
290  * @details All passed blobs should meet following requirements:
291  * - all blobs have equal tensor descriptors,
292  * - blobs layouts should be one of: NCHW, NHWC, NCDHW, NDHWC, NC, CN, C, CHW, HWC
293  * - batch dimensions should be equal to 1 or not defined (C, CHW, HWC).
294  * Resulting blob's tensor descriptor is constructed using tensor descriptors
295  * of passed blobs by setting batch dimension to blobs.size()
296  *
297  * @param blobs A vector of blobs that is copied to this object
298  */
299  explicit BatchedBlob(const std::vector<Blob::Ptr>& blobs);
300 
301  /**
302  * @brief Constructs a batched blob from a vector of blobs
303  * @details All passed blobs should meet following requirements:
304  * - all blobs have equal tensor descriptors,
305  * - blobs layouts should be one of: NCHW, NHWC, NCDHW, NDHWC, NC, CN, C, CHW, HWC
306  * - batch dimensions should be equal to 1 or not defined (C, CHW, HWC).
307  * Resulting blob's tensor descriptor is constructed using tensor descriptors
308  * of passed blobs by setting batch dimension to blobs.size()
309  *
310  * @param blobs A vector of blobs that is moved to this object
311  */
312  explicit BatchedBlob(std::vector<Blob::Ptr>&& blobs);
313 };
314 } // namespace InferenceEngine
This class represents a blob that contains other blobs - one per batch.
Definition: ie_compound_blob.h:276
BatchedBlob(std::vector< Blob::Ptr > &&blobs)
Constructs a batched blob from a vector of blobs.
BatchedBlob(const std::vector< Blob::Ptr > &blobs)
Constructs a batched blob from a vector of blobs.
This class represents a universal container in the Inference Engine.
Definition: ie_blob.h:37
std::shared_ptr< const Blob > CPtr
A smart pointer to the const Blob object.
Definition: ie_blob.h:47
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:42
This class represents a blob that contains other blobs.
Definition: ie_compound_blob.h:25
CompoundBlob(std::vector< Blob::Ptr > &&blobs)
Constructs a compound blob from a vector of blobs.
CompoundBlob(const std::vector< Blob::Ptr > &blobs)
Constructs a compound blob from a vector of blobs.
size_t byteSize() const noexcept override
Always returns 0
Represents a blob that contains three planes (Y,U and V) in I420 color format.
Definition: ie_compound_blob.h:180
I420Blob(const Blob::Ptr &y, const Blob::Ptr &u, const Blob::Ptr &v)
Constructs I420 blob from three planes Y, U and V.
Blob::Ptr & y() noexcept
Returns a reference to shared pointer to Y plane.
I420Blob(Blob::Ptr &&y, Blob::Ptr &&u, Blob::Ptr &&v)
Constructs I420 blob from three planes Y, U and V.
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:29
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:110
Represents a blob that contains two planes (Y and UV) in NV12 color format.
Definition: ie_compound_blob.h:126
NV12Blob(const Blob::Ptr &y, const Blob::Ptr &uv)
Constructs NV12 blob from two planes Y and UV.
NV12Blob(Blob::Ptr &&y, Blob::Ptr &&uv)
Constructs NV12 blob from two planes Y and UV.
virtual Blob::Ptr & y() noexcept
Returns a shared pointer to Y plane.
This class defines Tensor description.
Definition: ie_layouts.h:158
A header file for Blob and generic TBlob<>
Inference Engine C++ API.
Definition: cldnn_config.hpp:17
This structure describes ROI data for image-like tensors.
Definition: ie_layouts.h:329