Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .github/workflows/build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
- name: Setup environment
run: |
sudo apt-get install -y libssl-dev
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/build-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ jobs:
uses: microsoft/setup-msbuild@v2
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: true
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
# Full git history is needed to get a proper list of changed files
# within `super-linter`
fetch-depth: 0
submodules: true
- name: Super-linter
uses: super-linter/super-linter@v7.3.0 # x-release-please-version
env:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "third_party/spdlog"]
path = third_party/spdlog
url = https://github.com/gabime/spdlog.git
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ endif()
set(GLOO_INSTALL ON CACHE BOOL "")
mark_as_advanced(GLOO_INSTALL)

# Compile definitions for Gloo
set(GLOO_COMPILE_DEFS)

# Build shared or static libraries (override from parent project)
if(BUILD_SHARED_LIBS)
set(GLOO_STATIC_OR_SHARED SHARED CACHE STRING "")
Expand Down
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@ Optional dependencies are:

Please refer to [docs/](docs/) for detailed documentation.

## Cloning

Gloo makes use of [Git submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules)
for third-party build-time dependencies. When cloning, ensure that you
initialize and sync submodules:

``` shell
git clone --recurse-submodules https://github.com/pytorch/gloo.git # or use SSH remote
```

Or, if you already cloned without submodules, run the following in the existing
local repository:

``` shell
git submodule update --init --recursive
```

## Building

You can build Gloo using CMake.
Expand Down
21 changes: 20 additions & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ set(gloo_DEPENDENCY_LIBS "")
set(gloo_cuda_DEPENDENCY_LIBS "")
set(gloo_hip_DEPENDENCY_LIBS "")

# Dependency libraries for all Gloo targets (e.g. tests, benchmarks, etc.)
set(gloo_ALL_TARGETS_DEPENDENCY_LIBS "")

# Configure path to modules (for find_package)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")

Expand Down Expand Up @@ -104,7 +107,7 @@ if(USE_MPI)
message(STATUS "MPI libraries: " ${MPI_CXX_LIBRARIES})
include_directories(SYSTEM ${MPI_CXX_INCLUDE_PATH})
list(APPEND gloo_DEPENDENCY_LIBS ${MPI_CXX_LIBRARIES})
add_definitions(-DGLOO_USE_MPI=1)
list(APPEND GLOO_COMPILE_DEFS "GLOO_USE_MPI=1")
else()
message(WARNING "Not compiling with MPI support. Suppress this warning with -DUSE_MPI=OFF.")
set(USE_MPI OFF)
Expand Down Expand Up @@ -199,3 +202,19 @@ if(BUILD_TEST)
target_link_libraries(gtest INTERFACE ${GTEST_LIBRARIES})
endif()
endif()

set(SPDLOG_BUILD_SHARED OFF CACHE BOOL "" FORCE)
set(SPDLOG_BUILD_PIC ON CACHE BOOL "" FORCE)
set(SPDLOG_FMT_EXTERNAL OFF CACHE BOOL "" FORCE)

