ie_compound_blob.h
Go to the documentation of this file.
1 // Copyright (C) 2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 /**
6  * @brief A header file for CompoundBlob
7  * @file ie_compound_blob.h
8  */
9 #pragma once
10 
11 #include "ie_blob.h"
12 
13 #include <memory>
14 #include <vector>
15 #include <initializer_list>
16 
17 namespace InferenceEngine {
18 /**
19  * @brief This class represents a blob that contains other blobs
20  *
21  * Compound blob is a wrapper blob over references to underlying blobs. These blobs should share
22  * some properties and can be grouped into a single entity.
23  */
24 class INFERENCE_ENGINE_API_CLASS(CompoundBlob) : public Blob {
25 public:
26  /**
27  * @brief A smart pointer to the CompoundBlob object
28  */
29  using Ptr = std::shared_ptr<CompoundBlob>;
30 
31  /**
32  * @brief A smart pointer to the const CompoundBlob object
33  */
34  using CPtr = std::shared_ptr<const CompoundBlob>;
35 
36  /**
37  * @brief A virtual destructor
38  */
39  virtual ~CompoundBlob() = default;
40 
41  /**
42  * @brief A copy constructor
43  */
44  CompoundBlob(const CompoundBlob& blob);
45 
46  /**
47  * @brief A copy assignment operator
48  */
49  CompoundBlob& operator=(const CompoundBlob& blob) = default;
50 
51  /**
52  * @brief A move constructor
53  */
54  CompoundBlob(CompoundBlob&& blob);
55 
56  /**
57  * @brief A move assignment operator
58  */
59  CompoundBlob& operator=(CompoundBlob&& blob) = default;
60 
61  /**
62  * @brief Constructs a compound blob from a vector of blobs
63  * @param blobs A vector of blobs that is copied to this object
64  */
65  explicit CompoundBlob(const std::vector<Blob::Ptr>& blobs);
66 
67  /**
68  * @brief Constructs a compound blob from a vector of blobs
69  * @param blobs A vector of blobs that is moved to this object
70  */
71  explicit CompoundBlob(std::vector<Blob::Ptr>&& blobs);
72 
73  /**
74  * @brief Always returns 0
75  */
76  size_t byteSize() const noexcept override;
77 
78  /**
79  * @brief Always returns 0
80  */
81  size_t element_size() const noexcept override;
82 
83  /**
84  * @brief No operation is performed. Compound blob does not allocate/deallocate any data
85  */
86  void allocate() noexcept override;
87 
88  /**
89  * @brief No operation is performed. Compound blob does not allocate/deallocate any data
90  * @return false
91  */
92  bool deallocate() noexcept override;
93 
94  /**
95  * @brief Always returns an empty LockedMemory object
96  */
97  LockedMemory<void> buffer() noexcept override;
98 
99  /**
100  * @brief Always returns an empty LockedMemory object
101  */
102  LockedMemory<const void> cbuffer() const noexcept override;
103 
104  /**
105  * @brief Returns the number of underlying blobs in the compound blob
106  */
107  size_t size() const noexcept override;
108 
109  /**
110  * @brief Returns an underlying blob at index i
111  * @param i the index of the underlying Blob object
112  * @return A smart pointer to the underlying Blob object or nullptr in case of an error
113  */
114  virtual Blob::Ptr getBlob(size_t i) const noexcept;
115 
116 protected:
117  /**
118  * @brief A default constructor
119  */
120  CompoundBlob();
121 
122  /**
123  * @brief Compound blob container for underlying blobs
124  */
125  std::vector<Blob::Ptr> _blobs;
126 
127  /**
128  * @brief Returns nullptr as CompoundBlob is not allocator-based
129  */
130  const std::shared_ptr<IAllocator> &getAllocator() const noexcept override;
131 
132  /**
133  * @brief Returns nullptr as CompoundBlob is not allocator-based
134  */
135  void *getHandle() const noexcept override;
136 };
137 
138 /**
139  * @brief Represents a blob that contains two planes (Y and UV) in NV12 color format
140  */
141 class INFERENCE_ENGINE_API_CLASS(NV12Blob) : public CompoundBlob {
142 public:
143  /**
144  * @brief A smart pointer to the NV12Blob object
145  */
146  using Ptr = std::shared_ptr<NV12Blob>;
147 
148  /**
149  * @brief A smart pointer to the const NV12Blob object
150  */
151  using CPtr = std::shared_ptr<const NV12Blob>;
152 
153  /**
154  * @brief A deleted default constructor
155  */
156  NV12Blob() = delete;
157 
158  /**
159  * @brief Constructs NV12 blob from two planes Y and UV
160  * @param y Blob object that represents Y plane in NV12 color format
161  * @param uv Blob object that represents UV plane in NV12 color format
162  */
163  NV12Blob(const Blob::Ptr& y, const Blob::Ptr& uv);
164 
165  /**
166  * @brief Constructs NV12 blob from two planes Y and UV
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(Blob::Ptr&& y, Blob::Ptr&& uv);
171 
172  /**
173  * @brief A virtual destructor
174  */
175  virtual ~NV12Blob() = default;
176 
177  /**
178  * @brief A copy constructor
179  */
180  NV12Blob(const NV12Blob& blob) = default;
181 
182  /**
183  * @brief A copy assignment operator
184  */
185  NV12Blob& operator=(const NV12Blob& blob) = default;
186 
187  /**
188  * @brief A move constructor
189  */
190  NV12Blob(NV12Blob&& blob) = default;
191 
192  /**
193  * @brief A move assignment operator
194  */
195  NV12Blob& operator=(NV12Blob&& blob) = default;
196 
197  /**
198  * @brief Returns a shared pointer to Y plane
199  */
200  virtual Blob::Ptr& y() noexcept;
201 
202  /**
203  * @brief Returns a shared pointer to Y plane
204  */
205  virtual const Blob::Ptr& y() const noexcept;
206 
207  /**
208  * @brief Returns a shared pointer to UV plane
209  */
210  virtual Blob::Ptr& uv() noexcept;
211 
212  /**
213  * @brief Returns a shared pointer to UV plane
214  */
215  virtual const Blob::Ptr& uv() const noexcept;
216 };
217 
218 } // namespace InferenceEngine
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:107
Inference Engine API.
Definition: ie_argmax_layer.hpp:11
std::shared_ptr< CompoundBlob > Ptr
A smart pointer to the CompoundBlob object.
Definition: ie_compound_blob.h:29
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:45
std::shared_ptr< Blob > Ptr
A smart pointer containing Blob object.
Definition: ie_blob.h:40
This class represents a universal container in the Inference Engine.
Definition: ie_blob.h:35
Represents a blob that contains two planes (Y and UV) in NV12 color format.
Definition: ie_compound_blob.h:141
This class represents a blob that contains other blobs.
Definition: ie_compound_blob.h:24
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:27