Vectorization Part 2 – Why and What?

Vectorization Part 2 – Why and What?

New challenges in the financial markets driven by changes in market structure and regulations and accounting rules like Basel III, EMIR, Dodd Frank, MiFID II, Solvency II, IFRS 13, IRFS 9, and FRTB have increased demand for higher performance risk and analytics. Problems like XVA require orders of magnitude more calculations for accurate results. This demand for higher performance has put a focus on how to get the most out of the latest generation of hardware.

This is the second in a series of blogs on Vectorization which is a key tool for dramatically improving the performance of code running on modern CPUs. Vectorization is the process of converting an algorithm from operating on a single value at a time to operating on a set of values at one time. Modern CPUs provide direct support for vector operations where a single instruction is applied to multiple data (SIMD).

In my last blog I cover how CPUs have evolved and how software must leverage both Threading and Vectorization to get the highest performance possible from the latest generation of processors.

In this blog I cover the why and what of Vectorization.

Why Vectorize

Vectorization is the process of converting an algorithm from operating on a single value at a time to operating on a set of values (vector) at one time.

Modern CPUs provide direct support for vector operations where a single instruction is applied to multiple data (SIMD). For example a CPU with a 512 bit register could hold 16 32-bit single precision doubles and do a single calculation 16 times faster than executing a single instruction at a time. Combine this with threading and multi-core CPUs leads to orders of magnitude performance gains.

The following is code to add two vectors.

for (i = 0; i < 4; i++)

 c[i] = a[i] + b[i];

In a serial calculation, the individual vector (array) elements are added in sequence. The additional register space in modern CPUs is unused.

In a vectorized calculation, all elements of the vector (array) can be added in one calculation step.

What kind of problem is vectorizable?

Not all code can take advantage of vectorization. The problem set must be amenable to a vectorized solution. Vectorization works best on problems that require the same simple operation to be performed on each element in a data set. So, first of all, look for a loop. The prototypical example is used above - the addition of each element in an array.

for (i = 0; i < count; i++)

 c[i] = a[i] + b[i];

But many other primitive operators can also be vectorized. The kinds of matrix transformation seen in linear algebra are usually a good candidate for vectorization. The good news is that the Finance domain provides many problem sets that are suitable.

Issues that impact Vectorizing your code

There are a range of issues that can impact the effectiveness of vectorisation. Some of the more common ones include:

1.    Loop Dependencies (Avoid read-after-write)

for (i = 1; i < end; i++)

 f[i] = f[i-1] + b[i-1];

2.    Indirect Memory Access (Use loop index directly. Seek unit loop stride)

for (i = 0; i < end; i++)   

  c[idxC[i]] = a[i] + b[i];

3.    Non ‘Straight line’ code (function calls, conditions, unknown loop count)

for (i = 0; i < CalcEnd(); i++)

{                              

 if (DoJump())

   i += CalcJump(); 

  c[i] = a[i] + b[i];

}

Resources

Vectorization, Kirill Rogozhin, Intel, March 2017

Vectorization of Performance Dies for the Latest AVX SIMD, Kevin O’Leary, Intel, Aug 2016

A Guide to Vectorization with Intel? C++ Compilers, Intel, Nov 2010

Vectorization Codebook, Intel, Sep 2015

The Free Lunch Is Over - A Fundamental Turn Toward Concurrency in Software, Herb Sutter, March 2005

Recipe: Using Binomial Option Pricing Code as Representative Pricing Derivative Method, Shuo-li, Intel, June 2016

要查看或添加评论,请登录

Rohan Douglas的更多文章

  • What Trends are Impacting Asset Managers and Asset Owners?

    What Trends are Impacting Asset Managers and Asset Owners?

    Forward-looking investment management firms are searching for ways to outperform their peers. The firms that we see…

    1 条评论
  • Vectorization Part 4 - Application to CVA Aggregation

    Vectorization Part 4 - Application to CVA Aggregation

    New challenges in the financial markets driven by changes in market structure and regulations and accounting rules like…

    1 条评论
  • Vectorization Part 3 - Implemention

    Vectorization Part 3 - Implemention

    New challenges in the financial markets driven by changes in market structure and regulations and accounting rules like…

    8 条评论
  • Vectorization Part 1 – The Rise of Parallelism

    Vectorization Part 1 – The Rise of Parallelism

    New challenges in the financial markets driven by changes in market structure and regulations and accounting rules like…

    12 条评论
  • Last chance to register for FRTB webinar

    Last chance to register for FRTB webinar

    Last chance to register for Quantifi & Kauri Solutions' webinar on FRTB for Wen 25th January, 2017 at 10am EST / 3pm…

  • What can we learn from history?

    What can we learn from history?

    I recently finished an excellent book about the history of Rome that covers a 1,000 years of it's history from an…

    4 条评论
  • Quantifi London Conference, October 4th

    Quantifi London Conference, October 4th

    Quantifi is pleased to announce that registration is now OPEN for our 2016 Annual Conference! Join senior practitioners…

  • Quantifi New York Conference, 29th October

    Quantifi New York Conference, 29th October

    Please join us for our 2nd annual risk conference next week - The Dynamics Driving OTC Markets. We have a great speaker…

  • Please help me with Team for Kids in the NYC Marathon

    Please help me with Team for Kids in the NYC Marathon

    This year I’ve decided to take the plunge and run the New York City Marathon. Having not run much before this year, it…

  • British Heart Foundation London to Brighton bike ride

    British Heart Foundation London to Brighton bike ride

    We're taking part in the British Heart Foundation London to Brighton bike ride on Sunday June 21st. Spare a thought for…

社区洞察

其他会员也浏览了