MUDA
Loading...
Searching...
No Matches
field_entry.inl
1#include <muda/ext/field/sub_field.h>
2
3namespace muda
4{
5//using T = float;
6//constexpr auto Layout = FieldEntryLayout::RuntimeLayout;
7//constexpr auto SrcLayout = FieldEntryLayout::RuntimeLayout;
8//constexpr auto M = 3;
9//constexpr auto N = 3;
10template <typename T, FieldEntryLayout Layout, int M, int N>
11void FieldEntry<T, Layout, M, N>::copy_to(DeviceBuffer<ElementType>& dst) const
12{
13 dst.resize(count());
14 view().copy_to(dst);
15}
16
17template <typename T, FieldEntryLayout Layout, int M, int N>
18void FieldEntry<T, Layout, M, N>::copy_to(std::vector<ElementType>& dst) const
19{
20 dst.resize(count());
21 m_workpace.resize(count());
22 FieldEntryLaunch().copy(m_workpace.view(), view());
23 BufferLaunch().copy(dst.data(), std::as_const(m_workpace).view()).wait();
24}
25
26template <typename T, FieldEntryLayout Layout, int M, int N>
27void FieldEntry<T, Layout, M, N>::copy_from(const DeviceBuffer<ElementType>& src)
28{
29 MUDA_ASSERT(src.size() == count(),
30 "FieldEntry: size mismatch, src.size()=%d, this count()=%d, field entry can't resize itself when copying!",
31 src.size(),
32 count());
33 view().copy_from(src.view());
34}
35
36template <typename T, FieldEntryLayout Layout, int M, int N>
37void FieldEntry<T, Layout, M, N>::copy_from(const std::vector<ElementType>& src)
38{
39 MUDA_ASSERT(src.size() == count(),
40 "FieldEntry: size mismatch, src.size()=%d, this count()=%d, field entry can't resize itself when copying!",
41 src.size(),
42 count());
43 m_workpace.resize(count());
44 BufferLaunch().copy(m_workpace.view(), src.data()).wait();
45 FieldEntryLaunch().copy(view(), std::as_const(m_workpace).view()).wait();
46}
47
48template <typename T, FieldEntryLayout Layout, int M, int N>
49void FieldEntry<T, Layout, M, N>::fill(const ElementType& value)
50{
51 view().fill(value);
52}
53
54template <typename T, FieldEntryLayout Layout, int M, int N>
55template <FieldEntryLayout SrcLayout>
56void FieldEntry<T, Layout, M, N>::copy_from(const FieldEntry<T, SrcLayout, M, N>& src)
57{
58 MUDA_ASSERT(src.count() == count(),
59 "FieldEntry: size mismatch, src.count()=%d, this count()=%d, field entry can't resize itself when copying!",
60 src.count(),
61 count());
62 view().copy_from(src.view());
63}
64} // namespace muda