1 / 8

Auto-Vectorization

Auto-Vectorization. Jim Hogg Program Manager Visual C ++ Compiler Microsoft Corporation. A feature in the Visual Studio 11 C++ native compiler Tries to make your C++ loops run faster, by using vector registers and instructions

richelle
Download Presentation

Auto-Vectorization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

  2. A feature in the Visual Studio 11 C++ native compiler • Tries to make your C++ loops run faster, by using vector registers and instructions • Speedup varies with application. In tight loops, can reach 4X on ints or floats • You don’t need to request this option - it’s on-by-default • Just recompile your code and measure the speedup Auto-Vectorization : What is it?

  3. Auto-Vectorization: how does it work? All modern PC chips include vector registers and instructions Vector registers are called XMM0 – XMM15 Each vector register holds 4 ints or 4 floats Vector instructions are called SSE Instructions perform 4 operations in parallel

  4. Auto-Vectorization: Simple Loop 1.10 RAX ADD RAX, RBX SCALAR 1.20 RBX RAX 2.30 for (int i = 0; i < 1000; ++i) a[i] += b[i] 1.10 2.10 3.10 4.10 XMM1 VECTOR XMM2 1.20 2.20 3.20 4.20 ADDPS XMM1, XMM2 2.30 4.30 6.30 8.30 XMM1 for (inti = 0; i < 1000; i += 4) a[i : i+3] += b[i : i+3]

  5. Auto-Vectorization : Example const int dim = 1000000; float a[dim], b[dim]; int main() { for (int n = 0; n < dim; ++n) a[n] += sin(b[n]) * cos(b[n]); }

  6. Auto-Vectorization : Summary • Prior to Visual Studio 11, the C++ compiler emitted code that performed only scalar operations • In Visual Studio 11, the C++ compiler tries to use vector registers and instructions to speed up your C++ loops • Emits code to uses SSE vector registers and instructions automatically • No need to change your C++ source code • The feature is on-by-default • Adjusts to your computer at runtime (SSE2 or SSE4.1) • Transformations are always safe! • To try it out, just recompile your code, and run!

  7. Auto-Vectorization : Links • Channel 9 Video • http://channel9.msdn.com/Shows/C9-GoingNative/GoingNative-7-VC11-Auto-Vectorizer-C-NOW-LangNEXT • Blog Posts • http://blogs.msdn.com/b/nativeconcurrency/archive/2012/04/12/auto-vectorizer-in-visual-studio-11-overview.aspx

  8. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related