avoid Exp overhead when handling underflow with MKL
avoid Exp overhead when handling underflow with MKL

Summary:
I've been noticing when running caffe2 experiments that calling Exp with many values close to 0 causes MKL's underflow error handler to be called repeatedly, causing significant overhead while the result is correct (e.g. exp(x) = 0). I suggest setting the error mode to VML_ERRMODE_IGNORE for those functions, unless there are good reasons not to.

with the current function (see mkl_vml_kernel_sError and vsexp_cout_rare):
{F65147147}

with VML_ERRMODE_IGNORE:
{F65147148}

Let me know if you see a better workaround

Reviewed By: Yangqing

Differential Revision: D4277240

fbshipit-source-id: d44168da32caee4a3f88227ffb70cdc3d5314722

davinwang/caffe2,xzturn/caffe2,sf-wind/caffe2,pietern/caffe2,Yangqing/caffe2,sf-wind/caffe2,caffe2/caffe2,sf-wind/caffe2,davinwang/caffe2,xzturn/caffe2,davinwang/caffe2,Yangqing/caffe2,bwasti/caffe2,davinwang/caffe2,Yangqing/caffe2,pietern/caffe2,bwasti/caffe2,xzturn/caffe2,xzturn/caffe2,Yangqing/caffe2,pietern/caffe2,bwasti/caffe2,Yangqing/caffe2,pietern/caffe2,xzturn/caffe2,sf-wind/caffe2,bwasti/caffe2,pietern/caffe2,davinwang/caffe2,sf-wind/caffe2,bwasti/caffe2