Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
61cb4f2f
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
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,发现更多精彩内容 >>
提交
61cb4f2f
编写于
4月 18, 2018
作者:
D
dzhwinter
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
"fix ci"
上级
425a1e76
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
81 addition
and
80 deletion
+81
-80
paddle/fluid/operators/activation_op.cc
paddle/fluid/operators/activation_op.cc
+81
-80
未找到文件。
paddle/fluid/operators/activation_op.cc
浏览文件 @
61cb4f2f
...
...
@@ -13,16 +13,18 @@ See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/fluid/operators/activation_op.h"
#include <string>
#include "paddle/fluid/operators/mkldnn_activation_op.h"
namespace
paddle
{
namespace
operators
{
#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \
class OP_NAME##OpMaker : public framework::OpProtoAndCheckerMaker { \
class OP_NAME##OpMaker \
: public ::paddle::framework::OpProtoAndCheckerMaker { \
public: \
OP_NAME##OpMaker(OpProto *proto, OpAttrChecker *op_checker) \
:
framework::OpProtoAndCheckerMaker(proto, op_checker) {
\
:
::paddle::framework::OpProtoAndCheckerMaker(proto, op_checker) {
\
AddInput("X", "Input of " #OP_NAME "operator"); \
AddOutput("Out", "Output of" #OP_NAME "operator"); \
AddAttr<bool>("use_mkldnn", \
...
...
@@ -30,26 +32,28 @@ namespace operators {
.SetDefault(false); \
AddComment(#OP_COMMENT); \
} \
}
}
;
#define REGISTER_ACTIVATION_OP_GRAD_MAKER(OP_NAME, KERNEL_TYPE) \
class OP_NAME##GradMaker : public framework::SingleGradOpDescMaker { \
class OP_NAME##GradMaker \
: public ::paddle::framework::SingleGradOpDescMaker { \
public: \
using
framework::SingleGradOpDescMaker::SingleGradOpDescMaker;
\
using
::paddle::framework::SingleGradOpDescMaker::SingleGradOpDescMaker;
\
\
protected: \
std::unique_ptr<
framework::OpDesc> Apply() const override {
\
auto *op = new
framework::OpDesc();
\
std::unique_ptr<
::paddle::framework::OpDesc> Apply() const override {
\
auto *op = new
::paddle::framework::OpDesc();
\
op->SetType(#KERNEL_TYPE "_grad"); \
op->SetInput("Out", Output("Out")); \
op->SetInput(framework::GradVarName("Out"), OutputGrad("Out")); \
op->SetInput(::paddle::framework::GradVarName("Out"), \
OutputGrad("Out")); \
\
op->SetAttrMap(Attrs()); \
\
op->SetOutput(
framework::GradVarName("X"), InputGrad("X"));
\
return std::unique_ptr<
framework::OpDesc>(op);
\
op->SetOutput(
::paddle::framework::GradVarName("X"), InputGrad("X"));
\
return std::unique_ptr<
::paddle::framework::OpDesc>(op);
\
} \
}
}
;
class
ActivationOp
:
public
framework
::
OperatorWithKernel
{
public:
...
...
@@ -449,70 +453,67 @@ REGISTER_ACTIVATION_OP_MAKER(Square, SquareDoc);
REGISTER_ACTIVATION_OP_MAKER
(
Softplus
,
SoftplusDoc
);
REGISTER_ACTIVATION_OP_MAKER
(
Softsign
,
SoftsignDoc
);
// NOTE(*) only gradient can be inplaced need to register its gradient maker,
// To tell the executor which input variable is used. By default, every Input
// variable
// is used in gradient operator.
// The operator name written in lowercase intentionally.
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Sigmoid
,
sigmoid
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Exp
,
exp
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Relu
,
relu
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Exp
,
exp
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Tanh
,
tanh
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Sqrt
,
sqrt
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Ceil
,
ceil
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Floor
,
floor
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Reciprocal
,
reciprocal
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Relu6
,
relu6
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Sqrt
,
sqrt
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
SoftRelu
,
soft_relu
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Relu6
,
relu6
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Reciprocal
,
reciprocal
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
HardSigmoid
,
hard_sigmoid
);
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
#define REGISTER_INPLACE_ACTIVATION_OP(act_type, op_name) \
REGISTER_OPERATOR(act_type, ops::ActivationOp, ops::op_name##OpMaker, \
ops::op_name##GradMaker); \
REGISTER_OPERATOR(act_type##grad, ops::ActivationOpGrad)
#define REGISTER_ACTIVATION_OP(act_type, op_name) \
REGISTER_OP(act_type, ops::ActivationOp, ops::op_name##OpMaker, \
act_type##_grad, ops::ActivationOpGrad);
void
DummyFunctor
()
{}
#define FOR_EACH_INPLACE_OP_FUNCTOR(__macro) \
__macro(
sigmoid, S
igmoid); \
__macro(
relu, R
elu); \
__macro(
exp, E
xp); \
__macro(
tanh, T
anh); \
__macro(
ceil, C
eil); \
__macro(
floor, F
loor); \
__macro(
sqrt, S
qrt); \
__macro(
soft_relu, SoftR
elu); \
__macro(
relu6, R
elu6); \
__macro(
reciprocal, R
eciprocal); \
__macro(
hard_sigmoid, HardS
igmoid);
__macro(
Sigmoid, s
igmoid); \
__macro(
Relu, r
elu); \
__macro(
Exp, e
xp); \
__macro(
Tanh, t
anh); \
__macro(
Ceil, c
eil); \
__macro(
Floor, f
loor); \
__macro(
Sqrt, s
qrt); \
__macro(
SoftRelu, soft_r
elu); \
__macro(
Relu6, r
elu6); \
__macro(
Reciprocal, r
eciprocal); \
__macro(
HardSigmoid, hard_s
igmoid);
#define FOR_EACH_OP_FUNCTOR(__macro) \
__macro(logsigmoid, LogSigmoid); \
__macro(softshrink, SoftShrink); \
__macro(abs, Abs); \
__macro(cos, Cos); \
__macro(sin, Sin); \
__macro(round, Round); \
__macro(log, Log); \
__macro(square, Square); \
__macro(brelu, BRelu); \
__macro(pow, Pow); \
__macro(stanh, STanh); \
__macro(softplus, Softplus); \
__macro(softsign, Softsign); \
__macro(leaky_relu, LeakyRelu); \
__macro(tanh_shrink, TanhShrink); \
__macro(elu, ELU); \
__macro(hard_shrink, HardShrink); \
__macro(swish, Swish); \
__macro(thresholded_relu, ThresholdedRelu);
__macro(LogSigmoid, logsigmoid); \
__macro(SoftShrink, softshrink); \
__macro(Abs, abs); \
__macro(Cos, cos); \
__macro(Sin, sin); \
__macro(Round, round); \
__macro(Log, log); \
__macro(Square, square); \
__macro(BRelu, brelu); \
__macro(Pow, pow); \
__macro(STanh, stanh); \
__macro(Softplus, softplus); \
__macro(Softsign, softsign); \
__macro(LeakyRelu, leaky_relu); \
__macro(TanhShrink, tanh_shrink); \
__macro(ELU, elu); \
__macro(HardShrink, hard_shrink); \
__macro(Swish, swish); \
__macro(ThresholdedRelu, thresholded_relu);
#define REGISTER_INPLACE_ACTIVATION_OP(OP_NAME, KERNEL_TYPE) \
REGISTER_OPERATOR(KERNEL_TYPE, ::paddle::operators::ActivationOp, \
::paddle::operators::OP_NAME##OpMaker, \
::paddle::operators::OP_NAME##GradMaker); \
REGISTER_OPERATOR(KERNEL_TYPE##_grad, ::paddle::operators::ActivationOpGrad)
#define REGISTER_ACTIVATION_OP(OP_NAME, KERNEL_TYPE) \
REGISTER_OP(KERNEL_TYPE, ops::ActivationOp, ops::OP_NAME##OpMaker, \
KERNEL_TYPE##_grad, ops::ActivationOpGrad);
#define REGISTER_ACTIVATION_CPU_KERNEL(act_type, functor, grad_functor) \
REGISTER_OP_CPU_KERNEL( \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录