Skip to content

Commit cc938fa

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 cc938fa

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

CMakeLists.txt

Lines changed: 8 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)
@@ -832,3 +834,9 @@ if(USE_CUDA AND USE_CUTLASS)
832834
target_link_libraries(tvm PRIVATE fpA_intB_gemm)
833835
target_link_libraries(tvm_runtime PRIVATE fpA_intB_gemm)
834836
endif()
837+
838+
if(USE_CUDA AND USE_NCCL)
839+
find_nccl(${USE_NCCL})
840+
target_link_libraries(tvm PRIVATE nccl)
841+
target_link_libraries(tvm_runtime PRIVATE nccl)
842+
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/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)

0 commit comments

Comments
 (0)