PDA

View Full Version : Images without Image support?



wscrosswy
02-10-2011, 09:36 AM
So I'm looking to do some image manipulation with OpenCL. I have code up and running with images enabled on my CPU (thanks to the ATI SDK update), but I'd like to run it on my GPU, which does not support images. My initial thought was to do some sort of wrapper that handles images I've loaded as buffers instead of cl_images, but I don't really understand the implications of doing something like that...

I know I could no longer sample my images directly in the kernels, but could I access pixels directly by index instead? What's the deal with rectangular buffers? I thought buffers were one dimensional? (I know that's probably a silly question...) What are the hits on speed/concurrent operations? etc.

Has anybody attempted anything like this or have any thoughts?

Thanks in advance!

andrew.brownsword
02-11-2011, 11:24 AM
You can certainly do this, and it will work although performance will not be as good as if you were using the GPU's texture sampler units. You need to compute each pixel's linear address from the x/y(/z) coordinates. To do this you need to know the pitch of the image (i.e. the number of bytes from the start of one row to the start of the next row)...

For a 32-bit image (i.e. RGBA with 1 byte per channel) this would look like:

unsigned int pixel_pitch = pitch / sizeof(unsigned int); // pitch is usually provided as bytes
unsigned int *image = <pointer to your cl_mem object>;
unsigned int pixel = image[y*pixel_pitch+x];

wscrosswy
02-11-2011, 11:59 AM
Thanks so much - I have code up and running already! Just curious - is that the idea behind rectangular buffers? Somehow the idea of reading/writing a 2D/3D region of a 1D object was a bit lost on me, but I guess it's just helps so you don't have to manually convert linear -> 2/3D coordinates?

snadra
02-11-2011, 01:06 PM
I just curious why don't you want to use image2d_t or image3d_t? As I know ATI SDK supports it on GPU.

wscrosswy
02-11-2011, 01:18 PM
The SDK certainly supports them, but not all GPUs support images. You can query your GPU to check this.

AGGIE
03-09-2011, 05:27 AM
I just curious why don't you want to use image2d_t or image3d_t? As I know ATI SDK supports it on GPU.
Can I ask you we use another image instead of these
I have a problem to use these images.Please guide me!