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: " <<rows <<
" X "<<cols <<
"\n")
75 m_deviceDataPointer = clCreateBuffer(m_device->
getContext(), CL_MEM_READ_WRITE, sizeVec, NULL, &err);
76 if(err != CL_SUCCESS){std::cerr<<
"Error allocating memory on device\n";}
78 deviceDataHasChanged =
false;
87 DEBUG_TEXT_LEVEL2(
"DeAlloc: " <<m_rows<<
" X "<<m_cols <<
"\n")
89 clReleaseMemObject(m_deviceDataPointer);
101 DEBUG_TEXT_LEVEL2(
"HOST_TO_DEVICE!!!\n")
107 _rows = ((rows == -1) ? m_rows : rows);
108 _cols = ((cols == -1) ? m_cols : cols);
111 sizeVec = _rows * _cols *
sizeof(T);
113 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
117 err = clEnqueueWriteBuffer(m_device->getQueue(), m_deviceDataPointer, CL_TRUE, 0, sizeVec, (
void*)m_hostDataPointer, 0, NULL, NULL);
118 if(err != CL_SUCCESS){std::cerr<<
"Error copying data to device\n";}
120 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
124 deviceDataHasChanged =
false;
133 template <
typename T>
136 if(deviceDataHasChanged)
138 DEBUG_TEXT_LEVEL2(
"DEVICE_TO_HOST!!!\n")
143 _rows = ((rows == -1) ? m_rows : rows);
144 _cols = ((cols == -1) ? m_cols : cols);
146 sizeVec = _rows * _cols *
sizeof(T);
148 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
149 copyDownTimer.start();
152 err = clEnqueueReadBuffer(m_device->getQueue(), m_deviceDataPointer, CL_TRUE, 0, sizeVec, (
void*)m_hostDataPointer, 0, NULL, NULL);
153 if(err != CL_SUCCESS){std::cerr<<
"Error copying data from device\n";}
156 #ifdef SKEPU_MEASURE_TIME_DISTRIBUTION
157 copyDownTimer.stop();
160 deviceDataHasChanged =
false;
167 template <
typename T>
170 return m_deviceDataPointer;
176 template <
typename T>
179 deviceDataHasChanged =
true;
cl_mem getDeviceDataPointer() const
Definition: device_mem_pointer_matrix_cl.h:168
Defines a few macros that can be used to output text when debugging. The macros use std::cerr...
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:159
A class representing an OpenCL device memory allocation for Matrix.
Definition: device_mem_pointer_matrix_cl.h:36
void changeDeviceData()
Definition: device_mem_pointer_matrix_cl.h:177
A class representing an OpenCL device.
Definition: device_cl.h:37
void copyDeviceToHost(int rows=-1, int cols=-1) const
Definition: device_mem_pointer_matrix_cl.h:134
~DeviceMemPointer_Matrix_CL()
Definition: device_mem_pointer_matrix_cl.h:85
void copyHostToDevice(int rows=-1, int cols=-1) const
Definition: device_mem_pointer_matrix_cl.h:99