mirror of
https://github.com/saymrwulf/onnxruntime.git
synced 2026-07-19 19:00:47 +00:00
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:
parent
fdbe365c37
commit
a6bf1d0ad8
2 changed files with 6 additions and 2 deletions
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue