Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
56c1f666
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
337
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看板
提交
56c1f666
编写于
5月 14, 2020
作者:
D
dingminghui
提交者:
jackzhang235
5月 21, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix(mlu): fix unittest error caused by cancelling expanding tensor to 4 dims
上级
cf688607
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
47 addition
and
34 deletion
+47
-34
lite/kernels/mlu/bridges/batch_norm_op.cc
lite/kernels/mlu/bridges/batch_norm_op.cc
+9
-3
lite/kernels/mlu/bridges/conv_op.cc
lite/kernels/mlu/bridges/conv_op.cc
+13
-15
lite/kernels/mlu/bridges/dropout_op.cc
lite/kernels/mlu/bridges/dropout_op.cc
+5
-5
lite/kernels/mlu/bridges/fc_op.cc
lite/kernels/mlu/bridges/fc_op.cc
+6
-6
lite/kernels/mlu/bridges/fc_op_test.cc
lite/kernels/mlu/bridges/fc_op_test.cc
+3
-3
lite/kernels/mlu/bridges/layout_op.cc
lite/kernels/mlu/bridges/layout_op.cc
+2
-0
lite/kernels/mlu/bridges/softmax_op.cc
lite/kernels/mlu/bridges/softmax_op.cc
+9
-2
未找到文件。
lite/kernels/mlu/bridges/batch_norm_op.cc
浏览文件 @
56c1f666
...
@@ -48,18 +48,24 @@ int BatchNormConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -48,18 +48,24 @@ int BatchNormConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto
mean
=
scope
->
FindVar
(
mean_var_name
)
->
GetMutable
<
Tensor
>
();
auto
mean
=
scope
->
FindVar
(
mean_var_name
)
->
GetMutable
<
Tensor
>
();
auto
mean_dims
=
mean
->
dims
().
Vectorize
();
auto
mean_dims
=
mean
->
dims
().
Vectorize
();
if
(
mean_dims
.
size
()
<
4
)
{
mean_dims
.
insert
(
mean_dims
.
begin
(),
4
-
mean_dims
.
size
(),
1
);
}
auto
mean_tensor
=
graph
->
AddNode
(
auto
mean_tensor
=
graph
->
AddNode
(
mean_var_name
,
mean_dims
,
CNML_CONST
,
CNML_
CNHW
,
graph
->
FPType
());
mean_var_name
,
mean_dims
,
CNML_CONST
,
CNML_
NHWC
,
graph
->
FPType
());
auto
variance
=
scope
->
FindVar
(
variance_var_name
)
->
GetMutable
<
Tensor
>
();
auto
variance
=
scope
->
FindVar
(
variance_var_name
)
->
GetMutable
<
Tensor
>
();
auto
variance_dims
=
variance
->
dims
().
Vectorize
();
auto
variance_dims
=
variance
->
dims
().
Vectorize
();
if
(
variance_dims
.
size
()
<
4
)
{
variance_dims
.
insert
(
variance_dims
.
begin
(),
4
-
variance_dims
.
size
(),
1
);
}
auto
variance_tensor
=
graph
->
AddNode
(
auto
variance_tensor
=
graph
->
AddNode
(
variance_var_name
,
variance_dims
,
CNML_CONST
,
CNML_
CNHW
,
graph
->
FPType
());
variance_var_name
,
variance_dims
,
CNML_CONST
,
CNML_
NHWC
,
graph
->
FPType
());
auto
scale
=
scope
->
FindVar
(
scale_var_name
)
->
GetMutable
<
Tensor
>
();
auto
scale
=
scope
->
FindVar
(
scale_var_name
)
->
GetMutable
<
Tensor
>
();
auto
bias
=
scope
->
FindVar
(
bias_var_name
)
->
GetMutable
<
Tensor
>
();
auto
bias
=
scope
->
FindVar
(
bias_var_name
)
->
GetMutable
<
Tensor
>
();
int
co
=
static_cast
<
int
>
(
mean_dims
[
0
]);
int
co
=
static_cast
<
int
>
(
mean_dims
[
3
]);
std
::
vector
<
float
>
variance_trans
(
co
);
std
::
vector
<
float
>
variance_trans
(
co
);
std
::
vector
<
float
>
mean_trans
(
co
);
std
::
vector
<
float
>
mean_trans
(
co
);
...
...
lite/kernels/mlu/bridges/conv_op.cc
浏览文件 @
56c1f666
...
@@ -87,6 +87,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -87,6 +87,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
is_group_mode
=
false
;
is_group_mode
=
false
;
}
}
auto
input_tensor
=
graph
->
GetNode
(
input_var_name
);
const
auto
output_tensor
=
graph
->
AddNode
(
const
auto
output_tensor
=
graph
->
AddNode
(
output_var_name
,
output_shape
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
output_var_name
,
output_shape
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
std
::
vector
<
int64_t
>
cnml_filter_shape
=
{
std
::
vector
<
int64_t
>
cnml_filter_shape
=
{
...
@@ -142,7 +143,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -142,7 +143,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
std
::
vector
<
int64_t
>
bias_shape
;
std
::
vector
<
int64_t
>
bias_shape
;
if
(
bias_data_size
==
oc
)
{
if
(
bias_data_size
==
oc
)
{
// 0: {oc}
// 0: {oc}
bias_shape
=
{
oc
};
bias_shape
=
{
1
,
1
,
1
,
oc
};
}
else
if
(
bias_data_size
==
output_data_size
/
bs
)
{
}
else
if
(
bias_data_size
==
output_data_size
/
bs
)
{
LOG
(
FATAL
)
<<
"Unsupported ... ..."
;
LOG
(
FATAL
)
<<
"Unsupported ... ..."
;
// 1: {1, oc, oh, ow}
// 1: {1, oc, oh, ow}
...
@@ -156,11 +157,8 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -156,11 +157,8 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
<<
" isn't supported in conv2d Op when output dimension is "
<<
" isn't supported in conv2d Op when output dimension is "
<<
output_dims
;
<<
output_dims
;
}
}
bias_tensor
=
graph
->
AddNode
(
bias_var_name
,
bias_tensor
=
graph
->
AddNode
(
bias_dims
.
Vectorize
(),
bias_var_name
,
bias_shape
,
CNML_CONST
,
CNML_NHWC
,
graph
->
FPType
());
CNML_CONST
,
CNML_CNHW
,
graph
->
FPType
());
graph
->
BindConstData
(
bias_var_name
,
bias
);
graph
->
BindConstData
(
bias_var_name
,
bias
);
}
}
...
@@ -184,14 +182,14 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -184,14 +182,14 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
paddings
[
0
],
paddings
[
0
],
paddings
[
0
]));
paddings
[
0
]));
const
auto
mean_tensor
=
graph
->
AddNode
(
"first_conv_mean_tensor"
,
const
auto
mean_tensor
=
graph
->
AddNode
(
"first_conv_mean_tensor"
,
std
::
vector
<
int64_t
>
{
3
},
std
::
vector
<
int64_t
>
{
1
,
1
,
1
,
3
},
CNML_CONST
,
CNML_CONST
,
CNML_
CNHW
,
CNML_
NHWC
,
graph
->
FPType
());
graph
->
FPType
());
const
auto
std_tensor
=
graph
->
AddNode
(
"first_conv_std_tensor"
,
const
auto
std_tensor
=
graph
->
AddNode
(
"first_conv_std_tensor"
,
std
::
vector
<
int64_t
>
{
3
},
std
::
vector
<
int64_t
>
{
1
,
1
,
1
,
3
},
CNML_CONST
,
CNML_CONST
,
CNML_
CNHW
,
CNML_
NHWC
,
graph
->
FPType
());
graph
->
FPType
());
graph
->
BindConstRawData
(
"first_conv_mean_tensor"
,
graph
->
BindConstRawData
(
"first_conv_mean_tensor"
,
...
@@ -203,11 +201,11 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -203,11 +201,11 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
3
,
3
,
false
);
false
);
graph
->
GetNode
(
input_var_name
)
->
set_mlu_dtype
(
CNML_DATA_UINT8
);
input_tensor
->
set_mlu_dtype
(
CNML_DATA_UINT8
);
CNML_CALL
(
cnmlCreateConvFirstOpForward
(
CNML_CALL
(
cnmlCreateConvFirstOpForward
(
&
conv_op
,
&
conv_op
,
conv_param
,
conv_param
,
graph
->
GetNode
(
input_var_name
)
->
mlu_tensor
(),
input_tensor
->
mlu_tensor
(),
mean_tensor
->
mlu_tensor
(),
mean_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
...
@@ -224,7 +222,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -224,7 +222,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
CNML_CALL
(
cnmlCreateConvDepthwiseOpForward
(
CNML_CALL
(
cnmlCreateConvDepthwiseOpForward
(
&
conv_op
,
&
conv_op
,
conv_depthwise_param
,
conv_depthwise_param
,
graph
->
GetNode
(
input_var_name
)
->
mlu_tensor
(),
input_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
));
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
));
...
@@ -241,7 +239,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -241,7 +239,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
CNML_CALL
(
cnmlCreateConvGroupOpForward
(
CNML_CALL
(
cnmlCreateConvGroupOpForward
(
&
conv_op
,
&
conv_op
,
conv_param
,
conv_param
,
graph
->
GetNode
(
input_var_name
)
->
mlu_tensor
(),
input_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
,
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
,
...
@@ -263,7 +261,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -263,7 +261,7 @@ int ConvConverter(void* ctx, OpLite* op, KernelBase* kernel) {
CNML_CALL
(
cnmlCreateConvOpForward
(
CNML_CALL
(
cnmlCreateConvOpForward
(
&
conv_op
,
&
conv_op
,
conv_param
,
conv_param
,
graph
->
GetNode
(
input_var_name
)
->
mlu_tensor
(),
input_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
output_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
filter_tensor
->
mlu_tensor
(),
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
));
bias_tensor
?
bias_tensor
->
mlu_tensor
()
:
nullptr
));
...
...
lite/kernels/mlu/bridges/dropout_op.cc
浏览文件 @
56c1f666
...
@@ -33,15 +33,15 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -33,15 +33,15 @@ int DropoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
// Create act node and set params from op
// Create act node and set params from op
auto
x_var_name
=
op_info
->
Input
(
"X"
).
front
();
auto
x_var_name
=
op_info
->
Input
(
"X"
).
front
();
auto
out_var_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
out_var_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
mask_var_name
=
op_info
->
Output
(
"Mask"
).
front
();
/* auto mask_var_name = op_info->Output("Mask").front(); */
auto
output
=
scope
->
FindVar
(
out_var_name
)
->
GetMutable
<
Tensor
>
();
auto
output
=
scope
->
FindVar
(
out_var_name
)
->
GetMutable
<
Tensor
>
();
auto
output_dims
=
output
->
dims
().
Vectorize
();
auto
output_dims
=
output
->
dims
().
Vectorize
();
auto
output_tensor
=
graph
->
AddNode
(
auto
output_tensor
=
graph
->
AddNode
(
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
auto
mask
=
scope
->
FindVar
(
mask_var_name
)
->
GetMutable
<
Tensor
>
();
/* auto mask = scope->FindVar(mask_var_name)->GetMutable<Tensor>(); */
auto
mask_dims
=
mask
->
dims
().
Vectorize
();
/* auto mask_dims = mask->dims().Vectorize(); */
auto
mask_tensor
=
graph
->
AddNode
(
/* auto mask_tensor = graph->AddNode( */
mask_var_name
,
mask_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
/* mask_var_name, mask_dims, CNML_TENSOR, CNML_NCHW, graph->FPType()); */
// is_test is true by default
// is_test is true by default
// if(op_info->HasAttr("is_test")){
// if(op_info->HasAttr("is_test")){
...
...
lite/kernels/mlu/bridges/fc_op.cc
浏览文件 @
56c1f666
...
@@ -82,15 +82,15 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -82,15 +82,15 @@ int FCConverter(void* ctx, OpLite* op, KernelBase* kernel) {
if
(
HasInputArg
(
op_info
,
scope
,
"Bias"
))
{
if
(
HasInputArg
(
op_info
,
scope
,
"Bias"
))
{
bias_var_name
=
op_info
->
Input
(
"Bias"
).
front
();
bias_var_name
=
op_info
->
Input
(
"Bias"
).
front
();
auto
bias
=
scope
->
FindVar
(
bias_var_name
)
->
GetMutable
<
lite
::
Tensor
>
();
auto
bias
=
scope
->
FindVar
(
bias_var_name
)
->
GetMutable
<
lite
::
Tensor
>
();
auto
bias_dims
=
bias
->
dims
();
auto
bias_dims
=
bias
->
dims
()
.
Vectorize
()
;
CHECK
(
!
graph
->
HasNode
(
bias_var_name
));
CHECK
(
!
graph
->
HasNode
(
bias_var_name
));
if
(
bias_dims
.
size
()
<
4u
)
{
bias_dims
.
insert
(
bias_dims
.
begin
(),
4
-
bias_dims
.
size
(),
1
);
}
// CHECK_EQ(bias_dims.production(), n);
// CHECK_EQ(bias_dims.production(), n);
bias_tensor
=
graph
->
AddNode
(
bias_var_name
,
bias_tensor
=
graph
->
AddNode
(
bias_dims
.
Vectorize
(),
bias_var_name
,
bias_dims
,
CNML_CONST
,
CNML_NHWC
,
graph
->
FPType
());
CNML_CONST
,
CNML_CNHW
,
graph
->
FPType
());
graph
->
BindConstData
(
bias_var_name
,
bias
);
graph
->
BindConstData
(
bias_var_name
,
bias
);
}
}
cnmlBaseOp_t
fc_op
;
cnmlBaseOp_t
fc_op
;
...
...
lite/kernels/mlu/bridges/fc_op_test.cc
浏览文件 @
56c1f666
...
@@ -175,9 +175,9 @@ void test_fc(const std::vector<int64_t>& input_shape,
...
@@ -175,9 +175,9 @@ void test_fc(const std::vector<int64_t>& input_shape,
TEST
(
MLUBridges
,
fc
)
{
TEST
(
MLUBridges
,
fc
)
{
for
(
bool
use_bias
:
{
true
,
false
})
{
for
(
bool
use_bias
:
{
true
,
false
})
{
//
test_fc({1, 8, 8, 1}, {64, 4}, 1, use_bias);
test_fc
({
1
,
8
,
8
,
1
},
{
64
,
4
},
1
,
use_bias
);
//
test_fc({1, 5, 5, 1}, {25, 7}, 1, use_bias);
test_fc
({
1
,
5
,
5
,
1
},
{
25
,
7
},
1
,
use_bias
);
//
test_fc({1, 4, 1, 1}, {4, 8}, 1, use_bias);
test_fc
({
1
,
4
,
1
,
1
},
{
4
,
8
},
1
,
use_bias
);
test_fc
({
1
,
1024
,
1
,
1
},
{
1024
,
32
},
1
,
use_bias
);
test_fc
({
1
,
1024
,
1
,
1
},
{
1024
,
32
},
1
,
use_bias
);
}
}
}
}
...
...
lite/kernels/mlu/bridges/layout_op.cc
浏览文件 @
56c1f666
...
@@ -61,6 +61,7 @@ int LayoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -61,6 +61,7 @@ int LayoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
}
}
output_tensor
=
graph
->
AddNode
(
output_tensor
=
graph
->
AddNode
(
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
VLOG
(
3
)
<<
"layout transpose nchw to nhwc"
<<
std
::
endl
;
}
else
{
}
else
{
switch
(
x_dims
.
size
())
{
switch
(
x_dims
.
size
())
{
case
2
:
case
2
:
...
@@ -78,6 +79,7 @@ int LayoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -78,6 +79,7 @@ int LayoutConverter(void* ctx, OpLite* op, KernelBase* kernel) {
default:
default:
CHECK
(
0
)
<<
"Unsupport shpae"
;
CHECK
(
0
)
<<
"Unsupport shpae"
;
}
}
VLOG
(
3
)
<<
"layout transpose nhwc to nchw"
<<
std
::
endl
;
output_tensor
=
graph
->
AddNode
(
out_var_name
,
output_tensor
=
graph
->
AddNode
(
out_var_name
,
output_dims
,
output_dims
,
CNML_TENSOR
,
CNML_TENSOR
,
...
...
lite/kernels/mlu/bridges/softmax_op.cc
浏览文件 @
56c1f666
...
@@ -35,9 +35,16 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -35,9 +35,16 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) {
auto
out_var_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
out_var_name
=
op_info
->
Output
(
"Out"
).
front
();
auto
output
=
scope
->
FindVar
(
out_var_name
)
->
GetMutable
<
Tensor
>
();
auto
output
=
scope
->
FindVar
(
out_var_name
)
->
GetMutable
<
Tensor
>
();
auto
output_dims
=
output
->
dims
().
Vectorize
();
auto
output_dims
=
output
->
dims
().
Vectorize
();
auto
x_shape
=
scope
->
FindVar
(
x_var_name
)
->
GetMutable
<
Tensor
>
()
->
dims
().
Vectorize
();
// nchw axis to nhwc aixs
// nchw axis to nhwc aixs
int
nchw_to_nhwc_aixs_map
[
4
]
=
{
0
,
3
,
1
,
2
};
std
::
vector
<
int
>
nchw2nhwc_axis
(
x_shape
.
size
());
nchw2nhwc_axis
[
0
]
=
0
;
if
(
x_shape
.
size
()
>
1
)
nchw2nhwc_axis
[
1
]
=
x_shape
.
size
()
-
1
;
for
(
size_t
i
=
2
;
i
<
x_shape
.
size
();
++
i
)
{
nchw2nhwc_axis
[
i
]
=
i
-
1
;
}
int
axis
=
1
;
int
axis
=
1
;
if
(
op_info
->
HasAttr
(
"axis"
))
{
if
(
op_info
->
HasAttr
(
"axis"
))
{
axis
=
op_info
->
GetAttr
<
int
>
(
"axis"
);
axis
=
op_info
->
GetAttr
<
int
>
(
"axis"
);
...
@@ -45,7 +52,7 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) {
...
@@ -45,7 +52,7 @@ int SoftmaxConverter(void* ctx, OpLite* op, KernelBase* kernel) {
axis
=
output_dims
.
size
()
+
axis
;
axis
=
output_dims
.
size
()
+
axis
;
}
}
}
}
int
nhwc_axis
=
nchw
_to_nhwc_aixs_map
[
axis
];
int
nhwc_axis
=
nchw
2nhwc_axis
[
axis
];
auto
output_tensor
=
graph
->
AddNode
(
auto
output_tensor
=
graph
->
AddNode
(
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
out_var_name
,
output_dims
,
CNML_TENSOR
,
CNML_NCHW
,
graph
->
FPType
());
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录