Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
9e06a641
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看板
未验证
提交
9e06a641
编写于
4月 02, 2021
作者:
R
ronnywang
提交者:
GitHub
4月 02, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCM] fix softmax_with_cross_entropy_op (#31982)
上级
4490e8af
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
7 deletion
+20
-7
paddle/fluid/operators/math/cross_entropy.cu
paddle/fluid/operators/math/cross_entropy.cu
+8
-3
paddle/fluid/operators/math/softmax.cu
paddle/fluid/operators/math/softmax.cu
+6
-4
paddle/fluid/operators/softmax_with_cross_entropy_op.cu
paddle/fluid/operators/softmax_with_cross_entropy_op.cu
+4
-0
paddle/fluid/platform/dynload/miopen.h
paddle/fluid/platform/dynload/miopen.h
+2
-0
未找到文件。
paddle/fluid/operators/math/cross_entropy.cu
浏览文件 @
9e06a641
...
...
@@ -66,18 +66,23 @@ class CrossEntropyFunctor<platform::CUDADeviceContext, T> {
int
batch_size
=
prob
->
dims
()[
0
];
int
class_num
=
prob
->
dims
()[
1
];
#ifdef __HIPCC__
constexpr
int
kMaxBlockDim
=
256
;
#else
constexpr
int
kMaxBlockDim
=
512
;
#endif
if
(
softLabel
)
{
const
T
*
label_data
=
labels
->
data
<
T
>
();
int
block
=
class_num
>
512
?
512
int
block
=
class_num
>
kMaxBlockDim
?
kMaxBlockDim
:
pow
(
2
,
static_cast
<
int
>
(
std
::
log2
(
class_num
)));
SoftCrossEntropyKernel
<
T
><<<
batch_size
,
block
,
0
,
ctx
.
stream
()
>>>
(
loss_data
,
prob_data
,
label_data
,
class_num
);
}
else
{
const
int64_t
*
label_data
=
labels
->
data
<
int64_t
>
();
int
block
=
512
;
int
block
=
kMaxBlockDim
;
int
grid
=
(
batch_size
+
block
-
1
)
/
block
;
CrossEntropyKernel
<
T
><<<
grid
,
block
,
0
,
ctx
.
stream
()
>>>
(
loss_data
,
prob_data
,
label_data
,
batch_size
,
class_num
,
...
...
paddle/fluid/operators/math/softmax.cu
浏览文件 @
9e06a641
...
...
@@ -54,10 +54,11 @@ void SoftmaxCUDNNFunctor<T>::operator()(
xDesc
.
descriptor
<
T
>
(
layout
,
cudnn_tensor_dims
);
miopenTensorDescriptor_t
cudnn_y_desc
=
xDesc
.
descriptor
<
T
>
(
layout
,
cudnn_tensor_dims
);
PADDLE_ENFORCE_CUDA_SUCCESS
(
platform
::
dynload
::
miopenSoftmaxForward
(
PADDLE_ENFORCE_CUDA_SUCCESS
(
platform
::
dynload
::
miopenSoftmaxForward
_V2
(
context
.
cudnn_handle
(),
CudnnDataType
<
T
>::
kOne
(),
cudnn_x_desc
,
X
->
data
<
T
>
(),
CudnnDataType
<
T
>::
kZero
(),
cudnn_y_desc
,
Y
->
mutable_data
<
T
>
(
context
.
GetPlace
())));
Y
->
mutable_data
<
T
>
(
context
.
GetPlace
()),
MIOPEN_SOFTMAX_ACCURATE
,
MIOPEN_SOFTMAX_MODE_INSTANCE
));
#else
cudnnTensorDescriptor_t
cudnn_x_desc
=
xDesc
.
descriptor
<
T
>
(
layout
,
cudnn_tensor_dims
);
...
...
@@ -96,11 +97,12 @@ void SoftmaxGradCUDNNFunctor<T>::operator()(
dxDesc
.
descriptor
<
T
>
(
layout
,
cudnn_tensor_dims
);
miopenTensorDescriptor_t
cudnn_ygrad_desc
=
dyDesc
.
descriptor
<
T
>
(
layout
,
cudnn_tensor_dims
);
PADDLE_ENFORCE_CUDA_SUCCESS
(
platform
::
dynload
::
miopenSoftmaxBackward
(
PADDLE_ENFORCE_CUDA_SUCCESS
(
platform
::
dynload
::
miopenSoftmaxBackward
_V2
(
context
.
cudnn_handle
(),
CudnnDataType
<
T
>::
kOne
(),
cudnn_y_desc
,
Y
->
data
<
T
>
(),
cudnn_ygrad_desc
,
YGrad
->
data
<
T
>
(),
CudnnDataType
<
T
>::
kZero
(),
cudnn_xgrad_desc
,
XGrad
->
mutable_data
<
T
>
(
context
.
GetPlace
())));
XGrad
->
mutable_data
<
T
>
(
context
.
GetPlace
()),
MIOPEN_SOFTMAX_ACCURATE
,
MIOPEN_SOFTMAX_MODE_INSTANCE
));
#else
cudnnTensorDescriptor_t
cudnn_y_desc
=
yDesc
.
descriptor
<
T
>
(
layout
,
cudnn_tensor_dims
);
...
...
paddle/fluid/operators/softmax_with_cross_entropy_op.cu
浏览文件 @
9e06a641
...
...
@@ -672,7 +672,11 @@ template <typename T>
static
void
SoftmaxWithCrossEntropyFusedKernel
(
const
T
*
logits_data
,
const
T
*
labels_data
,
T
*
softmax_data
,
T
*
loss_data
,
int64_t
n
,
int64_t
d
,
int
axis_dim
,
gpuStream_t
stream
)
{
#ifdef __HIPCC__
constexpr
int
kMaxBlockDim
=
256
;
#else
constexpr
int
kMaxBlockDim
=
512
;
#endif
int64_t
block_dim
=
axis_dim
>=
kMaxBlockDim
?
kMaxBlockDim
:
(
1
<<
static_cast
<
int
>
(
std
::
log2
(
axis_dim
)));
...
...
paddle/fluid/platform/dynload/miopen.h
浏览文件 @
9e06a641
...
...
@@ -116,7 +116,9 @@ extern void EnforceCUDNNLoaded(const char* fn_name);
__macro(miopenPoolingForward); \
__macro(miopenPoolingBackward); \
__macro(miopenSoftmaxBackward); \
__macro(miopenSoftmaxBackward_V2); \
__macro(miopenSoftmaxForward); \
__macro(miopenSoftmaxForward_V2); \
__macro(miopenCreateDropoutDescriptor); \
__macro(miopenDestroyDropoutDescriptor); \
__macro(miopenRestoreDropoutDescriptor); \
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录