Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Free/open source C/C++ library of vectorized math functions? [closed]

I'm looking for a free/open source C/C++ (either is acceptable) library of vectorized versions of common math functions (such as ln or exp) similar to Intel's Vector Math Library for Linux. I'd like a library that would provide me with the ability to write something like:

double a[ARRAY_SIZE], b[ARRAY_SIZE];
for (int i = 0; i < ARRAY_SIZE; ++i) {
    a[i] = ln(b[i]);
}

as:

double a[ARRAY_SIZE], b[ARRAY_SIZE];
vectorized_ln(a, b, ARRAY_SIZE);

and have it use the full power of the SIMD instructions available on the Intel and AMD architectures. The development environment consists of GNU tools running on Linux. Intel's Math Kernel Library contains something called Vector Math Library which advertises "vector implementations of computationally intensive core mathematical functions" including basic functions, trig functions, etc, so I'm looking for something like that but for free.

like image 855
BD at Rivenhill Avatar asked Jul 31 '11 11:07

BD at Rivenhill


2 Answers

I developed an open-source (BSD) Yeppp! mathematical library, which provides some vector elementary functions (log, exp, sin, cos, tan), and is competitive with MKL in performance. Here is an example of using vector logarithm function from Yeppp!

like image 59
Marat Dukhan Avatar answered Oct 05 '22 01:10

Marat Dukhan


Felix von Leitner has written an extensive presentation on the actual assembly produced by various c compilers.

His notes on vectorization of simple operations start on slide 28.

  • For GCC 4.4 and a memset type loop

    • gcc -O2 generates a loop that writes one byte at a time
    • gcc -O3 vectorizes, writes 32-bit (x86) or 128-bit (x86 wit h SSE or x64) at a time
    • impressive: the vectorized code checks and fixes the alignment first

Slide 41 is entitled "Outsmarting the Compiler - simd-shift" and concludes that "gcc is smarter than the video codec programmer on all platforms"

Slide 42 is another case where gcc will automatically vectorize naive code.

All of which adds up to check first to see if the compiler you are using will simply deal with it for you.

like image 39
dmckee --- ex-moderator kitten Avatar answered Oct 05 '22 01:10

dmckee --- ex-moderator kitten