Skip to content

Commit

Permalink
gloo: build once, share between pytorch/caffe2
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: pytorch#12885

Differential Revision: D10492244

Pulled By: anderspapitto

fbshipit-source-id: 79af1ceb9bb0dab4585a728e64554ff4f38d6c32
  • Loading branch information
anderspapitto authored and facebook-github-bot committed Oct 22, 2018
1 parent df06fba commit 8f51c51
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ if(USE_GLOO)
include_directories(SYSTEM ${Gloo_INCLUDE_DIRS})
list(APPEND Caffe2_DEPENDENCY_LIBS gloo)
else()
set(GLOO_INSTALL OFF CACHE BOOL "" FORCE)
set(GLOO_INSTALL ON CACHE BOOL "" FORCE)
set(GLOO_STATIC_OR_SHARED STATIC CACHE STRING "" FORCE)

# Temporarily override variables to avoid building Gloo tests/benchmarks
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def run(self):
# All libraries that torch could depend on
dep_libs = [
'nccl', 'caffe2',
'libshm', 'libshm_windows', 'gloo', 'THD', 'c10d',
'libshm', 'libshm_windows', 'THD', 'c10d',
]

missing_pydep = '''
Expand Down Expand Up @@ -467,7 +467,6 @@ def check_file(f):
libs += ['libshm']
if USE_DISTRIBUTED:
if IS_LINUX:
libs += ['gloo']
libs += ['c10d']
libs += ['THD']
build_libs(libs)
Expand Down
13 changes: 5 additions & 8 deletions tools/build_pytorch_libs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,15 +127,14 @@ else
fi
fi
CPP_FLAGS=" -std=c++11 "
GLOO_FLAGS="-DBUILD_TEST=OFF "
THD_FLAGS=""
NCCL_ROOT_DIR=${NCCL_ROOT_DIR:-$INSTALL_DIR}
if [[ $USE_CUDA -eq 1 ]]; then
GLOO_FLAGS+="-DUSE_CUDA=1 -DNCCL_ROOT_DIR=$NCCL_ROOT_DIR"
GLOO_FLAGS+="-DNCCL_ROOT_DIR=$NCCL_ROOT_DIR"
fi
# Gloo infiniband support
if [[ $USE_GLOO_IBVERBS -eq 1 ]]; then
GLOO_FLAGS+=" -DUSE_IBVERBS=1 -DBUILD_SHARED_LIBS=1"
GLOO_FLAGS+=" -DUSE_IBVERBS=1"
THD_FLAGS="-DUSE_GLOO_IBVERBS=1"
fi
CWRAP_FILES="\
Expand Down Expand Up @@ -324,7 +323,9 @@ function build_caffe2() {
-DCMAKE_C_FLAGS="$USER_CFLAGS" \
-DCMAKE_CXX_FLAGS="$USER_CFLAGS" \
-DCMAKE_EXE_LINKER_FLAGS="$LDFLAGS $USER_LDFLAGS" \
-DCMAKE_SHARED_LINKER_FLAGS="$LDFLAGS $USER_LDFLAGS" ${EXTRA_CAFFE2_CMAKE_FLAGS[@]}
-DCMAKE_SHARED_LINKER_FLAGS="$LDFLAGS $USER_LDFLAGS" \
$GLOO_FLAGS \
${EXTRA_CAFFE2_CMAKE_FLAGS[@]}
# STOP!!! Are you trying to add a C or CXX flag? Add it
# to CMakeLists.txt and aten/CMakeLists.txt, not here.
# We need the vanilla cmake build to work.
Expand Down Expand Up @@ -370,10 +371,6 @@ for arg in "$@"; do
pushd $THIRD_PARTY_DIR
build_nccl
popd
elif [[ "$arg" == "gloo" ]]; then
pushd "$THIRD_PARTY_DIR"
build gloo $GLOO_FLAGS
popd
elif [[ "$arg" == "caffe2" ]]; then
build_caffe2
elif [[ "$arg" == "THD" ]]; then
Expand Down

0 comments on commit 8f51c51

Please sign in to comment.