Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
1a032f40
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1a032f40
编写于
8月 08, 2019
作者:
R
rensilin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
openmp
Change-Id: I51728c87923cc613acd8ef5afddbb4501f40cd1c
上级
3515e5fc
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
16 addition
and
16 deletion
+16
-16
BCLOUD
BCLOUD
+1
-1
paddle/fluid/train/custom_trainer/feed/dataset/data_reader.cc
...le/fluid/train/custom_trainer/feed/dataset/data_reader.cc
+12
-12
paddle/fluid/train/custom_trainer/feed/unit_test/test_datareader_omp.cc
...rain/custom_trainer/feed/unit_test/test_datareader_omp.cc
+3
-3
未找到文件。
BCLOUD
浏览文件 @
1a032f40
WORKROOT('../../../')
WORKROOT('../../../')
COMPILER('gcc482')
COMPILER('gcc482')
CPPFLAGS('-D_GNU_SOURCE -DNDEBUG')
CPPFLAGS('-D_GNU_SOURCE -DNDEBUG')
GLOBAL_CFLAGS_STR = '-g -O3 -pipe '
GLOBAL_CFLAGS_STR = '-g -O3 -pipe
-fopenmp
'
CFLAGS(GLOBAL_CFLAGS_STR)
CFLAGS(GLOBAL_CFLAGS_STR)
GLOBAL_CXXFLAGS_STR = GLOBAL_CFLAGS_STR + ' -std=c++11 '
GLOBAL_CXXFLAGS_STR = GLOBAL_CFLAGS_STR + ' -std=c++11 '
CXXFLAGS(GLOBAL_CXXFLAGS_STR)
CXXFLAGS(GLOBAL_CXXFLAGS_STR)
...
...
paddle/fluid/train/custom_trainer/feed/dataset/data_reader.cc
浏览文件 @
1a032f40
#include "paddle/fluid/train/custom_trainer/feed/dataset/data_reader.h"
#include "paddle/fluid/train/custom_trainer/feed/dataset/data_reader.h"
#include <cstdio>
#include <cstdio>
#include <atomic>
#include <glog/logging.h>
#include <glog/logging.h>
#include <omp.h>
#include <omp.h>
...
@@ -136,20 +137,17 @@ public:
...
@@ -136,20 +137,17 @@ public:
auto
file_list
=
data_file_list
(
data_dir
);
auto
file_list
=
data_file_list
(
data_dir
);
int
file_list_size
=
file_list
.
size
();
int
file_list_size
=
file_list
.
size
();
std
::
atomic
<
bool
>
is_failed
(
false
);
VLOG
(
5
)
<<
"omg max_threads: "
<<
omp_get_max_threads
();
#pragma omp parallel for
#pragma omp parallel for
for
(
int
i
=
0
;
i
<
file_list_size
;
++
i
)
{
for
(
int
i
=
0
;
i
<
file_list_size
;
++
i
)
{
VLOG
(
5
)
<<
"omg num_threads: "
<<
omp_get_num_threads
()
<<
", start read: "
<<
i
<<
std
::
endl
;
}
for
(
int
i
=
0
;
i
<
file_list_size
;
++
i
)
{
//VLOG(5) << "omg num_threads: " << omp_get_num_threads() << ", start read: " << i;
const
auto
&
filepath
=
file_list
[
i
];
const
auto
&
filepath
=
file_list
[
i
];
{
if
(
!
is_failed
)
{
std
::
shared_ptr
<
FILE
>
fin
=
_file_system
->
open_read
(
filepath
,
_pipeline_cmd
);
std
::
shared_ptr
<
FILE
>
fin
=
_file_system
->
open_read
(
filepath
,
_pipeline_cmd
);
if
(
fin
==
nullptr
)
{
if
(
fin
==
nullptr
)
{
VLOG
(
2
)
<<
"fail to open file: "
<<
filepath
<<
", with cmd: "
<<
_pipeline_cmd
;
VLOG
(
2
)
<<
"fail to open file: "
<<
filepath
<<
", with cmd: "
<<
_pipeline_cmd
;
return
-
1
;
is_failed
=
true
;
continue
;
}
}
char
*
buffer
=
nullptr
;
char
*
buffer
=
nullptr
;
size_t
buffer_size
=
0
;
size_t
buffer_size
=
0
;
...
@@ -172,21 +170,23 @@ public:
...
@@ -172,21 +170,23 @@ public:
}
}
if
(
ferror
(
fin
.
get
())
!=
0
)
{
if
(
ferror
(
fin
.
get
())
!=
0
)
{
VLOG
(
2
)
<<
"fail to read file: "
<<
filepath
;
VLOG
(
2
)
<<
"fail to read file: "
<<
filepath
;
return
-
1
;
is_failed
=
true
;
continue
;
}
}
}
}
if
(
_file_system
->
err_no
()
!=
0
)
{
if
(
_file_system
->
err_no
()
!=
0
)
{
_file_system
->
reset_err_no
();
_file_system
->
reset_err_no
();
return
-
1
;
is_failed
=
true
;
continue
;
}
}
}
}
writer
->
Flush
();
writer
->
Flush
();
if
(
!
(
*
writer
))
{
if
(
!
(
*
writer
))
{
VLOG
(
2
)
<<
"fail when write to channel"
;
VLOG
(
2
)
<<
"fail when write to channel"
;
return
-
1
;
is_failed
=
true
;
}
}
data_channel
->
Close
();
data_channel
->
Close
();
return
0
;
return
is_failed
?
-
1
:
0
;
}
}
virtual
const
DataParser
*
get_parser
()
{
virtual
const
DataParser
*
get_parser
()
{
...
@@ -194,7 +194,7 @@ public:
...
@@ -194,7 +194,7 @@ public:
}
}
private:
private:
std
::
string
_done_file_name
;
// without data_dir
q
std
::
string
_done_file_name
;
// without data_dir
std
::
string
_filename_prefix
;
std
::
string
_filename_prefix
;
std
::
unique_ptr
<
FileSystem
>
_file_system
;
std
::
unique_ptr
<
FileSystem
>
_file_system
;
};
};
...
...
paddle/fluid/train/custom_trainer/feed/unit_test/test_datareader_omp.cc
浏览文件 @
1a032f40
...
@@ -104,6 +104,7 @@ public:
...
@@ -104,6 +104,7 @@ public:
std
::
shared_ptr
<
TrainerContext
>
context_ptr
;
std
::
shared_ptr
<
TrainerContext
>
context_ptr
;
std
::
unique_ptr
<
FileSystem
>
fs
;
std
::
unique_ptr
<
FileSystem
>
fs
;
int
thread_num
=
1
;
int
thread_num
=
1
;
const
int
n_run
=
5
;
};
};
std
::
vector
<
DataItem
>
DataReaderOmpTest
::
std_items
;
std
::
vector
<
DataItem
>
DataReaderOmpTest
::
std_items
;
...
@@ -128,7 +129,6 @@ TEST_F(DataReaderOmpTest, LineDataReaderSingleThread) {
...
@@ -128,7 +129,6 @@ TEST_F(DataReaderOmpTest, LineDataReaderSingleThread) {
ASSERT_EQ
(
string
::
format_string
(
"%s/%s.txt"
,
test_data_dir
,
std_items
[
i
].
id
.
c_str
()),
data_file_list
[
i
]);
ASSERT_EQ
(
string
::
format_string
(
"%s/%s.txt"
,
test_data_dir
,
std_items
[
i
].
id
.
c_str
()),
data_file_list
[
i
]);
}
}
constexpr
int
n_run
=
10
;
int
same_count
=
0
;
int
same_count
=
0
;
for
(
int
i
=
0
;
i
<
n_run
;
++
i
)
{
for
(
int
i
=
0
;
i
<
n_run
;
++
i
)
{
auto
channel
=
framework
::
MakeChannel
<
DataItem
>
(
128
);
auto
channel
=
framework
::
MakeChannel
<
DataItem
>
(
128
);
...
@@ -172,7 +172,6 @@ TEST_F(DataReaderOmpTest, LineDataReaderMuiltThread) {
...
@@ -172,7 +172,6 @@ TEST_F(DataReaderOmpTest, LineDataReaderMuiltThread) {
fout
.
close
();
fout
.
close
();
ASSERT_TRUE
(
data_reader
->
is_data_ready
(
test_data_dir
));
ASSERT_TRUE
(
data_reader
->
is_data_ready
(
test_data_dir
));
constexpr
int
n_run
=
10
;
int
same_count
=
0
;
int
same_count
=
0
;
int
sort_same_count
=
0
;
int
sort_same_count
=
0
;
for
(
int
i
=
0
;
i
<
n_run
;
++
i
)
{
for
(
int
i
=
0
;
i
<
n_run
;
++
i
)
{
...
@@ -200,7 +199,8 @@ TEST_F(DataReaderOmpTest, LineDataReaderMuiltThread) {
...
@@ -200,7 +199,8 @@ TEST_F(DataReaderOmpTest, LineDataReaderMuiltThread) {
}
}
// n_run次有不同的(证明是多线程)
// n_run次有不同的(证明是多线程)
// ASSERT_GT(n_run, same_count);
ASSERT_EQ
(
4
,
omp_get_max_threads
());
ASSERT_GT
(
n_run
,
same_count
);
// 但排序后都是相同的
// 但排序后都是相同的
ASSERT_EQ
(
n_run
,
sort_same_count
);
ASSERT_EQ
(
n_run
,
sort_same_count
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录