Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle-Lite
提交
b7f6ed3d
P
Paddle-Lite
项目概览
PaddlePaddle
/
Paddle-Lite
通知
331
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看板
提交
b7f6ed3d
编写于
12月 25, 2019
作者:
L
Liu Yiqun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize the InferShape of fc, gru and lookup_table.
上级
14e04200
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
30 addition
and
31 deletion
+30
-31
lite/core/tensor.cc
lite/core/tensor.cc
+5
-3
lite/core/tensor.h
lite/core/tensor.h
+1
-4
lite/kernels/x86/fc_compute.h
lite/kernels/x86/fc_compute.h
+5
-5
lite/operators/fc_op.cc
lite/operators/fc_op.cc
+7
-6
lite/operators/gru_op.cc
lite/operators/gru_op.cc
+7
-5
lite/operators/lookup_table_op.cc
lite/operators/lookup_table_op.cc
+5
-8
未找到文件。
lite/core/tensor.cc
浏览文件 @
b7f6ed3d
...
@@ -47,9 +47,11 @@ value_type DDimLite::count(int start, int end) const {
...
@@ -47,9 +47,11 @@ value_type DDimLite::count(int start, int end) const {
DDimLite
DDimLite
::
Slice
(
int
start
,
int
end
)
const
{
DDimLite
DDimLite
::
Slice
(
int
start
,
int
end
)
const
{
start
=
std
::
max
(
start
,
0
);
start
=
std
::
max
(
start
,
0
);
end
=
std
::
min
(
end
,
static_cast
<
int
>
(
data_
.
size
()));
end
=
std
::
min
(
end
,
static_cast
<
int
>
(
data_
.
size
()));
value_type
arr
[
kMaxDimLength
];
DDimLite
new_dim
(
end
-
start
);
memcpy
(
arr
,
data_
.
data
()
+
start
,
(
end
-
start
)
*
sizeof
(
value_type
));
for
(
int
i
=
start
;
i
<
end
;
++
i
)
{
return
DDimLite
(
arr
,
end
-
start
);
new_dim
[
i
-
start
]
=
data_
[
i
];
}
return
new_dim
;
}
}
std
::
string
DDimLite
::
repr
()
const
{
std
::
string
DDimLite
::
repr
()
const
{
...
...
lite/core/tensor.h
浏览文件 @
b7f6ed3d
...
@@ -73,10 +73,7 @@ class DDimLite {
...
@@ -73,10 +73,7 @@ class DDimLite {
DDimLite
()
=
default
;
DDimLite
()
=
default
;
explicit
DDimLite
(
const
std
::
vector
<
value_type
>
&
x
)
{
ConstructFrom
(
x
);
}
explicit
DDimLite
(
const
std
::
vector
<
value_type
>
&
x
)
{
ConstructFrom
(
x
);
}
explicit
DDimLite
(
const
value_type
*
arr
,
size_t
size
)
{
explicit
DDimLite
(
size_t
size
)
{
data_
.
resize
(
size
);
}
data_
.
resize
(
size
);
memcpy
(
data_
.
data
(),
arr
,
data_
.
size
()
*
sizeof
(
value_type
));
}
void
ConstructFrom
(
const
std
::
vector
<
value_type
>
&
x
)
{
void
ConstructFrom
(
const
std
::
vector
<
value_type
>
&
x
)
{
data_
.
resize
(
x
.
size
());
data_
.
resize
(
x
.
size
());
...
...
lite/kernels/x86/fc_compute.h
浏览文件 @
b7f6ed3d
...
@@ -83,12 +83,12 @@ class FCFunctor {
...
@@ -83,12 +83,12 @@ class FCFunctor {
// NOTE: here need to mutable_data for temporary Tensor X1 and Y1,
// NOTE: here need to mutable_data for temporary Tensor X1 and Y1,
// the overhead is unmeasured.
// the overhead is unmeasured.
lite
::
Tensor
X1
;
Tensor
X1
;
X1
.
Resize
(
{
M
*
KK
}
);
X1
.
Resize
(
std
::
vector
<
int64_t
>
({
M
*
KK
})
);
T
*
X1_data
=
X1
.
mutable_data
<
T
>
();
T
*
X1_data
=
X1
.
mutable_data
<
T
>
();
lite
::
Tensor
Y1
;
Tensor
Y1
;
Y1
.
Resize
(
{
M
*
(
N
+
4
)}
);
Y1
.
Resize
(
std
::
vector
<
int64_t
>
({
M
*
NN
})
);
Y1_data
=
Y1
.
mutable_data
<
T
>
();
Y1_data
=
Y1
.
mutable_data
<
T
>
();
auto
parallel_memcpy_x
=
[
&
](
int64_t
begin
,
int64_t
end
)
{
auto
parallel_memcpy_x
=
[
&
](
int64_t
begin
,
int64_t
end
)
{
...
@@ -115,7 +115,7 @@ class FCFunctor {
...
@@ -115,7 +115,7 @@ class FCFunctor {
if
(
!
B
)
{
if
(
!
B
)
{
auto
parallel_memcpy_y
=
[
&
](
int64_t
begin
,
int64_t
end
)
{
auto
parallel_memcpy_y
=
[
&
](
int64_t
begin
,
int64_t
end
)
{
for
(
int64_t
i
=
begin
;
i
<
end
;
i
++
)
{
for
(
int64_t
i
=
begin
;
i
<
end
;
i
++
)
{
memcpy
(
Y
+
i
*
N
,
Y1_data
+
i
*
(
N
+
4
)
,
N
*
sizeof
(
T
));
memcpy
(
Y
+
i
*
N
,
Y1_data
+
i
*
NN
,
N
*
sizeof
(
T
));
}
}
};
};
lite
::
x86
::
RunParallelFor
(
0
,
M
,
parallel_memcpy_y
);
lite
::
x86
::
RunParallelFor
(
0
,
M
,
parallel_memcpy_y
);
...
...
lite/operators/fc_op.cc
浏览文件 @
b7f6ed3d
...
@@ -49,16 +49,17 @@ bool FcOpLite::CheckShape() const {
...
@@ -49,16 +49,17 @@ bool FcOpLite::CheckShape() const {
}
}
bool
FcOpLite
::
InferShape
()
const
{
bool
FcOpLite
::
InferShape
()
const
{
const
auto
input_dims
=
param_
.
input
->
dims
();
const
auto
&
input_dims
=
param_
.
input
->
dims
();
const
auto
w_dims
=
param_
.
w
->
dims
();
const
auto
&
w_dims
=
param_
.
w
->
dims
();
int
in_num_col_dims
=
param_
.
in_num_col_dims
;
// Set output dims
// Set output dims
std
::
vector
<
int64_t
>
output_dims
(
param_
.
in_num_col_dims
+
1
,
0
);
DDim
output_dims
(
in_num_col_dims
+
1
);
for
(
int
i
=
0
;
i
<
param_
.
in_num_col_dims
;
++
i
)
{
for
(
int
i
=
0
;
i
<
in_num_col_dims
;
++
i
)
{
output_dims
[
i
]
=
input_dims
[
i
];
output_dims
[
i
]
=
input_dims
[
i
];
}
}
output_dims
.
back
()
=
w_dims
[
1
];
output_dims
[
in_num_col_dims
]
=
w_dims
[
1
];
param_
.
output
->
Resize
(
lite
::
DDim
(
output_dims
)
);
param_
.
output
->
Resize
(
output_dims
);
// share LoD
// share LoD
// param_.output->set_lod(param_.input->lod());
// param_.output->set_lod(param_.input->lod());
...
...
lite/operators/gru_op.cc
浏览文件 @
b7f6ed3d
...
@@ -52,15 +52,17 @@ bool GRUOpLite::CheckShape() const {
...
@@ -52,15 +52,17 @@ bool GRUOpLite::CheckShape() const {
}
}
bool
GRUOpLite
::
InferShape
()
const
{
bool
GRUOpLite
::
InferShape
()
const
{
auto
input_dims
=
param_
.
input
->
dims
();
auto
&
input_dims
=
param_
.
input
->
dims
();
auto
weight_dims
=
param_
.
weight
->
dims
();
auto
&
weight_dims
=
param_
.
weight
->
dims
();
int
frame_size
=
weight_dims
[
0
];
int
frame_size
=
weight_dims
[
0
];
auto
batch_size
=
input_dims
[
0
];
auto
batch_size
=
input_dims
[
0
];
param_
.
batch_gate
->
Resize
(
input_dims
);
param_
.
batch_gate
->
Resize
(
input_dims
);
param_
.
batch_reset_hidden_prev
->
Resize
(
lite
::
DDim
({
batch_size
,
frame_size
}));
param_
.
batch_hidden
->
Resize
(
lite
::
DDim
({
batch_size
,
frame_size
}));
auto
out_dims
=
DDim
({
batch_size
,
frame_size
});
param_
.
hidden
->
Resize
(
lite
::
DDim
({
batch_size
,
frame_size
}));
param_
.
batch_reset_hidden_prev
->
Resize
(
out_dims
);
param_
.
batch_hidden
->
Resize
(
out_dims
);
param_
.
hidden
->
Resize
(
out_dims
);
*
(
param_
.
hidden
->
mutable_lod
())
=
param_
.
input
->
lod
();
*
(
param_
.
hidden
->
mutable_lod
())
=
param_
.
input
->
lod
();
return
true
;
return
true
;
...
...
lite/operators/lookup_table_op.cc
浏览文件 @
b7f6ed3d
...
@@ -37,17 +37,14 @@ bool LookupTableOpLite::CheckShape() const {
...
@@ -37,17 +37,14 @@ bool LookupTableOpLite::CheckShape() const {
}
}
bool
LookupTableOpLite
::
InferShape
()
const
{
bool
LookupTableOpLite
::
InferShape
()
const
{
auto
table_dims
=
param_
.
W
->
dims
();
auto
&
table_dims
=
param_
.
W
->
dims
();
auto
ids_dims
=
param_
.
Ids
->
dims
();
auto
&
ids_dims
=
param_
.
Ids
->
dims
();
auto
out_dims
=
ids_dims
;
int
ids_rank
=
ids_dims
.
size
();
int
ids_rank
=
ids_dims
.
size
();
out_dims
[
ids_rank
-
1
]
=
table_dims
[
1
];
std
::
vector
<
int64_t
>
out_dims
;
param_
.
Out
->
Resize
(
out_dims
);
for
(
int
i
=
0
;
i
<
ids_rank
-
1
;
++
i
)
{
out_dims
.
push_back
(
ids_dims
[
i
]);
}
out_dims
.
push_back
(
table_dims
[
1
]);
param_
.
Out
->
Resize
(
lite
::
DDim
{
out_dims
});
param_
.
Out
->
set_lod
(
param_
.
Ids
->
lod
());
param_
.
Out
->
set_lod
(
param_
.
Ids
->
lod
());
return
true
;
return
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录