Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
18aca3f5
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看板
未验证
提交
18aca3f5
编写于
12月 09, 2021
作者:
F
Feng Xing
提交者:
GitHub
12月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
format softmax forward (#37927)
上级
fdf62e1e
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
20 addition
and
12 deletion
+20
-12
paddle/fluid/operators/softmax_cudnn_op.cu.h
paddle/fluid/operators/softmax_cudnn_op.cu.h
+20
-12
未找到文件。
paddle/fluid/operators/softmax_cudnn_op.cu.h
浏览文件 @
18aca3f5
...
@@ -222,15 +222,27 @@ __global__ void WarpSoftmaxForward(T* softmax, const T* src,
...
@@ -222,15 +222,27 @@ __global__ void WarpSoftmaxForward(T* softmax, const T* src,
idx_max_v
[
i
]
=
idx_max
/
kVSize
;
idx_max_v
[
i
]
=
idx_max
/
kVSize
;
}
}
//
read data from global memory
//
data src
AccT
srcdata
[
kBatchSize
][
kLoopsV
][
kVSize
];
AccT
srcdata
[
kBatchSize
][
kLoopsV
][
kVSize
];
kps
::
Init
<
AccT
,
kStep
>
(
&
srcdata
[
0
][
0
][
0
],
kLowInf
);
T
src_tmp
[
kBatchSize
][
kLoopsV
][
kVSize
];
T
src_tmp
[
kBatchSize
][
kLoopsV
][
kVSize
];
kps
::
Init
<
AccT
,
kStep
>
(
&
srcdata
[
0
][
0
][
0
],
kLowInf
);
kps
::
Init
<
T
,
kStep
>
(
&
src_tmp
[
0
][
0
][
0
],
-
std
::
numeric_limits
<
T
>::
infinity
());
kps
::
Init
<
T
,
kStep
>
(
&
src_tmp
[
0
][
0
][
0
],
-
std
::
numeric_limits
<
T
>::
infinity
());
// data dst
T
out_tmp
[
kBatchSize
][
kLoopsV
][
kVSize
];
// max value
AccT
max
[
kBatchSize
];
kps
::
Init
<
AccT
,
kBatchSize
>
(
&
max
[
0
],
kLowInf
);
// sum value
AccT
sum
[
kBatchSize
]
=
{
0
};
// read data from global memory
#pragma unroll
#pragma unroll
for
(
int
i
=
0
;
i
<
kBatchSize
;
++
i
)
{
for
(
int
i
=
0
;
i
<
kBatchSize
;
++
i
)
{
int
ptr
=
(
first_batch
+
i
)
*
stride
;
const
VecT
*
src_v
=
const
VecT
*
src_v
=
reinterpret_cast
<
const
VecT
*>
(
&
src
[
ptr
]);
reinterpret_cast
<
const
VecT
*>
(
&
src
[(
first_batch
+
i
)
*
stride
]);
VecT
*
reg_v
=
reinterpret_cast
<
VecT
*>
(
&
src_tmp
[
i
][
0
][
0
]);
VecT
*
reg_v
=
reinterpret_cast
<
VecT
*>
(
&
src_tmp
[
i
][
0
][
0
]);
kps
::
ReadData
<
VecT
,
VecT
,
kLoopsV
,
1
,
1
,
true
>
(
kps
::
ReadData
<
VecT
,
VecT
,
kLoopsV
,
1
,
1
,
true
>
(
&
reg_v
[
0
],
&
src_v
[
0
],
idx_max_v
[
i
],
0
,
kWarpSize
,
1
);
&
reg_v
[
0
],
&
src_v
[
0
],
idx_max_v
[
i
],
0
,
kWarpSize
,
1
);
...
@@ -239,15 +251,12 @@ __global__ void WarpSoftmaxForward(T* softmax, const T* src,
...
@@ -239,15 +251,12 @@ __global__ void WarpSoftmaxForward(T* softmax, const T* src,
}
}
// compute max
// compute max
AccT
max
[
kBatchSize
];
kps
::
Init
<
AccT
,
kBatchSize
>
(
&
max
[
0
],
kLowInf
);
kps
::
Reduce
<
AccT
,
kVItem
,
kBatchSize
,
1
,
ReduceMaxFunctor
<
AccT
>
,
kps
::
Reduce
<
AccT
,
kVItem
,
kBatchSize
,
1
,
ReduceMaxFunctor
<
AccT
>
,
kMode
::
kLocalMode
>
(
&
max
[
0
],
&
srcdata
[
0
][
0
][
0
],
kMode
::
kLocalMode
>
(
&
max
[
0
],
&
srcdata
[
0
][
0
][
0
],
ReduceMaxFunctor
<
AccT
>
(),
true
);
ReduceMaxFunctor
<
AccT
>
(),
true
);
WarpReduceMax
<
AccT
,
kBatchSize
,
kWarpSize
>
(
max
);
WarpReduceMax
<
AccT
,
kBatchSize
,
kWarpSize
>
(
max
);
// compute sum
// compute sum
AccT
sum
[
kBatchSize
]
=
{
0
};
for
(
int
i
=
0
;
i
<
kBatchSize
;
++
i
)
{
for
(
int
i
=
0
;
i
<
kBatchSize
;
++
i
)
{
kps
::
ElementwiseUnary
<
AccT
,
AccT
,
kVItem
,
1
,
1
,
ExpSubFunctor
<
AccT
>>
(
kps
::
ElementwiseUnary
<
AccT
,
AccT
,
kVItem
,
1
,
1
,
ExpSubFunctor
<
AccT
>>
(
&
srcdata
[
i
][
0
][
0
],
&
srcdata
[
i
][
0
][
0
],
ExpSubFunctor
<
AccT
>
(
max
[
i
]));
&
srcdata
[
i
][
0
][
0
],
&
srcdata
[
i
][
0
][
0
],
ExpSubFunctor
<
AccT
>
(
max
[
i
]));
...
@@ -257,15 +266,14 @@ __global__ void WarpSoftmaxForward(T* softmax, const T* src,
...
@@ -257,15 +266,14 @@ __global__ void WarpSoftmaxForward(T* softmax, const T* src,
kps
::
AddFunctor
<
AccT
>
(),
true
);
kps
::
AddFunctor
<
AccT
>
(),
true
);
WarpReduceSum
<
AccT
,
kBatchSize
,
kWarpSize
>
(
sum
);
WarpReduceSum
<
AccT
,
kBatchSize
,
kWarpSize
>
(
sum
);
// write result to global memory
// write data to global memory
T
out_tmp
[
kBatchSize
][
kLoopsV
][
kVSize
];
#pragma unroll
#pragma unroll
for
(
int
i
=
0
;
i
<
kBatchSize
;
++
i
)
{
for
(
int
i
=
0
;
i
<
kBatchSize
;
++
i
)
{
VecT
*
softmax_v
=
reinterpret_cast
<
VecT
*>
(
&
softmax
[(
first_batch
+
i
)
*
stride
]);
VecT
*
reg_v
=
reinterpret_cast
<
VecT
*>
(
&
out_tmp
[
i
][
0
][
0
]);
kps
::
ElementwiseUnary
<
AccT
,
T
,
kVItem
,
1
,
1
,
UnaryDivFunctor
<
AccT
>>
(
kps
::
ElementwiseUnary
<
AccT
,
T
,
kVItem
,
1
,
1
,
UnaryDivFunctor
<
AccT
>>
(
&
out_tmp
[
i
][
0
][
0
],
&
srcdata
[
i
][
0
][
0
],
UnaryDivFunctor
<
AccT
>
(
sum
[
i
]));
&
out_tmp
[
i
][
0
][
0
],
&
srcdata
[
i
][
0
][
0
],
UnaryDivFunctor
<
AccT
>
(
sum
[
i
]));
int
softmax_ptr
=
(
first_batch
+
i
)
*
stride
;
VecT
*
softmax_v
=
reinterpret_cast
<
VecT
*>
(
&
softmax
[
softmax_ptr
]);
VecT
*
reg_v
=
reinterpret_cast
<
VecT
*>
(
&
out_tmp
[
i
][
0
][
0
]);
kps
::
WriteData
<
VecT
,
VecT
,
kLoopsV
,
1
,
1
,
true
>
(
kps
::
WriteData
<
VecT
,
VecT
,
kLoopsV
,
1
,
1
,
true
>
(
&
softmax_v
[
0
],
&
reg_v
[
0
],
idx_max_v
[
i
],
0
,
kWarpSize
,
1
);
&
softmax_v
[
0
],
&
reg_v
[
0
],
idx_max_v
[
i
],
0
,
kWarpSize
,
1
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录