Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
eb610740
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看板
未验证
提交
eb610740
编写于
2月 10, 2023
作者:
Z
zhangkaihuo
提交者:
GitHub
2月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry-pick] Fix bn performance degradation (#50382)
att, cherry-pick: #48563 , #50287
上级
59fec5d6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
5 deletion
+22
-5
paddle/phi/kernels/gpu/batch_norm_grad_kernel.cu
paddle/phi/kernels/gpu/batch_norm_grad_kernel.cu
+22
-5
未找到文件。
paddle/phi/kernels/gpu/batch_norm_grad_kernel.cu
浏览文件 @
eb610740
...
@@ -855,7 +855,8 @@ void BatchNormGradRawKernel(const Context &ctx,
...
@@ -855,7 +855,8 @@ void BatchNormGradRawKernel(const Context &ctx,
}
}
// CUDNN only support small batch size
// CUDNN only support small batch size
bool
use_native_nhwc
=
bool
use_native_nhwc
=
d_x
?
(
x_dims
.
size
()
==
4
&&
compute_format
==
DataLayout
::
kNHWC
)
d_x
?
(
x_dims
.
size
()
==
4
&&
compute_format
==
DataLayout
::
kNHWC
&&
H
*
W
>=
CUDNN_SPATIAL_THRESHOLD_EVAL
)
:
false
;
:
false
;
const
bool
use_native_kernel
=
const
bool
use_native_kernel
=
((
x_dims
.
size
()
==
2
&&
N
>=
CUDNN_PER_ACTIVATION_THRESHOLD
)
||
((
x_dims
.
size
()
==
2
&&
N
>=
CUDNN_PER_ACTIVATION_THRESHOLD
)
||
...
@@ -933,6 +934,21 @@ void BatchNormGradRawKernel(const Context &ctx,
...
@@ -933,6 +934,21 @@ void BatchNormGradRawKernel(const Context &ctx,
flag_ptr
);
flag_ptr
);
}
}
// 2. reduce_sum(x, dy, mean) => dscale, dbias
// 2. reduce_sum(x, dy, mean) => dscale, dbias
BatchNormParamType
<
T
>
*
dscale
=
nullptr
;
BatchNormParamType
<
T
>
*
dbias
=
nullptr
;
bool
with_scale
=
false
;
if
(
d_scale
&&
d_bias
)
{
dscale
=
ctx
.
template
Alloc
<
BatchNormParamType
<
T
>
>
(
d_scale
);
dbias
=
ctx
.
template
Alloc
<
BatchNormParamType
<
T
>
>
(
d_bias
);
}
else
{
DenseTensor
dscale_mem
=
phi
::
Empty
<
BatchNormParamType
<
T
>
,
Context
>
(
ctx
,
{
C
});
DenseTensor
dbias_mem
=
phi
::
Empty
<
BatchNormParamType
<
T
>
,
Context
>
(
ctx
,
{
C
});
dscale
=
dscale_mem
.
data
<
BatchNormParamType
<
T
>>
();
dbias
=
dbias_mem
.
data
<
BatchNormParamType
<
T
>>
();
}
BNBackward2DChannelLastStage2
<
T
,
block_size
>
BNBackward2DChannelLastStage2
<
T
,
block_size
>
<<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
<<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
transformed_d_y
.
template
data
<
T
>(),
transformed_d_y
.
template
data
<
T
>(),
...
@@ -944,8 +960,8 @@ void BatchNormGradRawKernel(const Context &ctx,
...
@@ -944,8 +960,8 @@ void BatchNormGradRawKernel(const Context &ctx,
H
*
W
*
D
,
H
*
W
*
D
,
epsilon
,
epsilon
,
block_data_ptr
,
block_data_ptr
,
ctx
.
template
Alloc
<
BatchNormParamType
<
T
>
>
(
d_scale
)
,
dscale
,
ctx
.
template
Alloc
<
BatchNormParamType
<
T
>
>
(
d_bias
)
,
dbias
,
flag_ptr
);
flag_ptr
);
// 3. elementwise_mul(scale, mean, inv_var, dy, dscale, dbias) => dx
// 3. elementwise_mul(scale, mean, inv_var, dy, dscale, dbias) => dx
...
@@ -954,8 +970,8 @@ void BatchNormGradRawKernel(const Context &ctx,
...
@@ -954,8 +970,8 @@ void BatchNormGradRawKernel(const Context &ctx,
transformed_d_y
.
template
data
<
T
>(),
transformed_d_y
.
template
data
<
T
>(),
transformed_x
.
template
data
<
T
>(),
transformed_x
.
template
data
<
T
>(),
scale
.
template
data
<
BatchNormParamType
<
T
>
>
(),
scale
.
template
data
<
BatchNormParamType
<
T
>
>
(),
d
_scale
->
data
<
BatchNormParamType
<
T
>>
()
,
d
scale
,
d
_bias
->
data
<
BatchNormParamType
<
T
>>
()
,
d
bias
,
mean_ptr
,
mean_ptr
,
variance_ptr
,
variance_ptr
,
C
,
C
,
...
@@ -1165,6 +1181,7 @@ void BatchNormGradRawKernel(const Context &ctx,
...
@@ -1165,6 +1181,7 @@ void BatchNormGradRawKernel(const Context &ctx,
paddle
::
platform
::
dynload
::
cudnnDestroyTensorDescriptor
(
paddle
::
platform
::
dynload
::
cudnnDestroyTensorDescriptor
(
bn_param_desc_
));
bn_param_desc_
));
#endif
#endif
}
else
{
}
else
{
const
auto
*
running_mean
=
mean
.
get_ptr
();
const
auto
*
running_mean
=
mean
.
get_ptr
();
const
auto
*
running_var
=
variance
.
get_ptr
();
const
auto
*
running_var
=
variance
.
get_ptr
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录