|
| 1 | +# Copyright (c) 2019 Advanced Micro Devices, Inc. All rights reserved. |
| 2 | + |
| 3 | +cmake_minimum_required(VERSION 2.8.12) |
| 4 | + |
| 5 | +set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "") |
| 6 | + |
| 7 | +project(rccl CXX) |
| 8 | + |
| 9 | +find_package(ROCM |
| 10 | + REQUIRED |
| 11 | + PATHS |
| 12 | + /opt/rocm) |
| 13 | + |
| 14 | +include(ROCMInstallTargets) |
| 15 | +include(ROCMPackageConfigHelpers) |
| 16 | +include(ROCMSetupVersion) |
| 17 | +include(ROCMInstallSymlinks) |
| 18 | +include(ROCMCreatePackage) |
| 19 | + |
| 20 | +option(BUILD_TESTS "Build test programs" ON) |
| 21 | + |
| 22 | +# In order to support function calls within the kernel, we must use hcc as the |
| 23 | +# compiler |
| 24 | +set(CMAKE_CXX_COMPILER "/opt/rocm/bin/hcc") |
| 25 | + |
| 26 | +# parse version from Makefile NCCL_MAJOR, NCCL_MINOR, NCCL_PATCH must exist |
| 27 | +# NCCL_SUFFIX is optional NCCL_VERSION formatting is ((X) * 1000 + (Y) * 100 + |
| 28 | +# (Z)) so we must first detect one or two digits first |
| 29 | +file(READ makefiles/version.mk version_mk_text) |
| 30 | +if("${version_mk_text}" MATCHES "NCCL_MAJOR *:= *([0-9]*)") |
| 31 | + set(NCCL_MAJOR ${CMAKE_MATCH_1}) |
| 32 | +else() |
| 33 | + message(FATAL_ERROR "Failed to parse NCCL_MAJOR") |
| 34 | +endif() |
| 35 | +if("${version_mk_text}" MATCHES "NCCL_MINOR *:= *([0-9]*)") |
| 36 | + set(NCCL_MINOR ${CMAKE_MATCH_1}) |
| 37 | +else() |
| 38 | + message(FATAL_ERROR "Failed to parse NCCL_MINOR") |
| 39 | +endif() |
| 40 | +if("${version_mk_text}" MATCHES "NCCL_PATCH *:= *([0-9]*)") |
| 41 | + set(NCCL_PATCH ${CMAKE_MATCH_1}) |
| 42 | +else() |
| 43 | + message(FATAL_ERROR "Failed to parse NCCL_PATCH") |
| 44 | +endif() |
| 45 | +if("${version_mk_text}" MATCHES "NCCL_SUFFIX *:= *([0-9]*)") |
| 46 | + set(NCCL_SUFFIX ${CMAKE_MATCH_1}) |
| 47 | +else() |
| 48 | + set(NCCL_SUFFIX) |
| 49 | +endif() |
| 50 | +if("${version_mk_text}" MATCHES "PKG_REVISION *:= *([0-9]*)") |
| 51 | + set(PKG_REVISION ${CMAKE_MATCH_1}) |
| 52 | +else() |
| 53 | + message(FATAL_ERROR "Failed to parse PKG_REVISION") |
| 54 | +endif() |
| 55 | +if("${NCCL_PATCH}" MATCHES "[0-9][0-9]") |
| 56 | + set(NCCL_VERSION "${NCCL_MAJOR}${NCCL_MINOR}${NCCL_PATCH}") |
| 57 | +else() |
| 58 | + set(NCCL_VERSION "${NCCL_MAJOR}${NCCL_MINOR}0${NCCL_PATCH}") |
| 59 | +endif() |
| 60 | + |
| 61 | +rocm_setup_version(VERSION |
| 62 | + "${NCCL_MAJOR}.${NCCL_MINOR}.${NCCL_PATCH}-${PKG_REVISION}") |
| 63 | + |
| 64 | +list(APPEND CMAKE_PREFIX_PATH |
| 65 | + /opt/rocm |
| 66 | + /opt/rocm/hip |
| 67 | + /opt/rocm/hcc) |
| 68 | + |
| 69 | +find_package(hip REQUIRED) |
| 70 | + |
| 71 | +link_libraries(-amdgpu-target=gfx803 |
| 72 | + -amdgpu-target=gfx900 |
| 73 | + -amdgpu-target=gfx906 |
| 74 | + -hc-function-calls) |
| 75 | + |
| 76 | +option(BUILD_SHARED_LIBS "Build as a shared library" ON) |
| 77 | + |
| 78 | +configure_file(src/nccl.h.in ${PROJECT_BINARY_DIR}/rccl.h) |
| 79 | +configure_file(src/nccl.h.in ${PROJECT_BINARY_DIR}/nccl.h) |
| 80 | + |
| 81 | +include_directories(${PROJECT_BINARY_DIR}) # for generated rccl.h header |
| 82 | +include_directories(src) |
| 83 | +include_directories(src/include) |
| 84 | +include_directories(src/collectives) |
| 85 | +include_directories(src/collectives/device) |
| 86 | + |
| 87 | +set(CU_SOURCES |
| 88 | + src/bootstrap.cu |
| 89 | + src/collectives/all_gather.cu |
| 90 | + src/collectives/all_reduce.cu |
| 91 | + src/collectives/broadcast.cu |
| 92 | + src/collectives/reduce.cu |
| 93 | + src/collectives/reduce_scatter.cu |
| 94 | + src/collectives/device/functions.cu |
| 95 | + src/init.cu |
| 96 | + src/misc/enqueue.cu |
| 97 | + src/misc/group.cu |
| 98 | + src/misc/ibvwrap.cu |
| 99 | + src/misc/nvmlwrap_stub.cu |
| 100 | + src/misc/rings.cu |
| 101 | + src/misc/utils.cu |
| 102 | + src/ring.cu |
| 103 | + src/transport.cu |
| 104 | + src/transport/net.cu |
| 105 | + src/transport/net_ib.cu |
| 106 | + src/transport/net_socket.cu |
| 107 | + src/transport/p2p.cu |
| 108 | + src/transport/shm.cu) |
| 109 | + |
| 110 | +set(CPP_SOURCES) |
| 111 | +foreach(filename ${CU_SOURCES}) |
| 112 | + string(REPLACE ".cu" |
| 113 | + ".cpp" |
| 114 | + cpp_filename |
| 115 | + ${filename}) |
| 116 | + configure_file(${filename} ${cpp_filename} COPYONLY) |
| 117 | + list(APPEND CPP_SOURCES ${cpp_filename}) |
| 118 | +endforeach(filename) |
| 119 | + |
| 120 | +list(APPEND CPP_SOURCES src/collectives/device/all_gather_0.cpp) |
| 121 | +list(APPEND CPP_SOURCES src/collectives/device/all_reduce_0.cpp) |
| 122 | +list(APPEND CPP_SOURCES src/collectives/device/all_reduce_1.cpp) |
| 123 | +list(APPEND CPP_SOURCES src/collectives/device/all_reduce_2.cpp) |
| 124 | +list(APPEND CPP_SOURCES src/collectives/device/all_reduce_3.cpp) |
| 125 | +list(APPEND CPP_SOURCES src/collectives/device/broadcast_0.cpp) |
| 126 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_0.cpp) |
| 127 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_1.cpp) |
| 128 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_2.cpp) |
| 129 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_3.cpp) |
| 130 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_scatter_0.cpp) |
| 131 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_scatter_1.cpp) |
| 132 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_scatter_2.cpp) |
| 133 | +list(APPEND CPP_SOURCES src/collectives/device/reduce_scatter_3.cpp) |
| 134 | + |
| 135 | +add_library(rccl ${CPP_SOURCES}) |
| 136 | + |
| 137 | +if(TRACE) |
| 138 | + add_definitions(-DENABLE_TRACE) |
| 139 | +endif() |
| 140 | + |
| 141 | +if(TARGET hip::device) |
| 142 | + target_link_libraries(rccl PRIVATE hip::device) |
| 143 | + target_link_libraries(rccl INTERFACE hip::host) |
| 144 | +else() |
| 145 | + target_link_libraries(rccl PUBLIC hip::hip_hcc ${hcc_LIBRARIES} numa) |
| 146 | +endif() |
| 147 | + |
| 148 | +rocm_install_targets(TARGETS |
| 149 | + rccl |
| 150 | + PREFIX |
| 151 | + rccl) |
| 152 | +install(FILES ${PROJECT_BINARY_DIR}/rccl.h |
| 153 | + DESTINATION rccl/${CMAKE_INSTALL_INCLUDEDIR}) |
| 154 | + |
| 155 | +rocm_export_targets(NAMESPACE |
| 156 | + roc:: |
| 157 | + PREFIX |
| 158 | + rccl |
| 159 | + TARGETS |
| 160 | + rccl |
| 161 | + DEPENDS |
| 162 | + hip) |
| 163 | + |
| 164 | +set(CPACK_DEBIAN_PACKAGE_DEPENDS "hip_hcc") |
| 165 | +set(CPACK_RPM_PACKAGE_REQUIRES "hip_hcc") |
| 166 | + |
| 167 | +rocm_create_package( |
| 168 | + NAME |
| 169 | + rccl |
| 170 | + DESCRIPTION |
| 171 | + "Optimized primitives for collective multi-GPU communication" |
| 172 | + MAINTAINER |
| 173 | + |
| 174 | + LDCONFIG) |
| 175 | + |
| 176 | +rocm_install_symlink_subdir(rccl) |
| 177 | + |
| 178 | +if(BUILD_TESTS) |
| 179 | + add_subdirectory(test) |
| 180 | +endif() |
0 commit comments