Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Oneflow-Inc
oneflow
提交
6529a7c5
O
oneflow
项目概览
Oneflow-Inc
/
oneflow
上一次同步 2 年多
通知
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,体验更适合开发者的 AI 搜索 >>
提交
6529a7c5
编写于
5月 23, 2018
作者:
W
willzhang4a58
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
two buf in one stream
Former-commit-id: dcf1b183c3b86ac547f9ac4581e2d05de0feb853
上级
51065dc5
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
137 addition
and
24 deletion
+137
-24
examples/mnist/predict.net
examples/mnist/predict.net
+1
-1
oneflow/core/job/improver.cpp
oneflow/core/job/improver.cpp
+1
-1
oneflow/core/persistence/cyclic_persistent_in_stream_without_local_copy.cpp
...stence/cyclic_persistent_in_stream_without_local_copy.cpp
+4
-2
oneflow/core/persistence/cyclic_persistent_in_stream_without_local_copy.h
...sistence/cyclic_persistent_in_stream_without_local_copy.h
+1
-1
oneflow/core/persistence/normal_persistent_in_stream.h
oneflow/core/persistence/normal_persistent_in_stream.h
+2
-0
oneflow/core/persistence/persistent_in_stream_without_local_copy.cpp
...e/persistence/persistent_in_stream_without_local_copy.cpp
+54
-16
oneflow/core/persistence/persistent_in_stream_without_local_copy.h
...ore/persistence/persistent_in_stream_without_local_copy.h
+12
-3
oneflow/core/thread/thread_pool.cpp
oneflow/core/thread/thread_pool.cpp
+34
-0
oneflow/core/thread/thread_pool.h
oneflow/core/thread/thread_pool.h
+28
-0
未找到文件。
examples/mnist/predict.net
浏览文件 @
6529a7c5
op {
op {
name: "decode"
name: "decode"
decode_ofrecord_conf {
decode_ofrecord_conf {
data_dir: "/dataset/mnist_kaggle/t
est
/6"
data_dir: "/dataset/mnist_kaggle/t
rain
/6"
blob {
blob {
name: "img_raw"
name: "img_raw"
data_type: kFloat
data_type: kFloat
...
...
oneflow/core/job/improver.cpp
浏览文件 @
6529a7c5
...
@@ -177,7 +177,7 @@ uint64_t Improver::AvailableMemSize(int64_t machine_id, int64_t memory_zone_id)
...
@@ -177,7 +177,7 @@ uint64_t Improver::AvailableMemSize(int64_t machine_id, int64_t memory_zone_id)
JobDesc
*
job_desc
=
Global
<
JobDesc
>::
Get
();
JobDesc
*
job_desc
=
Global
<
JobDesc
>::
Get
();
if
(
memory_zone_id
==
job_desc
->
GpuDeviceNum
())
{
if
(
memory_zone_id
==
job_desc
->
GpuDeviceNum
())
{
mem_size
-=
job_desc
->
reserved_host_mem_byte
();
mem_size
-=
job_desc
->
reserved_host_mem_byte
();
mem_size
-=
job_desc
->
persistence_buf_byte
()
*
record_load_task_num_
.
at
(
machine_id
);
mem_size
-=
job_desc
->
persistence_buf_byte
()
*
2
*
record_load_task_num_
.
at
(
machine_id
);
}
else
{
}
else
{
mem_size
-=
job_desc
->
reserved_device_mem_byte
();
mem_size
-=
job_desc
->
reserved_device_mem_byte
();
}
}
...
...
oneflow/core/persistence/cyclic_persistent_in_stream_without_local_copy.cpp
浏览文件 @
6529a7c5
#include "oneflow/core/persistence/cyclic_persistent_in_stream_without_local_copy.h"
#include "oneflow/core/persistence/cyclic_persistent_in_stream_without_local_copy.h"
#include "oneflow/core/job/job_desc.h"
namespace
oneflow
{
namespace
oneflow
{
...
@@ -10,8 +11,9 @@ CyclicPersistentInStreamWithoutLocalCopy::CyclicPersistentInStreamWithoutLocalCo
...
@@ -10,8 +11,9 @@ CyclicPersistentInStreamWithoutLocalCopy::CyclicPersistentInStreamWithoutLocalCo
}
}
void
CyclicPersistentInStreamWithoutLocalCopy
::
UpdateBuffer
()
{
void
CyclicPersistentInStreamWithoutLocalCopy
::
UpdateBuffer
()
{
if
(
is_first_update_buffer_
==
false
&&
file_size
()
<=
mut_buffer
()
->
size
()
-
1
)
{
if
(
is_first_update_buffer_
==
false
set_cur_buf_begin
(
mut_buffer
()
->
data
());
&&
file_size
()
<=
Global
<
JobDesc
>::
Get
()
->
persistence_buf_byte
())
{
set_cur_buf_begin
(
mut_buffer
());
}
else
{
}
else
{
PersistentInStreamWithoutLocalCopy
::
UpdateBuffer
();
PersistentInStreamWithoutLocalCopy
::
UpdateBuffer
();
}
}
...
...
oneflow/core/persistence/cyclic_persistent_in_stream_without_local_copy.h
浏览文件 @
6529a7c5
...
@@ -9,7 +9,7 @@ class CyclicPersistentInStreamWithoutLocalCopy final : public PersistentInStream
...
@@ -9,7 +9,7 @@ class CyclicPersistentInStreamWithoutLocalCopy final : public PersistentInStream
public:
public:
OF_DISALLOW_COPY_AND_MOVE
(
CyclicPersistentInStreamWithoutLocalCopy
);
OF_DISALLOW_COPY_AND_MOVE
(
CyclicPersistentInStreamWithoutLocalCopy
);
CyclicPersistentInStreamWithoutLocalCopy
()
=
delete
;
CyclicPersistentInStreamWithoutLocalCopy
()
=
delete
;
~
CyclicPersistentInStreamWithoutLocalCopy
()
=
default
;
~
CyclicPersistentInStreamWithoutLocalCopy
()
{
WaitUntilStandByBufferReadyBytesNotEqualZero
();
}
CyclicPersistentInStreamWithoutLocalCopy
(
fs
::
FileSystem
*
fs
,
const
std
::
string
&
file_path
);
CyclicPersistentInStreamWithoutLocalCopy
(
fs
::
FileSystem
*
fs
,
const
std
::
string
&
file_path
);
...
...
oneflow/core/persistence/normal_persistent_in_stream.h
浏览文件 @
6529a7c5
...
@@ -18,6 +18,8 @@ class NormalPersistentInStream final : public PersistentInStreamWithoutLocalCopy
...
@@ -18,6 +18,8 @@ class NormalPersistentInStream final : public PersistentInStreamWithoutLocalCopy
NormalPersistentInStream
(
fs
::
FileSystem
*
fs
,
const
std
::
string
&
file_path
)
NormalPersistentInStream
(
fs
::
FileSystem
*
fs
,
const
std
::
string
&
file_path
)
:
NormalPersistentInStream
(
fs
,
file_path
,
0
)
{}
:
NormalPersistentInStream
(
fs
,
file_path
,
0
)
{}
~
NormalPersistentInStream
()
{
WaitUntilStandByBufferReadyBytesNotEqualZero
();
}
private:
private:
void
AddNForCurFilePos
(
uint64_t
n
)
override
{
set_cur_file_pos
(
cur_file_pos
()
+
n
);
}
void
AddNForCurFilePos
(
uint64_t
n
)
override
{
set_cur_file_pos
(
cur_file_pos
()
+
n
);
}
};
};
...
...
oneflow/core/persistence/persistent_in_stream_without_local_copy.cpp
浏览文件 @
6529a7c5
#include "oneflow/core/persistence/persistent_in_stream_without_local_copy.h"
#include "oneflow/core/persistence/persistent_in_stream_without_local_copy.h"
#include "oneflow/core/job/job_desc.h"
#include "oneflow/core/job/job_desc.h"
#include
<cstring>
#include
"oneflow/core/thread/thread_pool.h"
namespace
oneflow
{
namespace
oneflow
{
static
ThreadPool
g_persistent_in_thread_pool
(
1
);
PersistentInStreamWithoutLocalCopy
::~
PersistentInStreamWithoutLocalCopy
()
{
WaitUntilStandByBufferReadyBytesNotEqualZero
();
delete
[]
standby_buffer_
;
delete
[]
buffer_
;
}
int32_t
PersistentInStreamWithoutLocalCopy
::
ReadLine
(
std
::
string
*
l
)
{
int32_t
PersistentInStreamWithoutLocalCopy
::
ReadLine
(
std
::
string
*
l
)
{
if
(
IsEof
())
{
return
-
1
;
}
if
(
IsEof
())
{
return
-
1
;
}
l
->
clear
();
l
->
clear
();
...
@@ -27,8 +35,8 @@ int32_t PersistentInStreamWithoutLocalCopy::Read(char* s, size_t n) {
...
@@ -27,8 +35,8 @@ int32_t PersistentInStreamWithoutLocalCopy::Read(char* s, size_t n) {
while
(
n
)
{
while
(
n
)
{
if
(
cur_buf_begin_
==
cur_buf_end_
)
{
UpdateBuffer
();
}
if
(
cur_buf_begin_
==
cur_buf_end_
)
{
UpdateBuffer
();
}
CHECK_LT
(
cur_buf_begin_
,
cur_buf_end_
);
CHECK_LT
(
cur_buf_begin_
,
cur_buf_end_
);
int64_t
copy_size
=
std
::
min
(
cur_buf_end_
-
cur_buf_begin_
,
static_cast
<
int64_t
>
(
n
)
);
size_t
copy_size
=
std
::
min
<
size_t
>
(
cur_buf_end_
-
cur_buf_begin_
,
n
);
std
::
memcpy
(
s
,
cur_buf_begin_
,
static_cast
<
size_t
>
(
copy_size
)
);
memcpy
(
s
,
cur_buf_begin_
,
copy_size
);
s
+=
copy_size
;
s
+=
copy_size
;
cur_buf_begin_
+=
copy_size
;
cur_buf_begin_
+=
copy_size
;
n
-=
copy_size
;
n
-=
copy_size
;
...
@@ -41,26 +49,56 @@ PersistentInStreamWithoutLocalCopy::PersistentInStreamWithoutLocalCopy(fs::FileS
...
@@ -41,26 +49,56 @@ PersistentInStreamWithoutLocalCopy::PersistentInStreamWithoutLocalCopy(fs::FileS
uint64_t
offset
)
{
uint64_t
offset
)
{
fs
->
NewRandomAccessFile
(
file_path
,
&
file_
);
fs
->
NewRandomAccessFile
(
file_path
,
&
file_
);
file_size_
=
fs
->
GetFileSize
(
file_path
);
file_size_
=
fs
->
GetFileSize
(
file_path
);
CHECK_LT
(
offset
,
file_size_
);
standby_buffer_
=
new
char
[
Global
<
JobDesc
>::
Get
()
->
persistence_buf_byte
()
+
1
];
standby_buffer_ready_bytes_
=
0
;
cur_file_pos_
=
offset
;
cur_file_pos_
=
offset
;
buffer_
.
resize
(
Global
<
JobDesc
>::
Get
()
->
persistence_buf_byte
()
+
1
);
file_read_done_
=
false
;
cur_buf_begin_
=
buffer_
.
data
();
buffer_
=
new
char
[
Global
<
JobDesc
>::
Get
()
->
persistence_buf_byte
()
+
1
];
cur_buf_end_
=
buffer_
.
data
();
cur_buf_begin_
=
buffer_
;
cur_buf_end_
=
buffer_
;
*
cur_buf_end_
=
'\0'
;
*
cur_buf_end_
=
'\0'
;
}
AsyncUpdateStandByBuffer
();
bool
PersistentInStreamWithoutLocalCopy
::
IsEof
()
const
{
return
cur_buf_begin_
==
cur_buf_end_
&&
cur_file_pos_
==
file_size_
;
}
}
void
PersistentInStreamWithoutLocalCopy
::
UpdateBuffer
()
{
void
PersistentInStreamWithoutLocalCopy
::
UpdateBuffer
()
{
CHECK_EQ
(
cur_buf_begin_
,
cur_buf_end_
);
CHECK_EQ
(
cur_buf_begin_
,
cur_buf_end_
);
uint64_t
n
=
std
::
min
(
buffer_
.
size
()
-
1
,
file_size_
-
cur_file_pos_
);
WaitUntilStandByBufferReadyBytesNotEqualZero
(
);
if
(
n
==
0
)
{
return
;
}
if
(
standby_buffer_ready_bytes_
==
-
1
)
{
return
;
}
file_
->
Read
(
cur_file_pos_
,
n
,
buffer_
.
data
()
);
std
::
swap
(
standby_buffer_
,
buffer_
);
cur_buf_begin_
=
buffer_
.
data
()
;
cur_buf_begin_
=
buffer_
;
cur_buf_end_
=
buffer_
.
data
()
+
n
;
cur_buf_end_
=
buffer_
+
standby_buffer_ready_bytes_
;
*
cur_buf_end_
=
'\0'
;
*
cur_buf_end_
=
'\0'
;
AddNForCurFilePos
(
n
);
standby_buffer_ready_bytes_
=
0
;
AsyncUpdateStandByBuffer
();
}
void
PersistentInStreamWithoutLocalCopy
::
WaitUntilStandByBufferReadyBytesNotEqualZero
()
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
standby_buffer_ready_mtx_
);
standby_buffer_ready_cond_
.
wait
(
lck
,
[
this
]()
{
return
standby_buffer_ready_bytes_
!=
0
;
});
}
void
PersistentInStreamWithoutLocalCopy
::
AsyncUpdateStandByBuffer
()
{
g_persistent_in_thread_pool
.
AddWork
([
this
]()
{
uint64_t
n
=
std
::
min
(
Global
<
JobDesc
>::
Get
()
->
persistence_buf_byte
(),
file_size_
-
cur_file_pos_
);
if
(
n
>
0
)
{
file_
->
Read
(
cur_file_pos_
,
n
,
standby_buffer_
);
AddNForCurFilePos
(
n
);
}
if
(
cur_file_pos_
==
file_size_
)
{
file_read_done_
=
true
;
}
std
::
unique_lock
<
std
::
mutex
>
lck
(
standby_buffer_ready_mtx_
);
if
(
n
>
0
)
{
standby_buffer_ready_bytes_
=
n
;
}
else
{
standby_buffer_ready_bytes_
=
-
1
;
}
standby_buffer_ready_cond_
.
notify_all
();
});
}
bool
PersistentInStreamWithoutLocalCopy
::
IsEof
()
const
{
return
cur_buf_begin_
==
cur_buf_end_
&&
file_read_done_
;
}
}
}
// namespace oneflow
}
// namespace oneflow
oneflow/core/persistence/persistent_in_stream_without_local_copy.h
浏览文件 @
6529a7c5
...
@@ -10,7 +10,7 @@ class PersistentInStreamWithoutLocalCopy : public PersistentInStream {
...
@@ -10,7 +10,7 @@ class PersistentInStreamWithoutLocalCopy : public PersistentInStream {
public:
public:
OF_DISALLOW_COPY_AND_MOVE
(
PersistentInStreamWithoutLocalCopy
);
OF_DISALLOW_COPY_AND_MOVE
(
PersistentInStreamWithoutLocalCopy
);
PersistentInStreamWithoutLocalCopy
()
=
delete
;
PersistentInStreamWithoutLocalCopy
()
=
delete
;
virtual
~
PersistentInStreamWithoutLocalCopy
()
=
default
;
virtual
~
PersistentInStreamWithoutLocalCopy
();
int32_t
ReadLine
(
std
::
string
*
l
)
override
;
int32_t
ReadLine
(
std
::
string
*
l
)
override
;
int32_t
Read
(
char
*
s
,
size_t
n
)
override
;
int32_t
Read
(
char
*
s
,
size_t
n
)
override
;
...
@@ -21,18 +21,27 @@ class PersistentInStreamWithoutLocalCopy : public PersistentInStream {
...
@@ -21,18 +21,27 @@ class PersistentInStreamWithoutLocalCopy : public PersistentInStream {
virtual
void
UpdateBuffer
();
virtual
void
UpdateBuffer
();
virtual
void
AddNForCurFilePos
(
uint64_t
n
)
=
0
;
virtual
void
AddNForCurFilePos
(
uint64_t
n
)
=
0
;
uint64_t
file_size
()
const
{
return
file_size_
;
}
uint64_t
file_size
()
const
{
return
file_size_
;
}
std
::
vector
<
char
>*
mut_buffer
()
{
return
&
buffer_
;
}
char
*
mut_buffer
()
{
return
buffer_
;
}
uint64_t
cur_file_pos
()
const
{
return
cur_file_pos_
;
}
uint64_t
cur_file_pos
()
const
{
return
cur_file_pos_
;
}
void
set_cur_file_pos
(
uint64_t
val
)
{
cur_file_pos_
=
val
;
}
void
set_cur_file_pos
(
uint64_t
val
)
{
cur_file_pos_
=
val
;
}
void
set_cur_buf_begin
(
char
*
val
)
{
cur_buf_begin_
=
val
;
}
void
set_cur_buf_begin
(
char
*
val
)
{
cur_buf_begin_
=
val
;
}
void
WaitUntilStandByBufferReadyBytesNotEqualZero
();
private:
private:
void
AsyncUpdateStandByBuffer
();
bool
IsEof
()
const
;
bool
IsEof
()
const
;
std
::
unique_ptr
<
fs
::
RandomAccessFile
>
file_
;
std
::
unique_ptr
<
fs
::
RandomAccessFile
>
file_
;
uint64_t
file_size_
;
uint64_t
file_size_
;
char
*
standby_buffer_
;
int64_t
standby_buffer_ready_bytes_
;
std
::
mutex
standby_buffer_ready_mtx_
;
std
::
condition_variable
standby_buffer_ready_cond_
;
uint64_t
cur_file_pos_
;
uint64_t
cur_file_pos_
;
std
::
vector
<
char
>
buffer_
;
std
::
atomic
<
bool
>
file_read_done_
;
char
*
buffer_
;
char
*
cur_buf_begin_
;
char
*
cur_buf_begin_
;
char
*
cur_buf_end_
;
char
*
cur_buf_end_
;
};
};
...
...
oneflow/core/thread/thread_pool.cpp
0 → 100644
浏览文件 @
6529a7c5
#include "oneflow/core/thread/thread_pool.h"
namespace
oneflow
{
ThreadPool
::
ThreadPool
(
int32_t
thread_num
)
:
work_chans_
(
thread_num
),
threads_
(
thread_num
),
cur_chan_idx_
(
0
)
{
FOR_RANGE
(
int32_t
,
i
,
0
,
thread_num
)
{
Channel
<
std
::
function
<
void
()
>>*
chan
=
&
(
work_chans_
.
at
(
i
));
threads_
[
i
]
=
std
::
thread
([
chan
]()
{
std
::
function
<
void
()
>
work
;
while
(
chan
->
Receive
(
&
work
)
==
0
)
{
work
();
}
});
}
}
ThreadPool
::~
ThreadPool
()
{
FOR_RANGE
(
int32_t
,
i
,
0
,
work_chans_
.
size
())
{
work_chans_
.
at
(
i
).
CloseSendEnd
();
work_chans_
.
at
(
i
).
CloseReceiveEnd
();
threads_
.
at
(
i
).
join
();
}
}
void
ThreadPool
::
AddWork
(
std
::
function
<
void
()
>
work
)
{
if
(
work_chans_
.
size
()
>
1
)
{
std
::
unique_lock
<
std
::
mutex
>
lck
(
cur_chan_idx_mtx_
);
work_chans_
.
at
(
cur_chan_idx_
).
Send
(
work
);
cur_chan_idx_
=
(
cur_chan_idx_
+
1
)
%
work_chans_
.
size
();
}
else
{
work_chans_
.
at
(
cur_chan_idx_
).
Send
(
work
);
}
}
}
// namespace oneflow
oneflow/core/thread/thread_pool.h
0 → 100644
浏览文件 @
6529a7c5
#ifndef ONEFLOW_CORE_THREAD_THREAD_POOL_H_
#define ONEFLOW_CORE_THREAD_THREAD_POOL_H_
#include "oneflow/core/common/util.h"
#include "oneflow/core/common/channel.h"
namespace
oneflow
{
class
ThreadPool
final
{
public:
OF_DISALLOW_COPY_AND_MOVE
(
ThreadPool
);
ThreadPool
()
=
delete
;
ThreadPool
(
int32_t
thread_num
);
~
ThreadPool
();
void
AddWork
(
std
::
function
<
void
()
>
work
);
private:
std
::
vector
<
Channel
<
std
::
function
<
void
()
>>>
work_chans_
;
std
::
vector
<
std
::
thread
>
threads_
;
std
::
mutex
cur_chan_idx_mtx_
;
int32_t
cur_chan_idx_
;
};
}
// namespace oneflow
#endif // ONEFLOW_CORE_THREAD_THREAD_POOL_H_
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录