Newer
Older
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <cstddef>
#include <cuda_runtime.h>
#include "CudaMemory.cuh"
#include "cuda_macro.h"
/*! \brief Allocate a chunk of memory
*
* Allocate a chunk of memory
*
* \param sz size of the chunk of memory to allocate in byte
*
*/
bool CudaMemory::allocate(size_t sz)
{
//! Allocate the device memory
if (dm == NULL)
{CUDA_SAFE_CALL(cudaAlloc(&dv,sz,cudaAlloc));}
}
/*! \brief destroy a chunk of memory
*
* Destroy a chunk of memory
*
*/
void CudaMemory::destroy()
{
CUDA_SAFE_CALL(cudaDestroy(dv));
}
/*! \brief copy the device memory to a pointer
*
* copy the device memory to a pointer
*
*/
void CudaMemory::copyToPointer()
{
// check if we have a host buffer, if not allocate it
if (hm == NULL)
{CUDA_SAFE_CALL(cudaHostAlloc(&hm,sz*sizeof(T),cudaHostAllocMapped))}
// put on queue a copy from device to host
t.call();
// put on queue a memory copy from pointers
}
void CudaMemory::copyDeviceToDevice()
{
// put on queue a copy from device to device
t.call();
}
bool CudaMemory::copy(memory m)
{
//! Here we try to cast memory into OpenFPMwdeviceCudaMemory
CudaMemory * ofpm = dynamic_cast<CudaMemory>(m);
//! if we fail we get the pointer and simply copy from the pointer
if (ofpm == NULL)
{
// copy the memory from device to host and from host to device
copyFromPointer(t);
}
else
{
// they are the same memory type, use cuda/thrust buffer copy
copyDeviceToDevice();
}
}
bool CudaMemory::copy(OpenFPMwdeviceCudaMemory m)
{
// they are the same type of memory so copy from device to device
copyDeviceToDevice();
}
size_t CudaMemory::size()
{
dv->size();
}
bool CudaMemory::resize(size_t sz)
{
//! Allocate the device memory
if (dv == NULL)
{dv = new boost::shared_ptr<void>(new thrust::device_vector<void>());}
else
{dv.get()->resize(sz);}
}