SingularInversions / FaceGenBaseLibrary

A simple cross-platform C++17 library for developing computational 3D graphics applications.
MIT License
46 stars 23 forks source link

library function 'exp' much slower on Ubuntu than Windows or MacOS #2

Closed ab-cpp closed 7 years ago

ab-cpp commented 7 years ago
  1. Build the library (64bit release) using either the visual studio solution files or makefiles for Ubuntu/MacOS gcc/clang.
  2. Run the command 'fgbl testm cpp exp' to get a speed measure for each platform. The executable for each platform is at ~/bin/'os'/'compiler'/64/release/
  3. The 'win' and 'osx' builds are more than 10x faster than 'ubuntu' builds on similar hardware (gcc or clang but both using 'libstdc++.so). The 'osx' build also uses clang and dynamic libs (.dylib).
  4. The source code for this test is at ~/source/LibFgBase/src/FgCmdTestmCpp.cpp:106

Why is Ubuntu so much slower and how can we fix this issue ?

clbr commented 7 years ago

The issue is that glibc's math functions are slow. Solutions include using an alternative libm, such as the ones from AMD and Intel (only optimized for their own processors, and closed source), or getting an optimized implementation from elsewhere.

For example, I tested https://github.com/herumi/fmath - replacing the exp() call with fmath::expd() improved the speed from 34ns to 9ns on my system. And that free implementation is quite likely not as good as the ones from the processor manufacturers, which are likely used in the Windows and OS X libm.

Does this qualify for the bounty? There is no simple, open source solution - nobody has made an optimized, open source libm that would target processors from all manufacturers.

ab-cpp commented 7 years ago

Yes, unless someone posts a significantly better answer you will get the bounty. I guess I should have tried stackoverflow first :)

clbr commented 7 years ago

http://www.agner.org/optimize/blog/read.php?i=209&v=t This has more background on math libraries.