Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
44bae42d
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看板
提交
44bae42d
编写于
12月 19, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
follow comments
上级
31323f79
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
18 addition
and
8 deletion
+18
-8
paddle/operators/get_places_op.cc
paddle/operators/get_places_op.cc
+15
-5
python/paddle/v2/fluid/layers/utils.py
python/paddle/v2/fluid/layers/utils.py
+2
-2
python/paddle/v2/fluid/tests/test_layers.py
python/paddle/v2/fluid/tests/test_layers.py
+1
-1
未找到文件。
paddle/operators/get_places_op.cc
浏览文件 @
44bae42d
...
...
@@ -14,6 +14,9 @@ limitations under the License. */
#include "paddle/framework/op_registry.h"
#include "paddle/platform/place.h"
#ifdef PADDLE_WITH_CUDA
#include "paddle/platform/gpu_info.h"
#endif
namespace
paddle
{
namespace
operators
{
...
...
@@ -26,7 +29,7 @@ class GetPlacesOp : public framework::OperatorBase {
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
auto
use_gpu
=
Attr
<
bool
>
(
"use_gpu
"
);
std
::
string
device_type
=
Attr
<
std
::
string
>
(
"device_type
"
);
auto
trainer_count
=
Attr
<
int
>
(
"trainer_count"
);
auto
out_var_name
=
Output
(
"Out"
);
...
...
@@ -36,11 +39,16 @@ class GetPlacesOp : public framework::OperatorBase {
auto
&
places
=
*
(
out_var
->
GetMutable
<
std
::
vector
<
platform
::
Place
>>
());
places
.
resize
(
trainer_count
);
if
(
use_gpu
)
{
if
(
device_type
==
"CUDA"
)
{
#ifdef PADDLE_WITH_CUDA
PADDLE_ENFORCE_LT
(
trainer_count
,
GetCUDADeviceCount
());
for
(
int
i
=
0
;
i
<
trainer_count
;
i
++
)
{
places
.
emplace_back
(
platform
::
GPUPlace
(
i
));
}
}
else
{
#else
PADDLE_THROW
(
"'GPUPlace' is not supported in CPU only device."
);
#endif
}
else
if
(
device_type
==
"CPU"
)
{
for
(
int
i
=
0
;
i
<
trainer_count
;
i
++
)
{
places
.
emplace_back
(
platform
::
CPUPlace
());
}
...
...
@@ -55,9 +63,11 @@ class GetPlacesOpProtoMaker : public framework::OpProtoAndCheckerMaker {
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddOutput
(
"Out"
,
"vector of Place"
);
AddAttr
<
int
>
(
"trainer_count"
,
"(int)trainer count"
).
SetDefault
(
1
);
AddAttr
<
bool
>
(
"use_gpu"
,
"(bool)use gpu"
).
SetDefault
(
false
);
AddAttr
<
std
::
string
>
(
"device_type"
,
"(string), deivce type can be
\"
CPU
\"
and
\"
CUDA
\"
"
)
.
InEnum
({
"CPU"
,
"CUDA"
});
AddComment
(
R"DOC(
GetPlaces Operator
.
Returns a list of places based on flags. The list will be used for parallel execution
.
)DOC"
);
}
...
...
python/paddle/v2/fluid/layers/utils.py
浏览文件 @
44bae42d
...
...
@@ -8,14 +8,14 @@ from ..framework import Variable
__all__
=
[
'get_places'
]
def
get_places
(
use_gpu
,
trainer_count
):
def
get_places
(
trainer_count
,
device_type
=
"CPU"
):
helper
=
LayerHelper
(
'get_places'
,
**
locals
())
out_places
=
helper
.
create_tmp_variable
(
dtype
=
helper
.
input_dtype
())
helper
.
append_op
(
type
=
'get_places'
,
outputs
=
{
"Out"
:
[
out_places
]},
attrs
=
{
"
use_gpu"
:
use_gpu
,
"
device_type"
:
device_type
,
'trainer_count'
:
trainer_count
,
})
...
...
python/paddle/v2/fluid/tests/test_layers.py
浏览文件 @
44bae42d
...
...
@@ -173,7 +173,7 @@ class TestBook(unittest.TestCase):
def
test_get_places
(
self
):
program
=
Program
()
with
program_guard
(
program
):
x
=
layers
.
get_places
(
use_gpu
=
True
,
trainer_count
=
4
)
x
=
layers
.
get_places
(
trainer_count
=
4
)
print
(
str
(
program
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录