This bugzilla service is closed. All entries have been migrated to https://gitlab.com/libeigen/eigen
Bug 1214 - BDCSVD hangs the machine
Summary: BDCSVD hangs the machine
Status: RESOLVED FIXED
Alias: None
Product: Eigen
Classification: Unclassified
Component: SVD (show other bugs)
Version: 3.3 (current stable)
Hardware: x86 - 64-bit Linux
: Normal Crash
Assignee: Nobody
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 3.3
  Show dependency treegraph
 
Reported: 2016-05-02 09:35 UTC by eugvas
Modified: 2019-12-04 15:45 UTC (History)
2 users (show)



Attachments

Description eugvas 2016-05-02 09:35:24 UTC
When compiling the following code against the Eigen version 3.3-beta1
http://stackoverflow.com/questions/36959506/eigen-library-svd-is-slow-compared-to-gsl
with the Intel compiler icc version 13.1.3, the code hangs on the call to BDCSVD. The same code compiled with g++ 4.4.7 runs fine. Optimization levels -O1 to -O3 have been tried.
Additionally, during the compilation with icc several screens of warnings are issued (apparetnly not related to the problem, but annoying):
Eigen/src/Core/ProductEvaluators.h(543): warning #2536: type qualifiers are meaningless here
Comment 1 Gael Guennebaud 2016-05-02 15:09:49 UTC
Indeed, by default icc performs numerous unsafe floating point optimizations breaking any D&C SVD implementation. You need to disable them by compiling with "-fp-model precise".

I'm not sure what we could do on our side (beyond adding such a note in the documentation).
Comment 2 eugvas 2016-05-02 15:37:26 UTC
Thanks, with this flag it works fine, although is a bit slower than the code produced by gcc (~20%).
Comment 3 Christoph Hertzberg 2016-05-02 16:01:12 UTC
Most of the time, an up-to-date gcc is the best choice for Eigen code.

Regarding a work-around for icc: Are there ways to prohibit certain optimizations locally (e.g., via #pragma)? Or could/should we protect some assignments with inline-assembler instructions (in case icc is detected).

Also, wouldn't this bug occur with `g++ -ffast-math` as well?
Comment 4 eugvas 2016-05-02 16:40:07 UTC
> Also, wouldn't this bug occur with `g++ -ffast-math` as well?

In fact yes, tried gcc 4.4.7 and 4.9.3, both produce a code that hangs.
Thus it would be better to somehow trick compilers into skipping the unsafe optimizations even if compiled with this flag. For my project, icc (with this flag on by default) produces code that is sometimes twice as fast as the one from gcc (which has it off by default), which is quite a big difference - not sure how much is gained by this flag though.
Comment 5 Gael Guennebaud 2016-05-02 21:15:25 UTC
I tried with:

#pragma float_control(precise, on, push)

but that only works if I put it at the beginning of the .cpp file and pop it after the function doing the instantiation/calls to BDCSVD.
Comment 6 Gael Guennebaud 2016-05-03 19:38:28 UTC
Actually, it seems that compiling with -no-ftz is enough (ftz = flush denormals to zero). So the issue might be fixed through a careful analysis...
Comment 7 Gael Guennebaud 2016-05-03 20:58:29 UTC
sorry, with -no-ftz it does not hang, but it lacks accuracy...
Comment 8 Gael Guennebaud 2016-05-03 21:17:27 UTC
https://bitbucket.org/eigen/eigen/commits/41f1156257f7/ 
Summary: Bug 1214: consider denormals as zero in D&C SVD. This also workaround infinite binary search when compiling with ICC's unsafe optimizations.

Remains to add a note in the doc.
Comment 9 Gael Guennebaud 2016-05-04 10:54:37 UTC
doc: https://bitbucket.org/eigen/eigen/commits/9f1b62f8c825/
Comment 10 Nobody 2019-12-04 15:45:42 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to gitlab.com's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.com/libeigen/eigen/issues/1214.

Note You need to log in before you can comment on or make changes to this bug.