Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
32053d84
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,发现更多精彩内容 >>
提交
32053d84
编写于
9月 01, 2018
作者:
L
Li Xinqi
提交者:
Jinhui Yuan
9月 01, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
gdb breakpoints function (#1192)
上级
ccc3b389
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
104 addition
and
7 deletion
+104
-7
oneflow/core/common/gdb.cpp
oneflow/core/common/gdb.cpp
+75
-7
oneflow/core/common/gdb.h
oneflow/core/common/gdb.h
+24
-0
oneflow/core/kernel/kernel.cpp
oneflow/core/kernel/kernel.cpp
+5
-0
未找到文件。
oneflow/core/common/gdb.cpp
浏览文件 @
32053d84
#include "oneflow/core/register/blob.h"
#include "oneflow/core/register/blob.h"
#include "oneflow/core/kernel/kernel_util.h"
#include "oneflow/core/kernel/kernel_util.h"
#include "oneflow/core/common/util.h"
#include "oneflow/core/common/protobuf.h"
namespace
oneflow
{
namespace
oneflow
{
// used by gdb only
// used by gdb only
namespace
gdb
{
namespace
gdb
{
namespace
{
static
char
*
MallocThenCpyD2H
(
const
char
*
gpu_src
,
size_t
size
)
{
char
*
cpu_dst
=
reinterpret_cast
<
char
*>
(
malloc
(
size
));
cudaMemcpy
(
cpu_dst
,
gpu_src
,
size
,
cudaMemcpyDeviceToHost
);
return
cpu_dst
;
}
static
void
CpyH2DThenFree
(
char
*
gpu_dst
,
char
*
cpu_src
,
size_t
size
)
{
cudaMemcpy
(
gpu_dst
,
cpu_src
,
size
,
cudaMemcpyHostToDevice
);
free
(
cpu_src
);
}
template
<
typename
T
>
void
LoadFromStrFile
(
T
*
buf
,
const
std
::
string
&
file_name
)
{
std
::
ifstream
file
(
file_name
);
CHECK
(
file
.
is_open
());
std
::
string
line
;
for
(
int64_t
i
=
0
;
std
::
getline
(
file
,
line
);
++
i
)
{
buf
[
i
]
=
oneflow_cast
<
T
>
(
line
);
}
file
.
close
();
}
}
// namespace
// used by passing std::string param
// used by passing std::string param
static
std
::
string
param0
;
static
std
::
string
param0
;
static
const
Blob
*
CpuBlobCopiedFromGpuBlobPtr
(
uint64_t
gpu_blob_ptr
)
{
static
void
CudaMemCpyH2DThenFreeCpuPtr
(
uint64_t
gpu_dst
,
uint64_t
cpu_src
,
size_t
size
)
{
Blob
*
gpu_blob
=
reinterpret_cast
<
Blob
*>
(
gpu_blob_ptr
);
CpyH2DThenFree
(
reinterpret_cast
<
char
*>
(
gpu_dst
),
reinterpret_cast
<
char
*>
(
cpu_src
),
size
);
char
*
cpu_body_ptr
=
reinterpret_cast
<
char
*>
(
malloc
(
gpu_blob
->
ByteSizeOfDataContentField
()));
}
cudaMemcpy
(
cpu_body_ptr
,
gpu_blob
->
dptr
(),
gpu_blob
->
ByteSizeOfDataContentField
(),
cudaMemcpyDeviceToHost
);
static
void
*
MallocCpuBufThenCudaMemCpyD2H
(
uint64_t
gpu_src
,
size_t
size
)
{
return
new
Blob
(
const_cast
<
Regst
*>
(
gpu_blob
->
regst
()),
gpu_blob
->
blob_desc_ptr
(),
return
MallocThenCpyD2H
(
reinterpret_cast
<
char
*>
(
gpu_src
),
size
);
reinterpret_cast
<
char
*>
(
gpu_blob
->
mut_header_ptr
()),
cpu_body_ptr
);
}
static
void
FloatBufLoadFromStrFile
(
uint64_t
ptr
,
const
char
*
file_name
)
{
LoadFromStrFile
(
reinterpret_cast
<
float
*>
(
ptr
),
std
::
string
(
file_name
));
}
static
void
Int32BufLoadFromStrFile
(
uint64_t
ptr
,
const
char
*
file_name
)
{
LoadFromStrFile
(
reinterpret_cast
<
int32_t
*>
(
ptr
),
std
::
string
(
file_name
));
}
}
static
Blob
*
Blob4BnInOp
(
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>*
BnInOp2Blob
,
static
Blob
*
Blob4BnInOp
(
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>*
BnInOp2Blob
,
...
@@ -23,6 +56,41 @@ static Blob* Blob4BnInOp(const std::function<Blob*(const std::string&)>* BnInOp2
...
@@ -23,6 +56,41 @@ static Blob* Blob4BnInOp(const std::function<Blob*(const std::string&)>* BnInOp2
return
(
*
BnInOp2Blob
)(
std
::
string
(
bn_in_op
));
return
(
*
BnInOp2Blob
)(
std
::
string
(
bn_in_op
));
}
}
static
HashMap
<
std
::
string
,
std
::
vector
<
std
::
string
>>
GetAllBlobNames
(
const
OpAttribute
&
op_attribute
)
{
std
::
list
<
std
::
string
>
attrs
{
"input_bns"
,
"input_diff_bns"
,
"output_bns"
,
"output_diff_bns"
,
"data_tmp_bns"
,
"fw_buf_bns"
,
"bw_buf_bns"
,
"model_bns"
,
"model_diff_bns"
,
"const_model_bns"
,
"forward_model_bns"
,
"const_buf_bns"
,
"pb_input_bns"
,
"pb_output_bns"
,
};
HashMap
<
std
::
string
,
std
::
vector
<
std
::
string
>>
ret
;
for
(
const
auto
&
attr
:
attrs
)
{
const
auto
&
repeated_field
=
GetPbRpfFromPbMessage
<
std
::
string
>
(
op_attribute
,
attr
);
if
(
repeated_field
.
empty
()
==
false
)
{
ret
.
insert
({
attr
,
PbRpf2StdVec
(
repeated_field
)});
}
}
return
ret
;
}
void
ForwardEnterBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
)
{
// do nothing
}
void
ForwardLeaveBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
)
{
// do nothing
}
void
BackwardEnterBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
)
{
// do nothing
}
void
BackwardLeaveBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
)
{
// do nothing
}
}
// namespace gdb
}
// namespace gdb
}
// namespace oneflow
}
// namespace oneflow
oneflow/core/common/gdb.h
0 → 100644
浏览文件 @
32053d84
#ifndef ONEFLOW_CORE_COMMON_GDB_H_
#define ONEFLOW_CORE_COMMON_GDB_H_
namespace
oneflow
{
namespace
gdb
{
void
ForwardEnterBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
);
void
ForwardLeaveBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
);
void
BackwardEnterBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
);
void
BackwardLeaveBreakPoint
(
const
OpAttribute
&
op_attribute
,
const
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>&
BnInOp2Blob
);
}
// namespace gdb
}
// namespace oneflow
#endif // ONEFLOW_CORE_COMMON_GDB_H_
oneflow/core/kernel/kernel.cpp
浏览文件 @
32053d84
#include "oneflow/core/kernel/kernel.h"
#include "oneflow/core/kernel/kernel.h"
#include "oneflow/core/common/gdb.h"
namespace
oneflow
{
namespace
oneflow
{
...
@@ -30,9 +31,13 @@ void Kernel::InitModelAndConstBuf(const KernelCtx& ctx, const ParallelContext* p
...
@@ -30,9 +31,13 @@ void Kernel::InitModelAndConstBuf(const KernelCtx& ctx, const ParallelContext* p
void
Kernel
::
Launch
(
const
KernelCtx
&
ctx
,
void
Kernel
::
Launch
(
const
KernelCtx
&
ctx
,
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
BnInOp2Blob
)
const
{
std
::
function
<
Blob
*
(
const
std
::
string
&
)
>
BnInOp2Blob
)
const
{
if
(
kernel_conf_
.
is_forward
())
{
if
(
kernel_conf_
.
is_forward
())
{
gdb
::
ForwardEnterBreakPoint
(
op_attribute
(),
BnInOp2Blob
);
Forward
(
ctx
,
BnInOp2Blob
);
Forward
(
ctx
,
BnInOp2Blob
);
gdb
::
ForwardLeaveBreakPoint
(
op_attribute
(),
BnInOp2Blob
);
}
else
{
}
else
{
gdb
::
BackwardEnterBreakPoint
(
op_attribute
(),
BnInOp2Blob
);
Backward
(
ctx
,
BnInOp2Blob
);
Backward
(
ctx
,
BnInOp2Blob
);
gdb
::
BackwardLeaveBreakPoint
(
op_attribute
(),
BnInOp2Blob
);
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录