1 // Copyright (C) 2018 Intel Corporation
3 // SPDX-License-Identifier: Apache-2.0
8 #include "memory/memory_descriptor_ref.hpp"
10 #include "memory/memory_descriptor_view.hpp"
11 #include "memory/memory_descriptor.hpp"
13 #include "util/md_io.hpp"
15 #include <util/iota_range.hpp>
20 MemoryDescriptorRef::MemoryDescriptorRef()
25 MemoryDescriptorRef::MemoryDescriptorRef(MemoryDescriptorView& view):
28 m_span.redim(view.span().dims_count());
29 for (auto i: util::iota(m_span.dims_count()))
31 m_span[i] = util::Span(0, view.span()[i].length());
35 MemoryDescriptorRef::MemoryDescriptorRef(MemoryDescriptorView& view,
36 const memory::DynMdSpan& span):
43 MemoryDescriptorRef::~MemoryDescriptorRef()
48 MemoryDescriptorView* MemoryDescriptorRef::getView()
53 const MemoryDescriptorView* MemoryDescriptorRef::getView() const
58 MemoryDescriptor*MemoryDescriptorRef::getDescriptor()
60 if (nullptr == m_parent)
64 return m_parent->getDescriptor();
67 const MemoryDescriptor* MemoryDescriptorRef::getDescriptor() const
69 if (nullptr == m_parent)
73 return m_parent->getDescriptor();
76 const memory::DynMdSpan& MemoryDescriptorRef::span() const
78 ASSERT(nullptr != *this);
82 memory::DynMdSize MemoryDescriptorRef::size() const
87 std::size_t MemoryDescriptorRef::elementSize() const
89 ASSERT(nullptr != getDescriptor());
90 return getDescriptor()->elementSize();
93 memory::DynMdSpan MemoryDescriptorRef::originSpan() const
95 ASSERT(nullptr != *this);
96 return m_span + m_parent->span().origin();
99 memory::DynMdView<void> MemoryDescriptorRef::getExternalView() const
101 ASSERT(nullptr != getDescriptor());
102 auto srcView = getDescriptor()->getExternalView();
103 if (nullptr == srcView)
107 return srcView.slice(originSpan());
110 bool operator==(std::nullptr_t, const MemoryDescriptorRef& ref)
112 return ref.m_parent == nullptr;
115 bool operator==(const MemoryDescriptorRef& ref, std::nullptr_t)
117 return ref.m_parent == nullptr;
120 bool operator!=(std::nullptr_t, const MemoryDescriptorRef& ref)
122 return ref.m_parent != nullptr;
125 bool operator!=(const MemoryDescriptorRef& ref, std::nullptr_t)
127 return ref.m_parent != nullptr;
130 std::ostream& operator<<(std::ostream& os, const MemoryDescriptorRef& ref)
134 os << static_cast<void*>(nullptr);
139 os << "span: " << ref.span() << ", ";
140 if (ref.originSpan() != ref.span())
142 os << std::endl << "origin span: " << ref.originSpan() << ", ";
144 os << std::endl << "view: " << ref.getView() << " (" << ref.getView()->span() << "), ";
145 os << std::endl << "descriptor: " << ref.getDescriptor() << " (" << ref.getDescriptor()->dimensions() << ") ";