Skip to content

Commit f55576f

Browse files
committed
[CMake] Add NCCL to TVM and TVM Runtime
This PR introduces NCCL in the cmake system. NCCL is NVIDIA's library for distributed communication.
1 parent 072a5c1 commit f55576f

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ include(cmake/utils/Utils.cmake)
66
include(cmake/utils/Summary.cmake)
77
include(cmake/utils/Linker.cmake)
88
include(cmake/utils/FindCUDA.cmake)
9+
include(cmake/utils/FindNCCL.cmake)
910
include(cmake/utils/FindOpenCL.cmake)
1011
include(cmake/utils/FindVulkan.cmake)
1112
include(cmake/utils/FindLLVM.cmake)
@@ -25,6 +26,7 @@ endif()
2526
# and add set(OPTION VALUE) to override these build options.
2627
# Alernatively, use cmake -DOPTION=VALUE through command-line.
2728
tvm_option(USE_CUDA "Build with CUDA" OFF)
29+
tvm_option(USE_NCCL "Build with NCCL" OFF)
2830
tvm_option(USE_OPENCL "Build with OpenCL" OFF)
2931
tvm_option(USE_OPENCL_ENABLE_HOST_PTR "Enable OpenCL memory object access to host" OFF)
3032
tvm_option(USE_OPENCL_GTEST "Path to OpenCL specific gtest version for runtime cpp tests." /path/to/opencl/gtest)
@@ -338,6 +340,7 @@ list(APPEND COMPILER_SRCS "src/target/datatype/myfloat/myfloat.cc")
338340
tvm_file_glob(GLOB RUNTIME_SRCS
339341
src/runtime/*.cc
340342
src/runtime/vm/*.cc
343+
src/runtime/disco/*.cc
341344
src/runtime/minrpc/*.cc
342345
)
343346

@@ -421,6 +424,13 @@ if(USE_PROFILER)
421424
list(APPEND RUNTIME_SRCS ${RUNTIME_VM_PROFILER_SRCS})
422425
endif(USE_PROFILER)
423426

427+
if(USE_CUDA AND USE_NCCL)
428+
message(STATUS "Build with NCCL...")
429+
find_nccl(${USE_NCCL})
430+
tvm_file_glob(GLOB RUNTIME_NCCL_SRC src/runtime/disco/nccl/*.cc)
431+
list(APPEND RUNTIME_SRCS ${RUNTIME_NCCL_SRC})
432+
endif()
433+
424434
if(USE_AOT_EXECUTOR)
425435
message(STATUS "Build with AOT Executor support...")
426436
file(GLOB RUNTIME_AOT_EXECUTOR_SRCS src/runtime/aot_executor/*.cc)
@@ -832,3 +842,8 @@ if(USE_CUDA AND USE_CUTLASS)
832842
target_link_libraries(tvm PRIVATE fpA_intB_gemm)
833843
target_link_libraries(tvm_runtime PRIVATE fpA_intB_gemm)
834844
endif()
845+
846+
if(USE_CUDA AND USE_NCCL)
847+
target_link_libraries(tvm PRIVATE nccl)
848+
target_link_libraries(tvm_runtime PRIVATE nccl)
849+
endif()

cmake/config.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@
4848
# - /path/to/cuda: use specific path to cuda toolkit
4949
set(USE_CUDA OFF)
5050

51+
# Whether to enable NCCL support:
52+
# - ON: enable NCCL with cmake's auto search
53+
# - OFF: disable NCCL
54+
# - /path/to/nccl: use specific path to nccl
55+
set(USE_NCCL OFF)
56+
5157
# Whether enable ROCM runtime
5258
#
5359
# Possible values:

cmake/modules/LibInfo.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ function(add_lib_info src_file)
6464
TVM_INFO_USE_CPP_RTVM="${USE_CPP_RTVM}"
6565
TVM_INFO_USE_CUBLAS="${USE_CUBLAS}"
6666
TVM_INFO_USE_CUDA="${USE_CUDA}"
67+
TVM_INFO_USE_NCCL="${USE_NCCL}"
6768
TVM_INFO_USE_CUDNN="${USE_CUDNN}"
6869
TVM_INFO_USE_CUSTOM_LOGGING="${USE_CUSTOM_LOGGING}"
6970
TVM_INFO_USE_CUTLASS="${USE_CUTLASS}"

cmake/utils/FindNCCL.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
# Variables used by this module, they can change the default behaviour and need
19+
# to be set before calling find_package:
20+
#
21+
# NCCL_ROOT - When set, this path is inspected instead of standard library
22+
# locations as the root of the NCCL installation.
23+
# The environment variable NCCL_ROOT overrides this variable.
24+
#
25+
# This module defines
26+
# Nccl_FOUND, whether nccl has been found
27+
# NCCL_INCLUDE_DIR, directory containing header
28+
# NCCL_LIBRARY, directory containing nccl library
29+
# This module assumes that the user has already called find_package(CUDA)
30+
31+
macro(find_nccl use_nccl)
32+
if(${use_nccl} MATCHES ${IS_FALSE_PATTERN})
33+
return()
34+
endif()
35+
if(${use_nccl} MATCHES ${IS_TRUE_PATTERN})
36+
find_path(NCCL_INCLUDE_DIR NAMES nccl.h)
37+
find_library(NCCL_LIBRARY NAMES nccl)
38+
else()
39+
find_path(NCCL_INCLUDE_DIR NAMES nccl.h HINTS ${use_nccl} ${use_nccl}/include)
40+
find_library(NCCL_LIBRARY NAMES nccl HINTS ${use_nccl} ${use_nccl}/lib)
41+
endif()
42+
include(FindPackageHandleStandardArgs)
43+
find_package_handle_standard_args(Nccl DEFAULT_MSG NCCL_INCLUDE_DIR NCCL_LIBRARY)
44+
if (Nccl_FOUND)
45+
message(STATUS "Found NCCL_LIBRARY: ${NCCL_LIBRARY}")
46+
message(STATUS "Found NCCL_INCLUDE_DIR: ${NCCL_INCLUDE_DIR}")
47+
add_library(nccl SHARED IMPORTED)
48+
set_target_properties(nccl
49+
PROPERTIES
50+
INTERFACE_INCLUDE_DIRECTORIES "${NCCL_INCLUDE_DIR}"
51+
IMPORTED_LOCATION "${NCCL_LIBRARY}")
52+
else()
53+
message(STATUS "NCCL not found")
54+
endif()
55+
mark_as_advanced(NCCL_INCLUDE_DIR NCCL_LIBRARY)
56+
endmacro(find_nccl)

src/support/libinfo.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
#define TVM_INFO_USE_CUDA "NOT-FOUND"
3636
#endif
3737

38+
#ifndef TVM_INFO_USE_NCCL
39+
#define TVM_INFO_USE_NCCL "NOT-FOUND"
40+
#endif
41+
3842
#ifndef TVM_INFO_CUDA_VERSION
3943
#define TVM_INFO_CUDA_VERSION "NOT-FOUND"
4044
#endif
@@ -281,6 +285,7 @@ TVM_DLL Map<String, String> GetLibInfo() {
281285
{"USE_CPP_RTVM", TVM_INFO_USE_CPP_RTVM},
282286
{"USE_CUBLAS", TVM_INFO_USE_CUBLAS},
283287
{"USE_CUDA", TVM_INFO_USE_CUDA},
288+
{"USE_NCCL", TVM_INFO_USE_NCCL},
284289
{"USE_CUDNN", TVM_INFO_USE_CUDNN},
285290
{"USE_CUSTOM_LOGGING", TVM_INFO_USE_CUSTOM_LOGGING},
286291
{"USE_CUTLASS", TVM_INFO_USE_CUTLASS},

0 commit comments

Comments
 (0)