6 if (mData.size() != src.size())
7 this->resize(src.size());
9 cuSafeCall(cudaMemcpy(this->begin(), src.begin(), src.size() *
sizeof(
T), cudaMemcpyDeviceToHost));
17 class Array<
T, DeviceType::GPU>
34 void resize(
const uint n);
46 DYN_FUNC
inline const T* begin()
const {
return mData; }
47 DYN_FUNC
inline T* begin() {
return mData; }
49 DeviceType deviceType() {
return DeviceType::GPU; }
51 GPU_FUNC
inline T& operator [] (
unsigned int id) {
55 GPU_FUNC
inline T& operator [] (
unsigned int id)
const {
59 DYN_FUNC
inline uint size()
const {
return mTotalNum; }
60 DYN_FUNC
inline bool isCPU()
const {
return false; }
61 DYN_FUNC
inline bool isGPU()
const {
return true; }
62 DYN_FUNC
inline bool isEmpty()
const {
return mData ==
nullptr; }
64 void assign(
const Array<T, DeviceType::GPU>& src);
65 void assign(
const Array<T, DeviceType::CPU>& src);
66 void assign(
const std::vector<T>& src);
68 void assign(
const Array<T, DeviceType::GPU>& src,
const uint count,
const uint dstOffset = 0,
const uint srcOffset = 0);
69 void assign(
const Array<T, DeviceType::CPU>& src,
const uint count,
const uint dstOffset = 0,
const uint srcOffset = 0);
70 void assign(
const std::vector<T>& src,
const uint count,
const uint dstOffset = 0,
const uint srcOffset = 0);
72 friend std::ostream& operator<<(std::ostream &out,
const Array<T, DeviceType::GPU>& dArray)
74 Array<T, DeviceType::CPU> hArray;
75 hArray.assign(dArray);
94 if (mTotalNum == n)
return;
101 int exp = (int)std::ceil(std::log2(
float(n)));
103 int bound = (int)std::pow(2,
exp);
105 if (n > mBufferNum || n <= mBufferNum / 2) {
111 cuSafeCall(cudaMalloc(&mData, bound *
sizeof(
T)));
118 void Array<T, DeviceType::GPU>::clear()
120 if (mData !=
nullptr)
122 cuSafeCall(cudaFree((
void*)mData));
133 cuSafeCall(cudaMemset((
void*)mData, 0, mTotalNum *
sizeof(
T)));
139 if (mTotalNum != src.size())
140 this->resize(src.size());
142 cuSafeCall(cudaMemcpy(mData, src.begin(), src.size() *
sizeof(
T), cudaMemcpyDeviceToDevice));
148 if (mTotalNum != src.size())
149 this->resize(src.size());
151 cuSafeCall(cudaMemcpy(mData, src.begin(), src.size() *
sizeof(
T), cudaMemcpyHostToDevice));
158 if (mTotalNum != src.size())
159 this->resize((
uint)src.size());
161 cuSafeCall(cudaMemcpy(mData, src.data(), src.size() *
sizeof(
T), cudaMemcpyHostToDevice));
167 cuSafeCall(cudaMemcpy(mData + dstOffset, src.data() + srcOffset, count *
sizeof(
T), cudaMemcpyHostToDevice));
173 cuSafeCall(cudaMemcpy(mData + dstOffset, src.begin() + srcOffset, count *
sizeof(
T), cudaMemcpyHostToDevice));
179 cuSafeCall(cudaMemcpy(mData + dstOffset, src.begin() + srcOffset, count *
sizeof(
T), cudaMemcpyDeviceToDevice));
This class is designed to be elegant, so it can be directly passed to GPU as parameters.
This is an implementation of AdditiveCCD based on peridyno.
Array< T, DeviceType::GPU > DArray
DYN_FUNC Complex< Real > exp(const Complex< Real > &)