Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
6cff3c96
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看板
未验证
提交
6cff3c96
编写于
1月 10, 2018
作者:
Y
Yu Yang
提交者:
GitHub
1月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7381 from reyoung/feature/refine_get_places_op
Polish GetPlacesOp
上级
a3202760
e5e206e2
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
26 addition
and
21 deletion
+26
-21
paddle/operators/get_places_op.cc
paddle/operators/get_places_op.cc
+16
-14
python/paddle/v2/fluid/layers/device.py
python/paddle/v2/fluid/layers/device.py
+10
-7
未找到文件。
paddle/operators/get_places_op.cc
浏览文件 @
6cff3c96
...
...
@@ -39,17 +39,19 @@ class GetPlacesOp : public framework::OperatorBase {
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
Place
&
place
)
const
override
{
std
::
string
device_type
=
Attr
<
std
::
string
>
(
"device_type"
);
bool
is_gpu
;
if
(
Attr
<
std
::
string
>
(
"device_type"
)
==
"AUTO"
)
{
is_gpu
=
platform
::
is_gpu_place
(
place
);
}
else
{
is_gpu
=
Attr
<
std
::
string
>
(
"device_type"
)
==
"CUDA"
;
}
auto
device_count
=
static_cast
<
size_t
>
(
Attr
<
int
>
(
"device_count"
));
if
(
device_count
==
0
)
{
if
(
device_type
==
"CUDA"
)
{
device_count
=
CUDADevCount
();
}
else
if
(
device_type
==
"CPU"
)
{
device_count
=
std
::
thread
::
hardware_concurrency
();
}
device_count
=
is_gpu
?
CUDADevCount
()
:
std
::
thread
::
hardware_concurrency
();
}
PADDLE_ENFORCE_NE
(
device_count
,
0
,
"Cannot indicate %s device count"
,
device_type
);
is_gpu
?
"GPU"
:
"CPU"
);
auto
out_var_name
=
Output
(
"Out"
);
auto
&
places
=
...
...
@@ -57,14 +59,14 @@ class GetPlacesOp : public framework::OperatorBase {
"Output variable %s cannot be found"
,
out_var_name
)
.
GetMutable
<
platform
::
PlaceList
>
());
places
.
reserve
(
device_count
);
if
(
device_type
==
"CUDA"
)
{
if
(
is_gpu
)
{
PADDLE_ENFORCE_LE
(
device_count
,
CUDADevCount
(),
"Only %d CUDA devices found, cannot set to %d"
,
CUDADevCount
(),
device_count
);
for
(
size_t
i
=
0
;
i
<
device_count
;
++
i
)
{
places
.
emplace_back
(
platform
::
CUDAPlace
(
i
));
places
.
emplace_back
(
platform
::
CUDAPlace
(
static_cast
<
int
>
(
i
)
));
}
}
else
if
(
device_type
==
"CPU"
)
{
}
else
{
for
(
size_t
i
=
0
;
i
<
device_count
;
++
i
)
{
places
.
emplace_back
(
platform
::
CPUPlace
());
}
...
...
@@ -77,10 +79,10 @@ class GetPlacesOpProtoMaker : public framework::OpProtoAndCheckerMaker {
GetPlacesOpProtoMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddOutput
(
"Out"
,
"vector of Place"
);
AddAttr
<
int
>
(
"device_count"
,
"device count"
).
SetDefault
(
1
);
AddAttr
<
std
::
string
>
(
"device_type"
,
R"(device type must be in ["CPU", "CUDA"])"
)
.
InEnum
({
"CPU"
,
"CUDA"
}
);
AddAttr
<
int
>
(
"device_count"
,
"device count"
).
SetDefault
(
0
);
AddAttr
<
std
::
string
>
(
"device_type"
,
"device type"
)
.
InEnum
({
"CUDA"
,
"CPU"
,
"AUTO"
}
)
.
SetDefault
(
"AUTO"
);
AddComment
(
R"DOC(
Returns a list of places based on flags. The list will be used for parallel
execution.
...
...
python/paddle/v2/fluid/layers/device.py
浏览文件 @
6cff3c96
...
...
@@ -4,19 +4,22 @@ All util layers.
from
..layer_helper
import
LayerHelper
from
..framework
import
unique_name
from
..registry
import
autodoc
__all__
=
[
'get_places'
]
def
get_places
(
device_count
=
0
,
device_type
=
"CPU"
):
@
autodoc
def
get_places
(
device_count
=
None
,
device_type
=
None
):
helper
=
LayerHelper
(
'get_places'
,
**
locals
())
out_places
=
helper
.
create_variable
(
name
=
unique_name
(
helper
.
name
+
".out"
))
attrs
=
dict
()
if
device_count
is
not
None
:
attrs
[
'device_count'
]
=
int
(
device_count
)
if
device_type
is
not
None
:
attrs
[
'device_type'
]
=
str
(
device_type
)
helper
.
append_op
(
type
=
'get_places'
,
outputs
=
{
"Out"
:
[
out_places
]},
attrs
=
{
"device_type"
:
device_type
,
'device_count'
:
device_count
,
})
type
=
'get_places'
,
outputs
=
{
"Out"
:
[
out_places
]},
attrs
=
attrs
)
return
out_places
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录