@@ -9,7 +9,7 @@ template<typename T> class CLMemory {
9
9
: m_clQueue(clQueue), m_bFree(false ), m_size(size), m_pData(pData) {
10
10
m_clMem = clCreateBuffer (clContext, flags, m_size, NULL , NULL );
11
11
}
12
-
12
+
13
13
CLMemory (cl_context & clContext, cl_command_queue & clQueue, const cl_mem_flags flags, const size_t count, const bool noAllocation = false )
14
14
: m_clQueue(clQueue), m_bFree(true ), m_size(sizeof (T) * count), m_pData(noAllocation ? NULL : new T[count]) {
15
15
m_clMem = clCreateBuffer (clContext, flags, m_size, NULL , NULL );
@@ -27,32 +27,34 @@ template<typename T> class CLMemory {
27
27
throw std::runtime_error (" clSetKernelArg failed - " + toString (arg_index) + " - " + toString (ret));
28
28
}
29
29
}
30
-
30
+
31
31
void setKernelArg (cl_kernel & clKernel, const cl_uint arg_index) const {
32
32
const cl_int ret = clSetKernelArg (clKernel, arg_index, sizeof (cl_mem), (void *) &m_clMem );
33
33
if ( ret != CL_SUCCESS ) {
34
34
throw std::runtime_error (" clSetKernelArg failed - " + toString (arg_index) + " - " + toString (ret));
35
35
}
36
36
}
37
-
37
+
38
38
void read (const bool bBlock, cl_event * pEvent = NULL ) const {
39
39
const cl_bool block = bBlock ? CL_TRUE : CL_FALSE;
40
- if ( clEnqueueReadBuffer (m_clQueue, m_clMem, block, 0 , m_size, m_pData, 0 , NULL , pEvent) != CL_SUCCESS ) {
41
- throw std::runtime_error (" clEnqueueReadBuffer failed" );
40
+ auto res = clEnqueueReadBuffer (m_clQueue, m_clMem, block, 0 , m_size, m_pData, 0 , NULL , pEvent);
41
+ if (res != CL_SUCCESS) {
42
+ throw std::runtime_error (" clEnqueueReadBuffer failed - " + toString (res));
42
43
}
43
44
}
44
-
45
+
45
46
void write (const bool bBlock) const {
46
47
const cl_bool block = bBlock ? CL_TRUE : CL_FALSE;
47
- if ( clEnqueueWriteBuffer (m_clQueue, m_clMem, block, 0 , m_size, m_pData, 0 , NULL , NULL ) != CL_SUCCESS ) {
48
- throw std::runtime_error (" clEnqueueWriteBuffer failed" );
48
+ auto res = clEnqueueWriteBuffer (m_clQueue, m_clMem, block, 0 , m_size, m_pData, 0 , NULL , NULL );
49
+ if ( res != CL_SUCCESS ) {
50
+ throw std::runtime_error (" clEnqueueWriteBuffer failed - " + toString (res));
49
51
}
50
52
}
51
-
53
+
52
54
T * const & data () const {
53
55
return m_pData;
54
56
}
55
-
57
+
56
58
T & operator [] (int x) const {
57
59
return m_pData[x];
58
60
}
@@ -64,16 +66,16 @@ template<typename T> class CLMemory {
64
66
T & operator *() const {
65
67
return *m_pData;
66
68
}
67
-
69
+
68
70
const size_t & size () const {
69
71
return m_size;
70
72
}
71
-
73
+
72
74
private:
73
75
const cl_command_queue m_clQueue;
74
76
const bool m_bFree;
75
77
const size_t m_size;
76
-
78
+
77
79
T * const m_pData;
78
80
cl_mem m_clMem;
79
81
};
0 commit comments