Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / ade / ade / include / memory / memory_descriptor_ref.hpp
1 // Copyright (C) 2018 Intel Corporation
2 //
3 // SPDX-License-Identifier: Apache-2.0
4 //
5
6 #ifndef MEMORY_DESCRIPTOR_REF_HPP
7 #define MEMORY_DESCRIPTOR_REF_HPP
8
9 #include <iosfwd>
10
11 #include "memory/memory_types.hpp"
12
13 namespace ade
14 {
15
16 class MemoryDescriptor;
17 class MemoryDescriptorView;
18
19 /// Lghtweight reference into MemoryDescriptorView
20 /// It can reference to a part of MemoryDescriptorView
21 class MemoryDescriptorRef final
22 {
23 public:
24     /// Constructs empty MemoryDescriptorRef
25     MemoryDescriptorRef();
26
27     /// Consructs MemoryDescriptorRef covering entire view
28     ///
29     /// @param view Source view
30     MemoryDescriptorRef(MemoryDescriptorView& view);
31
32     /// Consructs MemoryDescriptorRef covering part view
33     ///
34     /// @param view Source view
35     /// @param span Span into descriptor view, must be inside view dimensions
36     MemoryDescriptorRef(MemoryDescriptorView& view, const memory::DynMdSpan& span);
37     ~MemoryDescriptorRef();
38
39     MemoryDescriptorRef(const MemoryDescriptorRef&) = default;
40     MemoryDescriptorRef(MemoryDescriptorRef&&) = default;
41     MemoryDescriptorRef& operator=(const MemoryDescriptorRef&) = default;
42     MemoryDescriptorRef& operator=(MemoryDescriptorRef&&) = default;
43
44     /// Get source view
45     ///
46     /// @returns Source view
47     MemoryDescriptorView* getView();
48
49     /// Get source view
50     ///
51     /// @returns Source view
52     const MemoryDescriptorView* getView() const;
53
54     /// Get source descriptor
55     ///
56     /// @returns Source descriptor
57     MemoryDescriptor* getDescriptor();
58
59     /// Get source descriptor
60     ///
61     /// @returns Source descriptor
62     const MemoryDescriptor* getDescriptor() const;
63
64     /// Get span into current view
65     ///
66     /// @returns span
67     const memory::DynMdSpan& span() const;
68
69     /// Get span size
70     ///
71     /// @returns size
72     memory::DynMdSize size() const;
73
74     /// Get buffer element size
75     ///
76     /// @returns Size in bytes
77     std::size_t elementSize() const;
78
79     /// Get span into parent ref
80     ///
81     /// @returns span
82     memory::DynMdSpan originSpan() const;
83
84     /// Returns externally accessible memory view if any
85     ///
86     /// @returns View into externally accessible memory or null view
87     memory::DynMdView<void> getExternalView() const;
88
89     /// Check whether this object is null
90     friend bool operator==(std::nullptr_t, const MemoryDescriptorRef& ref);
91
92     /// Check whether this object is null
93     friend bool operator==(const MemoryDescriptorRef& ref, std::nullptr_t);
94
95     /// Check whether this object is null
96     friend bool operator!=(std::nullptr_t, const MemoryDescriptorRef& ref);
97
98     /// Check whether this object is null
99     friend bool operator!=(const MemoryDescriptorRef& ref, std::nullptr_t);
100 private:
101     MemoryDescriptorView* m_parent = nullptr;
102     memory::DynMdSpan m_span;
103 };
104
105 std::ostream& operator<<(std::ostream& os, const MemoryDescriptorRef& ref);
106
107 }
108
109 #endif // MEMORY_DESCRIPTOR_REF_HPP