Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
5f985000
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
12 个月 前同步成功
通知
692
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,发现更多精彩内容 >>
提交
5f985000
编写于
1月 10, 2018
作者:
D
dzhwinter
提交者:
Yang Yang(Tony)
1月 10, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make init device on all gpu by default (#7345)
* "init use all default devices" * "fix init test"
上级
f8d13c2a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
30 addition
and
58 deletion
+30
-58
paddle/framework/device_data_transform_test.cu
paddle/framework/device_data_transform_test.cu
+1
-2
paddle/framework/init.cc
paddle/framework/init.cc
+11
-28
paddle/framework/init.h
paddle/framework/init.h
+1
-1
paddle/framework/init_test.cc
paddle/framework/init_test.cc
+6
-11
paddle/framework/operator_test.cc
paddle/framework/operator_test.cc
+4
-4
paddle/inference/inference.cc
paddle/inference/inference.cc
+1
-1
paddle/platform/device_context.h
paddle/platform/device_context.h
+2
-0
paddle/testing/paddle_gtest_main.cc
paddle/testing/paddle_gtest_main.cc
+3
-3
python/paddle/v2/fluid/__init__.py
python/paddle/v2/fluid/__init__.py
+1
-5
python/paddle/v2/fluid/tests/test_batch_norm_op.py
python/paddle/v2/fluid/tests/test_batch_norm_op.py
+0
-3
未找到文件。
paddle/framework/device_data_transform_test.cu
浏览文件 @
5f985000
...
...
@@ -105,8 +105,7 @@ static void BuildVar(const std::string& param_name,
TEST
(
Operator
,
CPUtoGPU
)
{
using
namespace
paddle
::
framework
;
using
namespace
paddle
::
platform
;
ASSERT_EQ
(
InitDevices
({
"CPU"
,
"GPU:0"
}),
true
);
InitDevices
();
paddle
::
framework
::
Scope
scope
;
paddle
::
platform
::
CPUPlace
cpu_place
;
...
...
paddle/framework/init.cc
浏览文件 @
5f985000
...
...
@@ -40,40 +40,23 @@ void InitGflags(std::vector<std::string> &argv) {
});
}
bool
InitDevices
(
const
std
::
vector
<
std
::
string
>
&
devices
)
{
// device format
// CPU
// GPU:1
// TODO(dzhwinter) : add device format annotation for users.
void
InitDevices
()
{
/*Init all avaiable devices by default */
std
::
vector
<
platform
::
Place
>
places
;
for
(
auto
&
device
:
devices
)
{
auto
p
=
string
::
Piece
(
device
);
if
(
string
::
HasPrefix
(
p
,
"CPU"
))
{
places
.
emplace_back
(
platform
::
CPUPlace
());
}
else
if
(
string
::
HasPrefix
(
p
,
"GPU"
))
{
places
.
emplace_back
(
platform
::
CPUPlace
());
#ifdef PADDLE_WITH_CUDA
auto
pos
=
string
::
RFind
(
p
,
':'
,
string
::
Piece
::
npos
);
auto
number
=
device
.
substr
(
pos
+
1
);
places
.
emplace_back
(
platform
::
CUDAPlace
(
std
::
stoi
(
number
)));
int
count
=
platform
::
GetCUDADeviceCount
();
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
places
.
emplace_back
(
platform
::
CUDAPlace
(
i
));
}
#else
LOG
(
WARNING
)
<<
"'GPU' is not supported, Please re-compile with WITH_GPU option"
;
LOG
(
WARNING
)
<<
"'GPU' is not supported, Please re-compile with WITH_GPU option"
;
#endif
}
else
{
return
false
;
}
}
if
(
std
::
find_if
(
places
.
begin
(),
places
.
end
(),
[
&
](
const
platform
::
Place
&
place
)
{
return
platform
::
is_cpu_place
(
place
);
})
==
places
.
end
())
{
places
.
emplace_back
(
platform
::
CPUPlace
());
LOG
(
WARNING
)
<<
"Not specified CPU device, create CPU by Default."
;
}
platform
::
DeviceContextPool
::
Init
(
places
);
// framework::UseALL();
return
true
;
}
void
InitGLOG
(
const
std
::
string
&
prog_name
)
{
...
...
paddle/framework/init.h
浏览文件 @
5f985000
...
...
@@ -24,7 +24,7 @@ void InitGflags(std::vector<std::string> &argv);
void
InitGLOG
(
const
std
::
string
&
prog_name
);
bool
InitDevices
(
const
std
::
vector
<
std
::
string
>
&
devices
);
void
InitDevices
(
);
}
// namespace framework
}
// namespace paddle
paddle/framework/init_test.cc
浏览文件 @
5f985000
...
...
@@ -14,18 +14,13 @@ limitations under the License. */
#include "gtest/gtest.h"
#include "paddle/framework/init.h"
#include "paddle/platform/device_context.h"
TEST
(
Init
,
InitDevices
)
{
TEST
(
Init
Devices
,
CPU
)
{
using
paddle
::
framework
::
InitDevices
;
std
::
vector
<
std
::
string
>
ds1
=
{
"CPU"
};
ASSERT_EQ
(
InitDevices
(
ds1
),
true
);
using
paddle
::
platform
::
DeviceContextPool
;
#ifdef PADDLE_WITH_CUDA
std
::
vector
<
std
::
string
>
ds2
=
{
"CPU"
,
"GPU:0"
,
"GPU:1"
};
ASSERT_EQ
(
InitDevices
(
ds2
),
true
);
// test re-init
std
::
vector
<
std
::
string
>
ds3
=
{
"GPU:0"
,
"GPU:1"
};
ASSERT_EQ
(
InitDevices
(
ds3
),
true
);
#endif
InitDevices
();
DeviceContextPool
&
pool
=
DeviceContextPool
::
Instance
();
ASSERT_GE
(
pool
.
size
(),
1U
);
}
paddle/framework/operator_test.cc
浏览文件 @
5f985000
...
...
@@ -69,7 +69,7 @@ REGISTER_OP_WITHOUT_GRADIENT(test_operator,
paddle
::
framework
::
OpWithoutKernelCheckerMaker
);
TEST
(
OperatorBase
,
all
)
{
paddle
::
framework
::
InitDevices
(
{
"CPU"
}
);
paddle
::
framework
::
InitDevices
();
paddle
::
framework
::
proto
::
OpDesc
op_desc
;
op_desc
.
set_type
(
"test_operator"
);
BuildVar
(
"input"
,
{
"IN1"
},
op_desc
.
add_inputs
());
...
...
@@ -195,7 +195,7 @@ REGISTER_OP_CPU_KERNEL(op_with_kernel,
// test with single input
TEST
(
OpKernel
,
all
)
{
paddle
::
framework
::
InitDevices
(
{
"CPU"
}
);
paddle
::
framework
::
InitDevices
();
paddle
::
framework
::
proto
::
OpDesc
op_desc
;
op_desc
.
set_type
(
"op_with_kernel"
);
BuildVar
(
"x"
,
{
"IN1"
},
op_desc
.
add_inputs
());
...
...
@@ -225,7 +225,7 @@ REGISTER_OP_CPU_KERNEL(op_multi_inputs_with_kernel,
TEST
(
OpKernel
,
multi_inputs
)
{
using
namespace
paddle
::
framework
;
paddle
::
framework
::
InitDevices
(
{
"CPU"
}
);
paddle
::
framework
::
InitDevices
();
proto
::
OpDesc
op_desc
;
op_desc
.
set_type
(
"op_multi_inputs_with_kernel"
);
...
...
@@ -264,7 +264,7 @@ class OperatorClone : public paddle::framework::OperatorBase {
};
TEST
(
Operator
,
Clone
)
{
paddle
::
framework
::
InitDevices
(
{
"CPU"
}
);
paddle
::
framework
::
InitDevices
();
OperatorClone
a
(
"ABC"
,
paddle
::
framework
::
VariableNameMap
{},
paddle
::
framework
::
VariableNameMap
{},
paddle
::
framework
::
AttributeMap
{});
...
...
paddle/inference/inference.cc
浏览文件 @
5f985000
...
...
@@ -169,7 +169,7 @@ void InferenceEngine::Execute(const std::vector<framework::LoDTensor>& feeds,
}
auto
*
place
=
new
platform
::
CPUPlace
();
framework
::
InitDevices
(
{
"CPU"
}
);
framework
::
InitDevices
();
framework
::
Executor
*
executor
=
new
framework
::
Executor
(
*
place
);
framework
::
Scope
*
scope
=
new
framework
::
Scope
();
...
...
paddle/platform/device_context.h
浏览文件 @
5f985000
...
...
@@ -185,6 +185,8 @@ class DeviceContextPool {
const
typename
DefaultDeviceContextType
<
Place
>::
TYPE
*>
(
Get
(
place
));
}
size_t
size
()
const
{
return
device_contexts_
.
size
();
}
private:
static
DeviceContextPool
*
pool
;
constexpr
static
int
LEFT_SHIFT
=
8
;
...
...
paddle/testing/paddle_gtest_main.cc
浏览文件 @
5f985000
...
...
@@ -34,11 +34,11 @@ int main(int argc, char** argv) {
google
::
ParseCommandLineFlags
(
&
new_argc
,
&
new_argv_address
,
false
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
paddle
::
memory
::
Used
(
paddle
::
platform
::
CPUPlace
());
std
::
vector
<
std
::
string
>
devs
=
{
"CPU"
};
#ifdef PADDLE_WITH_CUDA
paddle
::
memory
::
Used
(
paddle
::
platform
::
CUDAPlace
(
0
));
devs
.
push_back
(
"GPU:0"
);
#endif
paddle
::
framework
::
InitDevices
(
devs
);
paddle
::
framework
::
InitDevices
();
return
RUN_ALL_TESTS
();
}
python/paddle/v2/fluid/__init__.py
浏览文件 @
5f985000
...
...
@@ -62,11 +62,7 @@ def __bootstrap__():
core
.
init_gflags
([
sys
.
argv
[
0
]]
+
[
"--tryfromenv="
+
","
.
join
(
read_env_flags
)])
core
.
init_glog
(
sys
.
argv
[
0
])
if
core
.
is_compile_gpu
():
core
.
init_devices
([
"CPU"
,
"GPU:0"
])
else
:
core
.
init_devices
([
"CPU"
])
core
.
init_devices
()
__bootstrap__
()
python/paddle/v2/fluid/tests/test_batch_norm_op.py
浏览文件 @
5f985000
...
...
@@ -341,9 +341,6 @@ class TestBatchNormOp(OpTest):
if
core
.
is_compile_gpu
()
and
core
.
op_support_gpu
(
"batch_norm"
):
places
.
append
(
core
.
CUDAPlace
(
0
))
core
.
init_devices
([
"CPU"
,
"GPU:0"
])
else
:
core
.
init_devices
([
"CPU"
])
for
place
in
places
:
for
data_format
in
[
"NCHW"
,
"NHWC"
]:
test_with_place
(
place
,
data_format
,
[
2
,
3
,
4
,
5
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录