-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDVBuffer.cpp
More file actions
66 lines (57 loc) · 1.27 KB
/
Copy pathDVBuffer.cpp
File metadata and controls
66 lines (57 loc) · 1.27 KB
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
#include "cuda_wrapper.h"
#include "DVBuffer.h"
namespace CUInline
{
DVBufferLike::DVBufferLike()
{
m_size = 0;
m_data = nullptr;
m_name_view_cls = "void*";
}
void DVBufferLike::from_host(void* hdata)
{
if (m_size>0)
cuMemcpyHtoD((CUdeviceptr)m_data, hdata, m_size);
}
void DVBufferLike::to_host(void* hdata, size_t begin, size_t end) const
{
if (end == (size_t)(-1) || end > m_size) end = m_size;
size_t n = end - begin;
if (n>0)
cuMemcpyDtoH(hdata, (CUdeviceptr)((char*)m_data + begin), n);
}
ViewBuf DVBufferLike::view() const
{
ViewBuf buf(sizeof(void*));
void **pview = (void**)buf.data();
*pview = m_data;
return buf;
}
DVBuffer::DVBuffer(size_t size, void* hdata)
{
TryInit();
m_size = size;
CUdeviceptr dptr;
cuMemAlloc(&dptr, m_size);
m_data = (void*)dptr;
if (hdata)
cuMemcpyHtoD(dptr, hdata, m_size);
else
cuMemsetD8(dptr, 0, m_size);
}
DVBuffer::~DVBuffer()
{
cuMemFree((CUdeviceptr)m_data);
}
DVBufferRange::DVBufferRange(size_t size, void* ddata)
{
m_size = size;
m_data = ddata;
}
DVBufferRange::DVBufferRange(const DVBufferLike& vec, size_t begin, size_t end)
{
if (end == (size_t)(-1) || end > vec.size()) end = vec.size();
m_size = end - begin;
m_data = (char*)vec.data() + begin;
}
}