[v1.7 patch] Disallow creation of ProcessGroupNCCL without GPUs. (#45642) (#46073)
Summary:
Note: This PR has been merged into master at b5a2f04089 after the 1.7 branch cut
(see original PR: #45642). This PR is to merge it into the 1.7 branch.
---- Original Commit Description Follows ---
Pull Request resolved: https://github.com/pytorch/pytorch/pull/45642
Prior to https://github.com/pytorch/pytorch/pull/45181, initializing a
NCCL process group would work even if no GPUs were present. Although, now since
init_process_group calls `barrier()` this would fail.
In general the problem was that we could initialize ProcessGroupNCCL without
GPUs and then if we called a method like `barrier()` the process would crash
since we do % numGPUs resulting in division by zero.
ghstack-source-id: 113490343
Test Plan: waitforbuildbot
Reviewed By: osalpekar
Differential Revision: D24038839
fbshipit-source-id: a1f1db52cabcfb83e06c1a11ae9744afbf03f8dc
Co-authored-by: Pritam Damania <pritam.damania@fb.com>