Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
8493f20e
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8493f20e
编写于
11月 27, 2019
作者:
G
GaoWei8
提交者:
Yiqun Liu
11月 27, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Polish the codes of fc when needs padding (#21378)
test=develop
上级
5d7d5482
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
14 deletion
+14
-14
paddle/fluid/framework/ir/fc_fuse_pass.cc
paddle/fluid/framework/ir/fc_fuse_pass.cc
+3
-3
paddle/fluid/operators/math/fc.cc
paddle/fluid/operators/math/fc.cc
+11
-11
未找到文件。
paddle/fluid/framework/ir/fc_fuse_pass.cc
浏览文件 @
8493f20e
...
...
@@ -94,20 +94,20 @@ int FCFusePass::ApplyFCPattern(Graph* graph, bool with_relu) const {
auto
*
weight
=
scope
->
FindVar
(
w
->
Name
())
->
GetMutable
<
LoDTensor
>
();
auto
place
=
weight
->
place
();
bool
use_gpu
=
Get
<
bool
>
(
"use_gpu"
);
auto
weight_data
=
weight
->
data
<
float
>
();
auto
*
weight_data
=
weight
->
data
<
float
>
();
auto
weight_dims
=
weight
->
dims
();
int
weight_num
=
product
(
weight_dims
);
int
w_h
=
weight_dims
[
0
];
int
w_w
=
weight_dims
[
1
];
if
(
!
use_gpu
)
{
if
(
w_h
%
128
==
0
&&
w_w
%
128
==
0
)
{
float
*
weight_data_tmp
=
new
float
[
weight_num
];
auto
*
weight_data_tmp
=
new
float
[
weight_num
];
for
(
int
i
=
0
;
i
<
w_h
;
i
++
)
{
memcpy
(
weight_data_tmp
+
i
*
w_w
,
weight_data
+
i
*
w_w
,
w_w
*
sizeof
(
float
));
}
weight
->
Resize
(
DDim
{
weight_dims
[
0
]
+
4
,
weight_dims
[
1
]
+
4
});
auto
weight_data_new
=
auto
*
weight_data_new
=
weight
->
mutable_data
<
float
>
(
platform
::
CPUPlace
());
for
(
int
i
=
0
;
i
<
w_h
;
i
++
)
{
memcpy
(
weight_data_new
+
i
*
(
w_w
+
4
),
weight_data_tmp
+
i
*
w_w
,
...
...
paddle/fluid/operators/math/fc.cc
浏览文件 @
8493f20e
...
...
@@ -30,28 +30,28 @@ class FCFunctor<platform::CPUDeviceContext, T> {
auto
blas
=
math
::
GetBlas
<
platform
::
CPUDeviceContext
,
T
>
(
context
);
framework
::
Tensor
Y1
;
T
*
Y1_data
=
nullptr
;
if
(
N
%
128
==
0
&&
K
%
128
==
0
)
{
auto
padding
=
N
%
128
==
0
&&
K
%
128
==
0
;
if
(
padding
)
{
const
int
NN
=
N
+
4
;
const
int
KK
=
K
+
4
;
framework
::
Tensor
X1
;
T
*
X1_data
=
X1
.
Resize
({
M
*
KK
}).
mutable_data
<
T
>
(
platform
::
CPUPlace
());
Y1_data
=
Y1
.
Resize
({
M
*
(
N
+
4
)}).
mutable_data
<
T
>
(
platform
::
CPUPlace
());
T
*
X1_data
=
X1
.
mutable_data
<
T
>
({
M
*
KK
},
platform
::
CPUPlace
());
Y1_data
=
Y1
.
mutable_data
<
T
>
({
M
*
(
N
+
4
)},
platform
::
CPUPlace
());
#ifdef PADDLE_WITH_MKLML
#pragma omp parallel for
#endif
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
memcpy
(
X1_data
+
i
*
KK
,
X
+
i
*
K
,
K
*
sizeof
(
X
[
0
]
));
memcpy
(
X1_data
+
i
*
KK
,
X
+
i
*
K
,
K
*
sizeof
(
T
));
}
framework
::
Tensor
W1
;
T
*
W1_data
=
nullptr
;
if
(
!
padding_weights
)
{
W1_data
=
W1
.
Resize
({(
K
+
4
)
*
(
N
+
4
)})
.
mutable_data
<
T
>
(
platform
::
CPUPlace
());
W1_data
=
W1
.
mutable_data
<
T
>
({(
K
+
4
)
*
(
N
+
4
)},
platform
::
CPUPlace
());
#ifdef PADDLE_WITH_MKLML
#pragma omp parallel for
#endif
for
(
int
i
=
0
;
i
<
K
;
i
++
)
{
memcpy
(
W1_data
+
i
*
NN
,
W
+
i
*
N
,
N
*
sizeof
(
W
[
0
]
));
memcpy
(
W1_data
+
i
*
NN
,
W
+
i
*
N
,
N
*
sizeof
(
T
));
}
}
blas
.
GEMM
(
false
,
false
,
M
,
N
,
K
,
static_cast
<
T
>
(
1.0
),
X1_data
,
KK
,
...
...
@@ -61,12 +61,12 @@ class FCFunctor<platform::CPUDeviceContext, T> {
blas
.
MatMul
(
M
,
N
,
K
,
X
,
W
,
Y
);
}
if
(
B
==
NULL
)
{
if
(
N
%
128
==
0
&&
K
%
128
==
0
)
{
if
(
padding
)
{
#ifdef PADDLE_WITH_MKLML
#pragma omp parallel for
#endif
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
memcpy
(
Y
+
i
*
N
,
Y1_data
+
i
*
(
N
+
4
),
N
*
sizeof
(
Y
[
0
]
));
memcpy
(
Y
+
i
*
N
,
Y1_data
+
i
*
(
N
+
4
),
N
*
sizeof
(
T
));
}
}
PADDLE_ENFORCE_EQ
(
relu
,
false
,
...
...
@@ -80,7 +80,7 @@ class FCFunctor<platform::CPUDeviceContext, T> {
.
At
(
N
);
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
T
*
dst
=
Y
+
i
*
N
;
T
*
src
=
(
N
%
128
==
0
&&
K
%
128
==
0
)
?
Y1_data
+
i
*
(
N
+
4
)
:
dst
;
T
*
src
=
(
padding
)
?
Y1_data
+
i
*
(
N
+
4
)
:
dst
;
compute
(
B
,
src
,
dst
,
N
);
}
}
else
{
...
...
@@ -92,7 +92,7 @@ class FCFunctor<platform::CPUDeviceContext, T> {
#endif
for
(
int
i
=
0
;
i
<
M
;
i
++
)
{
T
*
dst
=
Y
+
i
*
N
;
T
*
src
=
(
N
%
128
==
0
&&
K
%
128
==
0
)
?
Y1_data
+
i
*
(
N
+
4
)
:
dst
;
T
*
src
=
(
padding
)
?
Y1_data
+
i
*
(
N
+
4
)
:
dst
;
compute
(
B
,
src
,
dst
,
N
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录