Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
d8bd436f
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
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
...
@@ -13,6 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/fluid/operators/activation_op.h"
#include "paddle/fluid/operators/activation_op.h"
#include "paddle/fluid/operators/mkldnn_activation_op.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
...
@@ -25,11 +26,6 @@ class ActivationOp : public framework::OperatorWithKernel {
...
@@ -25,11 +26,6 @@ class ActivationOp : public framework::OperatorWithKernel {
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
SetOutputDim
(
"Out"
,
ctx
->
GetInputDim
(
"X"
));
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
ctx
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
}
framework
::
OpKernelType
GetExpectedKernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
ActivationHelper
().
GetKernelType
(
ctx
,
*
this
);
}
};
};
class
ActivationOpGrad
:
public
framework
::
OperatorWithKernel
{
class
ActivationOpGrad
:
public
framework
::
OperatorWithKernel
{
...
@@ -39,11 +35,6 @@ class ActivationOpGrad : public framework::OperatorWithKernel {
...
@@ -39,11 +35,6 @@ class ActivationOpGrad : public framework::OperatorWithKernel {
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
ctx
->
SetOutputDim
(
framework
::
GradVarName
(
"X"
),
ctx
->
GetInputDim
(
"Out"
));
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
{
class
SigmoidOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
@@ -546,11 +537,11 @@ REGISTER_OP(logsigmoid, ops::ActivationOp, ops::LogSigmoidOpMaker,
...
@@ -546,11 +537,11 @@ REGISTER_OP(logsigmoid, ops::ActivationOp, ops::LogSigmoidOpMaker,
REGISTER_OP
(
exp
,
ops
::
ActivationOp
,
ops
::
ExpOpMaker
,
exp_grad
,
REGISTER_OP
(
exp
,
ops
::
ActivationOp
,
ops
::
ExpOpMaker
,
exp_grad
,
ops
::
ActivationOpGrad
);
ops
::
ActivationOpGrad
);
REGISTER_OP
(
relu
,
ops
::
ActivationOp
,
ops
::
ReluOpMaker
,
relu_grad
,
REGISTER_OP
(
relu
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
ReluOpMaker
,
relu_grad
,
ops
::
ActivationOpGrad
);
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
tanh
,
ops
::
ActivationOp
,
ops
::
TanhOpMaker
,
tanh_grad
,
REGISTER_OP
(
tanh
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
TanhOpMaker
,
tanh_grad
,
ops
::
ActivationOpGrad
);
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
tanh_shrink
,
ops
::
ActivationOp
,
ops
::
TanhShrinkOpMaker
,
REGISTER_OP
(
tanh_shrink
,
ops
::
ActivationOp
,
ops
::
TanhShrinkOpMaker
,
tanh_shrink_grad
,
ops
::
ActivationOpGrad
);
tanh_shrink_grad
,
ops
::
ActivationOpGrad
);
...
@@ -558,11 +549,11 @@ REGISTER_OP(tanh_shrink, ops::ActivationOp, ops::TanhShrinkOpMaker,
...
@@ -558,11 +549,11 @@ REGISTER_OP(tanh_shrink, ops::ActivationOp, ops::TanhShrinkOpMaker,
REGISTER_OP
(
softshrink
,
ops
::
ActivationOp
,
ops
::
SoftShrinkOpMaker
,
REGISTER_OP
(
softshrink
,
ops
::
ActivationOp
,
ops
::
SoftShrinkOpMaker
,
softshrink_grad
,
ops
::
ActivationOpGrad
);
softshrink_grad
,
ops
::
ActivationOpGrad
);
REGISTER_OP
(
sqrt
,
ops
::
ActivationOp
,
ops
::
SqrtOpMaker
,
sqrt_grad
,
REGISTER_OP
(
sqrt
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
SqrtOpMaker
,
sqrt_grad
,
ops
::
ActivationOpGrad
);
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
abs
,
ops
::
ActivationOp
,
ops
::
AbsOpMaker
,
abs_grad
,
REGISTER_OP
(
abs
,
ops
::
Activation
WithMKLDNN
Op
,
ops
::
AbsOpMaker
,
abs_grad
,
ops
::
ActivationOpGrad
);
ops
::
Activation
WithMKLDNN
OpGrad
);
REGISTER_OP
(
ceil
,
ops
::
ActivationOp
,
ops
::
CeilOpMaker
,
ceil_grad
,
REGISTER_OP
(
ceil
,
ops
::
ActivationOp
,
ops
::
CeilOpMaker
,
ceil_grad
,
ops
::
ActivationOpGrad
);
ops
::
ActivationOpGrad
);
...
...
paddle/fluid/operators/activation_op.h
浏览文件 @
d8bd436f
...
@@ -24,25 +24,6 @@ limitations under the License. */
...
@@ -24,25 +24,6 @@ limitations under the License. */
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
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
>
template
<
typename
DeviceContext
,
typename
Functor
>
class
ActivationKernel
class
ActivationKernel
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEMENT_TYPE
>
{
:
public
framework
::
OpKernel
<
typename
Functor
::
ELEMENT_TYPE
>
{
...
...
paddle/fluid/operators/mkldnn_activation_op.h
浏览文件 @
d8bd436f
...
@@ -60,5 +60,52 @@ class MKLDNNActivationGradKernel
...
@@ -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 operators
}
// namespace paddle
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录