summaryrefslogtreecommitdiff
path: root/inference-engine/thirdparty/ade/ade/include/memory/memory_descriptor_ref.hpp
blob: 3e22dcd132291a4936c2e7fe6cfadc66135563d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright (C) 2018 Intel Corporation
//
// SPDX-License-Identifier: Apache-2.0
//

#ifndef MEMORY_DESCRIPTOR_REF_HPP
#define MEMORY_DESCRIPTOR_REF_HPP

#include <iosfwd>

#include "memory/memory_types.hpp"

namespace ade
{

class MemoryDescriptor;
class MemoryDescriptorView;

/// Lghtweight reference into MemoryDescriptorView
/// It can reference to a part of MemoryDescriptorView
class MemoryDescriptorRef final
{
public:
    /// Constructs empty MemoryDescriptorRef
    MemoryDescriptorRef();

    /// Consructs MemoryDescriptorRef covering entire view
    ///
    /// @param view Source view
    MemoryDescriptorRef(MemoryDescriptorView& view);

    /// Consructs MemoryDescriptorRef covering part view
    ///
    /// @param view Source view
    /// @param span Span into descriptor view, must be inside view dimensions
    MemoryDescriptorRef(MemoryDescriptorView& view, const memory::DynMdSpan& span);
    ~MemoryDescriptorRef();

    MemoryDescriptorRef(const MemoryDescriptorRef&) = default;
    MemoryDescriptorRef(MemoryDescriptorRef&&) = default;
    MemoryDescriptorRef& operator=(const MemoryDescriptorRef&) = default;
    MemoryDescriptorRef& operator=(MemoryDescriptorRef&&) = default;

    /// Get source view
    ///
    /// @returns Source view
    MemoryDescriptorView* getView();

    /// Get source view
    ///
    /// @returns Source view
    const MemoryDescriptorView* getView() const;

    /// Get source descriptor
    ///
    /// @returns Source descriptor
    MemoryDescriptor* getDescriptor();

    /// Get source descriptor
    ///
    /// @returns Source descriptor
    const MemoryDescriptor* getDescriptor() const;

    /// Get span into current view
    ///
    /// @returns span
    const memory::DynMdSpan& span() const;

    /// Get span size
    ///
    /// @returns size
    memory::DynMdSize size() const;

    /// Get buffer element size
    ///
    /// @returns Size in bytes
    std::size_t elementSize() const;

    /// Get span into parent ref
    ///
    /// @returns span
    memory::DynMdSpan originSpan() const;

    /// Returns externally accessible memory view if any
    ///
    /// @returns View into externally accessible memory or null view
    memory::DynMdView<void> getExternalView() const;

    /// Check whether this object is null
    friend bool operator==(std::nullptr_t, const MemoryDescriptorRef& ref);

    /// Check whether this object is null
    friend bool operator==(const MemoryDescriptorRef& ref, std::nullptr_t);

    /// Check whether this object is null
    friend bool operator!=(std::nullptr_t, const MemoryDescriptorRef& ref);

    /// Check whether this object is null
    friend bool operator!=(const MemoryDescriptorRef& ref, std::nullptr_t);
private:
    MemoryDescriptorView* m_parent = nullptr;
    memory::DynMdSpan m_span;
};

std::ostream& operator<<(std::ostream& os, const MemoryDescriptorRef& ref);

}

#endif // MEMORY_DESCRIPTOR_REF_HPP