Results 1 to 4 of 4

Thread: workaround for no pointers to image2d_t restriction

  1. #1

    workaround for no pointers to image2d_t restriction

    Hello,

    I need to read value from one of two images, like that:
    Code :
    for (i = 1; i < N; i++)
    {
    p = foo(i);
    if (cond)
      v = read_image_f(a, sampler, p);
    else
      v = read_image_f(b, sampler, p);
    }

    I would like to optimize the branch to be outside the loop:

    Code :
    image_2d_t* im = cond ? a : b;
    for (i = 1; i < N; i++)
    {
      p = foo(i);
      v = read_image_f(*im, sampler, p);
    }

    But OpenCL does not allow pointers to image2d_t.

    Any workaround for this?

  2. #2
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: workaround for no pointers to image2d_t restriction

    In OpenCL 1.2 you can use an image array.

    In older versions of OpenCL you can fission the loop:

    Code :
    if(cond)
    {
        for (i = 1; i < N; i++)
        {
            p = foo(i);
            v = read_imagef(a, sampler, p);
        }
    }
    else
    {
        for (i = 1; i < N; i++)
        {
            p = foo(i);
            v = read_imagef(b, sampler, p);
        }
    }

    I would personally let the compiler do that optimization instead so that the source code stays simple, unless this optimization was critical.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

  3. #3

    Re: workaround for no pointers to image2d_t restriction

    Thanks! (I work on Mac OS so no implementation for OpenCl 1.2 yet).
    How can I ensure that the compiler does this optimization? Can I look at the assembly?

  4. #4
    Senior Member
    Join Date
    May 2010
    Location
    Toronto, Canada
    Posts
    845

    Re: workaround for no pointers to image2d_t restriction

    You can't ensure that the compiler will make it, but it is a fairly common optimization. Some SDKs allow you to look at the machine code that is output by the compiler.
    Disclaimer: Employee of Qualcomm Canada. Any opinions expressed here are personal and do not necessarily reflect the views of my employer. LinkedIn profile.

Similar Threads

  1. Replies: 1
    Last Post: 10-06-2009, 11:48 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
  •