C++ Accelerated Massive Parallelism (C++ AMP) - Windows · PDF fileC++ Accelerated Massive...

1
C++ Accelerated Massive Parallelism (C++ AMP) What is C++ AMP, how can it help me, and where can I get it? C++ AMP is a key new C++ language feature plus an STL-like library. It's designed to help you increase the performance of your data-parallel algorithms by offloading them to hardware accelerators, e.g. GPUs. C++ AMP is an open specification. The Microsoft implementation is included in Visual Studio 2012, including rich debugger and profiler support. By using Visual Studio and the familiar C++ syntax, you can build one binary that can run on any hardware that's enabled for DirectX 11. C++ AMP brings the performance of data parallel hardware to the mainstream through minimal API additions, preserving your productivity, and without sacrificing hardware portability. What platforms and hardware does C++ AMP support? The initial C++ AMP release from Microsoft requires at least Windows 7 or Windows Server 2008 R2. Any hardware that has a DirectX 11 driver, such as most GPUs on the market, can be used to accelerate C++ AMP algorithms. There's also a CPU fallback that uses multi-core and SIMD instructions. Support for other platforms and hardware may become available from Microsoft or other compiler or hardware vendors. What new language feature does C++ AMP introduce? Microsoft added the restrict(amp) feature, which you can apply to any function (including lambdas) to declare that the function can be executed on a C++ AMP accelerator. The restrict keyword instructs the compiler to statically check that the function uses only those language features that are supported by most GPUs, for example, void myFunc() restrict(amp) {…} Microsoft or other implementers of the open C++ AMP spec could add other restrict specifiers for other purposes, including for purposes that are unrelated to C++ AMP. What new classes (APIs) does C++ AMP introduce? Beyond the new language feature, the rest of C++ AMP is available through the <amp.h> header file in the concurrency namespace. The key C++ AMP classes are: array (container for data on an accelerator), array_view (wrapper for data), index (N-dimensional point), extent (N-dimensional size), accelerator (computational resource, such as a GPU, on which to allocate memory and execute), and accelerator_view (view of an accelerator). There is also a global function, parallel_for_each, which you use to write a C++ AMP parallel loop. What does C++ AMP code look like? Here's an example of a C++ function that uses C++ AMP to add two 2-dimensional arrays together: void AddArrays(int n, int m, int * pA, int * pB, int * pSum) { concurrency::array_view<int,2> a(n, m, pA), b(n, m, pB), sum(n, m, pSum); concurrency::parallel_for_each(sum.extent, [=](concurrency::index<2> i) restrict(amp) { sum[i] = a[i] + b[i]; }); } Follow our blog: http://blogs.msdn.com/b/nativeconcurrency/ Ask questions: http://social.msdn.microsoft.com/Forums/en/parallelcppnative/threads An open specification implemented in Microsoft Visual Studio 2012

Transcript of C++ Accelerated Massive Parallelism (C++ AMP) - Windows · PDF fileC++ Accelerated Massive...

Page 1: C++ Accelerated Massive Parallelism (C++ AMP) - Windows · PDF fileC++ Accelerated Massive Parallelism (C++ AMP) ... Microsoft implementation is included in Visual Studio 2012, ...

C++ Accelerated Massive Parallelism (C++ AMP)

What is C++ AMP, how can it help me, and where can I get it?C++ AMP is a key new C++ language feature plus an STL-like library. It's designed to help you increase the performance of your data-parallel algorithms by offloading them to hardware accelerators, e.g. GPUs. C++ AMP is an open specification. The Microsoft implementation is included in Visual Studio 2012, including rich debugger and profiler support. By using Visual Studio and the familiar C++ syntax, you can build one binary that can run on any hardware that's enabled for DirectX 11.

C++ AMP brings the performance of data parallel hardware to the mainstream through minimal API additions, preserving your productivity, and without sacrificing hardware portability. What platforms and hardware does C++ AMP support?The initial C++ AMP release from Microsoft requires at least Windows 7 or Windows Server 2008 R2. Any hardware that has a DirectX 11 driver, such as most GPUs on the market, can be used to accelerate C++ AMP algorithms. There's also a CPU fallback that uses multi-core and SIMD instructions.

Support for other platforms and hardware may become available from Microsoft or other compiler or hardware vendors.

What new language feature does C++ AMP introduce?Microsoft added the restrict(amp) feature, which you can apply to any function (including lambdas) to declare that the function can be executed on a C++ AMP accelerator. The restrict keyword instructs the compiler to statically check that the function uses only those language features that are supported by most GPUs, for example, void myFunc() restrict(amp) {…}

Microsoft or other implementers of the open C++ AMP spec could add other restrict specifiers for other purposes, including for purposes that are unrelated to C++ AMP.

What new classes (APIs) does C++ AMP introduce?Beyond the new language feature, the rest of C++ AMP is available through the <amp.h> header file in the concurrency namespace. The key C++ AMP classes are: array (container for data on an accelerator), array_view (wrapper for data), index (N-dimensional point), extent (N-dimensional size), accelerator (computational resource, such as a GPU, on which to

allocate memory and execute), and accelerator_view (view of an accelerator).

There is also a global function, parallel_for_each, which you use to write a C++ AMP parallel loop.

What does C++ AMP code look like? Here's an example of a C++ function that uses C++ AMP to add two 2-dimensional arrays together:

void AddArrays(int n, int m, int * pA, int * pB, int * pSum) { concurrency::array_view<int,2> a(n, m, pA), b(n, m, pB), sum(n, m, pSum); concurrency::parallel_for_each(sum.extent, [=](concurrency::index<2> i) restrict(amp) { sum[i] = a[i] + b[i]; });}

Follow our blog: http://blogs.msdn.com/b/nativeconcurrency/Ask questions: http://social.msdn.microsoft.com/Forums/en/parallelcppnative/threads

An open specification implemented in Microsoft Visual Studio 2012