How Visual Studio Improves C++ Performance
Today at Build Jim Radigan and Don McCrady gave a presentation that discussed how the improved Visual Studio 2012 (VS2012) compiler can benefit developers programming in C++. Radigan began his talk, "Its all about performance: Using Visual C++ 2012 to Maximize Your Hardware", by giving a brief historical overview of the increases in computer power since the introduction of the original Pentium.
That first Pentium had 3.1 million transistors while the current generation Ivy Bridge CPUs have 1.4 billion transistors. As McCrady would later note, C++ AMP allows developers to utilize everything with one single langauge-- both the CPU, and the GPU that is increasingly present on CPU dies (in addition to the GPUs present in discrete expansion cards.)
While using code targeting C++ AMP can frequently provide the best performance versus generic code, Radigan continued by noting that the auto-vectorization and auto-parallelization optimizations present in VS2012 mean that in many cases recompiling existing C++ code can provide immediate benefits. As a result the optimizer present in VS2012 is double the size of previous versions.
Developers can mark sections of their code where they would like to ensure the compiler reviews for speed-up. Using the following pragma:
… enables developers to provide a hint to the compiler that it is believed that the loop containing the pragma should be spread over multiple cores (in this snippet 4 cores). The compiler will still make a full anaylsis so that if the marked piece of code is not appropriately parallelizable the compiler will not implement any optimizations.
The demonstration of a raytracer by Radigan exhibited a 16X performance increase simply by recompile the source under VS2012. Radigan emphasized that the improved compiler performance of VS2012 notwithstanding, there is no “magic bullet” available to automatically produce faster code. That said, the compiler team is contninously seeking to innovate as Windows 8, SQL Server, and Office are all C++ applications.
Radigan indicated that while nothing is available right now, he would like to add native C# support to AMP. (At present C# developers can make use of AMP via P/Invoke.) Finally, the C++ AMP specification is an open standard, but there is currently not an implementation on Apple's platform (iOS or Mac OS X) but in theory it is possible for one to be made.