Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
da963eab
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
da963eab
编写于
5月 06, 2023
作者:
Y
Yuang Liu
提交者:
GitHub
5月 06, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use int64 to calc dim for c softmax (#53541)
* use int64 to calc dim for c softmax * fix complie bug
上级
03fe3ce5
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
25 addition
and
25 deletion
+25
-25
paddle/fluid/operators/collective/c_softmax_with_cross_entropy_op.cu
...d/operators/collective/c_softmax_with_cross_entropy_op.cu
+25
-25
未找到文件。
paddle/fluid/operators/collective/c_softmax_with_cross_entropy_op.cu
浏览文件 @
da963eab
...
...
@@ -30,9 +30,9 @@ namespace paddle {
namespace
operators
{
static
constexpr
int
kNumCUDAThreads
=
512
;
static
constexpr
int
kNumMaxinumNumBlocks
=
4096
;
static
constexpr
int
64_t
kNumMaxinumNumBlocks
=
4096
;
static
inline
int
NumBlocks
(
const
in
t
N
)
{
static
inline
int
64_t
NumBlocks
(
const
int64_
t
N
)
{
return
std
::
min
((
N
+
kNumCUDAThreads
-
1
)
/
kNumCUDAThreads
,
kNumMaxinumNumBlocks
);
}
...
...
@@ -42,12 +42,12 @@ __global__ void MaskLabelByIndex(T* predicted_logits,
const
T
*
logit
,
const
IndexT
*
label
,
const
IndexT
ignore_index
,
const
int
start_index
,
const
int
end_index
,
const
int
64_t
start_index
,
const
int
64_t
end_index
,
const
int64_t
N
,
const
int64_t
D
,
const
int
nranks
)
{
CUDA_KERNEL_LOOP
(
i
,
N
)
{
CUDA_KERNEL_LOOP
_TYPE
(
i
,
N
,
int64_t
)
{
auto
real_label
=
label
[
i
];
PADDLE_ENFORCE
(((
real_label
<
D
*
nranks
)
&&
(
real_label
>=
0
))
||
(
real_label
==
ignore_index
),
...
...
@@ -71,8 +71,8 @@ __global__ void CaculateLoss(T* loss,
const
T
*
sum_exp_logits
,
const
IndexT
*
label
,
const
int64_t
ignore_index
,
const
int
N
)
{
CUDA_KERNEL_LOOP
(
i
,
N
)
{
const
int
64_t
N
)
{
CUDA_KERNEL_LOOP
_TYPE
(
i
,
N
,
int64_t
)
{
auto
real_label
=
static_cast
<
int64_t
>
(
label
[
i
]);
loss
[
i
]
=
ignore_index
==
real_label
?
static_cast
<
T
>
(
0
)
...
...
@@ -87,12 +87,12 @@ template <typename T, typename IndexT>
__global__
void
MaskLabelByIndexGrad
(
T
*
logits_grad
,
const
T
*
loss_grad
,
const
IndexT
*
labels
,
const
int
start_index
,
const
int
end_index
,
const
int
64_t
start_index
,
const
int
64_t
end_index
,
const
int64_t
N
,
const
int64_t
D
,
const
int64_t
ignore_index
)
{
CUDA_KERNEL_LOOP
(
i
,
N
*
D
)
{
CUDA_KERNEL_LOOP
_TYPE
(
i
,
N
*
D
,
int64_t
)
{
auto
row
=
i
/
D
;
auto
col
=
i
%
D
;
auto
lbl
=
static_cast
<
int64_t
>
(
labels
[
row
]);
...
...
@@ -152,8 +152,8 @@ struct CSoftmaxWithCrossEntropyFunctor<phi::GPUContext, T> {
const
auto
&
labels_dims
=
labels
->
dims
();
const
int
axis
=
logits_dims
.
size
()
-
1
;
const
int
N
=
phi
::
funcs
::
SizeToAxis
(
axis
,
logits_dims
);
const
int
D
=
phi
::
funcs
::
SizeFromAxis
(
axis
,
logits_dims
);
const
int
64_t
N
=
phi
::
funcs
::
SizeToAxis
<
int64_t
>
(
axis
,
logits_dims
);
const
int
64_t
D
=
phi
::
funcs
::
SizeFromAxis
<
int64_t
>
(
axis
,
logits_dims
);
phi
::
DenseTensor
logits_2d
,
softmax_2d
,
loss_2d
;
logits_2d
.
ShareDataWith
(
*
logits
).
Resize
({
N
,
D
});
...
...
@@ -200,10 +200,10 @@ struct CSoftmaxWithCrossEntropyFunctor<phi::GPUContext, T> {
auto
t
=
framework
::
EigenVector
<
T
>::
Flatten
(
predicted_logits
);
t
.
device
(
*
dev_ctx
.
eigen_device
())
=
t
.
constant
(
static_cast
<
T
>
(
0
));
const
int
start_index
=
rank
*
D
;
const
int
end_index
=
start_index
+
D
;
const
int
64_t
start_index
=
rank
*
D
;
const
int
64_t
end_index
=
start_index
+
D
;
int
blocks
=
NumBlocks
(
N
);
int
64_t
blocks
=
NumBlocks
(
N
);
int
threads
=
kNumCUDAThreads
;
const
auto
&
label_type
=
framework
::
TransToProtoVarType
(
labels
->
dtype
());
...
...
@@ -318,8 +318,8 @@ struct CSoftmaxWithCrossEntropyProcessGroupFunctor<phi::GPUContext, T> {
const
auto
&
labels_dims
=
labels
->
dims
();
const
int
axis
=
logits_dims
.
size
()
-
1
;
const
int
N
=
phi
::
funcs
::
SizeToAxis
(
axis
,
logits_dims
);
const
int
D
=
phi
::
funcs
::
SizeFromAxis
(
axis
,
logits_dims
);
const
int
64_t
N
=
phi
::
funcs
::
SizeToAxis
<
int64_t
>
(
axis
,
logits_dims
);
const
int
64_t
D
=
phi
::
funcs
::
SizeFromAxis
<
int64_t
>
(
axis
,
logits_dims
);
phi
::
DenseTensor
logits_2d
,
softmax_2d
,
loss_2d
;
logits_2d
.
ShareDataWith
(
*
logits
).
Resize
({
N
,
D
});
...
...
@@ -358,10 +358,10 @@ struct CSoftmaxWithCrossEntropyProcessGroupFunctor<phi::GPUContext, T> {
auto
t
=
framework
::
EigenVector
<
T
>::
Flatten
(
predicted_logits
);
t
.
device
(
*
dev_ctx
.
eigen_device
())
=
t
.
constant
(
static_cast
<
T
>
(
0
));
const
int
start_index
=
rank
*
D
;
const
int
end_index
=
start_index
+
D
;
const
int
64_t
start_index
=
rank
*
D
;
const
int
64_t
end_index
=
start_index
+
D
;
int
blocks
=
NumBlocks
(
N
);
int
64_t
blocks
=
NumBlocks
(
N
);
int
threads
=
kNumCUDAThreads
;
const
auto
&
label_type
=
framework
::
TransToProtoVarType
(
labels
->
dtype
());
...
...
@@ -454,17 +454,17 @@ class CSoftmaxWithCrossEntropyGradCUDAKernel : public framework::OpKernel<T> {
}
const
auto
sofrmax_dims
=
softmax
->
dims
();
const
int
axis
=
sofrmax_dims
.
size
()
-
1
;
const
int
N
=
phi
::
funcs
::
SizeToAxis
(
axis
,
sofrmax_dims
);
const
int
D
=
phi
::
funcs
::
SizeFromAxis
(
axis
,
sofrmax_dims
);
const
int
64_t
N
=
phi
::
funcs
::
SizeToAxis
<
int64_t
>
(
axis
,
sofrmax_dims
);
const
int
64_t
D
=
phi
::
funcs
::
SizeFromAxis
<
int64_t
>
(
axis
,
sofrmax_dims
);
phi
::
DenseTensor
logit_grad_2d
;
logit_grad_2d
.
ShareDataWith
(
*
logit_grad
).
Resize
({
N
,
D
});
int
blocks
=
NumBlocks
(
N
*
D
);
int
64_t
blocks
=
NumBlocks
(
N
*
D
);
int
threads
=
kNumCUDAThreads
;
const
auto
&
label_type
=
framework
::
TransToProtoVarType
(
labels
->
dtype
());
const
int
start_index
=
rank
*
D
;
const
int
end_index
=
start_index
+
D
;
const
int
64_t
start_index
=
rank
*
D
;
const
int
64_t
end_index
=
start_index
+
D
;
if
(
label_type
==
framework
::
proto
::
VarType
::
INT32
)
{
MaskLabelByIndexGrad
<
T
,
int32_t
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录