1 // Copyright (C) 2018 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
9 * @brief A header file for the TBlobProxy class definition
10 * @file ie_blob_proxy.hpp
17 namespace InferenceEngine {
21 * @brief This class enables creation of several blobs based on a single allocation but using different offsets for read/write
24 class TBlobProxy : public TBlob<T> {
25 using base = TBlob<T>;
29 * @brief A shared pointer to the TBlobProxy object
31 using Ptr = std::shared_ptr<TBlobProxy<T>>;
34 * @brief A move constructor
35 * @param p Precision type
37 * @param blob Source TBlob object to move from. It is deleted after a constructor call, since the ownership is transferred to the proxy
38 * @param offset Offset in memory
39 * @param dims Dimensions of the given blob
41 TBlobProxy(Precision p, Layout l, TBlob <T> &&blob, size_t offset, const SizeVector &dims)
42 : base(p, l, dims), realObject(make_shared_blob<T>(std::move(blob))),
43 offset(offset * blob.element_size()) {
48 * @brief A move constructor
49 * @param p Precision type
51 * @param blob Source Blob object to move from. It is deleted after a constructor call, since the ownership is transferred to the proxy
52 * @param offset Offset in memory
53 * @param dims Dimensions of the given blob
55 TBlobProxy(Precision p, Layout l, const Blob::Ptr &blob, size_t offset, const SizeVector &dims)
56 : base(p, l, dims), realObject(blob), offset(offset * blob->element_size()) {
62 * @param p Precision type
64 * @param blobProxy Source TBlobProxy object to copy from
65 * @param offset Offset in memory
66 * @param dims Dimensions of the given blob
68 TBlobProxy(Precision p, Layout l, const TBlobProxy<T> &blobProxy, size_t offset, const SizeVector &dims)
69 : TBlob<T>(p, l, dims), realObject(blobProxy.realObject), offset(offset * sizeof(T)) {
74 * @brief Creates a new empty rvalue LockedMemory instance of type void
75 * @return LockedMemory instance of type void
77 LockedMemory<void> buffer() override {
78 return {getAllocator().get(), getHandle(), offset};
82 * @brief Creates a new empty rvalue LockedMemory instance of type const void
83 * @return LockedMemory instance of type const void
85 LockedMemory<const void> cbuffer() const override {
86 return {getAllocator().get(), getHandle(), offset};
90 * @brief Creates a LockedMemory instance of the given type
91 * @return LockedMemory instance of the given type
93 LockedMemory <T> data() override {
94 return {getAllocator().get(), getHandle(), offset};
98 * @brief Creates a readOnly LockedMemory instance of the given type
99 * @return Read-only LockedMemory instance of the given type
101 LockedMemory<const T> readOnly() const override {
102 return {getAllocator().get(), getHandle(), offset};
107 * @brief Gets an allocator
108 * @return An allocator instance
110 const std::shared_ptr<IAllocator> &getAllocator() const noexcept override {
111 return realObject->getAllocator();
115 * @brief Gets a handle pointer
116 * @return A handle pointer
118 void *getHandle() const noexcept override {
119 return realObject->getHandle();
123 * @brief Checks whether proxy can be created with the requested offset and size parameters
126 if (realObject->size() * realObject->element_size() < base::size() * base::element_size() + offset) {
127 THROW_IE_EXCEPTION << "cannot create proxy, offsetInBytes=" << offset << ", sizeInBytes="
128 << base::size() * base::element_size() << ", out of original object size="
129 << realObject->size() * realObject->element_size();
134 * @brief Allocates TBlobProxy data
135 * Always throws exception. Not intended to be used
137 void allocate() override {
139 << "Proxy blob are not to use allocate, it should rely on actual blob allocation it proxies";
143 * @brief Deallocates TBlobProxy data
144 * Always throws exception. Not intended to be used
146 bool deallocate() override {
148 << "Proxy blob are not to use deallocate(), it should rely on actual blob allocation it proxies";
152 typename Blob::Ptr realObject;
155 } // namespace InferenceEngine