Skip to content

Commit

Permalink
[Bugfix] Include NCCL as a submodule (dmlc#2934)
Browse files Browse the repository at this point in the history
* Add NCCL as a submodule

* Allow using third_party/nccl or system nccl

* Add nccl_external as a dependency

* Fix conditional

Co-authored-by: Quan (Andy) Gan <[email protected]>
  • Loading branch information
nv-dlasalle and BarclayII authored May 25, 2021
1 parent 06b9ec2 commit 66eb240
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@
[submodule "third_party/nanoflann"]
path = third_party/nanoflann
url = https://github.com/jlblancoc/nanoflann
[submodule "third_party/nccl"]
path = third_party/nccl
url = https://github.com/nvidia/nccl
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ endif()
# and add set(OPTION VALUE) to override these build options.
# Alernatively, use cmake -DOPTION=VALUE through command-line.
dgl_option(USE_CUDA "Build with CUDA" OFF)
dgl_option(USE_SYSTEM_NCCL "Build using system's NCCL library" OFF)
dgl_option(USE_OPENMP "Build with OpenMP" ON)
dgl_option(USE_AVX "Build with AVX optimization" ON)
dgl_option(USE_FP16 "Build with fp16 support to enable mixed precision training" OFF)
Expand Down Expand Up @@ -159,13 +160,21 @@ if(USE_CUDA)
dgl_config_cuda(DGL_CUDA_SRC)
list(APPEND DGL_SRC ${DGL_CUDA_SRC})

include(cmake/util/FindNccl.cmake)
if (USE_SYSTEM_NCCL)
include(cmake/util/FindNccl.cmake)
else()
include(cmake/modules/NCCL.cmake)
endif()

include_directories(${NCCL_INCLUDE_DIR})
list(APPEND DGL_LINKER_LIBS ${NCCL_LIBRARY})
endif(USE_CUDA)

if(USE_CUDA)
cuda_add_library(dgl SHARED ${DGL_SRC})
if (NOT USE_SYSTEM_NCCL)
add_dependencies(dgl nccl_external)
endif()
else(USE_CUDA)
add_library(dgl SHARED ${DGL_SRC})
endif(USE_CUDA)
Expand Down
24 changes: 24 additions & 0 deletions cmake/modules/NCCL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
include(ExternalProject)

# set path to submodule
set(NCCL_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/nccl")

# NCCL doesn't have CMAKE, so build externally
ExternalProject_Add(nccl_external
SOURCE_DIR ${PROJECT_SOURCE_DIR}/third_party/nccl
BUILD_IN_SOURCE 1
CONFIGURE_COMMAND ""
BUILD_COMMAND
env
make
"src.build"
"-j"
"BUILDDIR=${NCCL_BUILD_DIR}"
BUILD_BYPRODUCTS "${NCCL_BUILD_DIR}/lib/libnccl_static.a"
INSTALL_COMMAND ""
)

# set output variables
set(NCCL_FOUND TRUE)
set(NCCL_LIBRARY "${NCCL_BUILD_DIR}/lib/libnccl_static.a")
set(NCCL_INCLUDE_DIR "${NCCL_BUILD_DIR}/include")
1 change: 1 addition & 0 deletions third_party/nccl
Submodule nccl added at 911d61

0 comments on commit 66eb240

Please sign in to comment.