-
Notifications
You must be signed in to change notification settings - Fork 24.8k
Correctly set CUDAGuard
in nccl collectives
#130921
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2591,7 +2591,7 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::collective( | |
work->stashed_for_allocator_safety_->push_back(input); | ||
} | ||
|
||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
at::cuda::OptionalCUDAGuard gpuGuard(device.index()); | ||
|
||
// Start event should only be recorded before the ncclGroupStart() | ||
if (work->timingEnabled_) { | ||
|
@@ -2752,8 +2752,6 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::collectiveCoalesced( | |
std::make_shared<std::vector<at::Tensor>>(inputs); | ||
} | ||
|
||
at::cuda::OptionalCUDAGuard gpuGuard; | ||
|
||
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. Why is this guard being removed instead of updated to device? 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. The |
||
// Start event should only be recorded before the ncclGroupStart() (which | ||
// happens inside AutoNcclGroup guard below) | ||
if (work->timingEnabled_) { | ||
|
@@ -3021,7 +3019,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.index()); | ||
|
||
if (!coalescing_state_) { | ||
// Start event should only be recorded before the ncclGroupStart() | ||
|
@@ -3912,13 +3910,13 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::barrier(const BarrierOptions& opts) { | |
// ensure that each process is on a different GPU | ||
auto numGPUs = at::cuda::getNumGPUs(); | ||
int16_t deviceIdx = static_cast<int16_t>(rank_ % numGPUs); | ||
LOG(INFO) | ||
LOG(WARNING) | ||
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. I think this change makes sense to me. |
||
<< logPrefix() | ||
<< c10::str( | ||
" using GPU ", | ||
"using GPU ", | ||
deviceIdx, | ||
" to perform barrier as devices used by this process are currently unknown. ", | ||
"This can potentially cause a hang if this rank to GPU mapping is incorrect.", | ||
"This can potentially cause a hang if this rank to GPU mapping is incorrect. ", | ||
oraluben marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"Specify device_ids in barrier() to force use of a particular device."); | ||
devices.emplace_back(guessDeviceForRank()); | ||
} else { | ||
|
@@ -3929,8 +3927,9 @@ c10::intrusive_ptr<Work> ProcessGroupNCCL::barrier(const BarrierOptions& opts) { | |
|
||
// Use one device only | ||
auto device = devices.back(); | ||
at::Tensor barrierTensor = | ||
at::empty({1}, at::TensorOptions().device(device).dtype(at::kByte)); | ||
at::cuda::OptionalCUDAGuard gpuGuard(device.index()); | ||
at::Tensor barrierTensor = at::empty( | ||
{1}, at::TensorOptions().device(at::DeviceType::CUDA).dtype(at::kByte)); | ||
// All reduce to achieve the barrier | ||
auto work = allreduce_impl(barrierTensor); | ||
|
||
|
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.
Is it the case that gpuGuard without index is not effective? Or does it default to device 0?