-
Notifications
You must be signed in to change notification settings - Fork 24.8k
[3/N] Set correct device to CUDA guards #134357
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
deafc2a
[3/N] Set correct device to CUDA guards
kwen2501 7983bcd
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 ffca276
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 23275a4
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 b915b61
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 5f0670a
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 8a90fdb
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 2ba49ab
Update on "[3/N] Set correct device to CUDA guards"
kwen2501 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 hidden or 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 |
---|---|---|
|
@@ -1103,11 +1103,8 @@ void ProcessGroupNCCL::abortCommsFromMap( | |
for (auto& it : ncclCommsMap) { | ||
auto& devName = it.first; | ||
auto& ncclComm = it.second; | ||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
at::DeviceIndex deviceIndex = getIndexFromDeviceKey(devName); | ||
if (deviceIndex >= 0) { | ||
gpuGuard.set_index(deviceIndex); | ||
} | ||
at::cuda::OptionalCUDAGuard gpuGuard(deviceIndex); | ||
LOG(INFO) << logPrefix() << "ProcessGroupNCCL destroying ncclComm_ " | ||
<< ncclComm->ncclComm_ << " on CUDA device: " << devName; | ||
ncclComm->ncclCommAbort(abortReason); | ||
|
@@ -2132,7 +2129,9 @@ std::shared_ptr<NCCLComm> ProcessGroupNCCL::getNCCLComm( | |
<< timerDeltaMs << " ms"; | ||
} | ||
|
||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
// Get the device index | ||
auto deviceIndex = device.index(); | ||
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. Nit: do we need the deviceIndex var? Looks like we just pass device to guard directly Ok probably we are using it somewhere, you moved the decl from below to above. |
||
at::cuda::OptionalCUDAGuard gpuGuard(device); | ||
|
||
// [Group Start/End Note] This is used to ensure that nccl communicator will | ||
// be created before communication primitives are called. Let's look at this | ||
|
@@ -2172,10 +2171,6 @@ std::shared_ptr<NCCLComm> ProcessGroupNCCL::getNCCLComm( | |
rank = p2pRank; | ||
} | ||
|
||
// Get the device index | ||
auto deviceIndex = device.index(); | ||
gpuGuard.set_index(deviceIndex); | ||
|
||
#ifdef NCCL_HAS_COMM_SPLIT | ||
if (options_->split_from) { | ||
TORCH_CHECK( | ||
|
@@ -2665,7 +2660,7 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::collective( | |
work->stashed_for_allocator_safety_->push_back(input); | ||
} | ||
|
||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
at::cuda::OptionalCUDAGuard gpuGuard(device); | ||
|
||
if (nanCheck) { | ||
checkForNan(input, ncclStream); | ||
|
@@ -2830,7 +2825,7 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::collectiveCoalesced( | |
std::make_shared<std::vector<at::Tensor>>(inputs); | ||
} | ||
|
||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
at::cuda::OptionalCUDAGuard gpuGuard(device); | ||
|
||
// Start event should only be recorded before the ncclGroupStart() (which | ||
// happens inside AutoNcclGroup guard below) | ||
|
@@ -3098,7 +3093,7 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::pointToPoint( | |
} | ||
|
||
// is gpuGuard needed for the if block below, or can i swap them | ||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
at::cuda::OptionalCUDAGuard gpuGuard(device); | ||
|
||
// Only check for NaN for send ops, for recv ops `tensor` can be a random | ||
// placeholder | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
For P2P comms, the deviceIndex could be -1 (invalid), as the keys in the map could be non deviceIndex, but rank to rank numbers. So we indeed need to check if deviceIndex >= 0
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.
Thanks for the information. Let me revert this change here and add the above comments into the code.