Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
251e4a8e
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
251e4a8e
编写于
4月 23, 2018
作者:
T
typhoonzero
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
unify fluid blocking queue
上级
6c0356e4
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
81 addition
and
46 deletion
+81
-46
paddle/fluid/framework/blocking_queue.h
paddle/fluid/framework/blocking_queue.h
+74
-0
paddle/fluid/framework/details/threaded_ssa_graph_executor.h
paddle/fluid/framework/details/threaded_ssa_graph_executor.h
+1
-40
paddle/fluid/operators/detail/grpc_client.h
paddle/fluid/operators/detail/grpc_client.h
+1
-1
paddle/fluid/operators/detail/grpc_server.cc
paddle/fluid/operators/detail/grpc_server.cc
+2
-2
paddle/fluid/operators/detail/grpc_server.h
paddle/fluid/operators/detail/grpc_server.h
+3
-3
未找到文件。
paddle/fluid/
operators/detail/simple_block
_queue.h
→
paddle/fluid/
framework/blocking
_queue.h
浏览文件 @
251e4a8e
...
...
@@ -17,36 +17,58 @@ limitations under the License. */
#include <condition_variable> // NOLINT
#include <deque>
#include <mutex> // NOLINT
#include <utility>
namespace
paddle
{
namespace
operators
{
namespace
detail
{
namespace
framework
{
template
<
typename
T
>
class
SimpleBlockQueue
{
private:
std
::
mutex
mutex_
;
std
::
condition_variable
condition_
;
std
::
deque
<
T
>
queue_
;
class
BlockingQueue
{
public:
void
Push
(
T
const
&
value
)
{
void
Push
(
const
T
&
item
)
{
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mutex_
);
q_
.
emplace_back
(
item
);
}
cv_
.
notify_one
();
}
template
<
typename
U
>
void
Extend
(
const
U
&
items
)
{
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
this
->
mutex_
);
queue_
.
push_front
(
value
);
std
::
lock_guard
<
std
::
mutex
>
g
(
mutex_
);
for
(
auto
&
item
:
items
)
{
q_
.
emplace_back
(
item
);
}
}
this
->
condition_
.
notify_one
();
cv_
.
notify_all
();
}
std
::
deque
<
T
>
PopAll
(
size_t
ms
,
bool
*
timeout
)
{
auto
time
=
std
::
chrono
::
system_clock
::
now
()
+
std
::
chrono
::
milliseconds
(
ms
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
*
timeout
=
!
cv_
.
wait_until
(
lock
,
time
,
[
this
]
{
return
!
q_
.
empty
();
});
std
::
deque
<
T
>
ret
;
if
(
!*
timeout
)
{
std
::
swap
(
ret
,
q_
);
}
return
ret
;
}
T
Pop
()
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
this
->
mutex_
);
this
->
condition_
.
wait
(
lock
,
[
=
]
{
return
!
this
->
queue
_
.
empty
();
});
T
rc
(
std
::
move
(
this
->
queue_
.
back
()));
this
->
queue_
.
pop_back
();
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
cv_
.
wait
(
lock
,
[
=
]
{
return
!
q
_
.
empty
();
});
T
rc
(
std
::
move
(
q_
.
front
()));
q_
.
pop_front
();
return
rc
;
}
private:
std
::
mutex
mutex_
;
std
::
condition_variable
cv_
;
std
::
deque
<
T
>
q_
;
};
}
// namespace detail
}
// namespace operators
}
// namespace framework
}
// namespace paddle
paddle/fluid/framework/details/threaded_ssa_graph_executor.h
浏览文件 @
251e4a8e
...
...
@@ -22,6 +22,7 @@
#include <functional>
#include "ThreadPool.h" // ThreadPool in thrird party
#include "paddle/fluid/framework/blocking_queue.h"
#include "paddle/fluid/framework/details/ssa_graph_executor.h"
namespace
paddle
{
...
...
@@ -30,46 +31,6 @@ class Scope;
namespace
details
{
template
<
typename
T
>
class
BlockingQueue
{
public:
void
Push
(
const
T
&
item
)
{
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mutex_
);
q_
.
emplace_back
(
item
);
}
cv_
.
notify_one
();
}
template
<
typename
U
>
void
Extend
(
const
U
&
items
)
{
{
std
::
lock_guard
<
std
::
mutex
>
g
(
mutex_
);
for
(
auto
&
item
:
items
)
{
q_
.
emplace_back
(
item
);
}
}
cv_
.
notify_all
();
}
std
::
deque
<
T
>
PopAll
(
size_t
ms
,
bool
*
timeout
)
{
auto
time
=
std
::
chrono
::
system_clock
::
now
()
+
std
::
chrono
::
milliseconds
(
ms
);
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
*
timeout
=
!
cv_
.
wait_until
(
lock
,
time
,
[
this
]
{
return
!
q_
.
empty
();
});
std
::
deque
<
T
>
ret
;
if
(
!*
timeout
)
{
std
::
swap
(
ret
,
q_
);
}
return
ret
;
}
private:
std
::
mutex
mutex_
;
std
::
condition_variable
cv_
;
std
::
deque
<
T
>
q_
;
};
class
ThreadedSSAGraphExecutor
:
public
SSAGraphExecutor
{
public:
ThreadedSSAGraphExecutor
(
size_t
num_threads
,
bool
use_event
,
...
...
paddle/fluid/operators/detail/grpc_client.h
浏览文件 @
251e4a8e
...
...
@@ -29,12 +29,12 @@ limitations under the License. */
#include "grpc++/support/byte_buffer.h"
#include "grpc++/support/slice.h"
#include "grpc/support/log.h"
#include "paddle/fluid/framework/blocking_queue.h"
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/selected_rows.h"
#include "paddle/fluid/operators/detail/sendrecvop_utils.h"
#include "paddle/fluid/operators/detail/simple_block_queue.h"
namespace
paddle
{
namespace
operators
{
...
...
paddle/fluid/operators/detail/grpc_server.cc
浏览文件 @
251e4a8e
...
...
@@ -90,7 +90,7 @@ class RequestGet final : public RequestBase {
::
grpc
::
ServerCompletionQueue
*
cq
,
framework
::
Scope
*
scope
,
const
platform
::
DeviceContext
*
dev_ctx
,
SimpleBlock
Queue
<
MessageWithName
>*
queue
)
framework
::
Blocking
Queue
<
MessageWithName
>*
queue
)
:
RequestBase
(
service
,
cq
,
dev_ctx
),
responder_
(
&
ctx_
),
scope_
(
scope
),
...
...
@@ -128,7 +128,7 @@ class RequestGet final : public RequestBase {
sendrecv
::
VariableMessage
request_
;
ServerAsyncResponseWriter
<::
grpc
::
ByteBuffer
>
responder_
;
framework
::
Scope
*
scope_
;
SimpleBlock
Queue
<
MessageWithName
>*
queue_
;
framework
::
Blocking
Queue
<
MessageWithName
>*
queue_
;
};
class
RequestPrefetch
final
:
public
RequestBase
{
...
...
paddle/fluid/operators/detail/grpc_server.h
浏览文件 @
251e4a8e
...
...
@@ -19,6 +19,7 @@ limitations under the License. */
#include <utility>
#include "grpc++/grpc++.h"
#include "paddle/fluid/framework/blocking_queue.h"
#include "paddle/fluid/framework/executor.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/program_desc.h"
...
...
@@ -29,7 +30,6 @@ limitations under the License. */
#include "paddle/fluid/operators/detail/send_recv.grpc.pb.h"
#include "paddle/fluid/operators/detail/send_recv.pb.h"
#include "paddle/fluid/operators/detail/sendrecvop_utils.h"
#include "paddle/fluid/operators/detail/simple_block_queue.h"
namespace
paddle
{
namespace
operators
{
...
...
@@ -37,7 +37,7 @@ namespace detail {
typedef
std
::
pair
<
std
::
string
,
std
::
shared_ptr
<
VariableResponse
>>
ReceivedMessage
;
typedef
SimpleBlock
Queue
<
ReceivedMessage
>
ReceivedQueue
;
typedef
framework
::
Blocking
Queue
<
ReceivedMessage
>
ReceivedQueue
;
typedef
std
::
pair
<
std
::
string
,
sendrecv
::
VariableMessage
>
MessageWithName
;
class
RequestBase
;
...
...
@@ -99,7 +99,7 @@ class AsyncGRPCServer final {
const
platform
::
DeviceContext
*
dev_ctx_
;
// received variable from RPC, operators fetch variable from this queue.
SimpleBlock
Queue
<
MessageWithName
>
var_get_queue_
;
framework
::
Blocking
Queue
<
MessageWithName
>
var_get_queue_
;
// client send variable to this queue.
ReceivedQueue
var_recv_queue_
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录