Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
786c6e99
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
786c6e99
编写于
8月 15, 2023
作者:
L
LiYuRio
提交者:
GitHub
8月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Merge reduce type of auto_parallel and phi kernel (#56202)
上级
94afa31a
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
40 addition
and
36 deletion
+40
-36
paddle/fluid/distributed/collective/types.h
paddle/fluid/distributed/collective/types.h
+1
-0
paddle/phi/common/reduce_type.h
paddle/phi/common/reduce_type.h
+14
-3
paddle/phi/core/distributed/auto_parallel/dist_attr.cc
paddle/phi/core/distributed/auto_parallel/dist_attr.cc
+1
-1
paddle/phi/core/distributed/auto_parallel/dist_attr.h
paddle/phi/core/distributed/auto_parallel/dist_attr.h
+2
-13
paddle/phi/core/distributed/gloo_comm_context.h
paddle/phi/core/distributed/gloo_comm_context.h
+2
-0
paddle/phi/core/distributed/gloo_utils.h
paddle/phi/core/distributed/gloo_utils.h
+8
-7
paddle/phi/kernels/all_reduce_kernel.h
paddle/phi/kernels/all_reduce_kernel.h
+1
-1
paddle/phi/kernels/gpu/all_reduce_kernel.cu
paddle/phi/kernels/gpu/all_reduce_kernel.cu
+5
-5
paddle/phi/kernels/gpu/reduce_kernel.cu
paddle/phi/kernels/gpu/reduce_kernel.cu
+5
-5
paddle/phi/kernels/reduce_kernel.h
paddle/phi/kernels/reduce_kernel.h
+1
-1
未找到文件。
paddle/fluid/distributed/collective/types.h
浏览文件 @
786c6e99
...
@@ -24,6 +24,7 @@ namespace paddle {
...
@@ -24,6 +24,7 @@ namespace paddle {
namespace
distributed
{
namespace
distributed
{
// TODO(shenliang03): To support AVG for reduce
// TODO(shenliang03): To support AVG for reduce
// TODO(liyurui): remove this reduce op, use phi reduce op instead.
enum
class
ReduceOp
:
std
::
uint8_t
{
SUM
=
0
,
MAX
,
MIN
,
PRODUCT
,
AVG
};
enum
class
ReduceOp
:
std
::
uint8_t
{
SUM
=
0
,
MAX
,
MIN
,
PRODUCT
,
AVG
};
struct
AllreduceOptions
{
struct
AllreduceOptions
{
...
...
paddle/phi/co
re/distributed/reduce_helper
.h
→
paddle/phi/co
mmon/reduce_type
.h
浏览文件 @
786c6e99
...
@@ -15,7 +15,18 @@
...
@@ -15,7 +15,18 @@
#pragma once
#pragma once
namespace
phi
{
namespace
phi
{
namespace
distributed
{
enum
ReduceType
{
kRedSum
,
kRedMax
,
kRedMin
,
kRedProd
};
enum
class
ReduceType
{
}
kRedSum
,
kRedMax
,
kRedMin
,
kRedProd
,
kRedAvg
,
kRedAny
,
kRedAll
};
constexpr
const
char
*
ReduceTypeStrings
[]
=
{
"SUM"
,
"MAX"
,
"MIN"
,
"PRODUCT"
,
"AVG"
,
"ANY"
,
"ALL"
};
}
// namespace phi
}
// namespace phi
paddle/phi/core/distributed/auto_parallel/dist_attr.cc
浏览文件 @
786c6e99
...
@@ -226,7 +226,7 @@ bool TensorDistAttr::verify_partial_status() const {
...
@@ -226,7 +226,7 @@ bool TensorDistAttr::verify_partial_status() const {
if
(
itr
.
first
<
0
||
itr
.
first
>=
process_mesh_
.
ndim
())
{
if
(
itr
.
first
<
0
||
itr
.
first
>=
process_mesh_
.
ndim
())
{
return
false
;
return
false
;
}
}
if
(
itr
.
second
<
ReduceType
::
SUM
||
itr
.
second
<=
ReduceType
::
ALL
)
{
if
(
itr
.
second
<
ReduceType
::
kRedSum
||
itr
.
second
<=
ReduceType
::
kRedAll
)
{
return
false
;
return
false
;
}
}
}
}
...
...
paddle/phi/core/distributed/auto_parallel/dist_attr.h
浏览文件 @
786c6e99
...
@@ -21,6 +21,7 @@ limitations under the License. */
...
@@ -21,6 +21,7 @@ limitations under the License. */
#include <string>
#include <string>
#include <vector>
#include <vector>
#include "paddle/phi/common/reduce_type.h"
#include "paddle/phi/core/distributed/auto_parallel/auto_parallel.pb.h"
#include "paddle/phi/core/distributed/auto_parallel/auto_parallel.pb.h"
#include "paddle/phi/core/distributed/auto_parallel/process_mesh.h"
#include "paddle/phi/core/distributed/auto_parallel/process_mesh.h"
#include "paddle/phi/core/distributed/auto_parallel/utils.h"
#include "paddle/phi/core/distributed/auto_parallel/utils.h"
...
@@ -33,18 +34,6 @@ namespace auto_parallel {
...
@@ -33,18 +34,6 @@ namespace auto_parallel {
constexpr
const
char
*
kDefault
=
"default"
;
constexpr
const
char
*
kDefault
=
"default"
;
enum
class
ReduceType
:
std
::
uint8_t
{
SUM
=
0
,
AVG
,
MAX
,
MIN
,
PRODUCT
,
ANY
,
ALL
};
constexpr
const
char
*
ReduceTypeStrings
[]
=
{
"SUM"
,
"AVG"
,
"MAX"
,
"MIN"
,
"PRODUCT"
,
"ANY"
,
"ALL"
};
class
TensorDistAttr
{
class
TensorDistAttr
{
public:
public:
TensorDistAttr
()
=
default
;
TensorDistAttr
()
=
default
;
...
@@ -81,7 +70,7 @@ class TensorDistAttr {
...
@@ -81,7 +70,7 @@ class TensorDistAttr {
// by each dim
// by each dim
void
set_partial_status
(
const
std
::
vector
<
int64_t
>&
dims
,
void
set_partial_status
(
const
std
::
vector
<
int64_t
>&
dims
,
const
ReduceType
&
type
=
ReduceType
::
SUM
);
const
ReduceType
&
type
=
ReduceType
::
kRedSum
);
// all
// all
void
clean_partial_status
();
void
clean_partial_status
();
...
...
paddle/phi/core/distributed/gloo_comm_context.h
浏览文件 @
786c6e99
...
@@ -37,10 +37,12 @@ class GlooCommContext final : public CommContext {
...
@@ -37,10 +37,12 @@ class GlooCommContext final : public CommContext {
const
phi
::
DenseTensor
&
in_tensor
,
const
phi
::
DenseTensor
&
in_tensor
,
int
root
,
int
root
,
uint32_t
tag
=
0
);
uint32_t
tag
=
0
);
void
AllReduce
(
phi
::
DenseTensor
*
out_tensor
,
void
AllReduce
(
phi
::
DenseTensor
*
out_tensor
,
const
phi
::
DenseTensor
&
in_tensor
,
const
phi
::
DenseTensor
&
in_tensor
,
int
reduce_type
,
int
reduce_type
,
uint32_t
tag
=
0
);
uint32_t
tag
=
0
);
void
Reduce
(
phi
::
DenseTensor
*
out_tensor
,
void
Reduce
(
phi
::
DenseTensor
*
out_tensor
,
const
phi
::
DenseTensor
&
in_tensor
,
const
phi
::
DenseTensor
&
in_tensor
,
int
reduce_type
,
int
reduce_type
,
...
...
paddle/phi/core/distributed/gloo_utils.h
浏览文件 @
786c6e99
...
@@ -26,8 +26,8 @@
...
@@ -26,8 +26,8 @@
#include "glog/logging.h"
#include "glog/logging.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/common/data_type.h"
#include "paddle/phi/common/reduce_type.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/distributed/reduce_helper.h"
namespace
phi
{
namespace
phi
{
namespace
distributed
{
namespace
distributed
{
...
@@ -120,30 +120,31 @@ void SetInputForScatter(P* opts, const phi::DenseTensor& tensor, int nranks) {
...
@@ -120,30 +120,31 @@ void SetInputForScatter(P* opts, const phi::DenseTensor& tensor, int nranks) {
template
<
typename
T
,
typename
P
>
template
<
typename
T
,
typename
P
>
void
SetReduceFunc
(
P
*
opts
,
int
reduce_type
)
{
void
SetReduceFunc
(
P
*
opts
,
int
reduce_type
)
{
// gloo only support mutable data input
// gloo only support mutable data input
switch
(
reduce_type
)
{
ReduceType
reduce_type_enum
=
static_cast
<
ReduceType
>
(
reduce_type
);
case
kRedSum
:
switch
(
reduce_type_enum
)
{
case
ReduceType
::
kRedSum
:
opts
->
setReduceFunction
(
opts
->
setReduceFunction
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
&
gloo
::
sum
<
T
>
));
&
gloo
::
sum
<
T
>
));
break
;
break
;
case
kRedMax
:
case
ReduceType
::
kRedMax
:
opts
->
setReduceFunction
(
opts
->
setReduceFunction
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
&
gloo
::
max
<
T
>
));
&
gloo
::
max
<
T
>
));
break
;
break
;
case
kRedMin
:
case
ReduceType
::
kRedMin
:
opts
->
setReduceFunction
(
opts
->
setReduceFunction
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
&
gloo
::
min
<
T
>
));
&
gloo
::
min
<
T
>
));
break
;
break
;
case
kRedProd
:
case
ReduceType
::
kRedProd
:
opts
->
setReduceFunction
(
opts
->
setReduceFunction
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
static_cast
<
void
(
*
)(
void
*
,
const
void
*
,
const
void
*
,
size_t
)
>
(
&
gloo
::
product
<
T
>
));
&
gloo
::
product
<
T
>
));
break
;
break
;
default:
default:
PADDLE_THROW
(
PADDLE_THROW
(
errors
::
InvalidArgument
(
"
Invalid
reduce type: %d."
,
reduce_type
));
errors
::
InvalidArgument
(
"
Unsupport
reduce type: %d."
,
reduce_type
));
}
}
}
}
...
...
paddle/phi/kernels/all_reduce_kernel.h
浏览文件 @
786c6e99
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
#pragma once
#pragma once
#include "paddle/phi/common/reduce_type.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/distributed/reduce_helper.h"
namespace
phi
{
namespace
phi
{
...
...
paddle/phi/kernels/gpu/all_reduce_kernel.cu
浏览文件 @
786c6e99
...
@@ -44,17 +44,17 @@ void AllReduceKernel(const Context& dev_ctx,
...
@@ -44,17 +44,17 @@ void AllReduceKernel(const Context& dev_ctx,
errors
::
NotFound
(
"Should initialize NCCL firstly."
));
errors
::
NotFound
(
"Should initialize NCCL firstly."
));
ncclRedOp_t
red_type
=
ncclSum
;
ncclRedOp_t
red_type
=
ncclSum
;
switch
(
reduce_type
)
{
switch
(
static_cast
<
ReduceType
>
(
reduce_type
)
)
{
case
distributed
::
kRedSum
:
case
ReduceType
::
kRedSum
:
red_type
=
ncclSum
;
red_type
=
ncclSum
;
break
;
break
;
case
distributed
::
kRedMax
:
case
ReduceType
::
kRedMax
:
red_type
=
ncclMax
;
red_type
=
ncclMax
;
break
;
break
;
case
distributed
::
kRedMin
:
case
ReduceType
::
kRedMin
:
red_type
=
ncclMin
;
red_type
=
ncclMin
;
break
;
break
;
case
distributed
::
kRedProd
:
case
ReduceType
::
kRedProd
:
red_type
=
ncclProd
;
red_type
=
ncclProd
;
break
;
break
;
}
}
...
...
paddle/phi/kernels/gpu/reduce_kernel.cu
浏览文件 @
786c6e99
...
@@ -49,17 +49,17 @@ void ReduceKernel(const Context& dev_ctx,
...
@@ -49,17 +49,17 @@ void ReduceKernel(const Context& dev_ctx,
errors
::
NotFound
(
"Should initialize NCCL firstly."
));
errors
::
NotFound
(
"Should initialize NCCL firstly."
));
ncclRedOp_t
red_type
=
ncclSum
;
ncclRedOp_t
red_type
=
ncclSum
;
switch
(
reduce_type
)
{
switch
(
static_cast
<
ReduceType
>
(
reduce_type
)
)
{
case
distributed
::
kRedSum
:
case
ReduceType
::
kRedSum
:
red_type
=
ncclSum
;
red_type
=
ncclSum
;
break
;
break
;
case
distributed
::
kRedMax
:
case
ReduceType
::
kRedMax
:
red_type
=
ncclMax
;
red_type
=
ncclMax
;
break
;
break
;
case
distributed
::
kRedMin
:
case
ReduceType
::
kRedMin
:
red_type
=
ncclMin
;
red_type
=
ncclMin
;
break
;
break
;
case
distributed
::
kRedProd
:
case
ReduceType
::
kRedProd
:
red_type
=
ncclProd
;
red_type
=
ncclProd
;
break
;
break
;
}
}
...
...
paddle/phi/kernels/reduce_kernel.h
浏览文件 @
786c6e99
...
@@ -14,8 +14,8 @@
...
@@ -14,8 +14,8 @@
#pragma once
#pragma once
#include "paddle/phi/common/reduce_type.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/dense_tensor.h"
#include "paddle/phi/core/distributed/reduce_helper.h"
namespace
phi
{
namespace
phi
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录