-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
【Hackathon 6th Fundable Projects 3 No.13】barrier #67310
Closed
smallpoxscattered
wants to merge
12
commits into
PaddlePaddle:develop
from
smallpoxscattered:smallpox
+112
−215
Closed
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
81df751
trains barrier
smallpoxscattered c08f3bd
merge
smallpoxscattered c381aa5
trains barrier
smallpoxscattered 385a89a
trains barrier
smallpoxscattered 6a599ec
fix barrier
smallpoxscattered 88bea29
fix barrier
smallpoxscattered d1296d9
fix barrier
smallpoxscattered e6c643f
fix barrier
smallpoxscattered d3ee025
fix barrier
smallpoxscattered 3d0bfd0
fix barrier
smallpoxscattered 44cd7ec
fix barrier
smallpoxscattered 9a050a3
Merge branch 'develop' of github.com:smallpoxscattered/Paddle into sm…
smallpoxscattered File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) 2024 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/phi/core/kernel_registry.h" | ||
|
||
#if defined(PADDLE_WITH_GLOO) | ||
#include <gloo/barrier.h> | ||
#include "paddle/phi/core/distributed/gloo_comm_context.h" | ||
#endif | ||
|
||
namespace phi { | ||
|
||
template <typename T, typename Context> | ||
void BarrierKernel(const Context& dev_ctx, | ||
const DenseTensor& x_in, | ||
DenseTensor* out) { | ||
#if defined(PADDLE_WITH_GLOO) | ||
auto comm_ctx = | ||
static_cast<distributed::GlooCommContext*>(dev_ctx.GetCommContext()); | ||
PADDLE_ENFORCE_NE( | ||
comm_ctx, | ||
nullptr, | ||
errors::Unavailable("GlooCommContext is nullptr, collective op should " | ||
"has ring_id attr.")); | ||
#else | ||
PADDLE_THROW(phi::errors::Unavailable( | ||
"PaddlePaddle should compile with GLOO by setting WITH_GLOO=ON")); | ||
#endif | ||
} | ||
|
||
} // namespace phi | ||
|
||
PD_REGISTER_KERNEL(barrier, CPU, ALL_LAYOUT, phi::BarrierKernel, int) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2024 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 "glog/logging.h" | ||
|
||
#include "paddle/phi/backends/gpu/gpu_context.h" | ||
#include "paddle/phi/core/kernel_registry.h" | ||
|
||
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) | ||
#include "paddle/common/flags.h" | ||
#include "paddle/phi/backends/gpu/gpu_helper.h" | ||
#include "paddle/phi/core/distributed/nccl_comm_context.h" | ||
#include "paddle/phi/core/platform/collective_helper.h" | ||
COMMON_DECLARE_bool(dynamic_static_unified_comm); | ||
#endif | ||
|
||
namespace phi { | ||
|
||
template <typename T, typename Context> | ||
void BarrierKernel(const Context& dev_ctx, | ||
const DenseTensor& x_in, | ||
DenseTensor* out) { | ||
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) | ||
|
||
if (FLAGS_dynamic_static_unified_comm) { | ||
auto comm_ctx = | ||
static_cast<distributed::NCCLCommContext*>(dev_ctx.GetCommContext()); | ||
PADDLE_ENFORCE_NOT_NULL( | ||
comm_ctx, | ||
phi::errors::Unavailable( | ||
"NCCLCommContext is nullptr, collective op should " | ||
"has ring_id attr.")); | ||
auto stream = comm_ctx->GetStream(); | ||
ncclRedOp_t nccl_red_type = ncclSum; | ||
comm_ctx->AllReduce(out, x_in, nccl_red_type, stream); | ||
phi::backends::gpu::GpuStreamSync(stream); | ||
} | ||
#else | ||
PADDLE_THROW( | ||
phi::errors::Unavailable("PaddlePaddle should compile with NCCL.")); | ||
#endif | ||
} | ||
|
||
} // namespace phi | ||
|
||
PD_REGISTER_KERNEL(barrier, GPU, ALL_LAYOUT, phi::BarrierKernel, int) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -457,6 +457,17 @@ | |
data_type : param | ||
inplace : (in_sum_1 -> out_sum_1), (in_sum_2 -> out_sum_2), (in_sum_3 -> out_sum_3), (in_num_accumulates -> out_num_accumulates), (in_old_num_accumulates -> out_old_num_accumulates), (in_num_updates -> out_num_updates) | ||
|
||
- op : barrier | ||
args : (Tensor x, int ring_id = 0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 注意:这里的ring_id 不能删 |
||
output : Tensor(out) | ||
infer_meta : | ||
func : UnchangedInferMeta | ||
param : [x] | ||
kernel : | ||
func : barrier | ||
data_type : x | ||
traits : paddle::dialect::ForwardOnlyTrait | ||
|
||
- op : batch_fc | ||
args : (Tensor input, Tensor w, Tensor bias) | ||
output : Tensor(out) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
phi 下算子,只用新通信库,即 FLAGS_dynamic_static_unified_comm = True。那么,
只保留 L46-L66,删掉 L68 - L75