Sending 2D data to device in openCL
Hello everyone !!
Can I send 2 dimensional data to device? If yes then how can I do that? Means how will be the declaration of the buffer memory? And also how can I fetch/ use these values in kernel function/device ?
Plz reply ASAP.
Yes, of course you can do that. Two ways: Buffer and Image.
Buffer: As on the host, dimension is just an abstraction since all memory is linear. Use Y * pitch + X to find a location.
Image: OpenCL has 2D image support. Depending on your needs and access patterns, this might make more sense than using a buffer.
Originally Posted by Dithermaster
Actually I want to send following data to device.
for (i=0; i<2; ++i)
for (j=0; j<2; ++j)
for (k=i; k<hsize-i; k += 2)
for (l=j; l<vsize-j; l += 2)
domimage[(i<<1)+j][l>>1][k>>1] =((double)image[l][k] + (double)image[l+1][k+1] +
(double)image[l][k+1] + (double)image[l+1][k])*0.25;
here hsize and vsize are int and used as image hieght and width. And image is a 2D array.
I can send and use the data image by using your method. But how can I use "domimage" data?
In OpenCL 1.x buffer and image data needs to be contiguous. OpenCL 2.x SVM could support your pointer-based non-contiguous data structure but there are no shipping implementations yet. In the meantime you either need to change your data structure to be contiguous or copy it into contiguous memory before transferring it to your OpenCL device.
Tags for this Thread