use mlaserf (#1999)

1. use MlasErf for Gelu. Eigen's erf is very slow.
2. change the ErfUpperAbsRange to 3.925 because MlasErf doesn't return 1 for 3.725
Motivation and Context
This commit is contained in:
Yufeng Li 2019-10-04 15:17:26 -07:00 committed by GitHub
parent fdbe365c37
commit a6bf1d0ad8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#include "core/common/common.h"
#include "core/framework/op_kernel.h"
#include "core/util/math_cpuonly.h"
#include "core/mlas/inc/mlas.h"
#include <unsupported/Eigen/SpecialFunctions>
namespace onnxruntime {
@ -38,7 +39,10 @@ class Gelu : public OpKernel {
const auto* X = context->Input<Tensor>(0);
Tensor* Y = context->Output(0, X->Shape());
EIGEN_X_VAR(xm);
EIGEN_Y = xm * 0.5f * ((xm * static_cast<float>(M_SQRT1_2)).erf() + 1.0f);
EIGEN_Y_VAR(ym);
ym = xm * static_cast<float>(M_SQRT1_2);
MlasComputeErf(Y->template MutableData<T>(), Y->template MutableData<T>(), X->Shape().Size());
ym = xm * 0.5f * (ym + 1.0f);
return Status::OK();
}
};

View file

@ -64,7 +64,7 @@ MLAS_INTERNAL_DATA const struct {
float Exp_C;
int32_t Exp_X7F;
} MlasErfConstants = {
3.725f,
3.925f,
0.921875f,
-5.99104969e-4f,
4.99339588e-3f,