

C++AMP: Accelerated Massive Parallelism - octopus
http://drdobbs.com/cpp/231000963

======
palish
Slides:
[http://ecn.channel9.msdn.com/content/DanielMoth_CppAMP_Intro...](http://ecn.channel9.msdn.com/content/DanielMoth_CppAMP_Intro.pdf)

=== Code example ===

Original, CPU-only code:

    
    
      void AddArrays(int n, int * pA, int * pB, int * pC)
      {
          for (int i=0; i<n; i++) 
          {
                  pC[i] = pA[i] + pB[i];
          }
      }
    

GPU optimized code:

    
    
      #include <amp.h>
      using namespace concurrency;
    
      void AddArrays(int n, int * pA, int * pB, int * pC)
      {
          array_view<int,1> a(n, pA);
          array_view<int,1> b(n, pB);
          array_view<int,1> sum(n, pC);
          parallel_for_each(
              sum.grid, 
              [=](index<1> idx) restrict(direct3d)
              {
                 sum[idx] = a[idx] + b[idx];
             }
          );
      }
    

First impressions: I like it.

~~~
wlievens
With some decent DFA you can automate this stuff.

------
malkia
If it something like OpenMP (meta language on top of general purpose one) then
I can see it, but if it's something that forces one to write always AMP code
in the same language, then it would get messy very fast. I much preffer
#pragma opm parallel for, rather than parallel_for<> and some syntax that
would try to get into the original language.

Why Microsoft can't reuse OpeNCL?

~~~
sc68cal
The same reason they introduced DirectX to compete with OpenGL. Lock-in.

~~~
chaffy
Maybe, but to be fair, that's only part of it. OpenCL is C99-based, and MS
wants a C++ solution. OpenCL introduces more problems than it solves,
primarily because the standards body mandated C99 and a low-level, driver-
style interface.

Have you ever seen an OpenCL Hello World program [1]? It's miserable.

[1]
[http://developer.apple.com/library/mac/#documentation/Perfor...](http://developer.apple.com/library/mac/#documentation/Performance/Conceptual/OpenCL_MacProgGuide/Example:Hello,World/Example:Hello,World.html)

~~~
malkia
Can you show us a DirectCompute one?

Btw, introducing C++ introduces problems too: RTTI, exceptions, and the fact
that templates are to be used (would tend to create bigger code).

~~~
chaffy
DirectCompute suffers much of the same problems as OpenCL.

Folks who want to program GPUs productively use Thrust [1].

[1] <http://code.google.com/p/thrust/>

------
georgieporgie
While I really like the quality and features of the VC++ compiler, I really
wish they would do something about the IDE that's gotten worse for C++ devs
over time...

