5 #ifndef DEVICE_MEM_POINTER_MATRIX_CL_H
6 #define DEVICE_MEM_POINTER_MATRIX_CL_H
12 #include <OpenCL/opencl.h>
50 cl_mem m_deviceDataPointer;
55 mutable bool deviceDataHasChanged;
71 size_t sizeVec = rows*cols*
sizeof(T);
73 DEBUG_TEXT_LEVEL2(
"Alloc: " <<sizeVec <<
"\n")
75 m_deviceDataPointer = clCreateBuffer(m_device->
getContext(), CL_MEM_READ_WRITE, sizeVec, NULL, &err);
78 std::cerr<<
"Error allocating memory on device\n";
81 deviceDataHasChanged =
false;
90 DEBUG_TEXT_LEVEL2(
"DeAlloc: " <<m_rows*m_cols*
sizeof(T) <<
"\n")
92 clReleaseMemObject(m_deviceDataPointer);
101 template <
typename T>
104 DEBUG_TEXT_LEVEL2(
"HOST_TO_DEVICE!!!\n")
110 _rows = ((rows == -1) ? m_rows : rows);
111 _cols = ((cols == -1) ? m_cols : cols);
114 sizeVec = _rows * _cols *
sizeof(T);
116 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
120 err = clEnqueueWriteBuffer(m_device->getQueue(), m_deviceDataPointer, CL_TRUE, 0, sizeVec, (
void*)m_hostDataPointer, 0, NULL, NULL);
121 if(err != CL_SUCCESS)
123 std::cerr<<
"Error copying data to device\n";
126 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
130 deviceDataHasChanged =
false;
139 template <
typename T>
142 if(deviceDataHasChanged)
144 DEBUG_TEXT_LEVEL2(
"DEVICE_TO_HOST!!!\n")
149 _rows = ((rows == -1) ? m_rows : rows);
150 _cols = ((cols == -1) ? m_cols : cols);
152 sizeVec = _rows * _cols *
sizeof(T);
154 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
155 copyDownTimer.start();
158 err = clEnqueueReadBuffer(m_device->getQueue(), m_deviceDataPointer, CL_TRUE, 0, sizeVec, (
void*)m_hostDataPointer, 0, NULL, NULL);
159 if(err != CL_SUCCESS)
161 std::cerr<<
"Error copying data from device\n";
165 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
166 copyDownTimer.stop();
169 deviceDataHasChanged =
false;
176 template <
typename T>
179 return m_deviceDataPointer;
185 template <
typename T>
188 deviceDataHasChanged =
true;
cl_mem getDeviceDataPointer() const
Definition: device_mem_pointer_matrix_cl.h:177
Contains a class declaration for the object that represents an OpenCL device.
DeviceMemPointer_Matrix_CL(T *start, int rows, int cols, Device_CL *device)
Definition: device_mem_pointer_matrix_cl.h:68
const cl_context & getContext() const
Definition: device_cl.h:170
A class representing an OpenCL device memory allocation for Matrix container. Not used much right now...
Definition: device_mem_pointer_matrix_cl.h:36
void changeDeviceData()
Definition: device_mem_pointer_matrix_cl.h:186
A class representing an OpenCL device.
Definition: device_cl.h:36
void copyDeviceToHost(int rows=-1, int cols=-1) const
Definition: device_mem_pointer_matrix_cl.h:140
~DeviceMemPointer_Matrix_CL()
Definition: device_mem_pointer_matrix_cl.h:88
void copyHostToDevice(int rows=-1, int cols=-1) const
Definition: device_mem_pointer_matrix_cl.h:102