Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b8c6e180
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
b8c6e180
编写于
9月 13, 2021
作者:
Z
zhulei
提交者:
GitHub
9月 13, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCM] fix top_k_v2 with large shape (#33783)
* [ROCM] fix top_k_v2 with large shape * [ROCM] fix top_k_v2 with large shape
上级
1ee237c1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
36 addition
and
0 deletion
+36
-0
paddle/fluid/operators/top_k_v2_op.cu
paddle/fluid/operators/top_k_v2_op.cu
+18
-0
python/paddle/fluid/tests/unittests/test_top_k_v2_op.py
python/paddle/fluid/tests/unittests/test_top_k_v2_op.py
+18
-0
未找到文件。
paddle/fluid/operators/top_k_v2_op.cu
浏览文件 @
b8c6e180
...
@@ -99,12 +99,21 @@ class TopkV2OpCUDAKernel : public framework::OpKernel<T> {
...
@@ -99,12 +99,21 @@ class TopkV2OpCUDAKernel : public framework::OpKernel<T> {
const
int
kMaxHeight
=
2048
;
const
int
kMaxHeight
=
2048
;
int
gridx
=
input_height
<
kMaxHeight
?
input_height
:
kMaxHeight
;
int
gridx
=
input_height
<
kMaxHeight
?
input_height
:
kMaxHeight
;
switch
(
GetDesiredBlockDim
(
input_width
))
{
switch
(
GetDesiredBlockDim
(
input_width
))
{
#ifdef PADDLE_WITH_HIP
FIXED_BLOCK_DIM
(
KeMatrixTopK
<
T
,
20
,
kBlockDim
><<<
gridx
,
kBlockDim
,
0
,
dev_ctx
.
stream
()
>>>
(
output_data
,
k
,
indices_data
,
input_data
,
input_width
,
input_width
,
static_cast
<
int
>
(
k
),
gridx
,
input_height
,
largest
));
#else
FIXED_BLOCK_DIM
(
FIXED_BLOCK_DIM
(
KeMatrixTopK
<
T
,
5
,
KeMatrixTopK
<
T
,
5
,
kBlockDim
><<<
gridx
,
kBlockDim
,
0
,
dev_ctx
.
stream
()
>>>
(
kBlockDim
><<<
gridx
,
kBlockDim
,
0
,
dev_ctx
.
stream
()
>>>
(
output_data
,
k
,
indices_data
,
input_data
,
input_width
,
output_data
,
k
,
indices_data
,
input_data
,
input_width
,
input_width
,
static_cast
<
int
>
(
k
),
gridx
,
input_height
,
input_width
,
static_cast
<
int
>
(
k
),
gridx
,
input_height
,
largest
));
largest
));
#endif
default:
default:
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
"the input data shape has error in the topk cuda kernel."
));
"the input data shape has error in the topk cuda kernel."
));
...
@@ -169,12 +178,21 @@ class TopkV2OpCUDAKernel : public framework::OpKernel<T> {
...
@@ -169,12 +178,21 @@ class TopkV2OpCUDAKernel : public framework::OpKernel<T> {
const
int
kMaxHeight
=
2048
;
const
int
kMaxHeight
=
2048
;
int
gridx
=
input_height
<
kMaxHeight
?
input_height
:
kMaxHeight
;
int
gridx
=
input_height
<
kMaxHeight
?
input_height
:
kMaxHeight
;
switch
(
GetDesiredBlockDim
(
input_width
))
{
switch
(
GetDesiredBlockDim
(
input_width
))
{
#ifdef PADDLE_WITH_HIP
FIXED_BLOCK_DIM
(
KeMatrixTopK
<
T
,
20
,
kBlockDim
><<<
gridx
,
kBlockDim
,
0
,
dev_ctx
.
stream
()
>>>
(
trans_out
.
data
<
T
>
(),
k
,
trans_ind
.
data
<
int64_t
>
(),
trans_input
.
data
<
T
>
(),
input_width
,
input_width
,
static_cast
<
int
>
(
k
),
gridx
,
input_height
,
largest
));
#else
FIXED_BLOCK_DIM
(
FIXED_BLOCK_DIM
(
KeMatrixTopK
<
T
,
5
,
KeMatrixTopK
<
T
,
5
,
kBlockDim
><<<
gridx
,
kBlockDim
,
0
,
dev_ctx
.
stream
()
>>>
(
kBlockDim
><<<
gridx
,
kBlockDim
,
0
,
dev_ctx
.
stream
()
>>>
(
trans_out
.
data
<
T
>
(),
k
,
trans_ind
.
data
<
int64_t
>
(),
trans_out
.
data
<
T
>
(),
k
,
trans_ind
.
data
<
int64_t
>
(),
trans_input
.
data
<
T
>
(),
input_width
,
input_width
,
trans_input
.
data
<
T
>
(),
input_width
,
input_width
,
static_cast
<
int
>
(
k
),
gridx
,
input_height
,
largest
));
static_cast
<
int
>
(
k
),
gridx
,
input_height
,
largest
));
#endif
default:
default:
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
PADDLE_THROW
(
platform
::
errors
::
Fatal
(
"the input data shape has error in the topk cuda kernel."
));
"the input data shape has error in the topk cuda kernel."
));
...
...
python/paddle/fluid/tests/unittests/test_top_k_v2_op.py
浏览文件 @
b8c6e180
...
@@ -131,6 +131,24 @@ class TestTopkOp5(TestTopkOp):
...
@@ -131,6 +131,24 @@ class TestTopkOp5(TestTopkOp):
self
.
outputs
=
{
'Out'
:
output
,
'Indices'
:
indices
}
self
.
outputs
=
{
'Out'
:
output
,
'Indices'
:
indices
}
class
TestTopkOp6
(
OpTest
):
def
init_args
(
self
):
self
.
k
=
100
self
.
axis
=
1
self
.
largest
=
True
def
setUp
(
self
):
self
.
op_type
=
"top_k_v2"
self
.
dtype
=
np
.
float64
self
.
input_data
=
np
.
random
.
rand
(
80
,
16384
)
self
.
init_args
()
self
.
inputs
=
{
'X'
:
self
.
input_data
}
self
.
attrs
=
{
'k'
:
self
.
k
,
'axis'
:
self
.
axis
,
'largest'
:
self
.
largest
}
output
,
indices
=
numpy_topk
(
self
.
input_data
,
axis
=
self
.
axis
,
k
=
self
.
k
,
largest
=
self
.
largest
)
self
.
outputs
=
{
'Out'
:
output
,
'Indices'
:
indices
}
class
TestTopKAPI
(
unittest
.
TestCase
):
class
TestTopKAPI
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
np
.
random
.
seed
(
123
)
np
.
random
.
seed
(
123
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录