Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4efdebc6
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
4efdebc6
编写于
2月 28, 2019
作者:
T
Tao Luo
提交者:
GitHub
2月 28, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15931 from yihuaxu/develop_
2c5c7b2a
_gelu_mkl_opt
Optimize gelu operation with mkl erf
上级
e5f9d3a4
73967886
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
2 deletion
+59
-2
cmake/external/mklml.cmake
cmake/external/mklml.cmake
+4
-2
paddle/fluid/operators/activation_op.h
paddle/fluid/operators/activation_op.h
+22
-0
paddle/fluid/operators/math/blas.h
paddle/fluid/operators/math/blas.h
+8
-0
paddle/fluid/operators/math/blas_impl.h
paddle/fluid/operators/math/blas_impl.h
+23
-0
paddle/fluid/platform/dynload/mklml.h
paddle/fluid/platform/dynload/mklml.h
+2
-0
未找到文件。
cmake/external/mklml.cmake
浏览文件 @
4efdebc6
...
...
@@ -39,8 +39,10 @@ IF(WIN32)
SET
(
MKLML_IOMP_LIB
${
MKLML_LIB_DIR
}
/libiomp5md.lib
)
SET
(
MKLML_SHARED_LIB
${
MKLML_LIB_DIR
}
/mklml.dll
)
SET
(
MKLML_SHARED_IOMP_LIB
${
MKLML_LIB_DIR
}
/libiomp5md.dll
)
ELSE
()
SET
(
MKLML_VER
"mklml_lnx_
${
TIME_VERSION
}
"
CACHE STRING
""
FORCE
)
ELSE
()
#TODO(intel-huying):
# Now enable Erf function in mklml library temporarily, it will be updated as offical version later.
SET
(
MKLML_VER
"Glibc225_vsErf_mklml_lnx_
${
TIME_VERSION
}
"
CACHE STRING
""
FORCE
)
SET
(
MKLML_URL
"http://paddlepaddledeps.cdn.bcebos.com/
${
MKLML_VER
}
.tgz"
CACHE STRING
""
FORCE
)
SET
(
MKLML_LIB
${
MKLML_LIB_DIR
}
/libmklml_intel.so
)
SET
(
MKLML_IOMP_LIB
${
MKLML_LIB_DIR
}
/libiomp5.so
)
...
...
paddle/fluid/operators/activation_op.h
浏览文件 @
4efdebc6
...
...
@@ -11,6 +11,7 @@ limitations under the License. */
#pragma once
#include <glog/logging.h>
#include <algorithm>
#include <string>
#include <unordered_set>
#include <utility>
...
...
@@ -24,6 +25,7 @@ limitations under the License. */
#include "paddle/fluid/framework/eigen.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/detail/safe_ref.h"
#include "paddle/fluid/operators/math/blas.h"
#include "paddle/fluid/platform/float16.h"
#ifdef PADDLE_WITH_MKLDNN
...
...
@@ -300,8 +302,28 @@ template <typename T>
struct
GeluFunctor
:
public
BaseActivationFunctor
<
T
>
{
template
<
typename
Device
,
typename
X
,
typename
Out
>
void
operator
()(
Device
d
,
X
x
,
Out
out
)
const
{
// Because the execute or device context can not be deliver here, it keep the
// marco for NVCC.
#if defined(PADDLE_WITH_MKLML) && !defined(_WIN32) && !defined(__APPLE__) && \
!defined(__OSX__) && !defined(PADDLE_WITH_CUDA)
auto
x_data
=
x
.
data
();
auto
out_data
=
out
.
data
();
int
n
=
std
::
min
(
x
.
size
(),
out
.
size
());
std
::
memset
(
out_data
,
0
,
n
*
sizeof
(
T
));
math
::
CBlas
<
T
>::
AXPY
(
n
,
static_cast
<
T
>
(
M_SQRT1_2
),
x_data
,
1
,
out_data
,
1
);
math
::
CBlas
<
T
>::
VMERF
(
n
,
out_data
,
out_data
,
VML_LA
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
out_data
[
i
]
+=
static_cast
<
T
>
(
1
);
}
math
::
CBlas
<
T
>::
VMUL
(
n
,
x_data
,
out_data
,
out_data
);
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
out_data
[
i
]
*=
static_cast
<
T
>
(
0.5
);
}
#else
auto
temp
=
(
x
*
static_cast
<
T
>
(
M_SQRT1_2
)).
erf
();
out
.
device
(
d
)
=
x
*
static_cast
<
T
>
(
0.5
)
*
(
static_cast
<
T
>
(
1
)
+
temp
);
#endif
}
};
...
...
paddle/fluid/operators/math/blas.h
浏览文件 @
4efdebc6
...
...
@@ -184,6 +184,9 @@ class Blas {
template
<
typename
T
>
void
VINV
(
int
n
,
const
T
*
a
,
T
*
y
)
const
;
template
<
typename
T
>
void
VMERF
(
int
n
,
const
T
*
a
,
T
*
y
,
int64_t
mode
)
const
;
private:
const
DeviceContext
&
context_
;
};
...
...
@@ -290,6 +293,11 @@ class BlasT : private Blas<DeviceContext> {
Base
()
->
template
VINV
<
T
>(
args
...);
}
template
<
typename
...
ARGS
>
void
VMERF
(
ARGS
...
args
)
const
{
Base
()
->
template
VMERF
<
T
>(
args
...);
}
private:
const
Blas
<
DeviceContext
>*
Base
()
const
{
return
static_cast
<
const
Blas
<
DeviceContext
>*>
(
this
);
...
...
paddle/fluid/operators/math/blas_impl.h
浏览文件 @
4efdebc6
...
...
@@ -123,6 +123,11 @@ struct CBlas<float> {
static
void
VINV
(
ARGS
...
args
)
{
platform
::
dynload
::
vsInv
(
args
...);
}
template
<
typename
...
ARGS
>
static
void
VMERF
(
ARGS
...
args
)
{
platform
::
dynload
::
vmsErf
(
args
...);
}
};
template
<
>
...
...
@@ -223,6 +228,11 @@ struct CBlas<double> {
static
void
VINV
(
ARGS
...
args
)
{
platform
::
dynload
::
vdInv
(
args
...);
}
template
<
typename
...
ARGS
>
static
void
VMERF
(
ARGS
...
args
)
{
platform
::
dynload
::
vmdErf
(
args
...);
}
};
#else
...
...
@@ -625,6 +635,19 @@ void Blas<DeviceContext>::VINV(int n, const T *a, T *y) const {
#endif
}
template
<
>
template
<
typename
T
>
void
Blas
<
platform
::
CPUDeviceContext
>::
VMERF
(
int
n
,
const
T
*
a
,
T
*
y
,
int64_t
mode
)
const
{
#ifdef PADDLE_WITH_MKLML
CBlas
<
T
>::
VMERF
(
n
,
a
,
y
,
mode
);
#else
for
(
int
i
=
0
;
i
<
n
;
++
i
)
{
y
[
i
]
=
std
::
erf
(
a
[
i
]);
}
#endif
}
}
// namespace math
}
// namespace operators
}
// namespace paddle
paddle/fluid/platform/dynload/mklml.h
浏览文件 @
4efdebc6
...
...
@@ -86,6 +86,8 @@ extern void* mklml_dso_handle;
__macro(vdPowx); \
__macro(vsInv); \
__macro(vdInv); \
__macro(vmsErf); \
__macro(vmdErf); \
__macro(MKL_Set_Num_Threads)
MKLML_ROUTINE_EACH
(
DECLARE_DYNAMIC_LOAD_MKLML_WRAP
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录