Results 1 to 4 of 4

Thread: Image2d or Buffer?

  1. #1
    Junior Member
    Join Date
    May 2012
    Posts
    2

    Image2d or Buffer?

    Hello everyone

    I'm fairly new to opencl and i mainly want to use it for image processing.
    So my question is, whether it is generally better to use Image2D instead of a regular uchar Buffer? Especially considering that my kernels will only be dealing with image sizes of lets say 640x480 pixels.

    For example, should this:

    Code :
    __kernel void convert2gray(__read_only image2d_t src, __write_only image2d_t dst)
    {...}

    usually be faster than this:

    Code :
    __kernel void convert2gray(__global unsigned char* src, __global unsigned char* dst)
    {...}

    ?

    I hope you understand, what i'm aiming at.

    Thanks for any reply in advance!

  2. #2
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Image2d or Buffer?

    In my experience, if you're dealing with bytes - just use images. Use the UNORM_INT8 type and do all your maths using floats. For specific algorithms on some hardware you may get better performance with arrays, but to start with just sticking to images makes things easier and they work well for many algorithms.

    If you're using floats with fixed addressing (i.e. linear access, no interpolation) and need to do several iterations on read/write data i've found arrays can be a fair bit faster (at least on the hardware i've used), so as always - it depends on your algorithms and what you're doing.

  3. #3
    Junior Member
    Join Date
    May 2012
    Posts
    2

    Re: Image2d or Buffer?

    Alright, I see. Thanks for the answer!

    So if I understand you correctly, using images could make things a little easier (more handy) . But, does using them ever speed things up by any occasion? Or in other words, could using arrays instead of images slow things down?

    Right now it seems that using images will in most cases not slow things down but will not speed them up either. So i might aswell use arrays for everything. Is that correct?

  4. #4
    Senior Member
    Join Date
    Aug 2011
    Posts
    271

    Re: Image2d or Buffer?

    Quote Originally Posted by henn1ng
    Alright, I see. Thanks for the answer!

    So if I understand you correctly, using images could make things a little easier (more handy) . But, does using them ever speed things up by any occasion? Or in other words, could using arrays instead of images slow things down?

    Right now it seems that using images will in most cases not slow things down but will not speed them up either. So i might aswell use arrays for everything. Is that correct?
    It totally depends on what you're doing. They will slow things down sometimes - although how much overhead they have depends on the hardware & driver too.

    Images are good if you need:
    - interpolation sampling (effectively free)
    - non-linear access (e.g. affine transformations, or y-order 2d)
    - automatic data conversion e.g. from ubyte to float and back again (effectively free)
    - 2d-spatial coherency

    Images have a different in-memory layout which is 2d-oriented. Arrays are slow for accessing bytes or non-linear access.

    You seem set on arrays, just do what you want really.

Similar Threads

  1. Image2d max size
    By chritolb29 in forum OpenCL
    Replies: 3
    Last Post: 04-12-2012, 05:19 AM
  2. Why create cl::Image2D from pointer?
    By wscrosswy in forum OpenCL
    Replies: 5
    Last Post: 01-20-2011, 05:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •