Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions gloo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ list(APPEND GLOO_HDRS
"${CMAKE_CURRENT_SOURCE_DIR}/types.h"
)

if(NOT MSVC)
list(APPEND GLOO_SRCS "${CMAKE_CURRENT_SOURCE_DIR}/allreduce_shm.cc")
list(APPEND GLOO_HDRS "${CMAKE_CURRENT_SOURCE_DIR}/allreduce_shm.h")
endif()

if(USE_CUDA)
file(GLOB GLOO_CUDA_SRCS
"${CMAKE_CURRENT_SOURCE_DIR}/cuda*.cc"
Expand Down
15 changes: 14 additions & 1 deletion gloo/allreduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "gloo/common/logging.h"
#include "gloo/math.h"
#include "gloo/types.h"
#include "gloo/allreduce_shm.h"

namespace gloo {

Expand Down Expand Up @@ -131,14 +132,25 @@ void allreduce(const detail::AllreduceOptionsImpl& opts) {
return;
}

switch (opts.algorithm) {
auto algorithm = opts.algorithm;

#ifndef _WIN32
if (context->isIntraNode()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check to make sure inputs are on CPU before setting it to shm? I believe this would fail when using local ibv cuda backend

Can also check device->hasGPUDirect() and instead disable for all GPU direct supported backends

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. I've changed the check condition to "(context->isIntraNode() && !context->getDevice()->hasGPUDirect())".

algorithm = detail::AllreduceOptionsImpl::SHM;
}
#endif

switch (algorithm) {
case detail::AllreduceOptionsImpl::UNSPECIFIED:
case detail::AllreduceOptionsImpl::RING:
ring(opts, reduceInputs, broadcastOutputs);
break;
case detail::AllreduceOptionsImpl::BCUBE:
bcube(opts, reduceInputs, broadcastOutputs);
break;
case detail::AllreduceOptionsImpl::SHM:
shm(opts);
break;
default:
GLOO_ENFORCE(false, "Algorithm not handled.");
}
Expand All @@ -153,6 +165,7 @@ void ring(
const auto slot = Slot::build(kAllreduceSlotPrefix, opts.tag);
const size_t totalBytes = opts.elements * opts.elementSize;


// Note: context->size > 1
const auto recvRank = (context->size + context->rank + 1) % context->size;
const auto sendRank = (context->size + context->rank - 1) % context->size;
Expand Down
1 change: 1 addition & 0 deletions gloo/allreduce.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ struct AllreduceOptionsImpl {
UNSPECIFIED = 0,
RING = 1,
BCUBE = 2,
SHM = 3,
};

explicit AllreduceOptionsImpl(const std::shared_ptr<Context>& context)
Expand Down
Loading
Loading