Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
89aa8b1a
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看板
未验证
提交
89aa8b1a
编写于
2月 11, 2022
作者:
Z
zn
提交者:
GitHub
2月 11, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[MLU]support c_gen_cncl_id_op run on MLU device (#39336)
Co-authored-by:
N
zhangna
<
zhangna@cambricon.com
>
上级
702bce57
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
139 addition
and
6 deletion
+139
-6
paddle/fluid/operators/collective/CMakeLists.txt
paddle/fluid/operators/collective/CMakeLists.txt
+6
-1
paddle/fluid/operators/collective/c_gen_cncl_id_op.cc
paddle/fluid/operators/collective/c_gen_cncl_id_op.cc
+119
-0
paddle/fluid/platform/gen_comm_id_helper.cc
paddle/fluid/platform/gen_comm_id_helper.cc
+10
-2
paddle/fluid/platform/gen_comm_id_helper.h
paddle/fluid/platform/gen_comm_id_helper.h
+3
-2
python/paddle/fluid/framework.py
python/paddle/fluid/framework.py
+1
-1
未找到文件。
paddle/fluid/operators/collective/CMakeLists.txt
浏览文件 @
89aa8b1a
...
...
@@ -11,7 +11,7 @@ foreach(src ${OPS})
set_source_files_properties
(
${
src
}
PROPERTIES COMPILE_FLAGS
${
COLLECTIVE_COMPILE_FLAGS
}
)
endforeach
()
register_operators
(
EXCLUDES c_gen_bkcl_id_op gen_bkcl_id_op c_gen_nccl_id_op gen_nccl_id_op c_gen_hccl_id_op gen_hccl_id_op DEPS
${
COLLECTIVE_DEPS
}
)
register_operators
(
EXCLUDES c_gen_bkcl_id_op gen_bkcl_id_op c_gen_nccl_id_op gen_nccl_id_op c_gen_hccl_id_op gen_hccl_id_op
c_gen_cncl_id_op
DEPS
${
COLLECTIVE_DEPS
}
)
if
(
WITH_NCCL OR WITH_RCCL
)
set
(
COLLECTIVE_DEPS
${
COLLECTIVE_DEPS
}
nccl_common collective_helper
)
...
...
@@ -29,6 +29,11 @@ if(WITH_XPU_BKCL)
op_library
(
gen_bkcl_id_op DEPS
${
COLLECTIVE_DEPS
}
)
endif
()
if
(
WITH_CNCL
)
set
(
COLLECTIVE_DEPS
${
COLLECTIVE_DEPS
}
collective_helper
)
op_library
(
c_gen_cncl_id_op DEPS
${
COLLECTIVE_DEPS
}
)
endif
()
if
(
WITH_ASCEND_CL
)
cc_library
(
gen_hccl_id_op_helper SRCS gen_hccl_id_op_helper.cc DEPS dynload_warpctc dynamic_loader scope
)
set
(
COLLECTIVE_DEPS
${
COLLECTIVE_DEPS
}
collective_helper gen_hccl_id_op_helper
)
...
...
paddle/fluid/operators/collective/c_gen_cncl_id_op.cc
0 → 100644
浏览文件 @
89aa8b1a
/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
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 <cncl.h>
#include <string>
#include "paddle/fluid/framework/op_proto_maker.h"
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/scope.h"
#include "paddle/fluid/framework/var_type_traits.h"
#include "paddle/fluid/platform/device_context.h"
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/place.h"
#include "paddle/fluid/platform/gen_comm_id_helper.h"
namespace
paddle
{
namespace
operators
{
static
void
GenCNCLID
(
std
::
vector
<
cnclCliqueId
>*
cncl_ids
)
{
for
(
size_t
i
=
0
;
i
<
cncl_ids
->
size
();
++
i
)
{
PADDLE_ENFORCE_MLU_SUCCESS
(
cnclGetCliqueId
(
&
(
*
cncl_ids
)[
i
]));
}
}
static
void
CopyCNCLIDToVar
(
const
std
::
vector
<
cnclCliqueId
>&
cncl_ids
,
std
::
function
<
std
::
string
(
size_t
)
>
func
,
const
framework
::
Scope
&
scope
)
{
for
(
size_t
i
=
0
;
i
<
cncl_ids
.
size
();
++
i
)
{
std
::
string
var_name
=
func
(
i
);
auto
var
=
scope
.
FindVar
(
var_name
);
PADDLE_ENFORCE_NOT_NULL
(
var
,
platform
::
errors
::
NotFound
(
"Variable with name %s is not found"
,
var_name
.
c_str
()));
auto
cncl_id
=
var
->
GetMutable
<
cnclCliqueId
>
();
memcpy
(
cncl_id
,
&
cncl_ids
[
i
],
sizeof
(
cnclCliqueId
));
}
}
class
CGenCNCLIdOp
:
public
framework
::
OperatorBase
{
public:
CGenCNCLIdOp
(
const
std
::
string
&
type
,
const
framework
::
VariableNameMap
&
inputs
,
const
framework
::
VariableNameMap
&
outputs
,
const
framework
::
AttributeMap
&
attrs
)
:
OperatorBase
(
type
,
inputs
,
outputs
,
attrs
)
{}
void
RunImpl
(
const
framework
::
Scope
&
scope
,
const
platform
::
Place
&
dev_place
)
const
override
{
int
rank
=
Attr
<
int
>
(
"rank"
);
int
ring_id
=
Attr
<
int
>
(
"ring_id"
);
std
::
function
<
std
::
string
(
size_t
)
>
func
=
[
&
](
size_t
i
)
->
std
::
string
{
return
Output
(
"Out"
);
};
std
::
string
endpoint
=
Attr
<
std
::
string
>
(
"endpoint"
);
int
server_fd
=
platform
::
SocketServer
::
GetInstance
(
endpoint
).
socket
();
std
::
vector
<
cnclCliqueId
>
cncl_ids
;
cncl_ids
.
resize
(
1
);
if
(
rank
==
0
)
{
GenCNCLID
(
&
cncl_ids
);
std
::
vector
<
std
::
string
>
endpoint_list
=
Attr
<
std
::
vector
<
std
::
string
>>
(
"other_endpoints"
);
platform
::
SendBroadCastCommID
(
endpoint_list
,
&
cncl_ids
,
ring_id
);
}
else
{
platform
::
RecvBroadCastCommID
(
server_fd
,
endpoint
,
&
cncl_ids
,
ring_id
);
}
CopyCNCLIDToVar
(
cncl_ids
,
func
,
scope
);
}
};
class
CGenCNCLIdOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
override
{
AddOutput
(
"Out"
,
"Raw variable contains a CNCL CliqueId instaces."
);
AddComment
(
R"DOC(
CGenCNCLId operator
For trainer 0: generate a new CliqueId and send it to all the other trainers.
For trainer 1~n: start a gRPC server to get the CliqueId, once got, stop the server.
)DOC"
);
AddAttr
<
std
::
string
>
(
"endpoint"
,
"(string), e.g. 127.0.0.1:6175 "
"current listen endpoint"
);
AddAttr
<
std
::
vector
<
std
::
string
>>
(
"other_endpoints"
,
"['trainer1_ip:port', 'trainer2_ip:port', ...] "
"list of other trainer endpoints"
)
.
SetDefault
({});
AddAttr
<
int
>
(
"rank"
,
"(int default 0) "
"The rank of the trainer in distributed training."
)
.
SetDefault
(
0
);
AddAttr
<
int
>
(
"ring_id"
,
"(int default 0) user specified ring id"
)
.
SetDefault
(
0
);
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
c_gen_cncl_id
,
ops
::
CGenCNCLIdOp
,
ops
::
CGenCNCLIdOpMaker
);
paddle/fluid/platform/gen_comm_id_helper.cc
浏览文件 @
89aa8b1a
...
...
@@ -13,7 +13,8 @@ See the License for the specific language governing permissions and
limitations under the License. */
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) || \
defined(PADDLE_WITH_XPU_BKCL) || defined(PADDLE_WITH_ASCEND_CL)
defined(PADDLE_WITH_XPU_BKCL) || defined(PADDLE_WITH_ASCEND_CL) || \
defined(PADDLE_WITH_CNCL)
#include "paddle/fluid/platform/gen_comm_id_helper.h"
#include <arpa/inet.h>
...
...
@@ -37,6 +38,10 @@ limitations under the License. */
#include "paddle/fluid/platform/collective_helper.h"
#endif
#if defined(PADDLE_WITH_CNCL)
#include <cncl.h>
#endif
DECLARE_int32
(
get_host_by_name_time
);
namespace
paddle
{
...
...
@@ -430,6 +435,9 @@ INSTANT_TEMPLATE(BKCLUniqueId)
#ifdef PADDLE_WITH_ASCEND_CL
INSTANT_TEMPLATE
(
HcclRootInfo
)
#endif
#ifdef PADDLE_WITH_CNCL
INSTANT_TEMPLATE
(
cnclCliqueId
)
#endif
}
// namespace platform
}
// namespace paddle
...
...
paddle/fluid/platform/gen_comm_id_helper.h
浏览文件 @
89aa8b1a
...
...
@@ -15,7 +15,8 @@ limitations under the License. */
#pragma once
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) || \
defined(PADDLE_WITH_XPU_BKCL) || defined(PADDLE_WITH_ASCEND_CL)
defined(PADDLE_WITH_XPU_BKCL) || defined(PADDLE_WITH_ASCEND_CL) || \
defined(PADDLE_WITH_CNCL)
#include <functional>
#include <memory>
#include <mutex>
...
...
python/paddle/fluid/framework.py
浏览文件 @
89aa8b1a
...
...
@@ -2467,7 +2467,7 @@ class Operator(object):
'c_comm_init'
,
'c_sync_calc_stream'
,
'c_sync_comm_stream'
,
'queue_generator'
,
'dequeue'
,
'enqueue'
,
'heter_listen_and_serv'
,
'c_wait_comm'
,
'c_wait_compute'
,
'c_gen_hccl_id'
,
'c_comm_init_hccl'
,
'copy_cross_scope'
'copy_cross_scope'
,
'c_gen_cncl_id'
}
def
__init__
(
self
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录