Skip to content

Commit

Permalink
Address clang-tidy warnings in ProcessGroupNCCL
Browse files Browse the repository at this point in the history
Noticed that in the internal diff for
#49069 there was a clang-tidy warning to
use emplace instead of push_back. This can save us a copy as it eliminates the
unnecessary in-place construction

Differential Revision: [D25800134](https://our.internmc.facebook.com/intern/diff/D25800134/)

ghstack-source-id: 119438816
Pull Request resolved: #50131
  • Loading branch information
rohan-varma committed Jan 6, 2021
1 parent 0535833 commit 3d719cd
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions torch/lib/c10d/ProcessGroupNCCL.cpp
Expand Up @@ -1413,7 +1413,7 @@ c10::intrusive_ptr<ProcessGroup::Work> ProcessGroupNCCL::barrier(
// Use user defined GPU device ids if provided
if (!opts.device_ids.empty()) {
for (auto device : opts.device_ids) {
devices.push_back(at::Device(at::DeviceType::CUDA, device));
devices.emplace_back(at::DeviceType::CUDA, device);
}
} else if (usedDeviceIdxs_.empty()) {
// This means there is not yet a NCCL collective being called
Expand All @@ -1423,10 +1423,10 @@ c10::intrusive_ptr<ProcessGroup::Work> ProcessGroupNCCL::barrier(
// ensure that each process is on a different GPU
auto numGPUs = at::cuda::getNumGPUs();
int16_t deviceIdx = static_cast<int16_t>(rank_ % numGPUs);
devices.push_back(at::Device(at::DeviceType::CUDA, deviceIdx));
devices.emplace_back(at::DeviceType::CUDA, deviceIdx);
} else {
for (auto usedDeviceIdx : usedDeviceIdxs_) {
devices.push_back(at::Device(at::DeviceType::CUDA, usedDeviceIdx));
devices.emplace_back(at::DeviceType::CUDA, usedDeviceIdx);
}
}

Expand Down

0 comments on commit 3d719cd

Please sign in to comment.