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
[Kunlun]add collective ops for multi XPU cards training and add Kunlun multi XPU cards CI #32302
Merged
wangxicoding
merged 16 commits into
PaddlePaddle:develop
from
vslyu:dev/add_xpu_colletive_ops1
Apr 21, 2021
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ad254e6
add print log in broadcast_op_xpu.cc
vslyu 4a9bd3a
add allreduce_sum api for xpu
vslyu 63ead73
merge origin dev/add_xpu_multimachine, add xpu_colletive_ops init
vslyu 5bace53
add allreduce_sum api for xpu
vslyu bc2bc9b
Merge remote-tracking branch 'upstream' into dev/add_xpu_colletive_ops
vslyu 2c6d536
fix
vslyu 648f490
add c_allreduce_op for xpu
vslyu b975c06
add c_reduce_op for xpu
vslyu 9473419
Merge remote-tracking branch 'origin/dev/add_xpu_colletive_ops' into …
vslyu a2c8443
add ut fof xpu collective ops
vslyu e51f000
fix ut fof xpu collective ops
vslyu ca9914b
add CI for xpu dist test case
vslyu 26bfd67
fix ut rules, test=kunlun
vslyu 2ab374e
notest, test=rocm
vslyu e1b90cb
notest, test=rocm
vslyu fcbec44
fix,test=develop
vslyu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
paddle/fluid/operators/collective/c_allreduce_max_op_xpu.cc
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,28 @@ | ||
/* 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/operators/collective/c_allreduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_allreduce_max, | ||
ops::CAllReduceOpXPUKernel<ops::kRedMax, float>) |
28 changes: 28 additions & 0 deletions
28
paddle/fluid/operators/collective/c_allreduce_min_op_xpu.cc
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,28 @@ | ||
/* 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/operators/collective/c_allreduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_allreduce_min, | ||
ops::CAllReduceOpXPUKernel<ops::kRedMin, float>) |
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
28 changes: 28 additions & 0 deletions
28
paddle/fluid/operators/collective/c_allreduce_prod_op_xpu.cc
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,28 @@ | ||
/* 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/operators/collective/c_allreduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_allreduce_prod, | ||
ops::CAllReduceOpXPUKernel<ops::kRedProd, float>) |
28 changes: 28 additions & 0 deletions
28
paddle/fluid/operators/collective/c_allreduce_sum_op_xpu.cc
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,28 @@ | ||
/* 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/operators/collective/c_allreduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_allreduce_sum, | ||
ops::CAllReduceOpXPUKernel<ops::kRedSum, float>) |
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,28 @@ | ||
/* 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/operators/collective/c_reduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_reduce_max, | ||
ops::CReduceOpXPUKernel<ops::kRedMax, float>) |
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,28 @@ | ||
/* 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/operators/collective/c_reduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_reduce_min, | ||
ops::CReduceOpXPUKernel<ops::kRedMin, float>) |
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 |
---|---|---|
|
@@ -24,10 +24,16 @@ limitations under the License. */ | |
#include "paddle/fluid/framework/lod_tensor.h" | ||
#include "paddle/fluid/framework/op_registry.h" | ||
|
||
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) | ||
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) || \ | ||
defined(PADDLE_WITH_XPU_BKCL) | ||
#include "paddle/fluid/platform/collective_helper.h" | ||
#include "paddle/fluid/platform/nccl_helper.h" | ||
#endif | ||
|
||
#if defined(PADDLE_WITH_XPU_BKCL) | ||
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. #if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL) 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. done~ |
||
#include "paddle/fluid/platform/bkcl_helper.h" | ||
#endif | ||
|
||
#if defined(PADDLE_WITH_GLOO) | ||
#include <gloo/reduce.h> | ||
#include "paddle/fluid/framework/fleet/gloo_wrapper.h" | ||
|
@@ -110,6 +116,69 @@ class CReduceOpCPUKernel : public framework::OpKernel<T> { | |
} | ||
}; | ||
|
||
template <ReduceType red_type, typename T> | ||
class CReduceOpXPUKernel : public framework::OpKernel<T> { | ||
public: | ||
void Compute(const framework::ExecutionContext& ctx) const override { | ||
#if defined(PADDLE_WITH_XPU_BKCL) | ||
auto in = ctx.Input<framework::Tensor>("X"); | ||
auto out = ctx.Output<framework::Tensor>("Out"); | ||
|
||
auto place = ctx.GetPlace(); | ||
BKCLDataType dtype = platform::ToBKCLDataType(in->type()); | ||
int64_t numel = in->numel(); | ||
const void* sendbuff = in->data<void>(); | ||
out->Resize(in->dims()); | ||
void* recvbuff = out->mutable_data<T>(place); | ||
|
||
int rid = ctx.Attr<int>("ring_id"); | ||
int root = ctx.Attr<int>("root_id"); | ||
auto comm = platform::BKCLCommContext::Instance().Get(rid, place); | ||
|
||
XPUStream stream = nullptr; | ||
if (ctx.Attr<bool>("use_calc_stream")) { | ||
auto dev_ctx = platform::DeviceContextPool::Instance().Get(place); | ||
stream = static_cast<platform::XPUDeviceContext*>(dev_ctx) | ||
->x_context() | ||
->xpu_stream; | ||
} else { | ||
stream = comm->stream(); | ||
} | ||
|
||
BKCLOp bkcl_red_type = BKCL_ADD; | ||
switch (red_type) { | ||
case kRedSum: | ||
bkcl_red_type = BKCL_ADD; | ||
break; | ||
|
||
case kRedMax: | ||
bkcl_red_type = BKCL_MAX; | ||
break; | ||
|
||
case kRedMin: | ||
bkcl_red_type = BKCL_MIN; | ||
break; | ||
|
||
case kRedProd: | ||
bkcl_red_type = BKCL_PRODUCT; | ||
break; | ||
|
||
default: | ||
PADDLE_THROW(platform::errors::InvalidArgument( | ||
"Invalid reduce type: %d", red_type)); | ||
} | ||
|
||
PADDLE_ENFORCE_EQ(bkcl_reduce(comm->comm(), sendbuff, recvbuff, numel, | ||
dtype, bkcl_red_type, root, stream), | ||
BKCL_SUCCESS, platform::errors::PreconditionNotMet( | ||
"BKCL all reduce failed")); | ||
#else | ||
PADDLE_THROW(platform::errors::PreconditionNotMet( | ||
"PaddlePaddle should be compiled with XPU.")); | ||
#endif | ||
} | ||
}; | ||
|
||
template <ReduceType red_type, typename T> | ||
class CReduceOpCUDAKernel : public framework::OpKernel<T> { | ||
public: | ||
|
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,28 @@ | ||
/* 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/operators/collective/c_reduce_op.h" | ||
|
||
namespace paddle { | ||
namespace platform { | ||
struct XPUPlace; | ||
struct float16; | ||
} // namespace platform | ||
} // namespace paddle | ||
|
||
namespace ops = paddle::operators; | ||
namespace plat = paddle::platform; | ||
|
||
REGISTER_OP_XPU_KERNEL(c_reduce_prod, | ||
ops::CReduceOpXPUKernel<ops::kRedProd, float>) |
Oops, something went wrong.
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.
#if defined(PADDLE_WITH_NCCL) || defined(PADDLE_WITH_RCCL)
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.
done~