Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
564dba17
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
564dba17
编写于
1月 04, 2018
作者:
Y
Yu Yang
提交者:
GitHub
1月 04, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7196 from reyoung/feature/async_drop_kid
Async to drop kid
上级
2b259bf1
7e10b818
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
6 deletion
+18
-6
paddle/framework/CMakeLists.txt
paddle/framework/CMakeLists.txt
+5
-3
paddle/framework/scope.cc
paddle/framework/scope.cc
+3
-1
paddle/framework/threadpool.h
paddle/framework/threadpool.h
+10
-2
未找到文件。
paddle/framework/CMakeLists.txt
浏览文件 @
564dba17
...
...
@@ -26,7 +26,10 @@ nv_test(lod_tensor_gpu_test SRCS lod_tensor_test.cu DEPS lod_tensor)
cc_test
(
variable_test SRCS variable_test.cc
)
cc_library
(
scope SRCS scope.cc DEPS glog
)
cc_library
(
threadpool SRCS threadpool.cc
)
cc_test
(
threadpool_test SRCS threadpool_test.cc DEPS threadpool
)
cc_library
(
scope SRCS scope.cc DEPS glog threadpool
)
cc_test
(
scope_test SRCS scope_test.cc DEPS scope
)
cc_library
(
data_transform SRCS data_transform.cc DEPS math_function tensor framework_proto
)
...
...
@@ -70,8 +73,7 @@ cc_test(var_type_inference_test SRCS var_type_inference_test.cc DEPS op_registry
cc_library
(
selected_rows SRCS selected_rows.cc DEPS tensor
)
cc_test
(
selected_rows_test SRCS selected_rows_test.cc DEPS selected_rows
)
cc_library
(
threadpool SRCS threadpool.cc
)
cc_test
(
threadpool_test SRCS threadpool_test.cc DEPS threadpool
)
cc_library
(
init SRCS init.cc DEPS gflags device_context place stringpiece
)
cc_test
(
init_test SRCS init_test.cc DEPS init
)
...
...
paddle/framework/scope.cc
浏览文件 @
564dba17
...
...
@@ -17,6 +17,7 @@ limitations under the License. */
#include <memory> // for unique_ptr
#include <mutex> // for call_once
#include "glog/logging.h"
#include "paddle/framework/threadpool.h"
#include "paddle/string/printf.h"
namespace
paddle
{
...
...
@@ -87,7 +88,8 @@ void Scope::DeleteScope(Scope* scope) {
auto
it
=
std
::
find
(
this
->
kids_
.
begin
(),
this
->
kids_
.
end
(),
scope
);
PADDLE_ENFORCE
(
it
!=
this
->
kids_
.
end
(),
"Cannot find %p as kid scope"
,
scope
);
this
->
kids_
.
erase
(
it
);
delete
scope
;
// Make delete async.
Async
([
scope
]
{
delete
scope
;
});
}
void
Scope
::
Rename
(
const
std
::
string
&
origin_name
,
...
...
paddle/framework/threadpool.h
浏览文件 @
564dba17
...
...
@@ -29,7 +29,6 @@ namespace framework {
class
ThreadPool
{
public:
typedef
std
::
packaged_task
<
void
()
>
Task
;
typedef
std
::
function
<
void
()
>
Fun
;
/**
* @brief Get a instance of threadpool, the thread number will
...
...
@@ -67,7 +66,8 @@ class ThreadPool {
* @return std::future<void>, we could wait for the task finished by
* f.wait().
*/
std
::
future
<
void
>
Run
(
const
Fun
&
fn
)
{
template
<
typename
Callback
>
std
::
future
<
void
>
Run
(
Callback
fn
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mutex_
);
Task
task
(
std
::
bind
(
fn
));
std
::
future
<
void
>
f
=
task
.
get_future
();
...
...
@@ -159,5 +159,13 @@ class ThreadPool {
std
::
condition_variable
completed_
;
};
// Run a function asynchronously.
// NOTE: The function must return void. If the function need to return a value,
// you can use lambda to capture a value pointer.
template
<
typename
Callback
>
std
::
future
<
void
>
Async
(
Callback
callback
)
{
return
ThreadPool
::
GetInstance
()
->
Run
(
callback
);
}
}
// namespace framework
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录