Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
07923ba0
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
07923ba0
编写于
2月 12, 2018
作者:
D
dzhwinter
提交者:
GitHub
2月 12, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Memory/dropout4 (#8407)
* "merge random generator kernel and mul" * "fix dropout"
上级
91aac572
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
21 deletion
+21
-21
paddle/fluid/operators/dropout_op.cu
paddle/fluid/operators/dropout_op.cu
+21
-21
未找到文件。
paddle/fluid/operators/dropout_op.cu
浏览文件 @
07923ba0
...
@@ -23,24 +23,23 @@ namespace paddle {
...
@@ -23,24 +23,23 @@ namespace paddle {
namespace
operators
{
namespace
operators
{
template
<
typename
T
,
typename
AttrType
>
template
<
typename
T
,
typename
AttrType
>
struct
MaskGenerator
{
__global__
void
RandomGenerator
(
const
size_t
n
,
const
int
seed
,
AttrType
dropout_prob
;
const
AttrType
dropout_prob
,
const
T
*
src
,
int
seed
;
T
*
mask_data
,
T
*
dst
)
{
thrust
::
minstd_rand
rng
;
rng
.
seed
(
seed
);
thrust
::
uniform_real_distribution
<
AttrType
>
dist
(
0
,
1
);
__host__
__device__
MaskGenerator
(
AttrType
dropout_prob
,
int
seed
)
int
idx
=
blockDim
.
x
*
blockIdx
.
x
+
threadIdx
.
x
;
:
dropout_prob
(
dropout_prob
),
seed
(
seed
)
{}
for
(;
idx
<
n
;
idx
+=
blockDim
.
x
*
gridDim
.
x
)
{
inline
__host__
__device__
T
operator
()(
const
unsigned
int
n
)
const
{
thrust
::
minstd_rand
rng
;
rng
.
seed
(
seed
);
thrust
::
uniform_real_distribution
<
AttrType
>
dist
(
0
,
1
);
rng
.
discard
(
n
);
if
(
dist
(
rng
)
<
dropout_prob
)
{
if
(
dist
(
rng
)
<
dropout_prob
)
{
return
static_cast
<
T
>
(
0
);
mask_data
[
idx
]
=
static_cast
<
T
>
(
0
);
}
else
{
mask_data
[
idx
]
=
static_cast
<
T
>
(
1
);
}
}
return
static_cast
<
T
>
(
1
)
;
dst
[
idx
]
=
mask_data
[
idx
]
*
src
[
idx
]
;
}
}
}
;
}
// It seems that Eigen::Tensor::setRandom in GPU will SEGFAULT.
// It seems that Eigen::Tensor::setRandom in GPU will SEGFAULT.
// Use std::random and thrust::random(thrust is a std library in CUDA) to
// Use std::random and thrust::random(thrust is a std library in CUDA) to
...
@@ -61,18 +60,19 @@ class GPUDropoutKernel : public framework::OpKernel<T> {
...
@@ -61,18 +60,19 @@ class GPUDropoutKernel : public framework::OpKernel<T> {
if
(
!
context
.
Attr
<
bool
>
(
"is_test"
))
{
if
(
!
context
.
Attr
<
bool
>
(
"is_test"
))
{
auto
*
mask
=
context
.
Output
<
Tensor
>
(
"Mask"
);
auto
*
mask
=
context
.
Output
<
Tensor
>
(
"Mask"
);
auto
*
mask_data
=
mask
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
*
mask_data
=
mask
->
mutable_data
<
T
>
(
context
.
GetPlace
());
int
size
=
framework
::
product
(
mask
->
dims
());
size_t
size
=
framework
::
product
(
mask
->
dims
());
auto
*
x_data
=
x
->
data
<
T
>
();
auto
*
y_data
=
y
->
mutable_data
<
T
>
(
context
.
GetPlace
());
std
::
random_device
rnd
;
std
::
random_device
rnd
;
int
seed
=
int
seed
=
context
.
Attr
<
bool
>
(
"fix_seed"
)
?
context
.
Attr
<
int
>
(
"seed"
)
:
rnd
();
context
.
Attr
<
bool
>
(
"fix_seed"
)
?
context
.
Attr
<
int
>
(
"seed"
)
:
rnd
();
thrust
::
counting_iterator
<
unsigned
int
>
index_sequence_begin
(
0
);
int
threads
=
512
;
thrust
::
transform
(
index_sequence_begin
,
index_sequence_begin
+
size
,
int
grid
=
(
x
->
numel
()
+
threads
-
1
)
/
threads
;
thrust
::
device_ptr
<
T
>
(
mask_data
),
RandomGenerator
<
T
,
AttrType
><<<
grid
,
threads
,
0
,
MaskGenerator
<
T
,
AttrType
>
(
dropout_prob
,
seed
));
context
.
cuda_device_context
().
stream
()
>>>
(
auto
M
=
EigenMatrix
<
T
>::
Reshape
(
*
mask
,
1
);
size
,
seed
,
dropout_prob
,
x_data
,
mask_data
,
y_data
);
Y
.
device
(
place
)
=
X
*
M
;
}
else
{
}
else
{
Y
.
device
(
place
)
=
X
*
(
1.0
f
-
dropout_prob
);
Y
.
device
(
place
)
=
X
*
(
1.0
f
-
dropout_prob
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录