Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
2fa91d71
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看板
未验证
提交
2fa91d71
编写于
2月 22, 2023
作者:
TaoTao Li
提交者:
GitHub
2月 22, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
* remove broadcast (#50701)
上级
629f20e2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
0 addition
and
279 deletion
+0
-279
paddle/fluid/operators/collective/broadcast_op.cc
paddle/fluid/operators/collective/broadcast_op.cc
+0
-84
paddle/fluid/operators/collective/broadcast_op.cu.cc
paddle/fluid/operators/collective/broadcast_op.cu.cc
+0
-90
paddle/fluid/operators/collective/broadcast_op_xpu.cc
paddle/fluid/operators/collective/broadcast_op_xpu.cc
+0
-105
未找到文件。
paddle/fluid/operators/collective/broadcast_op.cc
已删除
100644 → 0
浏览文件 @
629f20e2
/* Copyright (c) 2019 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 <algorithm>
#include <ostream>
#include <utility>
#include <vector>
#include "paddle/fluid/framework/op_registry.h"
namespace
paddle
{
namespace
operators
{
class
BroadcastOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Input(X) of BroadcastOp should not be null."
));
PADDLE_ENFORCE_EQ
(
ctx
->
HasOutput
(
"Out"
),
true
,
platform
::
errors
::
InvalidArgument
(
"Output(Output) of ConvOp should not be null."
));
}
};
class
BroadcastOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
void
Make
()
{
AddInput
(
"X"
,
"(Tensor), tensor to be broadcast."
);
AddOutput
(
"Out"
,
"(Tensor) the result of broadcast."
);
AddAttr
<
bool
>
(
"sync_mode"
,
"(bool) whether to synchronize the CUDA stream after nccl call."
)
.
SetDefault
(
false
);
AddAttr
<
int
>
(
"root"
,
"(int)."
).
SetDefault
(
0
).
EqualGreaterThan
(
0
);
AddComment
(
R"DOC(
***Broadcast Operator***
Call NCCL Broadcast internally. Note that this op must be used when one
thread is managing one GPU device.
)DOC"
);
}
};
template
<
typename
T
>
class
BroadcastOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_THROW
(
platform
::
errors
::
PreconditionNotMet
(
"Broadcast op can run on gpu place only for now."
));
}
};
}
// namespace operators
}
// namespace paddle
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_WITHOUT_GRADIENT
(
broadcast
,
ops
::
BroadcastOp
,
ops
::
BroadcastOpMaker
);
REGISTER_OP_CPU_KERNEL
(
broadcast
,
ops
::
BroadcastOpKernel
<
float
>
,
ops
::
BroadcastOpKernel
<
double
>
,
ops
::
BroadcastOpKernel
<
int
>
,
ops
::
BroadcastOpKernel
<
int64_t
>
,
ops
::
BroadcastOpKernel
<
plat
::
float16
>
);
paddle/fluid/operators/collective/broadcast_op.cu.cc
已删除
100644 → 0
浏览文件 @
629f20e2
/* Copyright (c) 2019 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 "paddle/fluid/framework/op_registry.h"
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
#include "paddle/fluid/platform/device/gpu/nccl_helper.h"
#endif
#include "paddle/fluid/framework/convert_utils.h"
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
namespace
paddle
{
namespace
operators
{
template
<
typename
T
>
class
NCCLBroadcastOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
platform
::
is_gpu_place
(
ctx
.
GetPlace
()),
true
,
platform
::
errors
::
PreconditionNotMet
(
"The place of ExecutionContext should be CUDAPlace."
));
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
int
dev_id
=
ctx
.
GetPlace
().
device
;
int
root_dev_id
=
ctx
.
Attr
<
int
>
(
"root"
);
auto
in
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"X"
);
auto
out
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Out"
);
PADDLE_ENFORCE_EQ
(
out
->
IsInitialized
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"Currently, the output of broadcast op must be initialized,"
"because this op can only be an In-Place operation."
));
void
*
send_recv_buffer
=
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
PADDLE_ENFORCE_EQ
(
send_recv_buffer
,
in
->
data
(),
platform
::
errors
::
PreconditionNotMet
(
"Currently, the broadcast op can "
"only be an In-Place operation."
));
auto
&
dev_ctx
=
ctx
.
template
device_context
<
phi
::
GPUContext
>();
auto
comm
=
dev_ctx
.
nccl_comm
();
auto
stream
=
dev_ctx
.
stream
();
PADDLE_ENFORCE_GPU_SUCCESS
(
platform
::
dynload
::
ncclBcast
(
send_recv_buffer
,
static_cast
<
size_t
>
(
in
->
numel
()),
platform
::
ToNCCLDataType
(
framework
::
TransToProtoVarType
(
in
->
dtype
())),
root_dev_id
,
comm
,
stream
));
VLOG
(
3
)
<<
"Bcast "
<<
ctx
.
InputNames
(
"X"
)[
0
]
<<
", ("
<<
in
->
numel
()
<<
")"
<<
" From "
<<
root_dev_id
<<
" to "
<<
dev_id
;
if
(
ctx
.
Attr
<
bool
>
(
"sync_mode"
))
{
platform
::
GpuStreamSync
(
stream
);
}
#else
PADDLE_THROW
(
platform
::
errors
::
PreconditionNotMet
(
"PaddlePaddle should compile with GPU."
));
#endif
}
};
}
// namespace operators
}
// namespace paddle
REGISTER_OP_CUDA_KERNEL
(
broadcast
,
ops
::
NCCLBroadcastOpKernel
<
float
>
,
ops
::
NCCLBroadcastOpKernel
<
double
>
,
ops
::
NCCLBroadcastOpKernel
<
int
>
,
ops
::
NCCLBroadcastOpKernel
<
int64_t
>
,
ops
::
NCCLBroadcastOpKernel
<
plat
::
float16
>
);
paddle/fluid/operators/collective/broadcast_op_xpu.cc
已删除
100644 → 0
浏览文件 @
629f20e2
/* Copyright (c) 2021 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 <algorithm>
#include <utility>
#include <vector>
#include "paddle/fluid/framework/data_type.h"
#include "paddle/fluid/framework/lod_tensor.h"
#include "paddle/fluid/framework/op_registry.h"
#if defined(PADDLE_WITH_XPU_BKCL)
#include "paddle/fluid/platform/collective_helper.h"
#include "paddle/fluid/platform/device/xpu/bkcl_helper.h"
#endif
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
namespace
paddle
{
namespace
operators
{
template
<
typename
T
>
class
BKCLBroadcastOpKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
platform
::
is_xpu_place
(
ctx
.
GetPlace
()),
true
,
platform
::
errors
::
PreconditionNotMet
(
"The place of ExecutionContext should be XPUPlace."
));
#if defined(PADDLE_WITH_XPU_BKCL)
int
dev_id
=
ctx
.
GetPlace
().
device
;
int
root_dev_id
=
ctx
.
Attr
<
int
>
(
"root"
);
auto
in
=
ctx
.
Input
<
phi
::
DenseTensor
>
(
"X"
);
auto
out
=
ctx
.
Output
<
phi
::
DenseTensor
>
(
"Out"
);
PADDLE_ENFORCE_EQ
(
out
->
IsInitialized
(),
true
,
platform
::
errors
::
PreconditionNotMet
(
"Currently, the output of broadcast op must be initialized,"
"because this op can only be an In-Place operation."
));
void
*
send_recv_buffer
=
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
PADDLE_ENFORCE_EQ
(
send_recv_buffer
,
in
->
data
(),
platform
::
errors
::
PreconditionNotMet
(
"Currently, the broadcast op can "
"only be an In-Place operation."
));
auto
&
dev_ctx
=
ctx
.
template
device_context
<
platform
::
XPUDeviceContext
>();
auto
comm
=
dev_ctx
.
bkcl_context
();
auto
stream
=
dev_ctx
.
x_context
()
->
xpu_stream
;
// TODO(wangxi16): bkcl_broadcast only support float type,
// need to converted other type to float before broadcasting.
// Broadcast is equivalent to no type of operation, does not affect
// correctness.
// Once bkcl_broadcast support other type, need chang to:
// BKCLDataType data_type = platform::ToBKCLDataType(in->type());
BKCLDataType
data_type
=
BKCL_FLOAT
;
size_t
scale
=
sizeof
(
T
)
/
sizeof
(
float
);
auto
ret
=
bkcl_broadcast
(
comm
,
send_recv_buffer
,
send_recv_buffer
,
static_cast
<
size_t
>
(
in
->
numel
())
*
scale
,
data_type
,
root_dev_id
,
stream
);
PADDLE_ENFORCE_EQ
(
ret
,
BKCL_SUCCESS
,
platform
::
errors
::
Unavailable
(
"bkcl_broadcast failed"
));
VLOG
(
3
)
<<
"Bcast "
<<
ctx
.
InputNames
(
"X"
)[
0
]
<<
", ("
<<
in
->
numel
()
<<
")"
<<
" From "
<<
root_dev_id
<<
" to "
<<
dev_id
;
if
(
ctx
.
Attr
<
bool
>
(
"sync_mode"
))
{
dev_ctx
.
Wait
();
}
#else
PADDLE_THROW
(
platform
::
errors
::
PreconditionNotMet
(
"PaddlePaddle should compile with XPU."
));
#endif
}
};
}
// namespace operators
}
// namespace paddle
REGISTER_OP_XPU_KERNEL
(
broadcast
,
ops
::
BKCLBroadcastOpKernel
<
float
>
,
ops
::
BKCLBroadcastOpKernel
<
double
>
,
ops
::
BKCLBroadcastOpKernel
<
int
>
,
ops
::
BKCLBroadcastOpKernel
<
int64_t
>
);
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录