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  */
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  Blob::Ptr createROI(const ROI& roi) const override;
121 
122 protected:
123  /**
124  * @brief A default constructor
125  */
127 
128  /**
129  * @brief Compound blob container for underlying blobs
130  */
131  std::vector<Blob::Ptr> _blobs;
132 
133  /**
134  * @brief Returns nullptr as CompoundBlob is not allocator-based
135  */
136  const std::shared_ptr<IAllocator>& getAllocator() const noexcept override;
137 
138  /**
139  * @brief Returns nullptr as CompoundBlob is not allocator-based
140  */
141  void* getHandle() const noexcept override;
142 };
143 
144 /**
145  * @brief Represents a blob that contains two planes (Y and UV) in NV12 color format
146  */
147 class INFERENCE_ENGINE_API_CLASS(NV12Blob): public CompoundBlob {
148 public:
149  /**
150  * @brief A smart pointer to the NV12Blob object
151  */
152  using Ptr = std::shared_ptr<NV12Blob>;
153 
154  /**
155  * @brief A smart pointer to the const NV12Blob object
156  */
157  using CPtr = std::shared_ptr<const NV12Blob>;
158 
159  /**
160  * @brief A deleted default constructor
161  */
162  NV12Blob() = delete;
163 
164  /**
165  * @brief Constructs NV12 blob from two planes Y and UV
166  *
167  * @param y Blob object that represents Y plane in NV12 color format
168  * @param uv Blob object that represents UV plane in NV12 color format
169  */
170  NV12Blob(const Blob::Ptr& y, const Blob::Ptr& uv);
171 
172  /**
173  * @brief Constructs NV12 blob from two planes Y and UV
174  *
175  * @param y Blob object that represents Y plane in NV12 color format
176  * @param uv Blob object that represents UV plane in NV12 color format
177  */
179 
180  /**
181  * @brief A virtual destructor
182  */
183  virtual ~NV12Blob() = default;
184 
185  /**
186  * @brief A copy constructor
187  */
188  NV12Blob(const NV12Blob& blob) = default;
189 
190  /**
191  * @brief A copy assignment operator
192  */
193  NV12Blob& operator=(const NV12Blob& blob) = default;
194 
195  /**
196  * @brief A move constructor
197  */
198  NV12Blob(NV12Blob&& blob) = default;
199 
200  /**
201  * @brief A move assignment operator
202  */
203  NV12Blob& operator=(NV12Blob&& blob) = default;
204 
205  /**
206  * @brief Returns a shared pointer to Y plane
207  */
208  virtual Blob::Ptr& y() noexcept;
209 
210  /**
211  * @brief Returns a shared pointer to Y plane
212  */
213  virtual const Blob::Ptr& y() const noexcept;
214 
215  /**
216  * @brief Returns a shared pointer to UV plane
217  */
218  virtual Blob::Ptr& uv() noexcept;
219 
220  /**
221  * @brief Returns a shared pointer to UV plane
222  */
223  virtual const Blob::Ptr& uv() const noexcept;
224 
225  Blob::Ptr createROI(const ROI& roi) const override;
226 };
227 
228 /**
229  * @brief Represents a blob that contains three planes (Y,U and V) in I420 color format
230  */
231 class INFERENCE_ENGINE_API_CLASS(I420Blob) : public CompoundBlob {
232 public:
233  /**
234  * @brief A smart pointer to the I420Blob object
235  */
236  using Ptr = std::shared_ptr<I420Blob>;
237 
238  /**
239  * @brief A smart pointer to the const I420Blob object
240  */
241  using CPtr = std::shared_ptr<const I420Blob>;
242 
243  /**
244  * @brief A deleted default constructor
245  */
246  I420Blob() = delete;
247 
248  /**
249  * @brief Constructs I420 blob from three planes Y, U and V
250  * @param y Blob object that represents Y plane in I420 color format
251  * @param u Blob object that represents U plane in I420 color format
252  * @param v Blob object that represents V plane in I420 color format
253  */
254  I420Blob(const Blob::Ptr& y, const Blob::Ptr& u, const Blob::Ptr& v);
255 
256  /**
257  * @brief Constructs I420 blob from three planes Y, U and V
258  * @param y Blob object that represents Y plane in I420 color format
259  * @param u Blob object that represents U plane in I420 color format
260  * @param v Blob object that represents V plane in I420 color format
261  */
263 
264  /**
265  * @brief A virtual destructor. It is made out of line for RTTI to
266  * work correctly on some platforms.
267  */
268  virtual ~I420Blob();
269 
270  /**
271  * @brief A copy constructor
272  */
273  I420Blob(const I420Blob& blob) = default;
274 
275  /**
276  * @brief A copy assignment operator
277  */
278  I420Blob& operator=(const I420Blob& blob) = default;
279 
280  /**
281  * @brief A move constructor
282  */
283  I420Blob(I420Blob&& blob) = default;
284 
285  /**
286  * @brief A move assignment operator
287  */
288  I420Blob& operator=(I420Blob&& blob) = default;
289 
290  /**
291  * @brief Returns a reference to shared pointer to Y plane
292  *
293  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
294  * the I420Blob object is destroyed.
295  *
296  * @return reference to shared pointer object of Y plane
297  */
298  Blob::Ptr& y() noexcept;
299 
300  /**
301  * @brief Returns a constant reference to shared pointer to Y plane
302  *
303  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
304  * the I420Blob object is destroyed.
305  *
306  * @return constant reference to shared pointer object of Y plane*
307  */
308  const Blob::Ptr& y() const noexcept;
309 
310  /**
311  * @brief Returns a reference to shared pointer to U plane
312  *
313  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
314  * the I420Blob object is destroyed.
315  *
316  * @return reference to shared pointer object of U plane
317  */
318  Blob::Ptr& u() noexcept;
319 
320  /**
321  * @brief Returns a constant reference to shared pointer to U plane
322  *
323  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
324  * the I420Blob object is destroyed.
325  *
326  * @return constant reference to shared pointer object of U plane
327  */
328  const Blob::Ptr& u() const noexcept;
329 
330  /**
331  * @brief Returns a reference to shared pointer to V plane
332  *
333  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
334  * the I420Blob object is destroyed.
335  *
336  * @return reference to shared pointer object of V plane
337  */
338  Blob::Ptr& v() noexcept;
339 
340  /**
341  * @brief Returns a constant reference to shared pointer to V plane
342  *
343  * Please note that reference to Blob::Ptr is returned. I.e. the reference will be valid until
344  * the I420Blob object is destroyed.
345  *
346  * @return constant reference to shared pointer object of V plane
347  */
348  const Blob::Ptr& v() const noexcept;
349 
350  Blob::Ptr createROI(const ROI& roi) const override;
351 };
352 } // namespace InferenceEngine
InferenceEngine::I420Blob
Represents a blob that contains three planes (Y,U and V) in I420 color format.
Definition: ie_compound_blob.h:231
InferenceEngine::NV12Blob::operator=
NV12Blob & operator=(NV12Blob &&blob)=default
A move assignment operator.
roi
Definition: ie_c_api.h:251
InferenceEngine::LockedMemory
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:111
InferenceEngine::CompoundBlob::operator=
CompoundBlob & operator=(const CompoundBlob &blob)=default
A copy assignment operator.
InferenceEngine::CompoundBlob::~CompoundBlob
virtual ~CompoundBlob()=default
A virtual destructor.
InferenceEngine::Blob::CPtr
std::shared_ptr< const Blob > CPtr
A smart pointer to the const Blob object.
Definition: ie_blob.h:48
InferenceEngine::I420Blob::I420Blob
I420Blob()=delete
A deleted default constructor.
InferenceEngine::CompoundBlob::byteSize
size_t byteSize() const noexcept override
Always returns 0.
InferenceEngine::CompoundBlob::CompoundBlob
CompoundBlob(std::vector< Blob::Ptr > &&blobs)
Constructs a compound blob from a vector of blobs.
ie_blob.h
A header file for Blob and generic TBlob<>
InferenceEngine::CompoundBlob::CompoundBlob
CompoundBlob(const std::vector< Blob::Ptr > &blobs)
Constructs a compound blob from a vector of blobs.
InferenceEngine::CompoundBlob::operator=
CompoundBlob & operator=(CompoundBlob &&blob)=default
A move assignment operator.
InferenceEngine::CompoundBlob
This class represents a blob that contains other blobs.
Definition: ie_compound_blob.h:25
InferenceEngine::NV12Blob::operator=
NV12Blob & operator=(const NV12Blob &blob)=default
A copy assignment operator.
InferenceEngine::CompoundBlob::CompoundBlob
CompoundBlob(CompoundBlob &&blob)
A move constructor.
InferenceEngine::I420Blob::I420Blob
I420Blob(I420Blob &&blob)=default
A move constructor.
InferenceEngine::NV12Blob::NV12Blob
NV12Blob(const Blob::Ptr &y, const Blob::Ptr &uv)
Constructs NV12 blob from two planes Y and UV.
InferenceEngine::I420Blob::I420Blob
I420Blob(const Blob::Ptr &y, const Blob::Ptr &u, const Blob::Ptr &v)
Constructs I420 blob from three planes Y, U and V.
InferenceEngine::IAllocator
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:29
InferenceEngine::I420Blob::operator=
I420Blob & operator=(I420Blob &&blob)=default
A move assignment operator.
InferenceEngine::NV12Blob::NV12Blob
NV12Blob(const NV12Blob &blob)=default
A copy constructor.
InferenceEngine::Blob::Ptr
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:43
InferenceEngine::I420Blob::I420Blob
I420Blob(Blob::Ptr &&y, Blob::Ptr &&u, Blob::Ptr &&v)
Constructs I420 blob from three planes Y, U and V.
InferenceEngine::I420Blob::operator=
I420Blob & operator=(const I420Blob &blob)=default
A copy assignment operator.
InferenceEngine::Blob
This class represents a universal container in the Inference Engine.
Definition: ie_blob.h:38
InferenceEngine::CompoundBlob::CompoundBlob
CompoundBlob(const CompoundBlob &blob)
A copy constructor.
InferenceEngine::I420Blob::~I420Blob
virtual ~I420Blob()
A virtual destructor. It is made out of line for RTTI to work correctly on some platforms.
InferenceEngine::NV12Blob::y
virtual Blob::Ptr & y() noexcept
Returns a shared pointer to Y plane.
InferenceEngine::NV12Blob
Represents a blob that contains two planes (Y and UV) in NV12 color format.
Definition: ie_compound_blob.h:147
InferenceEngine::ROI
This structure describes ROI data for image-like tensors.
Definition: ie_layouts.h:324
InferenceEngine::I420Blob::I420Blob
I420Blob(const I420Blob &blob)=default
A copy constructor.
InferenceEngine::NV12Blob::NV12Blob
NV12Blob(NV12Blob &&blob)=default
A move constructor.
InferenceEngine::NV12Blob::~NV12Blob
virtual ~NV12Blob()=default
A virtual destructor.
InferenceEngine::NV12Blob::NV12Blob
NV12Blob(Blob::Ptr &&y, Blob::Ptr &&uv)
Constructs NV12 blob from two planes Y and UV.
InferenceEngine::I420Blob::y
Blob::Ptr & y() noexcept
Returns a reference to shared pointer to Y plane.
InferenceEngine::NV12Blob::NV12Blob
NV12Blob()=delete
A deleted default constructor.