Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
61cb4f2f
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
提交
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,43 +13,47 @@ See the License for the specific language governing permissions and
...
@@ -13,43 +13,47 @@ 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 <string>
#include "paddle/fluid/operators/mkldnn_activation_op.h"
#include "paddle/fluid/operators/mkldnn_activation_op.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \
#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \
class OP_NAME##OpMaker : public framework::OpProtoAndCheckerMaker { \
class OP_NAME##OpMaker \
public: \
: public ::paddle::framework::OpProtoAndCheckerMaker { \
OP_NAME##OpMaker(OpProto *proto, OpAttrChecker *op_checker) \
public: \
: framework::OpProtoAndCheckerMaker(proto, op_checker) { \
OP_NAME##OpMaker(OpProto *proto, OpAttrChecker *op_checker) \
AddInput("X", "Input of " #OP_NAME "operator"); \
: ::paddle::framework::OpProtoAndCheckerMaker(proto, op_checker) { \
AddOutput("Out", "Output of" #OP_NAME "operator"); \
AddInput("X", "Input of " #OP_NAME "operator"); \
AddAttr<bool>("use_mkldnn", \
AddOutput("Out", "Output of" #OP_NAME "operator"); \
"(bool, default false) Only used in mkldnn kernel") \
AddAttr<bool>("use_mkldnn", \
.SetDefault(false); \
"(bool, default false) Only used in mkldnn kernel") \
AddComment(#OP_COMMENT); \
.SetDefault(false); \
} \
AddComment(#OP_COMMENT); \
}
} \
};
#define REGISTER_ACTIVATION_OP_GRAD_MAKER(OP_NAME, KERNEL_TYPE) \
class OP_NAME##GradMaker : public framework::SingleGradOpDescMaker { \
#define REGISTER_ACTIVATION_OP_GRAD_MAKER(OP_NAME, KERNEL_TYPE) \
public: \
class OP_NAME##GradMaker \
using framework::SingleGradOpDescMaker::SingleGradOpDescMaker; \
: public ::paddle::framework::SingleGradOpDescMaker { \
\
public: \
protected: \
using ::paddle::framework::SingleGradOpDescMaker::SingleGradOpDescMaker; \
std::unique_ptr<framework::OpDesc> Apply() const override { \
\
auto *op = new framework::OpDesc(); \
protected: \
op->SetType(#KERNEL_TYPE "_grad"); \
std::unique_ptr<::paddle::framework::OpDesc> Apply() const override { \
op->SetInput("Out", Output("Out")); \
auto *op = new ::paddle::framework::OpDesc(); \
op->SetInput(framework::GradVarName("Out"), OutputGrad("Out")); \
op->SetType(#KERNEL_TYPE "_grad"); \
\
op->SetInput("Out", Output("Out")); \
op->SetAttrMap(Attrs()); \
op->SetInput(::paddle::framework::GradVarName("Out"), \
\
OutputGrad("Out")); \
op->SetOutput(framework::GradVarName("X"), InputGrad("X")); \
\
return std::unique_ptr<framework::OpDesc>(op); \
op->SetAttrMap(Attrs()); \
} \
\
}
op->SetOutput(::paddle::framework::GradVarName("X"), InputGrad("X")); \
return std::unique_ptr<::paddle::framework::OpDesc>(op); \
} \
};
class
ActivationOp
:
public
framework
::
OperatorWithKernel
{
class
ActivationOp
:
public
framework
::
OperatorWithKernel
{
public:
public:
...
@@ -449,70 +453,67 @@ REGISTER_ACTIVATION_OP_MAKER(Square, SquareDoc);
...
@@ -449,70 +453,67 @@ REGISTER_ACTIVATION_OP_MAKER(Square, SquareDoc);
REGISTER_ACTIVATION_OP_MAKER
(
Softplus
,
SoftplusDoc
);
REGISTER_ACTIVATION_OP_MAKER
(
Softplus
,
SoftplusDoc
);
REGISTER_ACTIVATION_OP_MAKER
(
Softsign
,
SoftsignDoc
);
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
(
Sigmoid
,
sigmoid
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Exp
,
exp
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Relu
,
relu
);
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
(
Tanh
,
tanh
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Sqrt
,
sqrt
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Ceil
,
ceil
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Ceil
,
ceil
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Floor
,
floor
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Floor
,
floor
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Reciprocal
,
reciprocal
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Sqrt
,
sqrt
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
Relu6
,
relu6
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
SoftRelu
,
soft_relu
);
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
);
REGISTER_ACTIVATION_OP_GRAD_MAKER
(
HardSigmoid
,
hard_sigmoid
);
}
// namespace operators
}
// namespace operators
}
// namespace paddle
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
#define REGISTER_INPLACE_ACTIVATION_OP(act_type, op_name) \
void
DummyFunctor
()
{}
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);
#define FOR_EACH_INPLACE_OP_FUNCTOR(__macro) \
#define FOR_EACH_INPLACE_OP_FUNCTOR(__macro) \
__macro(
sigmoid, S
igmoid); \
__macro(
Sigmoid, s
igmoid); \
__macro(
relu, R
elu); \
__macro(
Relu, r
elu); \
__macro(
exp, E
xp); \
__macro(
Exp, e
xp); \
__macro(
tanh, T
anh); \
__macro(
Tanh, t
anh); \
__macro(
ceil, C
eil); \
__macro(
Ceil, c
eil); \
__macro(
floor, F
loor); \
__macro(
Floor, f
loor); \
__macro(
sqrt, S
qrt); \
__macro(
Sqrt, s
qrt); \
__macro(
soft_relu, SoftR
elu); \
__macro(
SoftRelu, soft_r
elu); \
__macro(
relu6, R
elu6); \
__macro(
Relu6, r
elu6); \
__macro(
reciprocal, R
eciprocal); \
__macro(
Reciprocal, r
eciprocal); \
__macro(
hard_sigmoid, HardS
igmoid);
__macro(
HardSigmoid, hard_s
igmoid);
#define FOR_EACH_OP_FUNCTOR(__macro) \
#define FOR_EACH_OP_FUNCTOR(__macro) \
__macro(logsigmoid, LogSigmoid); \
__macro(LogSigmoid, logsigmoid); \
__macro(softshrink, SoftShrink); \
__macro(SoftShrink, softshrink); \
__macro(abs, Abs); \
__macro(Abs, abs); \
__macro(cos, Cos); \
__macro(Cos, cos); \
__macro(sin, Sin); \
__macro(Sin, sin); \
__macro(round, Round); \
__macro(Round, round); \
__macro(log, Log); \
__macro(Log, log); \
__macro(square, Square); \
__macro(Square, square); \
__macro(brelu, BRelu); \
__macro(BRelu, brelu); \
__macro(pow, Pow); \
__macro(Pow, pow); \
__macro(stanh, STanh); \
__macro(STanh, stanh); \
__macro(softplus, Softplus); \
__macro(Softplus, softplus); \
__macro(softsign, Softsign); \
__macro(Softsign, softsign); \
__macro(leaky_relu, LeakyRelu); \
__macro(LeakyRelu, leaky_relu); \
__macro(tanh_shrink, TanhShrink); \
__macro(TanhShrink, tanh_shrink); \
__macro(elu, ELU); \
__macro(ELU, elu); \
__macro(hard_shrink, HardShrink); \
__macro(HardShrink, hard_shrink); \
__macro(swish, Swish); \
__macro(Swish, swish); \
__macro(thresholded_relu, ThresholdedRelu);
__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) \
#define REGISTER_ACTIVATION_CPU_KERNEL(act_type, functor, grad_functor) \
REGISTER_OP_CPU_KERNEL( \
REGISTER_OP_CPU_KERNEL( \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录