Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wk1234123
Paddle
提交
d8bd436f
P
Paddle
项目概览
wk1234123
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
4
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d8bd436f
编写于
3月 21, 2018
作者:
K
Krzysztof Binias
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed tests
上级
a64b312e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
56 addition
and
37 deletion
+56
-37
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+9
-18
paddle/fluid/operators/activation_op.h
paddle/fluid/operators/activation_op.h
+0
-19
paddle/fluid/operators/mkldnn_activation_op.h
paddle/fluid/operators/mkldnn_activation_op.h
+47
-0
未找到文件。
paddle/fluid/operators/activation_op.cc
浏览文件 @
d8bd436f
...
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/activation_op.h"
#include "paddle/fluid/operators/mkldnn_activation_op.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -25,11 +26,6 @@ class ActivationOp : public framework::OperatorWithKernel {
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
ActivationHelper
().
GetKernelType
(
ctx
,
*
this
);
}
};
class
ActivationOpGrad
:
public
framework
::
OperatorWithKernel
{
...
...
@@ -39,11 +35,6 @@ class ActivationOpGrad : public framework::OperatorWithKernel {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"Out"
));
}
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
ActivationHelper
().
GetKernelType
(
ctx
,
*
this
);
}
};
class
SigmoidOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
...
@@ -546,11 +537,11 @@ REGISTER_OP(logsigmoid, ops::ActivationOp, ops::LogSigmoidOpMaker,
REGISTER_OP
(
exp
,
ops
::
ActivationOp
,
ops
::
ExpOpMaker
,
exp_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
relu
,
ops
::
ActivationOp
,
ops
::
ReluOpMaker
,
relu_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
relu
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
ReluOpMaker
,
relu_grad
,
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
tanh
,
ops
::
ActivationOp
,
ops
::
TanhOpMaker
,
tanh_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
tanh
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
TanhOpMaker
,
tanh_grad
,
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
tanh_shrink
,
ops
::
ActivationOp
,
ops
::
TanhShrinkOpMaker
,
tanh_shrink_grad
,
ops
::
ActivationOpGrad
);
...
...
@@ -558,11 +549,11 @@ REGISTER_OP(tanh_shrink, ops::ActivationOp, ops::TanhShrinkOpMaker,
REGISTER_OP
(
softshrink
,
ops
::
ActivationOp
,
ops
::
SoftShrinkOpMaker
,
softshrink_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
sqrt
,
ops
::
ActivationOp
,
ops
::
SqrtOpMaker
,
sqrt_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
sqrt
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
SqrtOpMaker
,
sqrt_grad
,
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
abs
,
ops
::
ActivationOp
,
ops
::
AbsOpMaker
,
abs_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
abs
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
AbsOpMaker
,
abs_grad
,
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
ceil
,
ops
::
ActivationOp
,
ops
::
CeilOpMaker
,
ceil_grad
,
ops
::
ActivationOpGrad
);
...
...
paddle/fluid/operators/activation_op.h
浏览文件 @
d8bd436f
...
...
@@ -24,25 +24,6 @@ limitations under the License. */
namespace
paddle
{
namespace
operators
{
class
ActivationHelper
{
public:
framework
::
OpKernelType
GetKernelType
(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
OperatorWithKernel
&
oper
)
const
{
framework
::
LibraryType
library
{
framework
::
LibraryType
::
kPlain
};
#ifdef PADDLE_WITH_MKLDNN
if
(
library
==
framework
::
LibraryType
::
kPlain
&&
platform
::
CanMKLDNNBeUsed
(
ctx
))
{
library
=
framework
::
LibraryType
::
kMKLDNN
;
}
#endif
framework
::
DataLayout
layout
=
framework
::
DataLayout
::
kAnyLayout
;
return
framework
::
OpKernelType
(
framework
::
ToDataType
(
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
)
->
type
()),
ctx
.
GetPlace
(),
layout
,
library
);
}
};
template
<
typename
DeviceContext
,
typename
Functor
>
class
ActivationKernel
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEMENT_TYPE
>
{
...
...
paddle/fluid/operators/mkldnn_activation_op.h
浏览文件 @
d8bd436f
...
...
@@ -60,5 +60,52 @@ class MKLDNNActivationGradKernel
}
};
namespace
{
framework
::
OpKernelType
GetKernelType
(
const
framework
::
ExecutionContext
&
ctx
,
const
framework
::
OperatorWithKernel
&
oper
)
{
framework
::
LibraryType
library
{
framework
::
LibraryType
::
kPlain
};
#ifdef PADDLE_WITH_MKLDNN
if
(
library
==
framework
::
LibraryType
::
kPlain
&&
platform
::
CanMKLDNNBeUsed
(
ctx
))
{
library
=
framework
::
LibraryType
::
kMKLDNN
;
}
#endif
framework
::
DataLayout
layout
=
framework
::
DataLayout
::
kAnyLayout
;
return
framework
::
OpKernelType
(
framework
::
ToDataType
(
ctx
.
Input
<
framework
::
Tensor
>
(
"X"
)
->
type
()),
ctx
.
GetPlace
(),
layout
,
library
);
}
}
// anonymous namespace
class
ActivationWithMKLDNNOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
GetKernelType
(
ctx
,
*
this
);
}
};
class
ActivationWithMKLDNNOpGrad
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"Out"
));
}
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
GetKernelType
(
ctx
,
*
this
);
}
};
}
// namespace operators
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录