ie_compound_blob.h
Go to the documentation of this file.
1 // Copyright (C) 2018-2020 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 A virtual destructor
39  */
40  virtual ~CompoundBlob() = default;
41 
42  /**
43  * @brief A copy constructor
44  */
45  CompoundBlob(const CompoundBlob& blob);
46 
47  /**
48  * @brief A copy assignment operator
49  */
50  CompoundBlob& operator=(const CompoundBlob& blob) = default;
51 
52  /**
53  * @brief A move constructor
54  */
55  CompoundBlob(CompoundBlob&& blob);
56 
57  /**
58  * @brief A move assignment operator
59  */
60  CompoundBlob& operator=(CompoundBlob&& blob) = default;
61 
62  /**
63  * @brief Constructs a compound blob from a vector of blobs
64  *
65  * @param blobs A vector of blobs that is copied to this object
66  */
67  explicit CompoundBlob(const std::vector<Blob::Ptr>& blobs);
68 
69  /**
70  * @brief Constructs a compound blob from a vector of blobs
71  *
72  * @param blobs A vector of blobs that is moved to this object
73  */
74  explicit CompoundBlob(std::vector<Blob::Ptr>&& blobs);
75 
76  /**
77  * @brief Always returns 0
78  */
79  size_t byteSize() const noexcept override;
80 
81  /**
82  * @brief Always returns 0
83  */
84  size_t element_size() const noexcept override;
85 
86  /**
87  * @brief No operation is performed. Compound blob does not allocate/deallocate any data
88  */
89  void allocate() noexcept override;
90 
91  /**
92  * @brief No operation is performed. Compound blob does not allocate/deallocate any data
93  * @return false
94  */
95  bool deallocate() noexcept override;
96 
97  /**
98  * @brief Always returns an empty LockedMemory object
99  */
100  LockedMemory<void> buffer() noexcept override;
101 
102  /**
103  * @brief Always returns an empty LockedMemory object
104  */
105  LockedMemory<const void> cbuffer() const noexcept override;
106 
107  /**
108  * @brief Returns the number of underlying blobs in the compound blob
109  */
110  size_t size() const noexcept override;
111 
112  /**
113  * @brief Returns an underlying blob at index i
114  *
115  * @param i the index of the underlying Blob object
116  * @return A smart pointer to the underlying Blob object or nullptr in case of an error
117  */
118  virtual Blob::Ptr getBlob(size_t i) const noexcept;
119 
120 protected:
121  /**
122  * @brief A default constructor
123  */
124  CompoundBlob();
125 
126  /**
127  * @brief Compound blob container for underlying blobs
128  */
129  std::vector<Blob::Ptr> _blobs;
130 
131  /**
132  * @brief Returns nullptr as CompoundBlob is not allocator-based
133  */
134  const std::shared_ptr<IAllocator>& getAllocator() const noexcept override;
135 
136  /**
137  * @brief Returns nullptr as CompoundBlob is not allocator-based
138  */
139  void* getHandle() const noexcept override;
140 };
141 
142 /**
143  * @brief Represents a blob that contains two planes (Y and UV) in NV12 color format
144  */
145 class INFERENCE_ENGINE_API_CLASS(NV12Blob): public CompoundBlob {
146 public:
147  /**
148  * @brief A smart pointer to the NV12Blob object
149  */
150  using Ptr = std::shared_ptr<NV12Blob>;
151 
152  /**
153  * @brief A smart pointer to the const NV12Blob object
154  */
155  using CPtr = std::shared_ptr<const NV12Blob>;
156 
157  /**
158  * @brief A deleted default constructor
159  */
160  NV12Blob() = delete;
161 
162  /**
163  * @brief Constructs NV12 blob from two planes Y and UV
164  *
165  * @param y Blob object that represents Y plane in NV12 color format
166  * @param uv Blob object that represents UV plane in NV12 color format
167  */
168  NV12Blob(const Blob::Ptr& y, const Blob::Ptr& uv);
169 
170  /**
171  * @brief Constructs NV12 blob from two planes Y and UV
172  *
173  * @param y Blob object that represents Y plane in NV12 color format
174  * @param uv Blob object that represents UV plane in NV12 color format
175  */
176  NV12Blob(Blob::Ptr&& y, Blob::Ptr&& uv);
177 
178  /**
179  * @brief A virtual destructor
180  */
181  virtual ~NV12Blob() = default;
182 
183  /**
184  * @brief A copy constructor
185  */
186  NV12Blob(const NV12Blob& blob) = default;
187 
188  /**
189  * @brief A copy assignment operator
190  */
191  NV12Blob& operator=(const NV12Blob& blob) = default;
192 
193  /**
194  * @brief A move constructor
195  */
196  NV12Blob(NV12Blob&& blob) = default;
197 
198  /**
199  * @brief A move assignment operator
200  */
201  NV12Blob& operator=(NV12Blob&& blob) = default;
202 
203  /**
204  * @brief Returns a shared pointer to Y plane
205  */
206  virtual Blob::Ptr& y() noexcept;
207 
208  /**
209  * @brief Returns a shared pointer to Y plane
210  */
211  virtual const Blob::Ptr& y() const noexcept;
212 
213  /**
214  * @brief Returns a shared pointer to UV plane
215  */
216  virtual Blob::Ptr& uv() noexcept;
217 
218  /**
219  * @brief Returns a shared pointer to UV plane
220  */
221  virtual const Blob::Ptr& uv() const noexcept;
222 };
223 
224 /**
225  * @brief Represents a blob that contains three planes (Y,U and V) in I420 color format
226  */
227 class INFERENCE_ENGINE_API_CLASS(I420Blob) : public CompoundBlob {
228 public:
229  /**
230  * @brief A smart pointer to the I420Blob object
231  */
232  using Ptr = std::shared_ptr<I420Blob>;
233 
234  /**
235  * @brief A smart pointer to the const I420Blob object
236  */
237  using CPtr = std::shared_ptr<const I420Blob>;
238 
239  /**
240  * @brief A deleted default constructor
241  */
242  I420Blob() = delete;
243 
244  /**
245  * @brief Constructs I420 blob from three planes Y, U and V
246  * @param y Blob object that represents Y plane in I420 color format
247  * @param u Blob object that represents U plane in I420 color format
248  * @param v Blob object that represents V plane in I420 color format
249  */
250  I420Blob(const Blob::Ptr& y, const Blob::Ptr& u, const Blob::Ptr& v);
251 
252  /**
253  * @brief Constructs I420 blob from three planes Y, U and V
254  * @param y Blob object that represents Y plane in I420 color format
255  * @param u Blob object that represents U plane in I420 color format
256  * @param v Blob object that represents V plane in I420 color format
257  */
258  I420Blob(Blob::Ptr&& y, Blob::Ptr&& u, Blob::Ptr&& v);
259 
260  /**
261  * @brief A virtual destructor. It is made out of line for RTTI to
262  * work correctly on some platforms.
263  */
264  virtual ~I420Blob();
265 
266  /**
267  * @brief A copy constructor
268  */
269  I420Blob(const I420Blob& blob) = default;
270 
271  /**
272  * @brief A copy assignment operator
273  */
274  I420Blob& operator=(const I420Blob& blob) = default;
275 
276  /**
277  * @brief A move constructor
278  */
279  I420Blob(I420Blob&& blob) = default;
280 
281  /**
282  * @brief A move assignment operator
283  */
284  I420Blob& operator=(I420Blob&& blob) = default;
285 
286  /**
287  * @brief Returns a reference to shared pointer to Y plane
288  *
289  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
290  * the I420Blob object is destroyed.
291  *
292  * @return reference to shared pointer object of Y plane
293  */
294  Blob::Ptr& y() noexcept;
295 
296  /**
297  * @brief Returns a constant reference to shared pointer to Y plane
298  *
299  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
300  * the I420Blob object is destroyed.
301  *
302  * @return constant reference to shared pointer object of Y plane*
303  */
304  const Blob::Ptr& y() const noexcept;
305 
306  /**
307  * @brief Returns a reference to shared pointer to U plane
308  *
309  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
310  * the I420Blob object is destroyed.
311  *
312  * @return reference to shared pointer object of U plane
313  */
314  Blob::Ptr& u() noexcept;
315 
316  /**
317  * @brief Returns a constant reference to shared pointer to U plane
318  *
319  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
320  * the I420Blob object is destroyed.
321  *
322  * @return constant reference to shared pointer object of U plane
323  */
324  const Blob::Ptr& u() const noexcept;
325 
326  /**
327  * @brief Returns a reference to shared pointer to V plane
328  *
329  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
330  * the I420Blob object is destroyed.
331  *
332  * @return reference to shared pointer object of V plane
333  */
334  Blob::Ptr& v() noexcept;
335 
336  /**
337  * @brief Returns a constant reference to shared pointer to V plane
338  *
339  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
340  * the I420Blob object is destroyed.
341  *
342  * @return constant reference to shared pointer object of V plane
343  */
344  const Blob::Ptr& v() const noexcept;
345 };
346 } // namespace InferenceEngine
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:111
Inference Engine API.
Definition: ie_argmax_layer.hpp:15
std::shared_ptr< CompoundBlob > Ptr
A smart pointer to the CompoundBlob object.
Definition: ie_compound_blob.h:30
A header file for Blob and generic TBlob<>
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 universal container in the Inference Engine.
Definition: ie_blob.h:37
Represents a blob that contains two planes (Y and UV) in NV12 color format.
Definition: ie_compound_blob.h:145
This class represents a blob that contains other blobs.
Definition: ie_compound_blob.h:25
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:26
Represents a blob that contains three planes (Y,U and V) in I420 color format.
Definition: ie_compound_blob.h:227