Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
037ce12e
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
694
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
037ce12e
编写于
7月 03, 2018
作者:
Y
Yu Yang
提交者:
GitHub
7月 03, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #11907 from reyoung/feature/use_dev_ctx_for_op
Use std::map for Place <--> DeviceContext
上级
71b1c397
2d0e5592
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
13 addition
and
32 deletion
+13
-32
paddle/fluid/framework/details/op_handle_base.cc
paddle/fluid/framework/details/op_handle_base.cc
+2
-8
paddle/fluid/framework/details/op_handle_base.h
paddle/fluid/framework/details/op_handle_base.h
+2
-4
paddle/fluid/framework/details/reduce_and_gather.h
paddle/fluid/framework/details/reduce_and_gather.h
+1
-2
paddle/fluid/platform/device_context.cc
paddle/fluid/platform/device_context.cc
+2
-1
paddle/fluid/platform/device_context.h
paddle/fluid/platform/device_context.h
+3
-5
paddle/fluid/platform/place.h
paddle/fluid/platform/place.h
+3
-12
未找到文件。
paddle/fluid/framework/details/op_handle_base.cc
浏览文件 @
037ce12e
...
@@ -124,16 +124,10 @@ void OpHandleBase::RunAndRecordEvent(const std::function<void()> &callback) {
...
@@ -124,16 +124,10 @@ void OpHandleBase::RunAndRecordEvent(const std::function<void()> &callback) {
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
if
(
!
events_
.
empty
())
{
// Use event
if
(
!
events_
.
empty
())
{
// Use event
std
::
function
<
void
()
>
method
=
callback
;
std
::
function
<
void
()
>
method
=
callback
;
// NOTE(zcd): device context must be ordered here because RecordEvent
// will use a mutex to ensure the safe of multi-threads.
std
::
map
<
platform
::
DeviceContext
*
,
platform
::
Place
>
ordered_ctxes
;
for
(
auto
&
p
:
dev_ctxes_
)
{
for
(
auto
&
p
:
dev_ctxes_
)
{
ordered_ctxes
.
emplace
(
p
.
second
,
p
.
first
);
}
for
(
auto
&
p
:
ordered_ctxes
)
{
method
=
[
method
,
p
,
this
]()
{
method
=
[
method
,
p
,
this
]()
{
static_cast
<
platform
::
CUDADeviceContext
*>
(
p
.
first
)
->
RecordEvent
(
static_cast
<
platform
::
CUDADeviceContext
*>
(
p
.
second
)
->
RecordEvent
(
events_
.
at
(
boost
::
get
<
platform
::
CUDAPlace
>
(
p
.
second
).
device
),
events_
.
at
(
boost
::
get
<
platform
::
CUDAPlace
>
(
p
.
first
).
device
),
method
);
method
);
};
};
}
}
...
...
paddle/fluid/framework/details/op_handle_base.h
浏览文件 @
037ce12e
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
// limitations under the License.
// limitations under the License.
#pragma once
#pragma once
#include <map>
#include <string>
#include <string>
#include <vector>
#include <vector>
#include "paddle/fluid/framework/details/var_handle.h"
#include "paddle/fluid/framework/details/var_handle.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/macros.h"
#include "paddle/fluid/platform/macros.h"
...
@@ -92,9 +92,7 @@ class OpHandleBase {
...
@@ -92,9 +92,7 @@ class OpHandleBase {
std
::
vector
<
VarHandleBase
*>
inputs_
;
std
::
vector
<
VarHandleBase
*>
inputs_
;
std
::
vector
<
VarHandleBase
*>
outputs_
;
std
::
vector
<
VarHandleBase
*>
outputs_
;
std
::
unordered_map
<
platform
::
Place
,
platform
::
DeviceContext
*
,
std
::
map
<
platform
::
Place
,
platform
::
DeviceContext
*>
dev_ctxes_
;
platform
::
PlaceHash
>
dev_ctxes_
;
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
std
::
unordered_map
<
int
,
cudaEvent_t
>
events_
;
std
::
unordered_map
<
int
,
cudaEvent_t
>
events_
;
...
...
paddle/fluid/framework/details/reduce_and_gather.h
浏览文件 @
037ce12e
...
@@ -54,8 +54,7 @@ struct ReduceLoDTensor {
...
@@ -54,8 +54,7 @@ struct ReduceLoDTensor {
inline
void
GatherSelectedRows
(
inline
void
GatherSelectedRows
(
const
std
::
vector
<
const
SelectedRows
*>
&
src_selecte_rows_
,
const
std
::
vector
<
const
SelectedRows
*>
&
src_selecte_rows_
,
const
std
::
vector
<
platform
::
Place
>
&
in_places
,
const
std
::
vector
<
platform
::
Place
>
&
in_places
,
const
std
::
unordered_map
<
platform
::
Place
,
platform
::
DeviceContext
*
,
const
std
::
map
<
platform
::
Place
,
platform
::
DeviceContext
*>
&
dev_ctxes
,
platform
::
PlaceHash
>
&
dev_ctxes
,
const
platform
::
Place
&
out_place
,
SelectedRows
*
dst_selecte_rows
)
{
const
platform
::
Place
&
out_place
,
SelectedRows
*
dst_selecte_rows
)
{
PADDLE_ENFORCE
(
!
src_selecte_rows_
.
empty
());
PADDLE_ENFORCE
(
!
src_selecte_rows_
.
empty
());
...
...
paddle/fluid/platform/device_context.cc
浏览文件 @
037ce12e
...
@@ -10,6 +10,7 @@ See the License for the specific language governing permissions and
...
@@ -10,6 +10,7 @@ See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/device_context.h"
#include <set>
#include <string>
#include <string>
#include <unordered_set>
#include <unordered_set>
#include <vector>
#include <vector>
...
@@ -35,7 +36,7 @@ DeviceContextPool::DeviceContextPool(
...
@@ -35,7 +36,7 @@ DeviceContextPool::DeviceContextPool(
const
std
::
vector
<
platform
::
Place
>&
places
)
{
const
std
::
vector
<
platform
::
Place
>&
places
)
{
PADDLE_ENFORCE_GT
(
places
.
size
(),
0
);
PADDLE_ENFORCE_GT
(
places
.
size
(),
0
);
using
PtrType
=
std
::
unique_ptr
<
DeviceContext
>
;
using
PtrType
=
std
::
unique_ptr
<
DeviceContext
>
;
std
::
unordered_set
<
Place
,
PlaceHash
>
set
;
std
::
set
<
Place
>
set
;
for
(
auto
&
p
:
places
)
{
for
(
auto
&
p
:
places
)
{
set
.
insert
(
p
);
set
.
insert
(
p
);
}
}
...
...
paddle/fluid/platform/device_context.h
浏览文件 @
037ce12e
...
@@ -27,12 +27,12 @@ limitations under the License. */
...
@@ -27,12 +27,12 @@ limitations under the License. */
#include <mkldnn.hpp>
#include <mkldnn.hpp>
#endif
#endif
#include <map>
#include "glog/logging.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/place.h"
#include "unsupported/Eigen/CXX11/Tensor"
#include "unsupported/Eigen/CXX11/Tensor"
#include "glog/logging.h"
namespace
paddle
{
namespace
paddle
{
namespace
platform
{
namespace
platform
{
...
@@ -201,9 +201,7 @@ class DeviceContextPool {
...
@@ -201,9 +201,7 @@ class DeviceContextPool {
private:
private:
static
DeviceContextPool
*
pool
;
static
DeviceContextPool
*
pool
;
std
::
unordered_map
<
const
platform
::
Place
,
std
::
map
<
Place
,
std
::
unique_ptr
<
DeviceContext
>>
device_contexts_
;
std
::
unique_ptr
<
platform
::
DeviceContext
>
,
PlaceHash
>
device_contexts_
;
DISABLE_COPY_AND_ASSIGN
(
DeviceContextPool
);
DISABLE_COPY_AND_ASSIGN
(
DeviceContextPool
);
};
};
...
...
paddle/fluid/platform/place.h
浏览文件 @
037ce12e
...
@@ -30,6 +30,7 @@ struct CPUPlace {
...
@@ -30,6 +30,7 @@ struct CPUPlace {
// needed for variant equality comparison
// needed for variant equality comparison
inline
bool
operator
==
(
const
CPUPlace
&
)
const
{
return
true
;
}
inline
bool
operator
==
(
const
CPUPlace
&
)
const
{
return
true
;
}
inline
bool
operator
!=
(
const
CPUPlace
&
)
const
{
return
false
;
}
inline
bool
operator
!=
(
const
CPUPlace
&
)
const
{
return
false
;
}
inline
bool
operator
<
(
const
CPUPlace
&
)
const
{
return
false
;
}
};
};
struct
CUDAPlace
{
struct
CUDAPlace
{
...
@@ -42,6 +43,7 @@ struct CUDAPlace {
...
@@ -42,6 +43,7 @@ struct CUDAPlace {
return
device
==
o
.
device
;
return
device
==
o
.
device
;
}
}
inline
bool
operator
!=
(
const
CUDAPlace
&
o
)
const
{
return
!
(
*
this
==
o
);
}
inline
bool
operator
!=
(
const
CUDAPlace
&
o
)
const
{
return
!
(
*
this
==
o
);
}
inline
bool
operator
<
(
const
CUDAPlace
&
o
)
const
{
return
device
<
o
.
device
;
}
int
device
;
int
device
;
};
};
...
@@ -52,6 +54,7 @@ struct CUDAPinnedPlace {
...
@@ -52,6 +54,7 @@ struct CUDAPinnedPlace {
// needed for variant equality comparison
// needed for variant equality comparison
inline
bool
operator
==
(
const
CUDAPinnedPlace
&
)
const
{
return
true
;
}
inline
bool
operator
==
(
const
CUDAPinnedPlace
&
)
const
{
return
true
;
}
inline
bool
operator
!=
(
const
CUDAPinnedPlace
&
)
const
{
return
false
;
}
inline
bool
operator
!=
(
const
CUDAPinnedPlace
&
)
const
{
return
false
;
}
inline
bool
operator
<
(
const
CUDAPinnedPlace
&
)
const
{
return
false
;
}
};
};
struct
IsCUDAPlace
:
public
boost
::
static_visitor
<
bool
>
{
struct
IsCUDAPlace
:
public
boost
::
static_visitor
<
bool
>
{
...
@@ -89,18 +92,6 @@ bool is_cuda_pinned_place(const Place &);
...
@@ -89,18 +92,6 @@ bool is_cuda_pinned_place(const Place &);
bool
places_are_same_class
(
const
Place
&
,
const
Place
&
);
bool
places_are_same_class
(
const
Place
&
,
const
Place
&
);
bool
is_same_place
(
const
Place
&
,
const
Place
&
);
bool
is_same_place
(
const
Place
&
,
const
Place
&
);
struct
PlaceHash
{
std
::
size_t
operator
()(
const
Place
&
p
)
const
{
constexpr
size_t
num_dev_bits
=
4
;
std
::
hash
<
int
>
ihash
;
size_t
dev_id
=
0
;
if
(
is_gpu_place
(
p
))
{
dev_id
=
boost
::
get
<
CUDAPlace
>
(
p
).
device
;
}
return
ihash
(
dev_id
<<
num_dev_bits
|
p
.
which
());
}
};
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Place
&
);
std
::
ostream
&
operator
<<
(
std
::
ostream
&
,
const
Place
&
);
template
<
typename
Visitor
>
template
<
typename
Visitor
>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录