OpenCL - why are there any pointers at all?

Article: Introduction to OpenCL
By: Richard Cownie (tich.delete@this.pobox.com), December 17, 2010 11:51 am
Room: Moderated Discussions
Rob Thorpe (rthorpe@robertthorpeconsulting.com) on 12/17/10 wrote:
---------------------------

>I see. I'm sure that strength reduction and common subexpression elimination may
>miss some cases. But, will the programmer notice all cases?
>
>What case would a compiler be likely to miss?

It's more a question of the compiler having to make
choices, and not always making the same ones the programmer
would want to. Various optimizations interact in
complex ways: if you hoist an operation outside a loop,
does that then mean you need an extra register to hold
its result ? Is that a good idea, or is it better to
keep something else in that register and recalculate
the value each time ? Can you even tell, without a very
complex analysis of the operations and likely schedule ?
If the procedure has two loops, can you tell which is
more important to optimize ?

Compilers can do some amazing things that programmers
couldn't. And they can also screw up badly on cases
that would be obvious to a human.

>>It depends on the language specification whether it's the
>>programmer's job to ensure he doesn't pass the same array
>>twice, or the compiler's job to handle that case correctly.
>>I don't know which particular language you're talking about.
>>
>>But either way, *someone* has a problem, even without
>>pointer variables. And the possible solutions (copying
>>the arrays ? making pessimistic assumptions which inhibit
>>optimization ?) have a performance impact.
>
>Yes. But, it's still a simpler task than dealing with >overlaps as in C.

Not really. The compiler can assume that a[j] and b[j+1]
are distinct locations. But it can't assume that a[j] and
b[k] are distinct locations, except in a few cases where
an elaborate analysis might come with a proof about the
relationship between j and k. So most
of the time you still don't know anything useful about
the aliasing. Unless you punt and force the programmer
to avoid the aliased cases somehow.

[Aside: there was a bit of fuss recently when gcc-4.x
started using the strict-aliasing assumption - optimizing
on the assumption that pointers to different types would
never be aliases for the same storage. In theory the
language standards allow the compiler to do that, because
the result of such aliasing is undefined.
In practice it broke a lot of code and a lot of users
didn't like the change. Now I use "-fno-strict-aliasing"
and the new behavior is disabled.]
< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
OpenCL article onlineDavid Kanter2010/12/09 02:44 AM
  OpenCL article onlineXN2010/12/09 06:33 AM
    OpenCL article onlineDavid Kanter2010/12/09 01:54 PM
  OpenCL article onlineanon2010/12/09 02:33 PM
    OpenCL article onlineDavid Kanter2010/12/09 02:38 PM
      OpenCL article onlineIan Ameline2010/12/09 03:47 PM
      OpenCL article onlineAnon2010/12/09 08:27 PM
        OpenCL article onlineDavid Kanter2010/12/09 10:58 PM
  Performance portabilityBryan Catanzaro2010/12/10 12:43 PM
    Performance portabilityltcommander.data2010/12/10 07:11 PM
      It is difficult to runtime optimize away the difference between a CPU and GPUMark Roulo2010/12/10 07:50 PM
        It is difficult to runtime optimize away the difference between a CPU and GPUhobold2010/12/11 03:35 AM
          It is difficult to runtime optimize away the difference between a CPU and GPUMark Roulo2010/12/12 01:20 PM
            It is difficult to runtime optimize away the difference between a CPU and GPUhobold2010/12/12 03:31 PM
              It is difficult to runtime optimize away the difference between a CPU and GPUanon2010/12/12 04:24 PM
                It is difficult to runtime optimize away the difference between a CPU and GPUhobold2010/12/13 03:44 AM
        Specially when the language provides almost no hardware abstraction (NT)EduardoS2010/12/11 10:53 AM
    Performance portabilityWainwright2010/12/11 03:44 PM
      Performance portabilityEduardoS2010/12/11 03:57 PM
        Performance portabilityWainwright2010/12/11 04:02 PM
          Performance portabilityEduardoS2010/12/11 08:20 PM
            Performance portabilityWainwright2010/12/12 02:22 AM
      Performance portabilityDavid Kanter2010/12/11 05:53 PM
        Performance portabilityEduardoS2010/12/11 08:23 PM
          Performance portabilityDavid Kanter2010/12/11 09:06 PM
            Performance portabilityWainwright2010/12/12 02:26 AM
            Performance portabilityEduardoS2010/12/12 09:04 AM
  OpenCL article onlineAlan Commike2010/12/14 01:01 PM
  OpenCL - why are there any pointers at all?Rob Thorpe2010/12/16 03:45 AM
    OpenCL - why are there any pointers at all?EduardoS2010/12/16 01:51 PM
      OpenCL - why are there any pointers at all?Rob Thorpe2010/12/17 03:19 AM
        OpenCL - why are there any pointers at all?Richard Cownie2010/12/17 07:02 AM
          OpenCL - why are there any pointers at all?Rob Thorpe2010/12/17 08:29 AM
            OpenCL - why are there any pointers at all?Richard Cownie2010/12/17 09:13 AM
              OpenCL - why are there any pointers at all?Rob Thorpe2010/12/17 10:03 AM
                OpenCL - why are there any pointers at all?Richard Cownie2010/12/17 10:53 AM
                  OpenCL - why are there any pointers at all?Rob Thorpe2010/12/17 11:19 AM
                    OpenCL - why are there any pointers at all?Richard Cownie2010/12/17 11:51 AM
                OpenCL - why are there any pointers at all?hobold2010/12/17 11:06 AM
          OpenCL - why are there any pointers at all?EduardoS2010/12/18 07:58 AM
            OpenCL - why are there any pointers at all?anon2010/12/18 10:27 AM
            OpenCL - why are there any pointers at all?BorisG2010/12/18 10:33 AM
              OpenCL - why are there any pointers at all?Richard Cownie2010/12/18 02:39 PM
  OpenCL article onlineEmil Briggs2010/12/19 06:40 AM
Reply to this Topic
Name:
Email:
Topic:
Body: No Text
How do you spell avocado?