Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
64f1485a
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
64f1485a
编写于
2月 25, 2022
作者:
Z
Zhang Ting
提交者:
GitHub
2月 25, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace implementation with cuda kernel (#39795)
上级
bbe5228c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
28 addition
and
18 deletion
+28
-18
paddle/fluid/operators/dropout_impl.cu.h
paddle/fluid/operators/dropout_impl.cu.h
+22
-15
paddle/phi/kernels/funcs/functors.h
paddle/phi/kernels/funcs/functors.h
+6
-3
未找到文件。
paddle/fluid/operators/dropout_impl.cu.h
浏览文件 @
64f1485a
...
...
@@ -36,6 +36,7 @@ limitations under the License. */
#include "paddle/fluid/operators/elementwise/elementwise_op_impl.cu.h"
#include "paddle/fluid/platform/aligned_vector.h"
#include "paddle/fluid/platform/device/gpu/gpu_launch_config.h"
#include "paddle/phi/kernels/funcs/functors.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -270,32 +271,38 @@ void DropoutGradGPUKernelDriver(const platform::CUDADeviceContext& dev_ctx,
const
Tensor
&
mask
,
int64_t
size
,
Tensor
*
grad_x
,
bool
is_test
=
false
)
{
using
MT
=
typename
details
::
MPTypeTrait
<
T
>::
Type
;
auto
dX
=
EigenVector
<
T
>::
Flatten
(
*
grad_x
);
auto
dY
=
EigenVector
<
T
>::
Flatten
(
grad_y
);
auto
&
place
=
*
dev_ctx
.
eigen_device
();
auto
stream
=
dev_ctx
.
stream
();
MT
factor
;
if
(
is_test
)
{
if
(
dropout_implementation
==
"upscale_in_train"
)
{
dX
.
device
(
place
)
=
static_cast
<
T
>
(
1
)
*
dY
;
factor
=
static_cast
<
MT
>
(
1.0
f
)
;
}
else
{
dX
.
device
(
place
)
=
dY
*
static_cast
<
T
>
(
1.0
f
-
dropout_prob
);
factor
=
static_cast
<
M
T
>
(
1.0
f
-
dropout_prob
);
}
std
::
vector
<
const
framework
::
Tensor
*>
ins
=
{
&
grad_y
};
std
::
vector
<
framework
::
Tensor
*>
outs
=
{
grad_x
};
auto
functor
=
phi
::
funcs
::
ScaleFunctor
<
T
>
(
factor
);
paddle
::
operators
::
LaunchSameDimsElementwiseCudaKernel
<
T
>
(
dev_ctx
,
ins
,
&
outs
,
functor
);
}
else
{
auto
M
=
EigenVector
<
uint8_t
>::
Flatten
(
mask
);
std
::
vector
<
const
framework
::
Tensor
*>
ins
=
{
&
grad_y
,
&
mask
};
std
::
vector
<
framework
::
Tensor
*>
outs
=
{
grad_x
};
if
(
dropout_implementation
==
"upscale_in_train"
)
{
if
(
dropout_prob
==
1.0
f
)
{
dX
.
device
(
place
)
=
static_cast
<
T
>
(
0
)
*
dY
;
#ifdef PADDLE_WITH_HIP
hipMemset
(
grad_x
->
data
<
T
>
(),
0
,
size
*
sizeof
(
T
));
#else
cudaMemset
(
grad_x
->
data
<
T
>
(),
0
,
size
*
sizeof
(
T
));
#endif
}
else
{
auto
factor
=
static_cast
<
MT
>
(
1.0
f
/
(
1.0
f
-
dropout_prob
));
auto
stream
=
dev_ctx
.
stream
();
std
::
vector
<
const
framework
::
Tensor
*>
ins
=
{
&
grad_y
,
&
mask
};
std
::
vector
<
framework
::
Tensor
*>
outs
=
{
grad_x
};
auto
functor
=
CudaDropoutGradFunctor
<
T
,
uint8_t
>
(
factor
);
factor
=
static_cast
<
MT
>
(
1.0
f
/
(
1.0
f
-
dropout_prob
));
paddle
::
operators
::
LaunchSameDimsElementwiseCudaKernel
<
T
>
(
dev_ctx
,
ins
,
&
outs
,
functor
);
dev_ctx
,
ins
,
&
outs
,
CudaDropoutGradFunctor
<
T
,
uint8_t
>
(
factor
)
);
}
}
else
{
dX
.
device
(
place
)
=
dY
*
M
.
cast
<
T
>
();
factor
=
static_cast
<
MT
>
(
1.0
f
);
paddle
::
operators
::
LaunchSameDimsElementwiseCudaKernel
<
T
>
(
dev_ctx
,
ins
,
&
outs
,
CudaDropoutGradFunctor
<
T
,
uint8_t
>
(
factor
));
}
}
}
...
...
paddle/phi/kernels/funcs/functors.h
浏览文件 @
64f1485a
...
...
@@ -38,12 +38,15 @@ struct AddGradFunctor {
template
<
typename
T
>
struct
ScaleFunctor
{
explicit
ScaleFunctor
(
const
T
coeff
)
:
coeff_
(
coeff
)
{}
using
MT
=
typename
paddle
::
operators
::
details
::
MPTypeTrait
<
T
>::
Type
;
explicit
ScaleFunctor
(
const
MT
coeff
)
:
coeff_
(
coeff
)
{}
inline
HOSTDEVICE
T
operator
()(
T
ele
)
{
return
ele
*
coeff_
;
}
inline
HOSTDEVICE
T
operator
()(
T
ele
)
{
return
static_cast
<
T
>
(
static_cast
<
MT
>
(
ele
)
*
coeff_
);
}
private:
T
coeff_
;
M
T
coeff_
;
};
template
<
typename
T
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录