PeriDyno 1.0.0
Loading...
Searching...
No Matches
Array2D.inl
Go to the documentation of this file.
1#include "VkDeviceArray2D.h"
2#include "VkTransfer.h"
3
4namespace dyno {
5
6 template<typename T>
8 {
9 if (m_nx != src.size() || m_ny != src.size()) {
10 this->resize(src.nx(), src.ny());
11 }
12
13 vkTransfer(m_data, *src.handle());
14 //cuSafeCall(cudaMemcpy2D(m_data.data(), sizeof(T) * m_nx, src.begin(), src.pitch(), sizeof(T) * src.nx(), src.ny(), cudaMemcpyDeviceToHost));
15 }
16
17 template<typename T>
18 class Array2D<T, DeviceType::GPU>
19 {
20 public:
21 Array2D() {};
22
23 Array2D(uint nx, uint ny)
24 {
25 this->resize(nx, ny);
26 };
27
31 ~Array2D() {};
32
33 void resize(uint nx, uint ny);
34
35 void reset();
36
37 void clear();
38
39 Array2DInfo getInfo() { return m_data.getInfo(); }
40
41 inline const VkDeviceArray2D<T>* handle() const { return &m_data; }
42 inline VkDeviceArray2D<T>* handle() { return &m_data; }
43
44 VkBuffer buffer() const { return m_data.bufferHandle(); }
45
46 uint32_t bufferSize() { return m_data.bufferSize(); }
47
48 inline T* begin() const { return m_data; }
49
50 inline uint nx() const { return m_nx; }
51 inline uint ny() const { return m_ny; }
52// inline uint pitch() const { return m_pitch; }
53
54// DYN_FUNC inline T operator () (const uint i, const uint j) const
55// {
56// char* addr = (char*)m_data;
57// addr += j * m_pitch;
58//
59// return ((T*)addr)[i];
60// //return m_data[i + j* m_pitch];
61// }
62//
63// DYN_FUNC inline T& operator () (const uint i, const uint j)
64// {
65// char* addr = (char*)m_data;
66// addr += j * m_pitch;
67//
68// return ((T*)addr)[i];
69//
70// //return m_data[i + j* m_pitch];
71// }
72
73 inline int index(const uint i, const uint j) const
74 {
75 return i + j * m_nx;
76 }
77
78// void inline T operator [] (const uint id) const
79// {
80// return m_data[id];
81// }
82//
83// void inline T& operator [] (const uint id)
84// {
85// return m_data[id];
86// }
87
88 DYN_FUNC inline uint size() const { return m_nx * m_ny; }
89 DYN_FUNC inline bool isCPU() const { return false; }
90 DYN_FUNC inline bool isGPU() const { return true; }
91
92 void assign(const Array2D<T, DeviceType::GPU>& src);
93 void assign(const Array2D<T, DeviceType::CPU>& src);
94
95 private:
96 uint m_nx = 0;
97 uint m_ny = 0;
98
99 VkDeviceArray2D<T> m_data;
100 };
101
102 template<typename T>
104
105 template<typename T>
107 {
108 uint total = nx * ny;
109 if (m_data.size() == total) return;
110
111 if (total == 0) {
112 m_data.clear();
113 return;
114 }
115
116 m_data.resize(nx, ny);
117 //cuSafeCall(cudaMallocPitch((void**)&m_data, (size_t*)&m_pitch, (size_t)sizeof(T) * nx, (size_t)ny));
118
119 m_nx = nx;
120 m_ny = ny;
121 }
122
123 template<typename T>
125 {
126 //cuSafeCall(cudaMemset((void*)m_data, 0, m_pitch * m_ny));
127 }
128
129 template<typename T>
131 {
132 m_data.clear();
133
134 m_nx = 0;
135 m_ny = 0;
136 }
137
138 template<typename T>
140 {
141 if (m_nx != src.size() || m_ny != src.size()){
142 this->resize(src.nx(), src.ny());
143 }
144
145 vkTransfer(m_data, *src.handle());
146
147 //cuSafeCall(cudaMemcpy2D(m_data, m_pitch, src.begin(), src.pitch(), sizeof(T) * src.nx(), src.ny(), cudaMemcpyDeviceToDevice));
148 }
149
150 template<typename T>
152 {
153 if (m_nx != src.size() || m_ny != src.size()) {
154 this->resize(src.nx(), src.ny());
155 }
156
157 vkTransfer(m_data, *src.handle());
158
159 //cuSafeCall(cudaMemcpy2D(m_data, m_pitch, src.begin(), sizeof(T) *src.nx(), sizeof(T) * src.nx(), src.ny(), cudaMemcpyHostToDevice));
160 }
161}
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
Array2D< T, DeviceType::GPU > DArray2D
Definition Array2D.inl:90
unsigned int uint
Definition VkProgram.h:14
bool vkTransfer(VkHostArray< T > &dst, const VkDeviceArray< T > &src)
Definition VkTransfer.inl:7