Microsoft made an announcement last June about a new specification called C++ AMP (the AMP stands for Accelerated Massive Parallelism), a means to exploit data-parallel hardware in the C++ language. Seven months later and with the help of NVIDIA and AMD, Microsoft has published the C++ AMP spec.
Programs written in the AMP specification will be able to utilize both CPUs and GPUs, the idea being to make heterogeneous computing more transparent to the programmer. The process is actually pretty straightforward for developers because programs are essentially written in C++, with some additional language features and runtime library calls added to enable data parallel processing.
Microsoft’s description delves a bit deeper:
“The C++ AMP programming model includes multidimensional arrays, indexing, memory transfer, tiling, and a mathematical function library. C++ AMP language extensions and compiler restrictions enable you to control how data is moved from the CPU to the GPU and back, which enables you to control the performance impact of moving the data back and forth.”
After the announcement of C++ AMP, Microsoft’s Daniel Moth provided a Hello World example of the changes between standard C++ and C++ AMP.
AMP is not the first specification that allows heterogeneous parallelization. In 2008, the Khronos Group came up with OpenCL, a vendor-neutral, open standard for parallel programming that has many adherents. OpenCL uses C as a base language, and unlike AMP, relies on the programmer to deal with a lot of the low-level data shuffling. According to an Ars Technica article:
“The result is that in OpenCL there’s a big divide between the CPU world and the GPU world, and bridging the two requires lots of manual management by the programmer. C++ AMP makes using the GPU a lot more streamlined; the management is performed automatically, allowing developers to write more natural, high-level programs.”
There may be concern regarding performance, given the higher-level nature of C++AMP versus OpenCL, but Mark Ireton from AMD draws the same comparison to writing in C++ versus assembly:
“On a CPU, best performance, for a short piece of code executing on a single core, can be obtained by writing in assembler. There are developers that still do this. However, many more developers use C++. Programmer productivity is higher with languages like C++, and performance can be a little lower, but without languages such as C++, many applications are simply not feasible. A similar argument can be made for high-level languages such as Java or the .NET family.”
So the main advantage to AMP appears to be its ease-of-use, which potentially could open heterogeneous computing to a much wider array of developers. And because Microsoft has opened the spec to the community, other AMP implementations could be developed by hardware makers and other compiler vendors.