Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
20db8602
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
20db8602
编写于
6月 15, 2023
作者:
R
ronnywang
提交者:
GitHub
6月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[CustomDevice] add MOE support, PART1 (#54572)
上级
3261b106
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
159 addition
and
0 deletion
+159
-0
paddle/phi/backends/c_comm_lib.h
paddle/phi/backends/c_comm_lib.h
+19
-0
paddle/phi/backends/custom/custom_device.cc
paddle/phi/backends/custom/custom_device.cc
+71
-0
paddle/phi/backends/device_base.cc
paddle/phi/backends/device_base.cc
+13
-0
paddle/phi/backends/device_base.h
paddle/phi/backends/device_base.h
+10
-0
paddle/phi/backends/device_ext.h
paddle/phi/backends/device_ext.h
+11
-0
paddle/phi/backends/device_manager.cc
paddle/phi/backends/device_manager.cc
+24
-0
paddle/phi/backends/device_manager.h
paddle/phi/backends/device_manager.h
+11
-0
未找到文件。
paddle/phi/backends/c_comm_lib.h
浏览文件 @
20db8602
...
@@ -56,5 +56,24 @@ inline CCLDataType ToCCLDataType(phi::DataType type) {
...
@@ -56,5 +56,24 @@ inline CCLDataType ToCCLDataType(phi::DataType type) {
}
}
}
}
inline
phi
::
DataType
ToPhiDataType
(
CCLDataType
type
)
{
if
(
type
==
CCLDataType
::
CCL_DATA_TYPE_FP64
)
{
return
phi
::
DataType
::
FLOAT64
;
}
else
if
(
type
==
CCLDataType
::
CCL_DATA_TYPE_FP32
)
{
return
phi
::
DataType
::
FLOAT32
;
}
else
if
(
type
==
CCLDataType
::
CCL_DATA_TYPE_FP16
)
{
return
phi
::
DataType
::
FLOAT16
;
}
else
if
(
type
==
CCLDataType
::
CCL_DATA_TYPE_INT64
)
{
return
phi
::
DataType
::
INT64
;
}
else
if
(
type
==
CCLDataType
::
CCL_DATA_TYPE_INT32
)
{
return
phi
::
DataType
::
INT32
;
}
else
if
(
type
==
CCLDataType
::
CCL_DATA_TYPE_INT8
)
{
return
phi
::
DataType
::
INT8
;
}
else
{
PADDLE_THROW
(
phi
::
errors
::
Unimplemented
(
"This datatype in CCL is not supported."
));
}
}
}
// namespace ccl
}
// namespace ccl
}
// namespace phi
}
// namespace phi
paddle/phi/backends/custom/custom_device.cc
浏览文件 @
20db8602
...
@@ -802,6 +802,77 @@ class CustomDevice : public DeviceInterface {
...
@@ -802,6 +802,77 @@ class CustomDevice : public DeviceInterface {
reinterpret_cast
<
C_Stream
>
(
stream
.
raw_stream
())));
reinterpret_cast
<
C_Stream
>
(
stream
.
raw_stream
())));
}
}
void
CCLAllToAll
(
const
void
**
send_buf
,
const
size_t
*
send_count
,
const
ccl
::
CCLDataType
*
send_dtype
,
void
**
recv_buf
,
const
size_t
*
recv_count
,
const
ccl
::
CCLDataType
*
recv_dtype
,
size_t
rank
,
size_t
nranks
,
const
ccl
::
CCLComm
&
comm
,
const
stream
::
Stream
&
stream
)
override
{
if
(
pimpl_
->
xccl_all_to_all
)
{
std
::
vector
<
C_DataType
>
c_send_dtype
,
c_recv_dtype
;
for
(
size_t
i
=
0
;
i
<
nranks
;
++
i
)
{
c_send_dtype
.
push_back
(
ToXCCLDataType
(
send_dtype
[
i
]));
c_recv_dtype
.
push_back
(
ToXCCLDataType
(
recv_dtype
[
i
]));
}
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS
(
pimpl_
->
xccl_all_to_all
(
send_buf
,
send_count
,
c_send_dtype
.
data
(),
recv_buf
,
recv_count
,
c_recv_dtype
.
data
(),
rank
,
nranks
,
reinterpret_cast
<
C_CCLComm
>
(
comm
),
reinterpret_cast
<
C_Stream
>
(
stream
.
raw_stream
())));
}
else
if
(
pimpl_
->
xccl_send
&&
pimpl_
->
xccl_recv
)
{
// NOTE(wangran16): fallback to send and recv, while avoiding some devices
// not supporting asynchronous send and recv.
for
(
size_t
i
=
0
;
i
<
rank
;
++
i
)
{
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS
(
pimpl_
->
xccl_recv
(
recv_buf
[
i
],
recv_count
[
i
],
ToXCCLDataType
(
recv_dtype
[
i
]),
i
,
reinterpret_cast
<
C_CCLComm
>
(
comm
),
reinterpret_cast
<
C_Stream
>
(
stream
.
raw_stream
())));
}
for
(
size_t
i
=
0
;
i
<
nranks
;
++
i
)
{
if
(
i
!=
rank
)
{
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS
(
pimpl_
->
xccl_send
(
const_cast
<
void
*>
(
send_buf
[
i
]),
send_count
[
i
],
ToXCCLDataType
(
send_dtype
[
i
]),
i
,
reinterpret_cast
<
C_CCLComm
>
(
comm
),
reinterpret_cast
<
C_Stream
>
(
stream
.
raw_stream
())));
}
}
MemoryCopyD2D
(
rank
,
recv_buf
[
rank
],
send_buf
[
rank
],
send_count
[
rank
]
*
phi
::
SizeOf
(
phi
::
ccl
::
ToPhiDataType
(
send_dtype
[
rank
])),
&
stream
);
for
(
size_t
i
=
rank
+
1
;
i
<
nranks
;
++
i
)
{
PADDLE_ENFORCE_CUSTOM_DEVICE_SUCCESS
(
pimpl_
->
xccl_recv
(
recv_buf
[
i
],
recv_count
[
i
],
ToXCCLDataType
(
recv_dtype
[
i
]),
i
,
reinterpret_cast
<
C_CCLComm
>
(
comm
),
reinterpret_cast
<
C_Stream
>
(
stream
.
raw_stream
())));
}
}
else
{
PADDLE_THROW
(
phi
::
errors
::
Unavailable
(
"CCLAllToAll is not supported on %s."
,
Type
()));
}
}
void
BlasAXPBY
(
size_t
dev_id
,
void
BlasAXPBY
(
size_t
dev_id
,
const
stream
::
Stream
&
stream
,
const
stream
::
Stream
&
stream
,
phi
::
DataType
dtype
,
phi
::
DataType
dtype
,
...
...
paddle/phi/backends/device_base.cc
浏览文件 @
20db8602
...
@@ -356,6 +356,19 @@ void DeviceInterface::CCLRecv(void* recvbuf,
...
@@ -356,6 +356,19 @@ void DeviceInterface::CCLRecv(void* recvbuf,
INTERFACE_UNIMPLEMENT
;
INTERFACE_UNIMPLEMENT
;
}
}
void
DeviceInterface
::
CCLAllToAll
(
const
void
**
send_buf
,
const
size_t
*
send_count
,
const
ccl
::
CCLDataType
*
send_dtype
,
void
**
recv_buf
,
const
size_t
*
recv_count
,
const
ccl
::
CCLDataType
*
recv_dtype
,
size_t
rank
,
size_t
nranks
,
const
ccl
::
CCLComm
&
comm
,
const
stream
::
Stream
&
stream
)
{
INTERFACE_UNIMPLEMENT
;
}
// blas
// blas
void
DeviceInterface
::
BlasAXPBY
(
size_t
dev_id
,
void
DeviceInterface
::
BlasAXPBY
(
size_t
dev_id
,
const
stream
::
Stream
&
stream
,
const
stream
::
Stream
&
stream
,
...
...
paddle/phi/backends/device_base.h
浏览文件 @
20db8602
...
@@ -228,6 +228,16 @@ class DeviceInterface { // Driver / Runtime
...
@@ -228,6 +228,16 @@ class DeviceInterface { // Driver / Runtime
const
ccl
::
CCLComm
&
ccl_comm
,
const
ccl
::
CCLComm
&
ccl_comm
,
const
stream
::
Stream
&
stream
);
const
stream
::
Stream
&
stream
);
virtual
void
CCLAllToAll
(
const
void
**
send_buf
,
const
size_t
*
send_count
,
const
ccl
::
CCLDataType
*
send_dtype
,
void
**
recv_buf
,
const
size_t
*
recv_count
,
const
ccl
::
CCLDataType
*
recv_dtype
,
size_t
rank
,
size_t
nranks
,
const
ccl
::
CCLComm
&
comm
,
const
stream
::
Stream
&
stream
);
// blas
// blas
virtual
void
BlasAXPBY
(
size_t
dev_id
,
virtual
void
BlasAXPBY
(
size_t
dev_id
,
const
stream
::
Stream
&
stream
,
const
stream
::
Stream
&
stream
,
...
...
paddle/phi/backends/device_ext.h
浏览文件 @
20db8602
...
@@ -638,6 +638,17 @@ struct C_DeviceInterface {
...
@@ -638,6 +638,17 @@ struct C_DeviceInterface {
C_CCLComm
comm
,
C_CCLComm
comm
,
C_Stream
stream
);
C_Stream
stream
);
C_Status
(
*
xccl_all_to_all
)(
const
void
**
send_buf
,
const
size_t
*
send_count
,
const
C_DataType
*
send_dtype
,
void
**
recv_buf
,
const
size_t
*
recv_count
,
const
C_DataType
*
recv_dtype
,
size_t
rank
,
size_t
nranks
,
C_CCLComm
comm
,
C_Stream
stream
);
void
*
reserved_ccl_api
[
8
];
void
*
reserved_ccl_api
[
8
];
//////////////////
//////////////////
...
...
paddle/phi/backends/device_manager.cc
浏览文件 @
20db8602
...
@@ -596,6 +596,30 @@ void DeviceManager::CCLRecv(const std::string& device_type,
...
@@ -596,6 +596,30 @@ void DeviceManager::CCLRecv(const std::string& device_type,
dev_impl
->
CCLRecv
(
recvbuf
,
num
,
data_type
,
src_rank
,
ccl_comm
,
stream
);
dev_impl
->
CCLRecv
(
recvbuf
,
num
,
data_type
,
src_rank
,
ccl_comm
,
stream
);
}
}
void
DeviceManager
::
CCLAllToAll
(
const
std
::
string
&
device_type
,
const
void
**
send_buf
,
const
size_t
*
send_count
,
const
ccl
::
CCLDataType
*
send_dtype
,
void
**
recv_buf
,
const
size_t
*
recv_count
,
const
ccl
::
CCLDataType
*
recv_dtype
,
size_t
rank
,
size_t
nranks
,
const
ccl
::
CCLComm
&
comm
,
const
stream
::
Stream
&
stream
)
{
auto
dev_impl
=
GetDeviceInterfaceWithType
(
device_type
);
dev_impl
->
CCLAllToAll
(
send_buf
,
send_count
,
send_dtype
,
recv_buf
,
recv_count
,
recv_dtype
,
rank
,
nranks
,
comm
,
stream
);
}
// profiler
// profiler
void
DeviceManager
::
ProfilerInitialize
(
const
std
::
string
&
dev_type
,
void
DeviceManager
::
ProfilerInitialize
(
const
std
::
string
&
dev_type
,
phi
::
TraceEventCollector
*
collector
,
phi
::
TraceEventCollector
*
collector
,
...
...
paddle/phi/backends/device_manager.h
浏览文件 @
20db8602
...
@@ -241,6 +241,17 @@ class DeviceManager {
...
@@ -241,6 +241,17 @@ class DeviceManager {
const
ccl
::
CCLComm
&
ccl_comm
,
const
ccl
::
CCLComm
&
ccl_comm
,
const
stream
::
Stream
&
stream
);
const
stream
::
Stream
&
stream
);
static
void
CCLAllToAll
(
const
std
::
string
&
device_type
,
const
void
**
send_buf
,
const
size_t
*
send_count
,
const
ccl
::
CCLDataType
*
send_dtype
,
void
**
recv_buf
,
const
size_t
*
recv_count
,
const
ccl
::
CCLDataType
*
recv_dtype
,
size_t
rank
,
size_t
nranks
,
const
ccl
::
CCLComm
&
comm
,
const
stream
::
Stream
&
stream
);
// profiler
// profiler
static
void
ProfilerInitialize
(
const
std
::
string
&
dev_type
,
static
void
ProfilerInitialize
(
const
std
::
string
&
dev_type
,
phi
::
TraceEventCollector
*
collector
,
phi
::
TraceEventCollector
*
collector
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录