Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
马赛克医院
Paddle
提交
7a2aa486
P
Paddle
项目概览
马赛克医院
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7a2aa486
编写于
1月 17, 2018
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Unify data type in sequence_erase_op
上级
5ae0c97f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
14 addition
and
15 deletion
+14
-15
paddle/operators/sequence_erase_op.cu
paddle/operators/sequence_erase_op.cu
+14
-15
未找到文件。
paddle/operators/sequence_erase_op.cu
浏览文件 @
7a2aa486
...
...
@@ -23,13 +23,13 @@ using platform::PADDLE_CUDA_NUM_THREADS;
using
LoDTensor
=
framework
::
LoDTensor
;
template
<
typename
T
>
__global__
void
LabelErasedIdx
(
const
T
*
in_dat
,
const
int
in_len
,
const
T
*
tokens
,
const
in
t
tokens_len
,
in
t
*
num_erased
)
{
__global__
void
LabelErasedIdx
(
const
T
*
in_dat
,
const
int
64_t
in_len
,
const
int
*
tokens
,
const
size_
t
tokens_len
,
size_
t
*
num_erased
)
{
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
if
(
index
<
in_len
)
{
int
erased
=
0
;
for
(
in
t
i
=
0
;
i
<
tokens_len
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
tokens_len
;
++
i
)
{
if
(
in_dat
[
index
]
==
tokens
[
i
])
{
erased
=
1
;
}
...
...
@@ -41,9 +41,8 @@ __global__ void LabelErasedIdx(const T* in_dat, const int in_len,
}
}
template
<
typename
T
>
__global__
void
GetOutLod
(
const
T
*
num_erased
,
const
size_t
*
in_lod
,
const
int
lod_len
,
size_t
*
out_lod0
)
{
__global__
void
GetOutLod
(
const
size_t
*
num_erased
,
const
size_t
*
in_lod
,
const
size_t
lod_len
,
size_t
*
out_lod0
)
{
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
if
(
index
<
lod_len
)
{
out_lod0
[
index
]
=
in_lod
[
index
]
-
num_erased
[
in_lod
[
index
]];
...
...
@@ -51,8 +50,8 @@ __global__ void GetOutLod(const T* num_erased, const size_t* in_lod,
}
template
<
typename
T
>
__global__
void
SetOutput
(
const
T
*
in_dat
,
const
int
in_len
,
const
in
t
*
num_erased
,
T
*
out_dat
)
{
__global__
void
SetOutput
(
const
T
*
in_dat
,
const
int
64_t
in_len
,
const
size_
t
*
num_erased
,
T
*
out_dat
)
{
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
if
(
index
<
in_len
)
{
if
(
num_erased
[
index
]
==
num_erased
[
index
+
1
])
{
...
...
@@ -92,17 +91,17 @@ class SequenceEraseOpCUDAKernel : public framework::OpKernel<T> {
PADDLE_ENFORCE_EQ
(
lod
.
size
(),
1UL
,
"Only support one level sequence now."
);
PADDLE_ENFORCE_EQ
(
lod
[
0
].
back
(),
(
size_t
)
in
->
numel
(),
"The actual size mismatches with the LoD information."
);
auto
tokens
=
ctx
.
Attr
<
std
::
vector
<
T
>>
(
"tokens"
);
auto
tokens
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"tokens"
);
auto
in_len
=
in
->
numel
();
auto
in_dat
=
in
->
data
<
T
>
();
// Copy tokens to GPU
thrust
::
device_vector
<
T
>
dev_tokens
=
set_device_vector
<
T
,
std
::
vector
<
T
>>
(
tokens
);
T
*
dev_tokens_ptr
=
thrust
::
raw_pointer_cast
(
dev_tokens
.
data
());
thrust
::
device_vector
<
int
>
dev_tokens
=
set_device_vector
<
int
,
std
::
vector
<
int
>>
(
tokens
);
int
*
dev_tokens_ptr
=
thrust
::
raw_pointer_cast
(
dev_tokens
.
data
());
// Count number of elements to be erased
thrust
::
device_vector
<
in
t
>
num_erased
(
in_len
+
1
);
in
t
*
num_erased_ptr
=
thrust
::
raw_pointer_cast
(
num_erased
.
data
());
thrust
::
device_vector
<
size_
t
>
num_erased
(
in_len
+
1
);
size_
t
*
num_erased_ptr
=
thrust
::
raw_pointer_cast
(
num_erased
.
data
());
auto
stream
=
ctx
.
cuda_device_context
().
stream
();
LabelErasedIdx
<<<
(
in_len
-
1
)
/
PADDLE_CUDA_NUM_THREADS
+
1
,
PADDLE_CUDA_NUM_THREADS
,
0
,
stream
>>>
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录