1 // Copyright (C) 2018 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
6 #ifndef MEMORY_DESCRIPTOR_REF_HPP
7 #define MEMORY_DESCRIPTOR_REF_HPP
11 #include "memory/memory_types.hpp"
16 class MemoryDescriptor;
17 class MemoryDescriptorView;
19 /// Lghtweight reference into MemoryDescriptorView
20 /// It can reference to a part of MemoryDescriptorView
21 class MemoryDescriptorRef final
24 /// Constructs empty MemoryDescriptorRef
25 MemoryDescriptorRef();
27 /// Consructs MemoryDescriptorRef covering entire view
29 /// @param view Source view
30 MemoryDescriptorRef(MemoryDescriptorView& view);
32 /// Consructs MemoryDescriptorRef covering part view
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();
39 MemoryDescriptorRef(const MemoryDescriptorRef&) = default;
40 MemoryDescriptorRef(MemoryDescriptorRef&&) = default;
41 MemoryDescriptorRef& operator=(const MemoryDescriptorRef&) = default;
42 MemoryDescriptorRef& operator=(MemoryDescriptorRef&&) = default;
46 /// @returns Source view
47 MemoryDescriptorView* getView();
51 /// @returns Source view
52 const MemoryDescriptorView* getView() const;
54 /// Get source descriptor
56 /// @returns Source descriptor
57 MemoryDescriptor* getDescriptor();
59 /// Get source descriptor
61 /// @returns Source descriptor
62 const MemoryDescriptor* getDescriptor() const;
64 /// Get span into current view
67 const memory::DynMdSpan& span() const;
72 memory::DynMdSize size() const;
74 /// Get buffer element size
76 /// @returns Size in bytes
77 std::size_t elementSize() const;
79 /// Get span into parent ref
82 memory::DynMdSpan originSpan() const;
84 /// Returns externally accessible memory view if any
86 /// @returns View into externally accessible memory or null view
87 memory::DynMdView<void> getExternalView() const;
89 /// Check whether this object is null
90 friend bool operator==(std::nullptr_t, const MemoryDescriptorRef& ref);
92 /// Check whether this object is null
93 friend bool operator==(const MemoryDescriptorRef& ref, std::nullptr_t);
95 /// Check whether this object is null
96 friend bool operator!=(std::nullptr_t, const MemoryDescriptorRef& ref);
98 /// Check whether this object is null
99 friend bool operator!=(const MemoryDescriptorRef& ref, std::nullptr_t);
101 MemoryDescriptorView* m_parent = nullptr;
102 memory::DynMdSpan m_span;
105 std::ostream& operator<<(std::ostream& os, const MemoryDescriptorRef& ref);
109 #endif // MEMORY_DESCRIPTOR_REF_HPP