Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
c927939b
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,发现更多精彩内容 >>
提交
c927939b
编写于
6月 13, 2017
作者:
W
willzhang4a58
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add register_gpu_kernel, cpu_channel
上级
f187b057
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
59 addition
and
42 deletion
+59
-42
oneflow/core/actor/actor.cpp
oneflow/core/actor/actor.cpp
+1
-1
oneflow/core/actor/actor.h
oneflow/core/actor/actor.h
+1
-1
oneflow/core/actor/boxing_actor.cpp
oneflow/core/actor/boxing_actor.cpp
+2
-2
oneflow/core/actor/boxing_actor.h
oneflow/core/actor/boxing_actor.h
+1
-1
oneflow/core/actor/copy_actor.cpp
oneflow/core/actor/copy_actor.cpp
+1
-1
oneflow/core/actor/copy_actor.h
oneflow/core/actor/copy_actor.h
+1
-1
oneflow/core/actor/copy_comm_net_actor.cpp
oneflow/core/actor/copy_comm_net_actor.cpp
+1
-1
oneflow/core/actor/copy_hd_actor.cpp
oneflow/core/actor/copy_hd_actor.cpp
+1
-1
oneflow/core/actor/fw_data_comp_actor.cpp
oneflow/core/actor/fw_data_comp_actor.cpp
+2
-2
oneflow/core/actor/fw_data_comp_actor.h
oneflow/core/actor/fw_data_comp_actor.h
+1
-1
oneflow/core/actor/model_update_comp_actor.cpp
oneflow/core/actor/model_update_comp_actor.cpp
+5
-5
oneflow/core/actor/model_update_comp_actor.h
oneflow/core/actor/model_update_comp_actor.h
+5
-5
oneflow/core/kernel/convolution_kernel.cpp
oneflow/core/kernel/convolution_kernel.cpp
+3
-3
oneflow/core/kernel/convolution_kernel.cu
oneflow/core/kernel/convolution_kernel.cu
+4
-2
oneflow/core/kernel/convolution_kernel.h
oneflow/core/kernel/convolution_kernel.h
+4
-4
oneflow/core/kernel/kernel.cpp
oneflow/core/kernel/kernel.cpp
+1
-1
oneflow/core/kernel/kernel.h
oneflow/core/kernel/kernel.h
+5
-8
oneflow/core/kernel/kernel_context.h
oneflow/core/kernel/kernel_context.h
+16
-0
oneflow/core/kernel/kernel_manager.h
oneflow/core/kernel/kernel_manager.h
+4
-2
未找到文件。
oneflow/core/actor/actor.cpp
浏览文件 @
c927939b
...
...
@@ -44,7 +44,7 @@ void Actor::Init(const TaskProto& task_proto) {
}
void
Actor
::
WardKernel
(
const
KernelC
ontext
&
kernel_ctx
,
const
KernelC
tx
&
kernel_ctx
,
std
::
function
<
std
::
shared_ptr
<
RegstWarpper
>
(
uint64_t
)
>
Regst4RegstDescId
)
{
for
(
const
ExecKernel
&
ek
:
exec_kernel_vec_
)
{
(
ek
.
kernel
->*
ward_func_
)(
kernel_ctx
,
[
&
](
const
std
::
string
&
bn_in_op
)
{
...
...
oneflow/core/actor/actor.h
浏览文件 @
c927939b
...
...
@@ -34,7 +34,7 @@ class Actor {
Actor
()
=
default
;
void
WardKernel
(
const
KernelC
ontext
&
kernel_ctx
,
const
KernelC
tx
&
kernel_ctx
,
std
::
function
<
std
::
shared_ptr
<
RegstWarpper
>
(
uint64_t
)
>
Regst4RegstDescId
);
void
ForEachProducedRegst
(
std
::
function
<
void
(
Regst
*
)
>
);
uint64_t
RegstDescId4Name
(
const
std
::
string
&
name
)
const
{
...
...
oneflow/core/actor/boxing_actor.cpp
浏览文件 @
c927939b
...
...
@@ -11,7 +11,7 @@ void BoxingActor::Init(const TaskProto& task_proto) {
void
BoxingActor
::
ProcessMsg
(
const
ActorMsg
&
msg
,
const
ThreadContext
&
thread_ctx
)
{
KernelC
ontext
kernel_ctx
;
KernelC
tx
kernel_ctx
;
if
(
TryUpdtStateAsFromRegstReader
(
msg
.
regst_warpper
()
->
regst_raw_ptr
())
!=
0
)
{
std
::
shared_ptr
<
RegstWarpper
>
regst_wp
=
msg
.
regst_warpper
();
auto
waiting_in_regst_it
=
waiting_in_regst_
.
find
(
regst_wp
->
piece_id
());
...
...
@@ -36,7 +36,7 @@ void BoxingActor::ProcessMsg(const ActorMsg& msg,
}
}
void
BoxingActor
::
WardKernelAndSendMsg
(
const
KernelC
ontext
&
kernel_ctx
)
{
void
BoxingActor
::
WardKernelAndSendMsg
(
const
KernelC
tx
&
kernel_ctx
)
{
uint64_t
piece_id
=
ready_in_regst_
.
front
().
first
;
WardKernel
(
kernel_ctx
,
[
this
](
uint64_t
regst_desc_id
)
->
std
::
shared_ptr
<
RegstWarpper
>
{
Regst
*
regst
=
GetCurWriteableRegst
(
regst_desc_id
);
...
...
oneflow/core/actor/boxing_actor.h
浏览文件 @
c927939b
...
...
@@ -18,7 +18,7 @@ class BoxingActor final : public Actor {
using
RDescId2RwMap
=
HashMap
<
uint64_t
,
std
::
shared_ptr
<
RegstWarpper
>>
;
using
RDescId2RwMapPtr
=
std
::
unique_ptr
<
RDescId2RwMap
>
;
void
WardKernelAndSendMsg
(
const
KernelC
ontext
&
);
void
WardKernelAndSendMsg
(
const
KernelC
tx
&
);
// <piece_id, map>
HashMap
<
uint64_t
,
RDescId2RwMapPtr
>
waiting_in_regst_
;
...
...
oneflow/core/actor/copy_actor.cpp
浏览文件 @
c927939b
...
...
@@ -9,7 +9,7 @@ void CopyActor::Init(const TaskProto& task_proto) {
}
void
CopyActor
::
ProcessMsgWithKernelCtx
(
const
ActorMsg
&
msg
,
const
KernelC
ontext
&
kernel_ctx
)
{
const
KernelC
tx
&
kernel_ctx
)
{
if
(
TryUpdtStateAsFromRegstReader
(
msg
.
regst_warpper
()
->
regst_raw_ptr
())
!=
0
)
{
waiting_in_regst_
.
push
(
std
::
move
(
msg
.
regst_warpper
()));
}
...
...
oneflow/core/actor/copy_actor.h
浏览文件 @
c927939b
...
...
@@ -15,7 +15,7 @@ public:
protected:
CopyActor
()
=
default
;
void
ProcessMsgWithKernelCtx
(
const
ActorMsg
&
msg
,
const
KernelC
ontext
&
kernel_ctx
);
void
ProcessMsgWithKernelCtx
(
const
ActorMsg
&
msg
,
const
KernelC
tx
&
kernel_ctx
);
private:
std
::
queue
<
std
::
shared_ptr
<
RegstWarpper
>>
waiting_in_regst_
;
...
...
oneflow/core/actor/copy_comm_net_actor.cpp
浏览文件 @
c927939b
...
...
@@ -6,7 +6,7 @@ namespace oneflow {
void
CopyCommNetActor
::
ProcessMsg
(
const
ActorMsg
&
msg
,
const
ThreadContext
&
)
{
KernelC
ontext
kernel_ctx
;
KernelC
tx
kernel_ctx
;
ProcessMsgWithKernelCtx
(
msg
,
kernel_ctx
);
}
...
...
oneflow/core/actor/copy_hd_actor.cpp
浏览文件 @
c927939b
...
...
@@ -6,7 +6,7 @@ namespace oneflow {
void
CopyHdActor
::
ProcessMsg
(
const
ActorMsg
&
msg
,
const
ThreadContext
&
thread_ctx
)
{
KernelC
ontext
kernel_ctx
;
KernelC
tx
kernel_ctx
;
kernel_ctx
.
cuda_stream
=
thread_ctx
.
copy_hd_cuda_stream
;
ProcessMsgWithKernelCtx
(
msg
,
kernel_ctx
);
}
...
...
oneflow/core/actor/fw_data_comp_actor.cpp
浏览文件 @
c927939b
...
...
@@ -25,7 +25,7 @@ bool FwDataCompActor::IsReadReady() {
void
FwDataCompActor
::
ProcessMsg
(
const
ActorMsg
&
msg
,
const
ThreadContext
&
thread_ctx
)
{
KernelC
ontext
kernel_ctx
;
KernelC
tx
kernel_ctx
;
kernel_ctx
.
cuda_stream
=
thread_ctx
.
compute_cuda_stream
;
if
(
msg
.
msg_type
()
==
ActorMsgType
::
kCmdMsg
)
{
TODO
();
...
...
@@ -55,7 +55,7 @@ void FwDataCompActor::ProcessMsg(const ActorMsg& msg,
}
}
void
FwDataCompActor
::
WardKernelAndSendMsg
(
const
KernelC
ontext
&
kernel_ctx
)
{
void
FwDataCompActor
::
WardKernelAndSendMsg
(
const
KernelC
tx
&
kernel_ctx
)
{
CHECK_EQ
(
in_
.
front
()
->
piece_id
(),
expected_piece_id
());
ready_in_regst_
[
in_
.
front
()
->
regst_desc_id
()]
=
in_
.
front
();
uint64_t
piece_id
=
in_
.
front
()
->
piece_id
();
...
...
oneflow/core/actor/fw_data_comp_actor.h
浏览文件 @
c927939b
...
...
@@ -16,7 +16,7 @@ public:
private:
bool
IsReadReady
();
void
WardKernelAndSendMsg
(
const
KernelC
ontext
&
);
void
WardKernelAndSendMsg
(
const
KernelC
tx
&
);
uint64_t
expected_model_version_id_
;
uint64_t
model_regst_desc_id_
;
...
...
oneflow/core/actor/model_update_comp_actor.cpp
浏览文件 @
c927939b
...
...
@@ -12,14 +12,14 @@ void MdUpdtCompActor::Init(const TaskProto& task_proto) {
void
MdUpdtCompActor
::
ProcessMsg
(
const
ActorMsg
&
actor_msg
,
const
ThreadContext
&
thread_ctx
)
{
KernelC
ontext
kernel_ctx
;
KernelC
tx
kernel_ctx
;
kernel_ctx
.
cuda_stream
=
thread_ctx
.
compute_cuda_stream
;
(
this
->*
cur_handle_
)(
actor_msg
,
kernel_ctx
);
}
void
MdUpdtCompActor
::
HandleBeforeInitializeModel
(
const
ActorMsg
&
actor_msg
,
const
KernelC
ontext
&
kernel_ctx
)
{
const
KernelC
tx
&
kernel_ctx
)
{
CHECK
(
actor_msg
.
actor_cmd
()
==
ActorCmd
::
kInitializeModel
);
Regst
*
model_regst
=
GetCurWriteableRegst
(
model_regst_desc_id_
);
model_regst
->
set_model_version_id
(
0
);
...
...
@@ -46,7 +46,7 @@ void MdUpdtCompActor::HandleBeforeInitializeModel(
void
MdUpdtCompActor
::
HandleBeforeSendInitialModel
(
const
ActorMsg
&
actor_msg
,
const
KernelC
ontext
&
kernel_ctx
)
{
const
KernelC
tx
&
kernel_ctx
)
{
CHECK
(
actor_msg
.
actor_cmd
()
==
ActorCmd
::
kSendInitialModel
);
CurWriteDone
();
SetReadOnlyForRegstDescId
(
model_tmp_regst_desc_id_
);
...
...
@@ -55,7 +55,7 @@ void MdUpdtCompActor::HandleBeforeSendInitialModel(
void
MdUpdtCompActor
::
HandleForUpdateModel
(
const
ActorMsg
&
actor_msg
,
const
KernelC
ontext
&
kernel_ctx
)
{
const
KernelC
tx
&
kernel_ctx
)
{
if
(
actor_msg
.
msg_type
()
==
ActorMsgType
::
kCmdMsg
)
{
CHECK
(
actor_msg
.
actor_cmd
()
==
ActorCmd
::
kStop
);
TODO
();
...
...
@@ -69,7 +69,7 @@ void MdUpdtCompActor::HandleForUpdateModel(
void
MdUpdtCompActor
::
ProcessRegstFromMsg
(
std
::
shared_ptr
<
RegstWarpper
>
regst_warpper
,
const
KernelC
ontext
&
kernel_ctx
)
{
const
KernelC
tx
&
kernel_ctx
)
{
if
(
TryUpdtStateAsFromRegstReader
(
regst_warpper
->
regst_raw_ptr
())
!=
0
)
{
waiting_model_diff_acc_queue_
.
push
(
regst_warpper
);
}
...
...
oneflow/core/actor/model_update_comp_actor.h
浏览文件 @
c927939b
...
...
@@ -15,13 +15,13 @@ class MdUpdtCompActor final : public CompActor {
void
ProcessMsg
(
const
ActorMsg
&
,
const
ThreadContext
&
)
override
;
private:
void
HandleBeforeInitializeModel
(
const
ActorMsg
&
,
const
KernelC
ontext
&
);
void
HandleBeforeSendInitialModel
(
const
ActorMsg
&
,
const
KernelC
ontext
&
);
void
HandleForUpdateModel
(
const
ActorMsg
&
,
const
KernelC
ontext
&
);
void
HandleBeforeInitializeModel
(
const
ActorMsg
&
,
const
KernelC
tx
&
);
void
HandleBeforeSendInitialModel
(
const
ActorMsg
&
,
const
KernelC
tx
&
);
void
HandleForUpdateModel
(
const
ActorMsg
&
,
const
KernelC
tx
&
);
void
ProcessRegstFromMsg
(
std
::
shared_ptr
<
RegstWarpper
>
,
const
KernelC
ontext
&
);
void
ProcessRegstFromMsg
(
std
::
shared_ptr
<
RegstWarpper
>
,
const
KernelC
tx
&
);
void
(
MdUpdtCompActor
::*
cur_handle_
)(
const
ActorMsg
&
,
const
KernelC
ontext
&
);
void
(
MdUpdtCompActor
::*
cur_handle_
)(
const
ActorMsg
&
,
const
KernelC
tx
&
);
uint64_t
model_regst_desc_id_
;
uint64_t
model_tmp_regst_desc_id_
;
std
::
queue
<
std
::
shared_ptr
<
RegstWarpper
>>
waiting_model_diff_acc_queue_
;
...
...
oneflow/core/kernel/convolution_kernel.cpp
浏览文件 @
c927939b
...
...
@@ -5,19 +5,19 @@ namespace oneflow {
template
<
typename
floating_point_type
>
void
ConvolutionKernel
<
DeviceType
::
kCPU
,
floating_point_type
>::
Forward
(
const
KernelC
ontext
&
,
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
bn_in_op2blob_ptr
)
const
{
TODO
();
}
template
<
typename
floating_point_type
>
void
ConvolutionKernel
<
DeviceType
::
kCPU
,
floating_point_type
>::
Backward
(
const
KernelC
ontext
&
,
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
bn_in_op2blob_ptr
)
const
{
TODO
();
}
INSTANTIATE_CPU_KERNEL_CLASS
(
ConvolutionKernel
);
REGISTER_KERNEL
(
OperatorConf
::
kConvolutionConf
,
ConvolutionKernel
);
REGISTER_
CPU_
KERNEL
(
OperatorConf
::
kConvolutionConf
,
ConvolutionKernel
);
}
// namespace oneflow
oneflow/core/kernel/convolution_kernel.cu
浏览文件 @
c927939b
...
...
@@ -5,18 +5,20 @@ namespace oneflow {
template
<
typename
floating_point_type
>
void
ConvolutionKernel
<
DeviceType
::
kGPU
,
floating_point_type
>::
Forward
(
const
KernelC
ontext
&
,
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
bn_in_op2blob_ptr
)
const
{
TODO
();
}
template
<
typename
floating_point_type
>
void
ConvolutionKernel
<
DeviceType
::
kGPU
,
floating_point_type
>::
Backward
(
const
KernelC
ontext
&
,
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
bn_in_op2blob_ptr
)
const
{
TODO
();
}
INSTANTIATE_GPU_KERNEL_CLASS
(
ConvolutionKernel
);
REGISTER_GPU_KERNEL
(
OperatorConf
::
kConvolutionConf
,
ConvolutionKernel
);
}
// namespace oneflow
oneflow/core/kernel/convolution_kernel.h
浏览文件 @
c927939b
...
...
@@ -19,8 +19,8 @@ class ConvolutionKernel<DeviceType::kCPU, floating_point_type> final : public Ke
ConvolutionKernel
()
=
default
;
~
ConvolutionKernel
()
=
default
;
void
Forward
(
const
KernelC
ontext
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
void
Backward
(
const
KernelC
ontext
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
void
Forward
(
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
void
Backward
(
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
};
template
<
typename
floating_point_type
>
...
...
@@ -30,8 +30,8 @@ class ConvolutionKernel<DeviceType::kGPU, floating_point_type> final : public Ke
ConvolutionKernel
()
=
default
;
~
ConvolutionKernel
()
=
default
;
void
Forward
(
const
KernelC
ontext
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
void
Backward
(
const
KernelC
ontext
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
void
Forward
(
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
void
Backward
(
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
override
;
};
}
// namespace oneflow
...
...
oneflow/core/kernel/kernel.cpp
浏览文件 @
c927939b
...
...
@@ -9,7 +9,7 @@ void Kernel::InitFromOpProto(const OperatorProto& op_proto) {
}
void
Kernel
::
InitModelAndModelTmpBlobs
(
const
KernelC
ontext
&
ctx
,
const
KernelC
tx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
Blob4BnInOp
)
const
{
TODO
();
}
...
...
oneflow/core/kernel/kernel.h
浏览文件 @
c927939b
...
...
@@ -9,13 +9,10 @@
#include "oneflow/core/operator/operator.h"
#include "oneflow/core/operator/operator_manager.h"
#include "oneflow/core/operator/operator.pb.h"
#include "oneflow/core/kernel/kernel_context.h"
namespace
oneflow
{
struct
KernelContext
{
const
cudaStream_t
*
cuda_stream
;
};
class
Kernel
{
public:
OF_DISALLOW_COPY_AND_MOVE
(
Kernel
);
...
...
@@ -24,17 +21,17 @@ class Kernel {
void
InitFromOpProto
(
const
OperatorProto
&
op_proto
);
void
InitModelAndModelTmpBlobs
(
const
KernelC
ontext
&
ctx
,
const
KernelC
tx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
Blob4BnInOp
)
const
;
// for Forward / Bp Calculation in FwExecGragh node and BpExecGragh node
// through bn_in_op2blob_ptr function get the input blob and output blob
// the Kernel will using the input blob calculate the result and fill output
virtual
void
Forward
(
const
KernelC
ontext
&
ctx
,
const
KernelC
tx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
=
0
;
virtual
void
Backward
(
const
KernelC
ontext
&
ctx
,
const
KernelC
tx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
=
0
;
//
...
...
@@ -51,7 +48,7 @@ class Kernel {
};
using
KernelWardFunc
=
void
(
Kernel
::*
)(
const
KernelC
ontext
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
;
const
KernelC
tx
&
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
)
const
;
#define INSTANTIATE_CPU_KERNEL_CLASS(classname) \
char gInstantiationGuardCPU##classname; \
...
...
oneflow/core/kernel/kernel_context.h
0 → 100644
浏览文件 @
c927939b
#ifndef ONEFLOW_CORE_KERNEL_KERNEL_CONTEXT_H_
#define ONEFLOW_CORE_KERNEL_KERNEL_CONTEXT_H_
#include "oneflow/core/common/util.h"
#include "oneflow/core/common/channel.h"
namespace
oneflow
{
struct
KernelCtx
{
Channel
<
std
::
function
<
void
()
>>*
cpu_channel
;
const
cudaStream_t
*
cuda_stream
;
};
}
// namespace oneflow
#endif // ONEFLOW_CORE_KERNEL_KERNEL_CONTEXT_H_
oneflow/core/kernel/kernel_manager.h
浏览文件 @
c927939b
...
...
@@ -67,9 +67,11 @@ struct GpuDoubleKernelRegister {
}
};
#define REGISTER_KERNEL(OpTypeCase, KernelType) \
#define REGISTER_
CPU_
KERNEL(OpTypeCase, KernelType) \
static CpuFloatKernelRegister<OpTypeCase, KernelType<DeviceType::kCPU, float>> g_##KernelType##_cpu_float_regst_var; \
static CpuDoubleKernelRegister<OpTypeCase, KernelType<DeviceType::kCPU, double>> g_##KernelType##_cpu_double_regst_var; \
static CpuDoubleKernelRegister<OpTypeCase, KernelType<DeviceType::kCPU, double>> g_##KernelType##_cpu_double_regst_var;
#define REGISTER_GPU_KERNEL(OpTypeCase, KernelType) \
static GpuFloatKernelRegister<OpTypeCase, KernelType<DeviceType::kGPU, float>> g_##KernelType##_gpu_float_regst_var; \
static GpuDoubleKernelRegister<OpTypeCase, KernelType<DeviceType::kGPU, double>> g_##KernelType##_gpu_double_regst_var;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录