15

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?

Community
  • 1
  • 1
  • 1
    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 Apr 01 '13 at 01:36
  • Here you can get logarithms: https://stackoverflow.com/a/45898937/1915854 – Serge Rogatch Aug 26 '17 at 19:36
  • Agner Fog's [Vector Class Library](http://agner.org/optimize/#vectorclass) 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 Dec 25 '17 at 19:53

2 Answers2

10

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

Erik Schnetter
  • 452
  • 4
  • 8
  • 1
    That appears to be exactly the kind of package I'm looking for. I'll give it a try and get back to you. –  Apr 20 '13 at 07:49
  • 1
    That library looks very promising, but I ran into a a couple of problems: a) the version on bitbucket doesn't compile due to a #endif being missing b) the benchmark data looks very disappointing, usually VML is an order of magnitude slower in my testing - here MINGW on windws. And seems can't compile with MSVC – ibell Jun 11 '14 at 23:57
2

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

Erik Sjölund
  • 9,109
  • 7
  • 34
  • 60