Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
3153a201
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
332
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
271
列表
看板
标记
里程碑
合并请求
78
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle-Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
271
Issue
271
列表
看板
标记
里程碑
合并请求
78
合并请求
78
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3153a201
编写于
3月 15, 2020
作者:
D
dingminghui
提交者:
jackzhang235
3月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(leaky_relu): support leaky_relu
上级
2042a830
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
25 addition
and
7 deletion
+25
-7
lite/kernels/mlu/bridges/act_op.cc
lite/kernels/mlu/bridges/act_op.cc
+23
-6
lite/kernels/mlu/bridges/act_op_test.cc
lite/kernels/mlu/bridges/act_op_test.cc
+2
-1
未找到文件。
lite/kernels/mlu/bridges/act_op.cc
浏览文件 @
3153a201
...
...
@@ -31,20 +31,34 @@ int ActConverter(void* ctx, OpLite* op, KernelBase* kernel) {
VLOG
(
3
)
<<
"[MLU] Converting "
+
op_type
+
"..."
;
// Create act node and set params from op
auto
fp_type
=
graph
->
FPType
();
auto
x_var_name
=
op_info
->
Input
(
"X"
).
front
();
auto
out_var_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
output
=
scope
->
FindVar
(
out_var_name
)
->
GetMutable
<
Tensor
>
();
auto
output_dims
=
output
->
dims
().
Vectorize
();
auto
output_tensor
=
graph
->
AddNode
(
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NHWC
,
graph
->
FPType
()
);
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NHWC
,
fp_type
);
CHECK
(
graph
->
HasNode
(
x_var_name
));
auto
input_tensor
=
graph
->
GetNode
(
x_var_name
);
cnmlActiveFunction_t
act_type
=
OpTypeToCNMLActType
(
op_type
);
cnmlBaseOp_t
activation_op
;
CNML_CALL
(
cnmlCreateActiveOp
(
&
activation_op
,
act_type
,
input_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
()));
if
(
op_type
==
"leaky_relu"
)
{
auto
alpha
=
op_info
->
GetAttr
<
float
>
(
"alpha"
);
std
::
vector
<
int64_t
>
shape
=
{
1
,
1
,
1
,
1
};
std
::
string
alpha_var_name
=
string_format
(
"leaky_relu_alpha_%p"
,
op
);
auto
alpha_tensor
=
graph
->
AddNode
(
alpha_var_name
,
shape
,
CNML_CONST
,
CNML_NHWC
,
fp_type
);
graph
->
BindConstRawData
(
alpha_var_name
,
&
alpha
,
1
,
true
);
CNML_CALL
(
cnmlCreatePreluOp
(
&
activation_op
,
input_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
alpha_tensor
->
mlu_tensor
()));
}
else
{
cnmlActiveFunction_t
act_type
=
OpTypeToCNMLActType
(
op_type
);
CNML_CALL
(
cnmlCreateActiveOp
(
&
activation_op
,
act_type
,
input_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
()));
}
graph
->
FuseOp
(
activation_op
);
return
SUCCESS
;
}
...
...
@@ -59,3 +73,6 @@ REGISTER_SUBGRAPH_BRIDGE(sigmoid,
paddle
::
lite
::
subgraph
::
mlu
::
ActConverter
);
REGISTER_SUBGRAPH_BRIDGE
(
relu
,
kMLU
,
paddle
::
lite
::
subgraph
::
mlu
::
ActConverter
);
REGISTER_SUBGRAPH_BRIDGE
(
tanh
,
kMLU
,
paddle
::
lite
::
subgraph
::
mlu
::
ActConverter
);
REGISTER_SUBGRAPH_BRIDGE
(
leaky_relu
,
kMLU
,
paddle
::
lite
::
subgraph
::
mlu
::
ActConverter
);
lite/kernels/mlu/bridges/act_op_test.cc
浏览文件 @
3153a201
...
...
@@ -134,7 +134,7 @@ void test_act(std::vector<int64_t> x_shape, std::string op_type) {
TEST
(
MLUBridges
,
activation
)
{
std
::
vector
<
std
::
vector
<
int64_t
>>
shapes
{{
1
},
{
2
,
3
},
{
1
,
2
,
3
,
4
}};
std
::
vector
<
std
::
string
>
types
{
"sigmoid"
,
"relu"
,
"tanh"
};
std
::
vector
<
std
::
string
>
types
{
"sigmoid"
,
"relu"
,
"tanh"
,
"leaky_relu"
};
for
(
auto
x_shape
:
shapes
)
{
for
(
auto
op_type
:
types
)
{
test_act
(
x_shape
,
op_type
);
...
...
@@ -150,3 +150,4 @@ TEST(MLUBridges, activation) {
USE_SUBGRAPH_BRIDGE
(
sigmoid
,
kMLU
)
USE_SUBGRAPH_BRIDGE
(
relu
,
kMLU
)
USE_SUBGRAPH_BRIDGE
(
tanh
,
kMLU
)
USE_SUBGRAPH_BRIDGE
(
leaky_relu
,
kMLU
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录