Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
0990c87b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
0990c87b
编写于
10月 24, 2017
作者:
D
Dong Zhihong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
checkin nccl operator
上级
da1181bf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
42 addition
and
89 deletion
+42
-89
paddle/operators/nccl/nccl_gpu_common.h
paddle/operators/nccl/nccl_gpu_common.h
+2
-1
paddle/operators/nccl_op_test.cc
paddle/operators/nccl_op_test.cc
+0
-71
paddle/operators/nccl_op_test.cu
paddle/operators/nccl_op_test.cu
+30
-7
paddle/platform/nccl_test.cu
paddle/platform/nccl_test.cu
+2
-5
python/paddle/v2/framework/tests/test_nccl_allreduce_op.py
python/paddle/v2/framework/tests/test_nccl_allreduce_op.py
+8
-5
未找到文件。
paddle/operators/nccl/nccl_gpu_common.h
浏览文件 @
0990c87b
...
...
@@ -46,7 +46,8 @@ struct Communicator {
~
Communicator
()
{
for
(
size_t
i
=
0
;
i
<
comms_
.
size
();
++
i
)
{
PADDLE_ENFORCE
(
dynload
::
ncclCommDestroy
(
comms_
[
i
]));
// FIXME(dzh) : PADDLE_ENFORCE return void
dynload
::
ncclCommDestroy
(
comms_
[
i
]);
}
}
...
...
paddle/operators/nccl_op_test.cc
已删除
100644 → 0
浏览文件 @
da1181bf
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include "paddle/operators/nccl_op.h"
#include "glog/logging.h"
#include "gtest/gtest.h"
#include "paddle/platform/device_context.h"
#include "paddle/platform/enforce.h"
#include "paddle/platform/gpu_info.h"
#include <thrust/device_vector.h>
#include <memory>
#include <vector>
static
std
::
vector
<
int
>
gpu_list
;
using
f
=
paddle
::
framework
;
using
ops
=
paddle
::
operators
;
void
AddOp
(
const
std
::
string
&
type
,
const
f
::
VariableNameMap
&
inputs
,
const
f
::
VariableNameMap
&
outputs
,
f
::
AttributeMap
attrs
,
paddle
::
framework
::
BlockDescBind
*
block
)
{
for
(
auto
kv
:
outputs
)
{
for
(
auto
v
:
kv
.
second
)
{
auto
var
=
block
->
Var
(
v
);
var
->
SetDataType
(
paddle
::
framework
::
DataType
::
FP32
);
}
}
auto
op
=
block
->
AppendOp
();
op
->
SetType
(
type
);
for
(
auto
&
kv
:
inputs
)
{
op
->
SetInput
(
kv
.
first
,
kv
.
second
);
}
for
(
auto
&
kv
:
outputs
)
{
op
->
SetOutput
(
kv
.
first
,
kv
.
second
);
}
op
->
SetAttrMap
(
attrs
);
}
TEST
(
NCCL
,
ncclInitOp
)
{
f
::
ProgramDescBind
program
;
f
::
BlockDescBind
*
block
=
program
.
Block
(
0
);
}
int
main
(
int
argc
,
char
**
argv
)
{
static
constexpr
int
gpu_count
=
paddle
::
platform
::
GetCUDADeviceCount
();
for
(
int
i
=
0
;
i
<
gpu_count
;
++
i
)
{
gpu_list
.
emplace_back
(
i
);
}
if
(
dev_count
<=
1
)
{
LOG
(
WARNING
)
<<
"Cannot test multi-gpu nccl, because the CUDA device count is "
<<
dev_count
;
return
0
;
}
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
paddle/operators/nccl_op_test.cu
浏览文件 @
0990c87b
...
...
@@ -16,6 +16,11 @@
#include "glog/logging.h"
#include "gtest/gtest.h"
#include "paddle/framework/block_desc.h"
#include "paddle/framework/op_desc.h"
#include "paddle/framework/op_registry.h"
#include "paddle/framework/program_desc.h"
#include "paddle/framework/var_desc.h"
#include "paddle/platform/device_context.h"
#include "paddle/platform/enforce.h"
#include "paddle/platform/gpu_info.h"
...
...
@@ -26,8 +31,8 @@
static
std
::
vector
<
int
>
gpu_list
;
using
f
=
paddle
::
framework
;
using
ops
=
paddle
::
operators
;
namespace
f
=
paddle
::
framework
;
namespace
ops
=
paddle
::
operators
;
void
AddOp
(
const
std
::
string
&
type
,
const
f
::
VariableNameMap
&
inputs
,
const
f
::
VariableNameMap
&
outputs
,
f
::
AttributeMap
attrs
,
...
...
@@ -50,22 +55,40 @@ void AddOp(const std::string &type, const f::VariableNameMap &inputs,
op
->
SetAttrMap
(
attrs
);
}
TEST
(
NCCL
,
ncclInit
Op
)
{
TEST
(
NCCL
,
ncclInit
)
{
f
::
ProgramDescBind
program
;
f
::
BlockDescBind
*
block
=
program
.
Block
(
0
);
f
::
OpDescBind
*
op
=
block
->
AppendOp
();
paddle
::
platform
::
Communicator
comm
;
op
->
SetType
(
"ncclInit"
);
op
->
SetOutput
(
"Communicator"
,
)
AddOp
(
"ncclInit"
,
{},
{{
"Communicator"
,
{
comm
}}},
{{
"gpus"
,
{
gpu_list
}}},
block
);
}
// TEST(NCCL, ncclAllReduce) {
// f::ProgramDescBind program;
// f::BlockDescBind *block = program.Block(0);
// paddle::platform::Communicator comm;
// AddOp("ncclInit", {}, {{"Communicator", {comm}}, {"gpus", {gpu_list}}},
// block);
// }
int
main
(
int
argc
,
char
**
argv
)
{
static
constexpr
int
gpu_count
=
paddle
::
platform
::
GetCUDADeviceCount
();
for
(
int
i
=
0
;
i
<
gpu_count
;
++
i
)
{
gpu_list
.
emplace_back
(
i
);
}
static
int
dev_count
=
paddle
::
platform
::
GetCUDADeviceCount
();
if
(
dev_count
<=
1
)
{
LOG
(
WARNING
)
<<
"Cannot test multi-gpu nccl, because the CUDA device count is "
<<
dev_count
;
return
0
;
}
for
(
int
i
=
0
;
i
<
dev_count
;
++
i
)
{
gpu_list
.
emplace_back
(
i
);
}
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
paddle/platform/nccl_test.cu
浏览文件 @
0990c87b
...
...
@@ -31,9 +31,7 @@ namespace platform {
TEST
(
NCCL
,
init
)
{
std
::
vector
<
ncclComm_t
>
comms
;
comms
.
resize
(
dev_count
);
auto
status
=
dynload
::
ncclCommInitAll
(
comms
.
data
(),
dev_count
,
nullptr
);
PADDLE_ENFORCE
(
status
);
PADDLE_ENFORCE
(
dynload
::
ncclCommInitAll
(
comms
.
data
(),
dev_count
,
nullptr
));
for
(
int
i
=
0
;
i
<
dev_count
;
++
i
)
{
dynload
::
ncclCommDestroy
(
comms
[
i
]);
}
...
...
@@ -64,8 +62,7 @@ TEST(NCCL, all_reduce) {
std
::
vector
<
ncclComm_t
>
comms
;
comms
.
resize
(
dev_count
);
VLOG
(
1
)
<<
"Initializing ncclComm"
;
auto
status
=
dynload
::
ncclCommInitAll
(
comms
.
data
(),
dev_count
,
nullptr
);
PADDLE_ENFORCE
(
status
);
PADDLE_ENFORCE
(
dynload
::
ncclCommInitAll
(
comms
.
data
(),
dev_count
,
nullptr
));
VLOG
(
1
)
<<
"ncclComm initialized"
;
VLOG
(
1
)
<<
"Creating thread data"
;
std
::
vector
<
std
::
unique_ptr
<
PerThreadData
<
double
>>>
data
;
...
...
python/paddle/v2/framework/tests/test_nccl_allreduce_op.py
浏览文件 @
0990c87b
...
...
@@ -53,6 +53,9 @@ def thread_allreduce_op(thread_id, gpu_id):
op
=
create_op
(
scope
,
"ncclAllReduce"
,
inputs
,
outputs
,
attrs
=
{})
place
=
core
.
GPUPlace
(
gpus
[
i
])
set_input
(
scope
,
op
,
inputs
,
place
)
# # print scope.find_var("Out").get_tensor()
# # print scope.find_var("X").get_tensor()
print
scope
.
find_var
(
"Communicator"
).
get_communicator
()
ctx
=
core
.
DeviceContext
.
create
(
place
)
...
...
@@ -83,13 +86,13 @@ class TestNCCLAllReduce(unittest.TestCase):
i
,
gpus
[
i
],
))
th
.
start
()
ops
.
append
(
ops
)
for
t
h
in
ops
:
t
h
.
join
()
ops
.
append
(
th
)
for
t
in
ops
:
t
.
join
()
idx
=
0
for
out_name
,
out_dup
in
Operator
.
get_op_outputs
(
self
.
op
.
type
()
):
actual
=
np
.
array
(
scope
.
find_var
(
out_name
).
get_tensor
())
for
out_name
,
out_dup
in
Operator
.
get_op_outputs
(
self
.
op
_type
):
actual
=
np
.
array
(
g_
scope
.
find_var
(
out_name
).
get_tensor
())
expect
=
output_data
[
idx
]
idx
+=
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录