-
Notifications
You must be signed in to change notification settings - Fork 1
/
CMakeLists.txt
293 lines (254 loc) · 9.72 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
# Copyright (c) 2019-2020 Advanced Micro Devices, Inc. All rights reserved.
cmake_minimum_required(VERSION 3.5)
# We use C++14 features, this will add compile option: -std=c++14
set( CMAKE_CXX_STANDARD 14 )
# Without this line, it will add -std=gnu++14 instead, which has some issues.
set( CMAKE_CXX_EXTENSIONS OFF )
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "")
project(rccl CXX)
# Detect compiler support for target ID
if( CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" )
execute_process(COMMAND ${CMAKE_CXX_COMPILER} "--help"
OUTPUT_VARIABLE CXX_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_STRIP_TRAILING_WHITESPACE)
string(REGEX MATCH ".mcode\-object\-version" TARGET_ID_SUPPORT ${CXX_OUTPUT})
endif()
# Use target ID syntax if supported for AMDGPU_TARGETS
if(TARGET_ID_SUPPORT)
set(AMDGPU_TARGETS gfx803;gfx900;gfx906:xnack-;gfx908:xnack- CACHE STRING "List of specific machine types for library to target")
else()
set(AMDGPU_TARGETS gfx803;gfx900;gfx906;gfx908 CACHE STRING "List of specific machine types for library to target")
endif()
option(BUILD_TESTS "Build test programs" OFF)
option(INSTALL_DEPENDENCIES "Force install dependencies" OFF)
include(cmake/Dependencies.cmake)
# parse version from Makefile NCCL_MAJOR, NCCL_MINOR, NCCL_PATCH must exist
# NCCL_SUFFIX is optional NCCL_VERSION formatting is ((X) * 1000 + (Y) * 100 +
# (Z)) so we must first detect one or two digits first
file(READ makefiles/version.mk version_mk_text)
if("${version_mk_text}" MATCHES "NCCL_MAJOR *:= *([0-9]*)")
set(NCCL_MAJOR ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Failed to parse NCCL_MAJOR")
endif()
if("${version_mk_text}" MATCHES "NCCL_MINOR *:= *([0-9]*)")
set(NCCL_MINOR ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Failed to parse NCCL_MINOR")
endif()
if("${version_mk_text}" MATCHES "NCCL_PATCH *:= *([0-9]*)")
set(NCCL_PATCH ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Failed to parse NCCL_PATCH")
endif()
if("${version_mk_text}" MATCHES "NCCL_SUFFIX *:= *([0-9]*)")
set(NCCL_SUFFIX ${CMAKE_MATCH_1})
else()
set(NCCL_SUFFIX)
endif()
if("${version_mk_text}" MATCHES "PKG_REVISION *:= *([0-9]*)")
set(PKG_REVISION ${CMAKE_MATCH_1})
else()
message(FATAL_ERROR "Failed to parse PKG_REVISION")
endif()
if("${NCCL_PATCH}" MATCHES "[0-9][0-9]")
set(NCCL_VERSION "${NCCL_MAJOR}${NCCL_MINOR}${NCCL_PATCH}")
else()
set(NCCL_VERSION "${NCCL_MAJOR}${NCCL_MINOR}0${NCCL_PATCH}")
endif()
# Setup VERSION
set(VERSION_STRING "${NCCL_MAJOR}.${NCCL_MINOR}.${NCCL_PATCH}")
rocm_setup_version(VERSION ${VERSION_STRING})
list(APPEND CMAKE_PREFIX_PATH
/opt/rocm
/opt/rocm/hip
/opt/rocm/llvm
/opt/rocm/hcc)
find_package(hip REQUIRED)
message(STATUS "HIP compiler: ${HIP_COMPILER}")
message(STATUS "HIP runtime: ${HIP_RUNTIME}")
if(BUILD_STATIC)
option(BUILD_SHARED_LIBS "Build as a shared library" OFF)
else()
option(BUILD_SHARED_LIBS "Build as a shared library" ON)
endif()
configure_file(src/nccl.h.in ${PROJECT_BINARY_DIR}/rccl.h)
configure_file(src/nccl.h.in ${PROJECT_BINARY_DIR}/nccl.h)
include_directories(${PROJECT_BINARY_DIR}) # for generated rccl.h header
include_directories(src)
include_directories(src/include)
include_directories(src/collectives)
include_directories(src/collectives/device)
set(CU_SOURCES
src/collectives/device/all_reduce.cu
src/collectives/device/all_gather.cu
src/collectives/device/reduce.cu
src/collectives/device/broadcast.cu
src/collectives/device/reduce_scatter.cu
src/collectives/device/sendrecv.cu
src/collectives/device/gather.cu
src/collectives/device/scatter.cu
src/collectives/device/all_to_all.cu
src/collectives/device/all_to_allv.cu
src/collectives/device/functions.cu)
set(CPP_SOURCES)
foreach(filename ${CU_SOURCES})
string(REPLACE ".cu"
".cpp"
cpp_filename
${filename})
configure_file(${filename} ${cpp_filename} COPYONLY)
list(APPEND CPP_SOURCES ${cpp_filename})
endforeach(filename)
set(CC_SOURCES
src/init.cc
src/graph/trees.cc
src/graph/rings.cc
src/graph/paths.cc
src/graph/search.cc
src/graph/connect.cc
src/graph/tuning.cc
src/graph/topo.cc
src/graph/xml.cc
src/collectives/all_reduce_api.cc
src/collectives/all_gather_api.cc
src/collectives/reduce_api.cc
src/collectives/broadcast_api.cc
src/collectives/reduce_scatter_api.cc
src/collectives/sendrecv_api.cc
src/collectives/gather_api.cc
src/collectives/scatter_api.cc
src/collectives/all_to_all_api.cc
src/collectives/all_to_allv_api.cc
src/channel.cc
src/clique/CliqueManager.cc # RCCL
src/clique/HandleCache.cc # RCCL
src/clique/HandleShm.cc # RCCL
src/clique/Hash.cc # RCCL
src/clique/MsgQueue.cc # RCCL
src/clique/ShmObject.cc # RCCL
src/misc/argcheck.cc
src/misc/nvmlwrap_stub.cc
src/misc/utils.cc
src/misc/ibvwrap.cc
src/misc/nvmlwrap_stub.cc
src/transport/coll_net.cc
src/transport/net.cc
src/transport/net_ib.cc
src/transport/net_socket.cc
src/transport/p2p.cc
src/transport/shm.cc
src/transport.cc
src/debug.cc
src/group.cc
src/bootstrap.cc
src/proxy.cc
src/enqueue.cc)
foreach(filename ${CC_SOURCES})
list(APPEND CPP_SOURCES ${filename})
endforeach(filename)
add_library(rccl ${CPP_SOURCES})
if(TRACE)
add_definitions(-DENABLE_TRACE)
endif()
if(PROFILE)
add_definitions(-DENABLE_PROFILING)
endif()
set(COLLTRACE 1 CACHE BOOL "Collective Trace Option")
if(COLLTRACE)
add_definitions(-DENABLE_COLLTRACE)
endif()
foreach(target ${AMDGPU_TARGETS})
target_link_libraries(rccl PRIVATE --cuda-gpu-arch=${target})
endforeach()
if("${HIP_COMPILER}" MATCHES "clang")
foreach(target ${AMDGPU_TARGETS})
target_compile_options(rccl PRIVATE --cuda-gpu-arch=${target} PRIVATE -fgpu-rdc)
endforeach()
target_link_libraries(rccl PRIVATE -fgpu-rdc)
target_include_directories(rccl PRIVATE /opt/rocm/hsa/include)
find_program( hipcc_executable hipcc )
execute_process(COMMAND bash "-c" "${hipcc_executable} -help | grep 'parallel-jobs'" OUTPUT_VARIABLE hipcc_parallel_jobs)
if("${hipcc_parallel_jobs}" MATCHES "parallel-jobs")
target_compile_options(rccl PRIVATE -parallel-jobs=4 PRIVATE -Wno-format-nonliteral)
target_link_libraries(rccl PRIVATE -parallel-jobs=4)
endif()
# RCCL static lib uses -fgpu-rdc which requires hipcc as the linker and archiver
if(BUILD_STATIC)
target_link_libraries(rccl PRIVATE --emit-static-lib)
set(CMAKE_AR "${hipcc_executable}")
get_property(link_libraries TARGET rccl PROPERTY LINK_LIBRARIES)
string (REPLACE ";" " " LINK_PROPS "${link_libraries}")
set(CMAKE_CXX_ARCHIVE_CREATE "<CMAKE_AR> -o <TARGET> ${LINK_PROPS} <LINK_FLAGS> <OBJECTS>")
endif()
endif()
if("${HIP_COMPILER}" MATCHES "hcc")
find_program( hcc_executable hcc )
execute_process(COMMAND bash "-c" "${hcc_executable} --version | sed -e '1!d' -e 's/.*based on HCC\\s*//'" OUTPUT_VARIABLE hcc_version_string)
execute_process(COMMAND bash "-c" "echo \"${hcc_version_string}\" | awk -F\".\" '{ printf $1}'" OUTPUT_VARIABLE hcc_major_version)
execute_process(COMMAND bash "-c" "echo \"${hcc_version_string}\" | awk -F\".\" '{ printf $2}'" OUTPUT_VARIABLE hcc_minor_version)
if ("${hcc_major_version}.${hcc_minor_version}" VERSION_LESS "4.0")
target_link_libraries(rccl PRIVATE -hc-function-calls)
endif()
endif()
target_link_libraries(rccl PRIVATE hip::device numa)
target_link_libraries(rccl INTERFACE hip::host)
#Setup librccl.so version
rocm_set_soversion(rccl "1.0")
rocm_install_targets(TARGETS
rccl
PREFIX
rccl)
install(FILES ${PROJECT_BINARY_DIR}/rccl.h
DESTINATION rccl/${CMAKE_INSTALL_INCLUDEDIR})
rocm_export_targets(NAMESPACE
roc::
PREFIX
rccl
TARGETS
rccl
DEPENDS
hip)
set(CPACK_DEBIAN_PACKAGE_DEPENDS "hip-rocclr (>= 3.5.0)")
set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
set(CPACK_RPM_PACKAGE_REQUIRES "hip-rocclr >= 3.5.0")
set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "/opt" "/opt/rocm")
find_file (DEBIAN debian_version debconf.conf PATHS /etc)
if(DEBIAN)
# Write copyright file
file(WRITE "${CMAKE_BINARY_DIR}/copyright"
"Format: https://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: rccl
Source: https://github.com/ROCmSoftwarePlatform/rccl
Files: *
Copyright: (c) 2016-2020, NVIDIA CORPORATION. All rights reserved.
Modifications Copyright (c) 2020 Advanced Micro Devices, Inc. All rights reserved.
License: See LICENSE.txt for license information\n")
install(FILES "${CMAKE_BINARY_DIR}/copyright" DESTINATION /usr/share/doc/rccl)
# Write changelog file
find_program( date_executable date )
execute_process(COMMAND ${date_executable} -R OUTPUT_VARIABLE TIMESTAMP)
file(WRITE "${CMAKE_BINARY_DIR}/changelog"
"rccl (${VERSION_STRING}-1) unstable; urgency=medium
* Initial release.
-- RCCL Maintainer <[email protected]> ${TIMESTAMP}\n")
find_program( gzip_executable gzip )
execute_process(COMMAND bash "-c" "${gzip_executable} -9 -c ${CMAKE_BINARY_DIR}/changelog"
WORKING_DIRECTORY ${CMAKE_BINARY_DIR} OUTPUT_FILE "${CMAKE_BINARY_DIR}/changelog.Debian.gz")
install(FILES "${CMAKE_BINARY_DIR}/changelog.Debian.gz" DESTINATION /usr/share/doc/rccl)
set(CPACK_DEBIAN_PACKAGE_DESCRIPTION "ROCm Communication Collectives Library
Optimized primitives for collective multi-GPU communication")
endif()
rocm_create_package(
NAME
rccl
DESCRIPTION
"ROCm Communication Collectives Library"
MAINTAINER
"RCCL Maintainer <[email protected]>"
LDCONFIG)
rocm_install_symlink_subdir(rccl)
if(BUILD_TESTS)
add_subdirectory(test)
endif()