-
Notifications
You must be signed in to change notification settings - Fork 338
Intra-node shared memory (SHM) optimizations for CPU primitives #458
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
base: main
Are you sure you want to change the base?
Conversation
Hi @gaopengff! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
gloo/allreduce.cc
Outdated
if (is_intra_node(context->size)) { | ||
shm(opts); | ||
return; | ||
} |
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.
can we move this into the allreduce() function above? fits a bit better there since we pick the algorithm at that level
may be nice to add a RING_LOCAL or RING_SHMEM algorithm selector as well
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 your advice. We have added a new algorihtm selectordetail::AllreduceOptionsImpl::SHM and moved statement of checking intra-node to allreduce().
gloo/allreduce.cc
Outdated
@@ -153,6 +154,15 @@ void ring( | |||
const auto slot = Slot::build(kAllreduceSlotPrefix, opts.tag); | |||
const size_t totalBytes = opts.elements * opts.elementSize; | |||
|
|||
|
|||
if (is_intra_node(context->size)) { |
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.
we should also check if the tensor is a CUDA tensor and bypass if it is
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 cuda check, I think it's not necessary here. If the input tensors' device is cuda, pytorch will either copy cuda tensors to cpu before calling gloo::allreduce or use gloo::CudaAllreduceRingChunked do reduce cuda input directly. In that case gloo::allreduce is only for cpu inputs. Refer to pytorch code at ProcessGroupGlooCuda.cpp
|
||
bool is_intra_node(const int size) { | ||
// must launch with torchrun | ||
auto local_size_string = std::getenv("LOCAL_WORLD_SIZE"); |
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.
I don't think this check is safe -- for torchft for instance we often run with Gloo only cross host and if you're using an 8x8 configuration this would trigger shm logic for cross host comms
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.
In my understanding, world_size is 64 and the local_size is 8 if we launch program with 8x8 configuration, which won't introduce shm allreduce.
This PR is for RFC #455. It has implemented shm allreduce.