Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
a5e07475
O
oneflow
项目概览
Oneflow-Inc
/
oneflow
上一次同步 接近 3 年
通知
13
Star
2733
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oneflow
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
a5e07475
编写于
2月 12, 2019
作者:
S
ScXfjiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
change top_k from cpu only to normal version (gpu and cpu)
Former-commit-id: 2f625c9bb2e0199b734b09dc2330f10ce85bd80a
上级
ddfe95a9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
61 addition
and
19 deletion
+61
-19
oneflow/core/kernel/top_k_kernel.cpp
oneflow/core/kernel/top_k_kernel.cpp
+29
-16
oneflow/core/kernel/top_k_kernel.cu
oneflow/core/kernel/top_k_kernel.cu
+23
-0
oneflow/core/kernel/top_k_kernel.h
oneflow/core/kernel/top_k_kernel.h
+8
-2
oneflow/core/operator/top_k_op.cpp
oneflow/core/operator/top_k_op.cpp
+1
-1
未找到文件。
oneflow/core/kernel/top_k_kernel.cpp
浏览文件 @
a5e07475
...
...
@@ -32,8 +32,27 @@ void ForwardPartDataContent(const T* in, const Range range, const int32_t instan
}
// namespace
template
<
typename
T
>
void
TopKKernel
<
T
>::
ForwardDataContent
(
const
KernelCtx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
BnInOp2Blob
)
const
{
struct
TopKKernelUtil
<
DeviceType
::
kCPU
,
T
>
{
static
void
Forward
(
const
T
*
in
,
const
int32_t
instance_num
,
const
int32_t
instance_size
,
const
int32_t
k
,
const
bool
sorted
,
int32_t
*
fw_buf
,
int32_t
*
out
)
{
const
int32_t
part_num
=
std
::
min
(
instance_num
,
Global
<
ThreadMgr
>::
Get
()
->
compute_thread_pool
()
->
thread_num
());
const
BalancedSplitter
bs
(
instance_num
,
part_num
);
BlockingCounter
bc
(
part_num
);
FOR_RANGE
(
int32_t
,
part_id
,
0
,
part_num
)
{
Range
range
=
bs
.
At
(
part_id
);
Global
<
ThreadMgr
>::
Get
()
->
compute_thread_pool
()
->
AddWork
([
=
,
&
bc
]()
{
ForwardPartDataContent
(
in
,
range
,
instance_size
,
k
,
sorted
,
fw_buf
,
out
);
bc
.
Decrease
();
});
}
bc
.
WaitUntilCntEqualZero
();
}
};
template
<
DeviceType
device_type
,
typename
T
>
void
TopKKernel
<
device_type
,
T
>::
ForwardDataContent
(
const
KernelCtx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
BnInOp2Blob
)
const
{
const
Blob
*
in_blob
=
BnInOp2Blob
(
"in"
);
Blob
*
fw_buf_blob
=
BnInOp2Blob
(
"fw_buf"
);
Blob
*
out_blob
=
BnInOp2Blob
(
"out"
);
...
...
@@ -45,21 +64,15 @@ void TopKKernel<T>::ForwardDataContent(const KernelCtx& ctx,
int32_t
*
fw_buf
=
fw_buf_blob
->
mut_dptr
<
int32_t
>
();
int32_t
*
out
=
out_blob
->
mut_dptr
<
int32_t
>
();
const
auto
&
conf
=
this
->
op_conf
().
top_k_conf
();
const
int32_t
k
=
conf
.
k
();
const
int32_t
part_num
=
std
::
min
(
instance_num
,
Global
<
ThreadMgr
>::
Get
()
->
compute_thread_pool
()
->
thread_num
());
const
BalancedSplitter
bs
(
instance_num
,
part_num
);
BlockingCounter
bc
(
part_num
);
FOR_RANGE
(
int32_t
,
part_id
,
0
,
part_num
)
{
Range
range
=
bs
.
At
(
part_id
);
Global
<
ThreadMgr
>::
Get
()
->
compute_thread_pool
()
->
AddWork
([
=
,
&
bc
]()
{
ForwardPartDataContent
(
in
,
range
,
instance_size
,
k
,
conf
.
sorted
(),
fw_buf
,
out
);
bc
.
Decrease
();
});
}
bc
.
WaitUntilCntEqualZero
();
TopKKernelUtil
<
device_type
,
T
>::
Forward
(
in
,
instance_num
,
instance_size
,
conf
.
k
(),
conf
.
sorted
(),
fw_buf
,
out
);
}
ADD_CPU_DEFAULT_KERNEL_CREATOR
(
OperatorConf
::
kTopKConf
,
TopKKernel
,
FLOATING_DATA_TYPE_SEQ
);
#define INSTANTIATE_TOP_K_KERNEL_UTIL(type_cpp, type_proto) \
template struct TopKKernelUtil<DeviceType::kCPU, type_cpp>;
OF_PP_FOR_EACH_TUPLE
(
INSTANTIATE_TOP_K_KERNEL_UTIL
,
FLOATING_DATA_TYPE_SEQ
)
#undef INSTANTIATE_TOP_K_KERNEL_UTIL
ADD_DEFAULT_KERNEL_CREATOR
(
OperatorConf
::
kTopKConf
,
TopKKernel
,
FLOATING_DATA_TYPE_SEQ
);
}
// namespace oneflow
oneflow/core/kernel/top_k_kernel.cu
0 → 100644
浏览文件 @
a5e07475
#include "oneflow/core/kernel/top_k_kernel.h"
#include "oneflow/core/common/data_type.h"
#include "oneflow/core/common/util.h"
#include "oneflow/core/device/cuda_util.h"
#include "oneflow/core/kernel/kernel_util.h"
#include "oneflow/core/kernel/kernel_util.cuh"
namespace
oneflow
{
template
<
typename
T
>
struct
TopKKernelUtil
<
DeviceType
::
kGPU
,
T
>
{
static
void
Forward
(
const
T
*
in
,
const
int32_t
instance_num
,
const
int32_t
instance_size
,
const
int32_t
k
,
const
bool
sorted
,
int32_t
*
fw_buf
,
int32_t
*
out
)
{
UNIMPLEMENTED
();
}
};
#define INSTANTIATE_TOP_K_KERNEL_UTIL(type_cpp, type_proto) \
template struct TopKKernelUtil<DeviceType::kGPU, type_cpp>;
OF_PP_FOR_EACH_TUPLE
(
INSTANTIATE_TOP_K_KERNEL_UTIL
,
FLOATING_DATA_TYPE_SEQ
)
#undef INSTANTIATE_TOP_K_KERNEL_UTIL
}
// namespace oneflow
\ No newline at end of file
oneflow/core/kernel/top_k_kernel.h
浏览文件 @
a5e07475
...
...
@@ -6,8 +6,8 @@
namespace
oneflow
{
template
<
typename
T
>
class
TopKKernel
final
:
public
KernelIf
<
DeviceType
::
kCPU
>
{
template
<
DeviceType
device_type
,
typename
T
>
class
TopKKernel
final
:
public
KernelIf
<
device_type
>
{
public:
OF_DISALLOW_COPY_AND_MOVE
(
TopKKernel
);
TopKKernel
()
=
default
;
...
...
@@ -18,6 +18,12 @@ class TopKKernel final : public KernelIf<DeviceType::kCPU> {
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
};
template
<
DeviceType
device_type
,
typename
T
>
struct
TopKKernelUtil
{
static
void
Forward
(
const
T
*
in
,
const
int32_t
instance_num
,
const
int32_t
instance_size
,
const
int32_t
k
,
const
bool
sorted
,
int32_t
*
fw_buf
,
int32_t
*
out
);
};
}
// namespace oneflow
#endif // ONEFLOW_CORE_KERNEL_TOP_K_KERNEL_H_
oneflow/core/operator/top_k_op.cpp
浏览文件 @
a5e07475
...
...
@@ -33,6 +33,6 @@ void TopKOp::VirtualGenKernelConf(
kernel_conf
->
set_data_type
(
GetBlobDesc4BnInOp
(
"in"
)
->
data_type
());
}
REGISTER_
CPU_
OP
(
OperatorConf
::
kTopKConf
,
TopKOp
);
REGISTER_OP
(
OperatorConf
::
kTopKConf
,
TopKOp
);
}
// namespace oneflow
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录