-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rename REGISTER_COLLECTIVE_COMMUNICATION_FACTORY to REGISTER_COLLECTIVE_COMMUNICATION * refactor_ccl_allgather_and_reduce_scatter * refactor ccl::Reduce * remove useless code * refactor ccl::Broadcast * fix static check error * reslove comment * monir fix * reslove comments * fix macro lock error * refine * fix an idiot error * fix reduce functor bug * refactor_ccl_send_and_recv * refine * refine Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
- Loading branch information
1 parent
e3a9b89
commit 5259a7c
Showing
25 changed files
with
540 additions
and
231 deletions.
There are no files selected for viewing
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
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
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
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
51 changes: 51 additions & 0 deletions
51
oneflow/user/kernels/collective_communication/cpu/cpu_recv.cpp
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,51 @@ | ||
/* | ||
Copyright 2020 The OneFlow 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 "oneflow/core/common/data_type.h" | ||
#include "oneflow/core/ccl/ccl.h" | ||
#include "oneflow/core/job/rank_group.h" | ||
#include "oneflow/core/framework/transport_util.h" | ||
#include "oneflow/user/kernels/collective_communication/include/recv.h" | ||
|
||
namespace oneflow { | ||
|
||
namespace ccl { | ||
|
||
// Use CpuRecvImpl to avoid name conflict | ||
class CpuRecvImpl final : public Recv { | ||
public: | ||
OF_DISALLOW_COPY_AND_MOVE(CpuRecvImpl); | ||
CpuRecvImpl() : size_of_dtype_(0) {} | ||
~CpuRecvImpl() = default; | ||
|
||
void Init(DataType datatype) override { | ||
CHECK(IsPODDataType(datatype)); | ||
this->size_of_dtype_ = GetSizeOfDataType(datatype); | ||
} | ||
|
||
void Launch(ep::Stream* stream, void* out, size_t elem_cnt, int64_t src) const override { | ||
size_t buffer_size = elem_cnt * size_of_dtype_; | ||
CHECK_JUST(CpuRecv(out, buffer_size, src)); | ||
} | ||
|
||
private: | ||
size_t size_of_dtype_; | ||
}; | ||
|
||
REGISTER_COLLECTIVE_COMMUNICATION(DeviceType::kCPU, Recv, CpuRecvImpl); | ||
|
||
} // namespace ccl | ||
|
||
} // namespace oneflow |
51 changes: 51 additions & 0 deletions
51
oneflow/user/kernels/collective_communication/cpu/cpu_send.cpp
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,51 @@ | ||
/* | ||
Copyright 2020 The OneFlow 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 "oneflow/core/common/data_type.h" | ||
#include "oneflow/core/ccl/ccl.h" | ||
#include "oneflow/core/job/rank_group.h" | ||
#include "oneflow/core/framework/transport_util.h" | ||
#include "oneflow/user/kernels/collective_communication/include/send.h" | ||
|
||
namespace oneflow { | ||
|
||
namespace ccl { | ||
|
||
// Use CpuSendImpl to avoid name conflict | ||
class CpuSendImpl final : public Send { | ||
public: | ||
OF_DISALLOW_COPY_AND_MOVE(CpuSendImpl); | ||
CpuSendImpl() : size_of_dtype_(0) {} | ||
~CpuSendImpl() = default; | ||
|
||
void Init(DataType datatype) override { | ||
CHECK(IsPODDataType(datatype)); | ||
this->size_of_dtype_ = GetSizeOfDataType(datatype); | ||
} | ||
|
||
void Launch(ep::Stream* stream, const void* in, size_t elem_cnt, int64_t dst) const override { | ||
size_t buffer_size = elem_cnt * size_of_dtype_; | ||
CHECK_JUST(CpuSend(in, buffer_size, dst)); | ||
} | ||
|
||
private: | ||
size_t size_of_dtype_; | ||
}; | ||
|
||
REGISTER_COLLECTIVE_COMMUNICATION(DeviceType::kCPU, Send, CpuSendImpl); | ||
|
||
} // namespace ccl | ||
|
||
} // namespace oneflow |
53 changes: 53 additions & 0 deletions
53
oneflow/user/kernels/collective_communication/cuda/cuda_recv.cpp
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,53 @@ | ||
/* | ||
Copyright 2020 The OneFlow 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. | ||
*/ | ||
#ifdef WITH_CUDA | ||
#include "oneflow/user/kernels/collective_communication/include/recv.h" | ||
#include "oneflow/user/kernels/collective_communication/cuda/cuda_send_recv_util.h" | ||
#include "oneflow/core/device/nccl_util.h" | ||
|
||
namespace oneflow { | ||
|
||
namespace ccl { | ||
|
||
class CudaRecv final : public Recv { | ||
public: | ||
OF_DISALLOW_COPY_AND_MOVE(CudaRecv); | ||
CudaRecv() : nccl_datatype_() {} | ||
~CudaRecv() = default; | ||
|
||
void Init(DataType datatype) override { this->nccl_datatype_ = GetNcclDataType(datatype); } | ||
|
||
void Launch(ep::Stream* stream, void* out, size_t elem_cnt, int64_t src) const override { | ||
#if HAS_NCCL_SEND_RECV | ||
const auto& comm_and_peer_rank = GetNcclCommAndPeerNcclRank(src); | ||
OF_NCCL_CHECK(ncclRecv(out, elem_cnt, nccl_datatype_, comm_and_peer_rank.second, | ||
comm_and_peer_rank.first, stream->As<ep::CudaStream>()->cuda_stream())); | ||
#else | ||
UNIMPLEMENTED() << "GPU recv is only supported when nccl version >= 2.7" | ||
#endif // HAS_NCCL_SEND_RECV | ||
} | ||
|
||
private: | ||
ncclDataType_t nccl_datatype_; | ||
}; | ||
|
||
REGISTER_COLLECTIVE_COMMUNICATION(DeviceType::kCUDA, Recv, CudaRecv); | ||
|
||
} // namespace ccl | ||
|
||
} // namespace oneflow | ||
|
||
#endif // WITH_CUDA |
Oops, something went wrong.