1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
8 * @brief A header file for the TBlobProxy class definition
9 * @file ie_blob_proxy.hpp
16 namespace InferenceEngine {
20 * @brief This class enables creation of several blobs based on a single allocation but using different offsets for read/write
23 class TBlobProxy : public TBlob<T> {
24 using base = TBlob<T>;
28 * @brief A shared pointer to the TBlobProxy object
30 using Ptr = std::shared_ptr<TBlobProxy<T>>;
33 * @brief A move constructor
34 * @param p Precision type
36 * @param blob Source TBlob object to move from. It is deleted after a constructor call, since the ownership is transferred to the proxy
37 * @param offset Offset in memory
38 * @param dims Dimensions of the given blob
40 TBlobProxy(Precision p, Layout l, TBlob <T> &&blob, size_t offset, const SizeVector &dims)
41 : base(p, l, dims), realObject(make_shared_blob<T>(std::move(blob))),
42 offset(offset * blob.element_size()) {
47 * @brief A move constructor
48 * @param p Precision type
50 * @param blob Source Blob object to move from. It is deleted after a constructor call, since the ownership is transferred to the proxy
51 * @param offset Offset in memory
52 * @param dims Dimensions of the given blob
54 TBlobProxy(Precision p, Layout l, const Blob::Ptr &blob, size_t offset, const SizeVector &dims)
55 : base(p, l, dims), realObject(blob), offset(offset * blob->element_size()) {
61 * @param p Precision type
63 * @param blobProxy Source TBlobProxy object to copy from
64 * @param offset Offset in memory
65 * @param dims Dimensions of the given blob
67 TBlobProxy(Precision p, Layout l, const TBlobProxy<T> &blobProxy, size_t offset, const SizeVector &dims)
68 : TBlob<T>(p, l, dims), realObject(blobProxy.realObject), offset(offset * sizeof(T)) {
73 * @brief Creates a new empty rvalue LockedMemory instance of type void
74 * @return LockedMemory instance of type void
76 LockedMemory<void> buffer() noexcept override {
77 return {getAllocator().get(), getHandle(), offset};
81 * @brief Creates a new empty rvalue LockedMemory instance of type const void
82 * @return LockedMemory instance of type const void
84 LockedMemory<const void> cbuffer() const noexcept override {
85 return {getAllocator().get(), getHandle(), offset};
89 * @brief Creates a LockedMemory instance of the given type
90 * @return LockedMemory instance of the given type
92 LockedMemory <T> data() noexcept override {
93 return {getAllocator().get(), getHandle(), offset};
97 * @brief Creates a readOnly LockedMemory instance of the given type
98 * @return Read-only LockedMemory instance of the given type
100 LockedMemory<const T> readOnly() const noexcept override {
101 return {getAllocator().get(), getHandle(), offset};
106 * @brief Gets an allocator
107 * @return An allocator instance
109 const std::shared_ptr<IAllocator> &getAllocator() const noexcept override {
110 return realObject->getAllocator();
114 * @brief Gets a handle pointer
115 * @return A handle pointer
117 void *getHandle() const noexcept override {
118 return realObject->getHandle();
122 * @brief Checks whether proxy can be created with the requested offset and size parameters
125 if (realObject->size() * realObject->element_size() < base::size() * base::element_size() + offset) {
126 THROW_IE_EXCEPTION << "cannot create proxy, offsetInBytes=" << offset << ", sizeInBytes="
127 << base::size() * base::element_size() << ", out of original object size="
128 << realObject->size() * realObject->element_size();
133 * @brief Allocates TBlobProxy data
134 * Always throws exception. Not intended to be used
136 void allocate() noexcept override {}
139 * @brief Deallocates TBlobProxy data
140 * Always throws exception. Not intended to be used
142 bool deallocate() noexcept override {
147 typename Blob::Ptr realObject;
150 } // namespace InferenceEngine