-
Notifications
You must be signed in to change notification settings - Fork 197
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
Modify comm_split to avoid ucp #1649
Merged
rapids-bot
merged 4 commits into
rapidsai:branch-23.08
from
ChuckHastings:modify_split_to_avoid_ucp
Jul 24, 2023
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
bcf32b0
Modify comm_split to do allgather instead of requiring UCP
ChuckHastings 77e16b3
fix code formatting
ChuckHastings 5546d6f
Use sync_stream instead of cudaStreamSynchronize in the new code
ChuckHastings 40031ac
Merge branch 'branch-23.08' into modify_split_to_avoid_ucp
ChuckHastings 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 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 |
---|---|---|
|
@@ -28,6 +28,8 @@ | |
|
||
#include <raft/util/cudart_utils.hpp> | ||
|
||
#include <thrust/iterator/zip_iterator.h> | ||
|
||
#include <cuda_runtime.h> | ||
|
||
#include <ucp/api/ucp.h> | ||
|
@@ -140,48 +142,37 @@ class std_comms : public comms_iface { | |
|
||
RAFT_CUDA_TRY(cudaStreamSynchronize(stream_)); | ||
|
||
std::vector<int> subcomm_ranks{}; | ||
std::vector<ucp_ep_h> new_ucx_ptrs{}; | ||
|
||
for (int i = 0; i < get_size(); ++i) { | ||
if (h_colors[i] == color) { | ||
subcomm_ranks.push_back(i); | ||
if (ucp_worker_ != nullptr && subcomms_ucp_) { new_ucx_ptrs.push_back((*ucp_eps_)[i]); } | ||
} | ||
} | ||
ncclComm_t nccl_comm; | ||
|
||
// Create a structure to allgather... | ||
ncclUniqueId id{}; | ||
if (get_rank() == subcomm_ranks[0]) { // root of the new subcommunicator | ||
RAFT_NCCL_TRY(ncclGetUniqueId(&id)); | ||
std::vector<request_t> requests(subcomm_ranks.size() - 1); | ||
for (size_t i = 1; i < subcomm_ranks.size(); ++i) { | ||
isend(&id, sizeof(ncclUniqueId), subcomm_ranks[i], color, requests.data() + (i - 1)); | ||
} | ||
waitall(requests.size(), requests.data()); | ||
} else { | ||
request_t request{}; | ||
irecv(&id, sizeof(ncclUniqueId), subcomm_ranks[0], color, &request); | ||
waitall(1, &request); | ||
} | ||
// FIXME: this seems unnecessary, do more testing and remove this | ||
barrier(); | ||
rmm::device_uvector<ncclUniqueId> d_nccl_ids(get_size(), stream_); | ||
|
||
ncclComm_t nccl_comm; | ||
RAFT_NCCL_TRY(ncclCommInitRank(&nccl_comm, subcomm_ranks.size(), id, key)); | ||
|
||
if (ucp_worker_ != nullptr && subcomms_ucp_) { | ||
auto eps_sp = std::make_shared<ucp_ep_h*>(new_ucx_ptrs.data()); | ||
return std::unique_ptr<comms_iface>(new std_comms(nccl_comm, | ||
(ucp_worker_h)ucp_worker_, | ||
eps_sp, | ||
subcomm_ranks.size(), | ||
key, | ||
stream_, | ||
subcomms_ucp_)); | ||
} else { | ||
return std::unique_ptr<comms_iface>( | ||
new std_comms(nccl_comm, subcomm_ranks.size(), key, stream_)); | ||
} | ||
if (key == 0) { RAFT_NCCL_TRY(ncclGetUniqueId(&id)); } | ||
|
||
update_device(d_nccl_ids.data() + get_rank(), &id, 1, stream_); | ||
|
||
allgather(d_nccl_ids.data() + get_rank(), | ||
d_nccl_ids.data(), | ||
sizeof(ncclUniqueId), | ||
datatype_t::UINT8, | ||
stream_); | ||
|
||
auto offset = | ||
std::distance(thrust::make_zip_iterator(h_colors.begin(), h_keys.begin()), | ||
std::find_if(thrust::make_zip_iterator(h_colors.begin(), h_keys.begin()), | ||
thrust::make_zip_iterator(h_colors.end(), h_keys.end()), | ||
[color](auto tuple) { return thrust::get<0>(tuple) == color; })); | ||
|
||
auto subcomm_size = std::count(h_colors.begin(), h_colors.end(), color); | ||
|
||
update_host(&id, d_nccl_ids.data() + offset, 1, stream_); | ||
|
||
RAFT_CUDA_TRY(cudaStreamSynchronize(stream_)); | ||
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. We should probably use 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. Updated in latest push |
||
|
||
RAFT_NCCL_TRY(ncclCommInitRank(&nccl_comm, subcomm_size, id, key)); | ||
|
||
return std::unique_ptr<comms_iface>(new std_comms(nccl_comm, subcomm_size, key, stream_)); | ||
} | ||
|
||
void barrier() const | ||
|
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.
Now that we are using nccl instead of ucp, we should probably avoid any potential deadlocks from dying nccl ranks by using
sync_stream
here instead of the standard cuda synchronization.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.
Updated in latest push