[Math] BOOST_FPU_EXCEPTION_GUARD on Linux
Hello, I have a program that makes considerable use of the gamma distribution from Boost.Math. Profiling with OProfile has shown that, on Linux, this program spends about 20% of its runtime calling the functions fesetexceptflag() and feclearexcept(). The code responsible for calling these is in the BOOST_FPU_EXCEPTION_GUARD macro which is defined in boost/math/tools/config.hpp. I have looked back through the source history to see when and why this macro was added, and it was in changeset 3186 from September 2006 with the comment "More linux fixes: finally got AMD64 machines to behave correctly" (see https://svn.boost.org/trac/boost/changeset/3186). In Boost 1.54 the conditions under which the guard macro is defined have been refined since it was originally added, but the guard class itself remains the same as in 2006. Given the performance penalty I am suffering as a result of constantly clearing and reseting the floating point exception flags, I have a couple of questions about this functionality: 1) Can anyone provide a specific test case that did not work without the BOOST_FPU_EXCEPTION_GUARD functionality but was fixed by its addition? It would be very useful to have such a test case because then I can check if this is still a problem on recent versions of Linux. 2) The commit comment for changeset 3186 refers to AMD64. Does this mean the original problem only occurred on AMD CPUs, or does this refer to the architecture, and hence it affected both Intel and AMD CPUs? Many thanks, David Roberts
I have a program that makes considerable use of the gamma distribution from Boost.Math.
Profiling with OProfile has shown that, on Linux, this program spends about 20% of its runtime calling the functions fesetexceptflag() and feclearexcept(). >The code responsible for calling these is in the BOOST_FPU_EXCEPTION_GUARD macro which is defined in boost/math/tools/config.hpp.
Thanks for raising this, it's something that's been niggling in the back of my mind for a while.
I have looked back through the source history to see when and why this macro was added, and it was in changeset 3186 from September 2006 with the comment "More linux fixes: finally got AMD64 machines to behave correctly" (see https://svn.boost.org/trac/boost/changeset/3186). In Boost 1.54 the conditions under which the guard macro is defined have been refined since it was originally added, but the guard class itself remains the same as in 2006.
Given the performance penalty I am suffering as a result of constantly clearing and reseting the floating point exception flags, I have a couple of questions about this functionality: 1) Can anyone provide a specific test case that did not work without the BOOST_FPU_EXCEPTION_GUARD functionality but was fixed by its addition? > It would be very useful to have such a test case because then I can check if this is still a problem on recent versions of Linux.
Try disabling it and running the test cases in libs/math/test.
2) The commit comment for changeset 3186 refers to AMD64. Does this mean the original problem only occurred on AMD CPUs, or does this refer to the
architecture, and hence it affected both Intel and AMD CPUs?
As I recall this was a hardware issue on early AMD 64-bit CPU's, possibly a GLIBC issue too. In fact if I recall it was this issue: http://sourceware.org/bugzilla/show_bug.cgi?id=2445 which didn't get much help from the glibc guys :-( But basically if any of the FPU exception flags are set prior to a call to pow or exp, you risk getting a garbage answer back. I'll add a link to the above in the code. HTH, John.
participants (2)
-
David Roberts
-
John Maddock