Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
e8de775f
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e8de775f
编写于
12月 20, 2017
作者:
Q
qijun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename trainer_count to device_count
上级
aa320894
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
9 addition
and
9 deletion
+9
-9
paddle/operators/get_places_op.cc
paddle/operators/get_places_op.cc
+6
-6
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
浏览文件 @
e8de775f
...
...
@@ -30,7 +30,7 @@ class GetPlacesOp : public framework::OperatorBase {
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
std
::
string
device_type
=
Attr
<
std
::
string
>
(
"device_type"
);
auto
trainer_count
=
Attr
<
int
>
(
"trainer
_count"
);
auto
device_count
=
Attr
<
int
>
(
"device
_count"
);
auto
out_var_name
=
Output
(
"Out"
);
auto
*
out_var
=
scope
.
FindVar
(
out_var_name
);
...
...
@@ -38,18 +38,18 @@ class GetPlacesOp : public framework::OperatorBase {
out_var_name
);
auto
&
places
=
*
(
out_var
->
GetMutable
<
std
::
vector
<
platform
::
Place
>>
());
places
.
resize
(
trainer
_count
);
places
.
resize
(
device
_count
);
if
(
device_type
==
"CUDA"
)
{
#ifdef PADDLE_WITH_CUDA
PADDLE_ENFORCE_LT
(
trainer
_count
,
platform
::
GetCUDADeviceCount
());
for
(
int
i
=
0
;
i
<
trainer
_count
;
i
++
)
{
PADDLE_ENFORCE_LT
(
device
_count
,
platform
::
GetCUDADeviceCount
());
for
(
int
i
=
0
;
i
<
device
_count
;
i
++
)
{
places
.
emplace_back
(
platform
::
GPUPlace
(
i
));
}
#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
++
)
{
for
(
int
i
=
0
;
i
<
device
_count
;
i
++
)
{
places
.
emplace_back
(
platform
::
CPUPlace
());
}
}
...
...
@@ -62,7 +62,7 @@ class GetPlacesOpProtoMaker : public framework::OpProtoAndCheckerMaker {
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddOutput
(
"Out"
,
"vector of Place"
);
AddAttr
<
int
>
(
"
trainer_count"
,
"(int)trainer
count"
).
SetDefault
(
1
);
AddAttr
<
int
>
(
"
device_count"
,
"(int)device
count"
).
SetDefault
(
1
);
AddAttr
<
std
::
string
>
(
"device_type"
,
"(string), deivce type can be
\"
CPU
\"
and
\"
CUDA
\"
"
)
.
InEnum
({
"CPU"
,
"CUDA"
});
...
...
python/paddle/v2/fluid/layers/utils.py
浏览文件 @
e8de775f
...
...
@@ -8,7 +8,7 @@ from ..framework import Variable
__all__
=
[
'get_places'
]
def
get_places
(
trainer
_count
,
device_type
=
"CPU"
):
def
get_places
(
device
_count
,
device_type
=
"CPU"
):
helper
=
LayerHelper
(
'get_places'
,
**
locals
())
out_places
=
helper
.
create_tmp_variable
(
dtype
=
helper
.
input_dtype
())
helper
.
append_op
(
...
...
@@ -16,7 +16,7 @@ def get_places(trainer_count, device_type="CPU"):
outputs
=
{
"Out"
:
[
out_places
]},
attrs
=
{
"device_type"
:
device_type
,
'
trainer_count'
:
trainer
_count
,
'
device_count'
:
device
_count
,
})
return
out_places
python/paddle/v2/fluid/tests/test_layers.py
浏览文件 @
e8de775f
...
...
@@ -199,7 +199,7 @@ class TestBook(unittest.TestCase):
def
test_get_places
(
self
):
program
=
Program
()
with
program_guard
(
program
):
x
=
layers
.
get_places
(
trainer
_count
=
4
)
x
=
layers
.
get_places
(
device
_count
=
4
)
print
(
str
(
program
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录