Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
8256f6fa
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看板
未验证
提交
8256f6fa
编写于
10月 14, 2021
作者:
Z
Zeng Jinle
提交者:
GitHub
10月 14, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix lars (#36431)
上级
3cf57646
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
31 addition
and
10 deletion
+31
-10
paddle/fluid/operators/optimizers/lars_momentum_op.cu
paddle/fluid/operators/optimizers/lars_momentum_op.cu
+31
-10
未找到文件。
paddle/fluid/operators/optimizers/lars_momentum_op.cu
浏览文件 @
8256f6fa
...
...
@@ -165,8 +165,10 @@ __global__ void L2NormKernel(
int
tid
=
threadIdx
.
x
+
blockDim
.
x
*
blockIdx
.
x
;
int
grid_stride
=
LARS_BLOCK_SIZE
*
gridDim
.
x
;
const
MT
rescale_pow
=
rescale_grad
*
rescale_grad
;
s_buffer
[
0
]
=
static_cast
<
MT
>
(
0
);
s_buffer
[
1
]
=
static_cast
<
MT
>
(
0
);
if
(
threadIdx
.
x
==
0
)
{
s_buffer
[
0
]
=
static_cast
<
MT
>
(
0
);
s_buffer
[
1
]
=
static_cast
<
MT
>
(
0
);
}
MT
p_tmp
=
static_cast
<
MT
>
(
0
);
MT
g_tmp
=
static_cast
<
MT
>
(
0
);
...
...
@@ -175,8 +177,12 @@ __global__ void L2NormKernel(
p_tmp
=
static_cast
<
MT
>
(
p_data
[
tid
]);
g_tmp
=
static_cast
<
MT
>
(
g_data
[
tid
]);
}
s_buffer
[
0
]
+=
math
::
blockReduceSum
<
MT
>
(
p_tmp
*
p_tmp
,
FINAL_MASK
);
s_buffer
[
1
]
+=
math
::
blockReduceSum
<
MT
>
(
g_tmp
*
g_tmp
,
FINAL_MASK
);
MT
tmp0
=
math
::
blockReduceSum
<
MT
>
(
p_tmp
*
p_tmp
,
FINAL_MASK
);
MT
tmp1
=
math
::
blockReduceSum
<
MT
>
(
g_tmp
*
g_tmp
,
FINAL_MASK
);
if
(
threadIdx
.
x
==
0
)
{
s_buffer
[
0
]
+=
tmp0
;
s_buffer
[
1
]
+=
tmp1
;
}
}
else
{
/* Avoid occupy too much temp buffer. Slice the whole data into 2 parts,
the front of data whose quantity is excatly multiple of grid-thread
...
...
@@ -185,8 +191,12 @@ __global__ void L2NormKernel(
p_tmp
=
static_cast
<
MT
>
(
p_data
[
tid
]);
g_tmp
=
static_cast
<
MT
>
(
g_data
[
tid
]);
tid
+=
grid_stride
;
s_buffer
[
0
]
+=
math
::
blockReduceSum
<
MT
>
(
p_tmp
*
p_tmp
,
FINAL_MASK
);
s_buffer
[
1
]
+=
math
::
blockReduceSum
<
MT
>
(
g_tmp
*
g_tmp
,
FINAL_MASK
);
MT
tmp0
=
math
::
blockReduceSum
<
MT
>
(
p_tmp
*
p_tmp
,
FINAL_MASK
);
MT
tmp1
=
math
::
blockReduceSum
<
MT
>
(
g_tmp
*
g_tmp
,
FINAL_MASK
);
if
(
threadIdx
.
x
==
0
)
{
s_buffer
[
0
]
+=
tmp0
;
s_buffer
[
1
]
+=
tmp1
;
}
__syncthreads
();
}
MT
p_val
=
0
;
...
...
@@ -195,8 +205,12 @@ __global__ void L2NormKernel(
p_val
=
static_cast
<
MT
>
(
p_data
[
tid
]);
g_val
=
static_cast
<
MT
>
(
g_data
[
tid
]);
}
s_buffer
[
0
]
+=
math
::
blockReduceSum
<
MT
>
(
p_val
*
p_val
,
FINAL_MASK
);
s_buffer
[
1
]
+=
math
::
blockReduceSum
<
MT
>
(
g_val
*
g_val
,
FINAL_MASK
);
MT
tmp0
=
math
::
blockReduceSum
<
MT
>
(
p_val
*
p_val
,
FINAL_MASK
);
MT
tmp1
=
math
::
blockReduceSum
<
MT
>
(
g_val
*
g_val
,
FINAL_MASK
);
if
(
threadIdx
.
x
==
0
)
{
s_buffer
[
0
]
+=
tmp0
;
s_buffer
[
1
]
+=
tmp1
;
}
}
__syncthreads
();
...
...
@@ -208,8 +222,15 @@ __global__ void L2NormKernel(
cg
->
sync
();
// Grid sync for writring partial result to gloabl memory
MT
p_part_sum
=
threadIdx
.
x
<
gridDim
.
x
?
p_buffer
[
threadIdx
.
x
]
:
0
;
MT
g_part_sum
=
threadIdx
.
x
<
gridDim
.
x
?
g_buffer
[
threadIdx
.
x
]
:
0
;
*
p_n
=
Sqrt
(
math
::
blockReduceSum
<
MT
>
(
p_part_sum
,
FINAL_MASK
));
*
g_n
=
Sqrt
(
rescale_pow
*
math
::
blockReduceSum
<
MT
>
(
g_part_sum
,
FINAL_MASK
));
MT
tmp0
=
math
::
blockReduceSum
<
MT
>
(
p_part_sum
,
FINAL_MASK
);
MT
tmp1
=
math
::
blockReduceSum
<
MT
>
(
g_part_sum
,
FINAL_MASK
);
if
(
threadIdx
.
x
==
0
)
{
s_buffer
[
0
]
=
tmp0
;
s_buffer
[
1
]
=
tmp1
;
}
__syncthreads
();
*
p_n
=
Sqrt
(
s_buffer
[
0
]);
*
g_n
=
Sqrt
(
rescale_pow
*
s_buffer
[
1
]);
#endif
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录