1#include <muda/buffer/buffer_launch.h>
2#include <muda/compute_graph/compute_graph_builder.h>
6template <
bool IsConst,
typename T>
7MUDA_GENERIC BufferViewT<IsConst, T>::BufferViewT(auto_const_t<T>* data,
9 size_t size) MUDA_NOEXCEPT
16template <
bool IsConst,
typename T>
17MUDA_GENERIC BufferViewT<IsConst, T>::BufferViewT(auto_const_t<T>* data,
size_t size) MUDA_NOEXCEPT
24template <
bool IsConst,
typename T>
25template <
bool OtherIsConst>
26MUDA_GENERIC BufferViewT<IsConst, T>::BufferViewT(
const BufferViewT<OtherIsConst, T>& other) MUDA_NOEXCEPT
27 MUDA_REQUIRES(!OtherIsConst)
28 : m_data(other.m_data)
29 , m_offset(other.m_offset)
30 , m_size(other.m_size)
32 static_assert(!OtherIsConst,
"This must be non-const");
34template <
bool IsConst,
typename T>
35MUDA_GENERIC
auto BufferViewT<IsConst, T>::as_const() const MUDA_NOEXCEPT->ConstView
37 return ConstView{*
this};
40template <
bool IsConst,
typename T>
41MUDA_GENERIC
auto BufferViewT<IsConst, T>::data() const MUDA_NOEXCEPT->auto_const_t<T>*
43 return m_data + m_offset;
46template <
bool IsConst,
typename T>
47MUDA_GENERIC
auto BufferViewT<IsConst, T>::data(
size_t i)
const MUDA_NOEXCEPT->auto_const_t<T>*
53template <
bool IsConst,
typename T>
54MUDA_GENERIC
auto BufferViewT<IsConst, T>::origin_data() const MUDA_NOEXCEPT->auto_const_t<T>*
59template <
bool IsConst,
typename T>
60MUDA_GENERIC
auto BufferViewT<IsConst, T>::operator[](
size_t i)
const
61 MUDA_NOEXCEPT->auto_const_t<T>&
66template <
bool IsConst,
typename T>
67MUDA_GENERIC
auto BufferViewT<IsConst, T>::subview(
size_t offset,
size_t size)
const
68 MUDA_NOEXCEPT->ThisView
71 if(ComputeGraphBuilder::is_topo_building())
75 size = m_size - offset;
76 MUDA_KERNEL_ASSERT(offset + size <= m_size,
77 "BufferView out of range, size = %d, yours = %d",
80 return ThisView{m_data, m_offset + offset, size};
83template <
bool IsConst,
typename T>
84MUDA_GENERIC
auto BufferViewT<IsConst, T>::viewer() const MUDA_NOEXCEPT->ThisViewer
86 return ThisViewer{data(),
static_cast<int>(m_size)};
89template <
bool IsConst,
typename T>
90MUDA_GENERIC
auto BufferViewT<IsConst, T>::cviewer() const MUDA_NOEXCEPT->CViewer
92 return CViewer{data(),
static_cast<int>(m_size)};
95template <
bool IsConst,
typename T>
96MUDA_HOST
void BufferViewT<IsConst, T>::fill(
const T& v)
const MUDA_REQUIRES(!IsConst)
98 static_assert(!IsConst,
"This must be non-const");
101 .template fill<T>(*
this, v)
105template <
bool IsConst,
typename T>
106MUDA_HOST
void BufferViewT<IsConst, T>::copy_from(
const BufferViewT<true, T>& other)
const
107 MUDA_REQUIRES(!IsConst)
109 static_assert(!IsConst,
"This must be non-const");
112 .template copy<T>(*
this, other)
116template <
bool IsConst,
typename T>
117MUDA_HOST
void BufferViewT<IsConst, T>::copy_from(
const T* host)
const
118 MUDA_REQUIRES(!IsConst)
120 static_assert(!IsConst,
"This must be non-const");
123 .template copy<T>(*
this, host)
127template <
bool IsConst,
typename T>
128MUDA_HOST
void BufferViewT<IsConst, T>::copy_to(T* host)
const
131 .template copy<T>(host, *
this)
135template <
bool IsConst,
typename T>
136MUDA_GENERIC
auto BufferViewT<IsConst, T>::operator+(
int i)
const MUDA_NOEXCEPT->ThisView
138 return ThisView{m_data, m_offset + i, m_size - i};
141template <
bool IsConst,
typename T>
142MUDA_GENERIC
auto BufferViewT<IsConst, T>::operator*() const MUDA_NOEXCEPT->reference
147template <
bool IsConst,
typename T>
148MUDA_GENERIC
auto BufferViewT<IsConst, T>::operator[](
int i)
const MUDA_NOEXCEPT->auto_const_t<T>&