set(_save_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(third_party/spdlog EXCLUDE_FROM_ALL)
set(BUILD_SHARED_LIBS ${_save_BUILD_SHARED_LIBS})

if(GLOO_STATIC_OR_SHARED STREQUAL "STATIC")
list(APPEND gloo_ALL_TARGETS_DEPENDENCY_LIBS $<BUILD_INTERFACE:spdlog::spdlog_header_only>)
Copy link
Member

Choose a reason for hiding this comment

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

nice

else()
list(APPEND gloo_ALL_TARGETS_DEPENDENCY_LIBS spdlog::spdlog)
list(APPEND GLOO_COMPILE_DEFS SPDLOG_COMPILED_LIB)
endif()
2 changes: 1 addition & 1 deletion docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ extend `::gloo::Exception`.
## Assertions
Gloo asserts unexpected errors and logical invariants instead of expecting
callers to handle them. `GLOO_ENFORCE` macros are defined in
[`logging.h`](../gloo/common/logging.h)
[`enforce.h`](../gloo/common/enforce.h)
5 changes: 4 additions & 1 deletion gloo/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ if(USE_CUDA)
cuda_add_library(gloo_cuda ${GLOO_CUDA_SRCS} ${GLOO_STATIC_OR_SHARED})
endif()
target_link_libraries(gloo_cuda gloo ${gloo_cuda_DEPENDENCY_LIBS})
set_property(TARGET gloo_cuda APPEND PROPERTY LINK_LIBRARIES ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
endif()
if(USE_ROCM)
gloo_hip_add_library(gloo_hip ${GLOO_HIP_SRCS})
target_link_libraries(gloo_hip gloo)
set_property(TARGET gloo_hip APPEND PROPERTY LINK_LIBRARIES ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
endif()
if(USE_LIBUV)
target_link_libraries(gloo PRIVATE uv_a)
Expand All @@ -165,7 +167,8 @@ elseif(USE_TCP_OPENSSL_LOAD)
target_link_libraries(gloo PRIVATE dl)
endif()

target_link_libraries(gloo PRIVATE ${gloo_DEPENDENCY_LIBS})
target_link_libraries(gloo PRIVATE ${gloo_DEPENDENCY_LIBS} ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})
target_compile_definitions(gloo PRIVATE ${GLOO_COMPILE_DEFS})

# Add Interface include directories that are relocatable.
target_include_directories(gloo INTERFACE $<INSTALL_INTERFACE:include>)
Expand Down
2 changes: 1 addition & 1 deletion gloo/algorithm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include "gloo/algorithm.h"

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"

namespace gloo {

Expand Down
2 changes: 1 addition & 1 deletion gloo/allgather.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <array>
#include <cstring>

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/types.h"

namespace gloo {
Expand Down
2 changes: 1 addition & 1 deletion gloo/allgatherv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cstring>
#include <numeric>

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/types.h"

namespace gloo {
Expand Down
2 changes: 1 addition & 1 deletion gloo/allreduce.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <array>
#include <cstring>

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/math.h"
#include "gloo/types.h"

Expand Down
74 changes: 74 additions & 0 deletions gloo/allreduce_bcube.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "gloo/allreduce_bcube.h"

#include <string_view>

#include "gloo/common/log.h"

namespace gloo {

template <typename T>
void AllreduceBcube<T>::printElems(T* p, int count, int start) {
/* Early return if log level is not high enough, to prevent expensive code
* running. */
if (!spdlog::should_log(spdlog::level::trace))
return;

const std::size_t alignedStart = (start / wordsPerLine) * wordsPerLine;
fmt::memory_buffer line{};

/* Logs/flushes the line buffer - starting a new line */
auto printLine = [&]() {
if (!line.size())
return;
std::string_view sv{line.data(), line.size()};
GLOO_TRACE("{}", sv);
line.clear();
};

for (std::size_t x = alignedStart; x < start + count; ++x) {
if (x % wordsPerLine == 0) {
if (x != alignedStart)
printLine();
fmt::format_to(
std::back_inserter(line), "{} {:05}: ", fmt::ptr(&p[x]), x);
} else if (x % wordsPerSection == 0) {
fmt::format_to(std::back_inserter(line), "- ");
}

if (x < start)
fmt::format_to(std::back_inserter(line), "..... ");
else
fmt::format_to(std::back_inserter(line), "{:05} ", p[x]);
}
printLine();
}

template <typename T>
void AllreduceBcube<T>::printStageBuffer(const std::string& msg) {
if (printCheck(myRank_)) {
GLOO_TRACE("rank ({}) {}:", myRank_, msg);
printElems(&ptrs_[0][0], totalNumElems_);
}
}

template <typename T>
void AllreduceBcube<T>::printStepBuffer(
const std::string& stage,
int step,
int srcRank,
int destRank,
T* p,
int count,
int start) {
if (printCheck(myRank_)) {
GLOO_TRACE(
"{}: step ({}) srcRank ({}) -> destRank ({})",
stage,
step,
srcRank,
destRank);
printElems(p, count, start);
}
}

} // namespace gloo
46 changes: 3 additions & 43 deletions gloo/allreduce_bcube.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@
#include <string.h>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

#include "gloo/algorithm.h"
#include "gloo/common/error.h"
#include "gloo/context.h"

/**
Expand Down Expand Up @@ -537,48 +534,18 @@ class AllreduceBcube : public Algorithm {
static bool printCheck(int /*rank*/) {
return false;
}
/**
* Prints a break given the offset of an element about to be printed
* @param p Pointer to the elements
* @param x The current offset to the pointer to words
*/
static void printBreak(T* p, int x) {
if (0 == x % wordsPerLine) {
std::cout << std::endl
<< &p[x] << " " << std::setfill('0') << std::setw(5) << x
<< ": ";
} else if (0 == x % wordsPerSection) {
std::cout << "- ";
}
}
/**
* Pretty prints a list of elements
* @param p Pointer to the elements
* @param count The number of elements to be printed
* @param start The offset from which to print
*/
static void printElems(T* p, int count, int start = 0) {
auto alignedStart = (start / wordsPerLine) * wordsPerLine;
for (int x = alignedStart; x < start + count; ++x) {
printBreak(p, x);
if (x < start) {
std::cout << "..... ";
} else {
std::cout << std::setfill('0') << std::setw(5) << p[x] << " ";
}
}
}
static void printElems(T* p, int count, int start);
/**
* Prints contents in the ptrs array at a particular stage
* @param msg Custom message to be printed
*/
void printStageBuffer(const std::string& msg) {
if (printCheck(myRank_)) {
std::cout << "rank (" << myRank_ << ") " << msg << ": ";
printElems(&ptrs_[0][0], totalNumElems_);
std::cout << std::endl;
}
}
void printStageBuffer(const std::string& msg);

/**
* Prints specified buffer during a step
Expand All @@ -596,14 +563,7 @@ class AllreduceBcube : public Algorithm {
int destRank,
T* p,
int count,
int start = 0) {
if (printCheck(myRank_)) {
std::cout << stage << ": step (" << step << ") " << "srcRank (" << srcRank
<< ") -> " << "destRank (" << destRank << "): ";
printElems(p, count, start);
std::cout << std::endl;
}
}
int start = 0);
/**
* Get all the peers of node with specified rank
* @param rank Rank of the node for which peers are needed
Expand Down
2 changes: 1 addition & 1 deletion gloo/alltoall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <cstring>

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/types.h"

namespace gloo {
Expand Down
2 changes: 1 addition & 1 deletion gloo/alltoall.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/context.h"
#include "gloo/transport/unbound_buffer.h"

Expand Down
2 changes: 1 addition & 1 deletion gloo/alltoallv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cstring>
#include <numeric>

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/types.h"

namespace gloo {
Expand Down
2 changes: 1 addition & 1 deletion gloo/alltoallv.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#pragma once

#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/context.h"
#include "gloo/transport/unbound_buffer.h"

Expand Down
2 changes: 1 addition & 1 deletion gloo/benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set(GLOO_BENCHMARK_SRCS
)

add_executable(benchmark ${GLOO_BENCHMARK_SRCS})
target_link_libraries(benchmark gloo)
target_link_libraries(benchmark gloo ${gloo_ALL_TARGETS_DEPENDENCY_LIBS})

if(GLOO_INSTALL)
install(TARGETS benchmark DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
Expand Down
2 changes: 1 addition & 1 deletion gloo/benchmark/cuda_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "gloo/benchmark/benchmark.h"
#include "gloo/benchmark/runner.h"
#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/cuda_allreduce_bcube.h"
#include "gloo/cuda_allreduce_halving_doubling.h"
#include "gloo/cuda_allreduce_halving_doubling_pipelined.h"
Expand Down
2 changes: 1 addition & 1 deletion gloo/benchmark/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "gloo/broadcast_one_to_all.h"
#include "gloo/common/aligned_allocator.h"
#include "gloo/common/common.h"
#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/context.h"
#include "gloo/pairwise_exchange.h"
#include "gloo/reduce.h"
Expand Down
2 changes: 1 addition & 1 deletion gloo/benchmark/runner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "gloo/barrier_all_to_one.h"
#include "gloo/broadcast_one_to_all.h"
#include "gloo/common/common.h"
#include "gloo/common/logging.h"
#include "gloo/common/enforce.h"
#include "gloo/rendezvous/context.h"
#include "gloo/rendezvous/file_store.h"
#include "gloo/rendezvous/prefix_store.h"
Expand Down
Loading
Loading