auto-vectorization jim hogg program manager visual c++ compiler microsoft corporation

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

Upload: scott-armstrong

Post on 19-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

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

Auto-VectorizationJim HoggProgram ManagerVisual C++ CompilerMicrosoft Corporation

Page 2: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

Auto-Vectorization : What is it?• 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

Page 3: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

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

Auto-Vectorization : how does it work?

Page 4: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

ADD RAX, RBX

1.10

1.20

RAX

RBX

2.30

ADDPS XMM1, XMM2

XMM1

XMM2

1.10 2.10 3.10 4.10

RAX

1.20 2.20 3.20 4.20

2.30 4.30 6.30 8.30XMM1

SCALAR

VECTOR

for (int i = 0; i < 1000; ++i) a[i] += b[i]

for (int i = 0; i < 1000; i += 4) a[i : i+3] += b[i : i+3]

Auto-Vectorization : Simple Loop

Page 5: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

Auto-Vectorization : Exampleconst 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]);}

Vectorization Disabled

Auto-Vectorized

Speedup

108.7 millisecs 37.3 millisecs 2.9X

Page 6: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

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!

Page 7: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

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

Page 8: Auto-Vectorization Jim Hogg Program Manager Visual C++ Compiler Microsoft Corporation

© 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.