forked from michal1000w/GPUSmoke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdouble_buffer.cpp
68 lines (55 loc) · 1.33 KB
/
double_buffer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include "double_buffer.h"
#include <utility>
template <typename T>
DoubleBuffer<T>::DoubleBuffer(int devices)
{
A = 0;
B = 0;
nbytes = 0;
devicesCount = devices;
temporary = 0;
}
template <typename T>
DoubleBuffer<T>::DoubleBuffer(int nelements, int devicesCount, int deviceIndex)
{
this->devicesCount = devicesCount;
nbytes = sizeof(T)*nelements;
//cudaMalloc( (void**)&A, nbytes );
//cudaMalloc( (void**)&B, nbytes );
A = multiGPU_malloc<T>(this->devicesCount, deviceIndex, nelements);
B = multiGPU_malloc<T>(this->devicesCount, deviceIndex, nelements);
//checkCudaErrors(cudaHostAlloc(&temporary, nbytes, cudaHostAllocMapped));
printf("Allocated %.2f MB on GPU\n", 2*nbytes/(1024.f*1024.f));
}
template <typename T>
std::vector<T*>* DoubleBuffer<T>::readTarget()
{
return &A;
}
template<typename T>
void DoubleBuffer<T>::setDim(int3 dim) {
this->dim = dim;
}
template <typename T>
std::vector<T*>* DoubleBuffer<T>::writeTarget()
{
return &B;
}
template <typename T>
void DoubleBuffer<T>::swap()
{
std::swap(A,B);
}
template <typename T>
int DoubleBuffer<T>::byteCount()
{
return nbytes;
}
template <typename T>
DoubleBuffer<T>::~DoubleBuffer()
{
//cudaFree(A);
//cudaFree(B);
multiGPU_free(this->devicesCount, A);
multiGPU_free(this->devicesCount, B);
}