15
votes

I am looking for SIMD math libraries (preferably open source) for SSE and AVX. I mean for example if I have a AVX register v with 8 float values I want sin(v) to return the sin of all eight values at once.

AMD has a propreitery library, LibM http://developer.amd.com/tools/cpu-development/libm/ which has some SIMD math functions but LibM only uses AVX if it detects FMA4 which Intel CPUs don't have. Also I'm not sure it fully uses AVX as all the function names end in s4 (d2) and not s8 (d4). It give better performance than the standard math libraries on Intel CPUs but it's not much better.

Intel has the SVML as part of it's C++ compiler but the compiler suite is very expensive on Windows. Additionally, Intel cripples the library on non-Intel CPUs.

I found the following AVX library, http://software-lisc.fbk.eu/avx_mathfun/, which supports a few math functions (exp, log, sin, cos, and sincos). It gives very fast results for me, faster than SVML, but I have not checked the accuracy. It only works on single floating point and does not work in Visual Studio (though that would be easy to fix). It's based on another SSE library.

Does anyone have any other suggestions?

Edit: I found a SO thread that has many answers on this subject Vectorized Trig functions in C?

2
Although it is a proprietary solution, Intel's Math Kernel Library is a pretty comprehensive option. However, it performs best on Intel CPUs only. I believe it has been known in the past to divert down an unoptimized code path when running on a non-Intel processor. I'm not sure if that's the case on contemporary versions, though.Jason R
Here you can get logarithms: stackoverflow.com/a/45898937/1915854Serge Rogatch
Agner Fog's Vector Class Library is GPLed. It's more of a wrapper for Intel's intrinsics to make manual vectorization more convenient, but there are some math-library functions like exp and log.Peter Cordes

2 Answers

10
votes

I have implemented Vecmathlib https://bitbucket.org/eschnett/vecmathlib/ as a generic libraries for two other projects (The Einstein Toolkit, and pocl http://pocl.sourceforge.net/). Vecmathlib is open source, and is written in C++.

2
votes

Gromacs is a highly optimized molecular dynamics software package written in C++ that makes use of SIMD. As far as I know the mathematics SIMD functionality has not yet been split out into a separate library but I guess the implementation might be useful for others nonetheless.

https://github.com/gromacs/gromacs/blob/master/src/gromacs/simd/simd_math.h

http://manual.gromacs.org/documentation/2016.4/doxygen/html-lib/simd__math_8h.xhtml