Skip to content

Commit a5edcd0

Browse files
authored
Update to CMake 3.13 for better CUDA support and to enable build concurrency (horovod#3261)
Signed-off-by: Max H. Gerlach <[email protected]>
1 parent b96ecae commit a5edcd0

17 files changed

+1033
-34
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1414

1515
### Changed
1616

17+
- Moved to CMake version 3.13 with first-class CUDA language support and re-enabled parallelized builds. ([#3261](https://github.com/horovod/horovod/pull/3261))
18+
1719
### Deprecated
1820
- Deprecated ElasticRayExecutor APIs in favor of the new RayExecutor API for issue: [#3190](https://github.com/horovod/horovod/issues/3190).
1921
### Removed

CMakeLists.txt

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
1-
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
1+
cmake_minimum_required(VERSION 3.13 FATAL_ERROR)
22
if(POLICY CMP0074)
33
# 1. Introduced with 3.12.4.
44
# 2. *_ROOT variables will be checked
55
cmake_policy(SET CMP0074 NEW)
66
endif()
77

8-
if(${CMAKE_VERSION} VERSION_GREATER "3.4.0")
9-
find_program(CCACHE_PROGRAM ccache)
10-
if(CCACHE_PROGRAM)
8+
find_program(CCACHE_PROGRAM ccache)
9+
if(CCACHE_PROGRAM)
1110
set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
1211
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
1312
set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
14-
else()
13+
else()
1514
message(STATUS "Could not find CCache. Consider installing CCache to speed up compilation.")
16-
endif()
1715
endif()
1816

1917
project(horovod CXX)
@@ -23,7 +21,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
2321
set(CMAKE_CXX_EXTENSIONS OFF)
2422

2523
# Configure path to modules (for find_package)
26-
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/Modules/")
24+
set(CMAKE_MODULE_PATH
25+
${CMAKE_MODULE_PATH}
26+
"${PROJECT_SOURCE_DIR}/cmake/Modules/"
27+
"${PROJECT_SOURCE_DIR}/cmake/upstream/")
2728
include(cmake/Utilities.cmake)
2829

2930
create_metadata()
@@ -148,14 +149,33 @@ if (NOT "$ENV{HOROVOD_WITHOUT_MPI}" STREQUAL "1")
148149
endif()
149150

150151
# CUDA and ROCM
152+
set(CMAKE_CUDA_HOST_COMPILER ${CMAKE_CXX_COMPILER})
153+
if(NOT DEFINED CMAKE_CUDA_RUNTIME_LIBRARY)
154+
set(CMAKE_CUDA_RUNTIME_LIBRARY "Shared") # Set to "Static" or "Shared"
155+
endif()
156+
if (DEFINED ENV{HOROVOD_CUDA_HOME})
157+
set(CMAKE_CUDA_COMPILER $ENV{HOROVOD_CUDA_HOME}/bin/nvcc)
158+
endif()
159+
include(CheckLanguage)
160+
check_language(CUDA)
161+
if (CMAKE_CUDA_COMPILER)
162+
if ((CMAKE_CXX_COMPILER_ID MATCHES GNU) AND (CMAKE_SYSTEM_PROCESSOR MATCHES ppc64le))
163+
if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0)
164+
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -std=c++11")
165+
endif ()
166+
endif ()
167+
enable_language(CUDA)
168+
endif ()
169+
151170
macro(ADD_CUDA)
152-
if (DEFINED ENV{HOROVOD_CUDA_HOME})
153-
set(CUDA_TOOLKIT_ROOT_DIR $ENV{HOROVOD_CUDA_HOME})
171+
find_package(CUDAToolkit REQUIRED)
172+
include_directories(SYSTEM ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
173+
string(TOLOWER "${CMAKE_CUDA_RUNTIME_LIBRARY}" lowercase_CMAKE_CUDA_RUNTIME_LIBRARY)
174+
if (lowercase_CMAKE_CUDA_RUNTIME_LIBRARY STREQUAL "static")
175+
list(APPEND LINKER_LIBS CUDA::cudart_static)
176+
elseif (lowercase_CMAKE_CUDA_RUNTIME_LIBRARY STREQUAL "shared")
177+
list(APPEND LINKER_LIBS CUDA::cudart)
154178
endif()
155-
option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF)
156-
find_package(CUDA REQUIRED)
157-
include_directories(SYSTEM ${CUDA_INCLUDE_DIRS})
158-
list(APPEND LINKER_LIBS ${CUDA_LIBRARIES})
159179
list(APPEND SOURCES "${PROJECT_SOURCE_DIR}/horovod/common/ops/cuda_operations.cc"
160180
"${PROJECT_SOURCE_DIR}/horovod/common/ops/gpu_operations.cc")
161181
# CUDA + MPI
@@ -209,7 +229,7 @@ endif()
209229
if(HOROVOD_GPU_ALLREDUCE STREQUAL "D")
210230
message(DEPRECATION "DDL backend has been deprecated. Please, start using the NCCL backend by building Horovod with "
211231
"'HOROVOD_GPU_OPERATIONS=NCCL'. Will be removed in v0.21.0.")
212-
list(APPEND LINKER_LIBS "${CUDA_TOOLKIT_ROOT_DIR}/lib/libddl.so" "${CUDA_TOOLKIT_ROOT_DIR}/lib/libddl_pack.so")
232+
list(APPEND LINKER_LIBS "${CUDAToolkit_LIBRARY_ROOT}/lib/libddl.so" "${CUDAToolkit_LIBRARY_ROOT}/lib/libddl_pack.so")
213233
list(APPEND SOURCES "${PROJECT_SOURCE_DIR}/horovod/common/mpi/ddl_mpi_context_manager.cc"
214234
"${PROJECT_SOURCE_DIR}/horovod/common/ops/ddl_operations.cc")
215235
add_definitions(-DHAVE_DDL=1)

Dockerfile.test.cpu

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ RUN add-apt-repository ppa:ubuntu-toolchain-r/test
3333
RUN apt-get update -qq && apt-get install -y --no-install-recommends \
3434
wget \
3535
ca-certificates \
36-
cmake \
3736
openssh-client \
3837
openssh-server \
3938
git \
@@ -52,6 +51,9 @@ RUN ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python${PYTHON_VERSION/%.
5251
RUN wget --progress=dot:mega https://bootstrap.pypa.io/get-pip.py && python get-pip.py && rm get-pip.py
5352
RUN pip install --no-cache-dir -U --force pip setuptools requests pytest mock pytest-forked parameterized
5453

54+
# Install recent CMake.
55+
RUN pip install --no-cache-dir -U cmake~=3.13.0
56+
5557
# Add launch helper scripts
5658
RUN echo "env SPARK_HOME=/spark SPARK_DRIVER_MEM=512m PYSPARK_PYTHON=/usr/bin/python${PYTHON_VERSION} PYSPARK_DRIVER_PYTHON=/usr/bin/python${PYTHON_VERSION} \"\$@\"" > /spark_env.sh
5759
RUN echo /spark_env.sh pytest -v --capture=no --continue-on-collection-errors --junit-xml=/artifacts/junit.\$1.\${HOROVOD_RANK:-\${OMPI_COMM_WORLD_RANK:-\${PMI_RANK}}}.\$2.xml \${@:2} > /pytest.sh

Dockerfile.test.gpu

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ RUN CUDNN_MAJOR=$(cut -d '.' -f 1 <<< "${CUDNN_VERSION}"); \
3535
apt-get update -qq && apt-get install -y --allow-downgrades --allow-change-held-packages --no-install-recommends \
3636
wget \
3737
ca-certificates \
38-
cmake \
3938
openssh-client \
4039
openssh-server \
4140
git \
@@ -57,6 +56,9 @@ RUN ln -s -f /usr/bin/python${PYTHON_VERSION} /usr/bin/python${PYTHON_VERSION/%.
5756
RUN wget --progress=dot:mega https://bootstrap.pypa.io/get-pip.py && python get-pip.py && rm get-pip.py
5857
RUN pip install --no-cache-dir -U --force pip "setuptools<60.1.0" requests pytest mock pytest-forked parameterized
5958

59+
# Install recent CMake.
60+
RUN pip install --no-cache-dir -U cmake~=3.13.0
61+
6062
# Add launch helper scripts
6163
RUN echo "env SPARK_HOME=/spark SPARK_DRIVER_MEM=512m PYSPARK_PYTHON=/usr/bin/python${PYTHON_VERSION} PYSPARK_DRIVER_PYTHON=/usr/bin/python${PYTHON_VERSION} \"\$@\"" > /spark_env.sh
6264
RUN echo /spark_env.sh pytest -v --capture=no --continue-on-collection-errors --junit-xml=/artifacts/junit.\$1.\${HOROVOD_RANK:-\${OMPI_COMM_WORLD_RANK:-\${PMI_RANK}}}.\$2.xml \${@:2} > /pytest.sh

NOTICE

+35
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,38 @@
232232
The derived work can be found in the files:
233233

234234
- horovod/torch/sync_batch_norm.py
235+
236+
CMake - Cross Platform Makefile Generator
237+
Copyright 2000-2020 Kitware, Inc. and Contributors
238+
All rights reserved.
239+
240+
Redistribution and use in source and binary forms, with or without
241+
modification, are permitted provided that the following conditions
242+
are met:
243+
244+
* Redistributions of source code must retain the above copyright
245+
notice, this list of conditions and the following disclaimer.
246+
247+
* Redistributions in binary form must reproduce the above copyright
248+
notice, this list of conditions and the following disclaimer in the
249+
documentation and/or other materials provided with the distribution.
250+
251+
* Neither the name of Kitware, Inc. nor the names of Contributors
252+
may be used to endorse or promote products derived from this
253+
software without specific prior written permission.
254+
255+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
256+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
257+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
258+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
259+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
260+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
261+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
262+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
263+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
265+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
266+
267+
The derived work can be found in the files:
268+
269+
- cmake/upstream/FindCUDAToolkit.cmake

cmake/Modules/FindNCCL.cmake

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
# NCCL_LIBRARIES
1212
# NCCL_MAJOR_VERSION
1313
#
14-
# The path hints include CUDA_TOOLKIT_ROOT_DIR seeing as some folks
14+
# The path hints include CUDAToolkit_LIBRARY_ROOT seeing as some folks
1515
# install NCCL in the same location as the CUDA toolkit.
1616

1717
set(HOROVOD_NCCL_HOME $ENV{HOROVOD_NCCL_HOME} CACHE PATH "Folder contains NVIDIA NCCL")
1818
set(HOROVOD_NCCL_INCLUDE $ENV{HOROVOD_NCCL_INCLUDE} CACHE PATH "Folder contains NVIDIA NCCL headers")
1919
set(HOROVOD_NCCL_LIB $ENV{HOROVOD_NCCL_LIB} CACHE PATH "Folder contains NVIDIA NCCL libraries")
2020

21-
list(APPEND NCCL_ROOT ${HOROVOD_NCCL_HOME} ${CUDA_TOOLKIT_ROOT_DIR})
21+
list(APPEND NCCL_ROOT ${HOROVOD_NCCL_HOME} ${CUDAToolkit_LIBRARY_ROOT})
2222
# Compatible layer for CMake <3.12. NCCL_ROOT will be accounted in for searching paths and libraries for CMake >=3.12.
2323
list(APPEND CMAKE_PREFIX_PATH ${NCCL_ROOT})
2424

cmake/Modules/FindNVTX.cmake

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
set(HOROVOD_NVTX_INCLUDE $ENV{HOROVOD_NVTX_INCLUDE} CACHE PATH "Folder containing NVIDIA NVTX3 headers")
1212

13-
list(APPEND NVTX_ROOT ${CUDA_TOOLKIT_ROOT_DIR})
13+
list(APPEND NVTX_ROOT ${CUDAToolkit_LIBRARY_ROOT})
1414
# Compatible layer for CMake <3.12:
1515
list(APPEND CMAKE_PREFIX_PATH ${NVTX_ROOT})
1616

1717
find_path(NVTX_INCLUDE_DIR
18-
NAMES nvtx3/nvToolsExt.h
19-
HINTS ${HOROVOD_NVTX_INCLUDE})
18+
NAMES nvtx3/nvToolsExt.h
19+
HINTS ${HOROVOD_NVTX_INCLUDE})
2020

2121
include(FindPackageHandleStandardArgs)
2222
find_package_handle_standard_args(NVTX DEFAULT_MSG NVTX_INCLUDE_DIR)

cmake/Modules/FindTensorflow.cmake

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if (LEN EQUAL "4")
2222
string(REPLACE " " ";" Tensorflow_LIBRARIES_LIST "${Tensorflow_LIBRARIES}")
2323
list(GET Tensorflow_LIBRARIES_LIST 0 Tensorflow_LIB_PATH_ARGUMENT)
2424
string(REGEX REPLACE "^-L" "" Tensorflow_LIB_PATH ${Tensorflow_LIB_PATH_ARGUMENT})
25-
if (Tensorflow_VERSION VERSION_GREATER "2.6" OR Tensorflow_VERSION VERSION_EQUAL "2.6")
25+
if (Tensorflow_VERSION VERSION_GREATER_EQUAL "2.6")
2626
# XLA implementations and helpers for resource variables are in _pywrap_tensorflow_internal.so
2727
set(Tensorflow_LIBRARIES "${Tensorflow_LIBRARIES} ${Tensorflow_LIB_PATH}/python/_pywrap_tensorflow_internal.so")
2828
endif()

cmake/build_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_nvcc_bin():
9191
'Make sure it is added to your path or in $HOROVOD_CUDA_HOME/bin.')
9292

9393
def get_nvcc_flags():
94-
default_flags = ['--std=c++11', '-O3', '-Xcompiler', '-fPIC']
94+
default_flags = ['-O3', '-Xcompiler', '-fPIC']
9595
cc_list_env = os.environ.get('HOROVOD_BUILD_CUDA_CC_LIST')
9696

9797
# Invoke nvcc and extract all supported compute capabilities for CUDA toolkit version

0 commit comments

Comments
 (0)