cancel
Showing results for 
Search instead for 
Did you mean: 

Archives Discussions

spectral
Adept II

Image + structures

Hi,

I currently use a simple structure to store some datas but would like to store them into the "image" buffer.

So, I would like to know if there is a "simple" way to do this, without take care about image_with/image_height and seeing the image buffer as a simple memory buffer ?

 

BTW : I ask this because I have see several examples where peoples are doing long computation, data reorganization in memory, etc etc ... just to retreive their data. I would like to avoid this if possible !

 

Thanks

0 Likes
5 Replies
genaganna
Journeyman III

Originally posted by: viewon01 Hi,

I currently use a simple structure to store some datas but would like to store them into the "image" buffer.

So, I would like to know if there is a "simple" way to do this, without take care about image_with/image_height and seeing the image buffer as a simple memory buffer ?

 BTW : I ask this because I have see several examples where peoples are doing long computation, data reorganization in memory, etc etc ... just to retreive their data. I would like to avoid this if possible !

 



There is no way to change image data format. These are pre-defined formats.

0 Likes

Thanks,

But why can't we see it as a sequential bytes buffer ?a byte offset can be easily converted to a pixel_X/pixel_Y. Maybe it is a question of performance, alignment etc... ?

0 Likes

Originally posted by: viewon01 But why can't we see it as a sequential bytes buffer ?

You can access if you know how particular hardware stores. It is very difficult to understand those storage format and no vender will disclose these. You need to use samplers and image read/write functions to load or store date from images.

a byte offset can be easily converted to a pixel_X/pixel_Y. Maybe it is a question of performance, alignment etc... ?

Use buffers for easy access.

Are you targeting CPU or GPU?

0 Likes

Ok, thanks...

I target GPU here, I have no advantage to use images on the CPU.

The goal is to store some datas that are often accessed.

0 Likes

If you are accessing the data in a regular coalescable pattern, arrays will be faster.  But you should avoid arrays-of-structures and use structures-of-arrays instead (which means: no structures).

The reason you can't see the memory as sequential is because it isn't stored using sequential addresses.  i.e. the actual addressing on images is 'scrambled' so it has 2-d rather than 1-d cache associativity.

e.g. say you had memory which stored 4x4xRGBA pixels in a single 64-byte cache line.

An access to img(x,y) then becomes an access to cache line:

 line= (x/4 + y/4 * img.width/4)

, and the 4 bytes from cache element:

 index = ((x&3)+(y&3)*4)*4

But that's just one possible way - it could change depending on the data format, vendor, or even graphics card version.  Which is why OpenCL doesn't support any such feature.  About the best you have is clEnqueueCopyImageToBuffer and it's inverse which may use hardware or at least vendor-specific hardware information to do it effeciently.

 

0 Likes