|
1 | | -# ######################################################################## |
2 | | -# Copyright 2022 Advanced Micro Devices, Inc. |
3 | | -# ######################################################################## |
4 | | -#Adding pthread flag for linking |
5 | | -set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") |
| 1 | +# Copyright (c) 2019-2025 Advanced Micro Devices, Inc. All rights reserved. |
6 | 2 |
|
7 | | -cmake_minimum_required(VERSION 3.16.3 FATAL_ERROR) |
8 | | - |
9 | | -project(RCCL-tests VERSION 2.12.10 LANGUAGES CXX) |
| 3 | +# CMake version minimum requirements |
| 4 | +#================================================================================================== |
| 5 | +cmake_minimum_required(VERSION 3.16 FATAL_ERROR) |
10 | 6 |
|
11 | | -# Get ROCm path from environment if available |
12 | | -if (DEFINED ENV{ROCM_PATH}) |
13 | | - set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Path to ROCm installation") |
14 | | -else() |
15 | | - set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to ROCm installation") |
| 7 | +# CMake Toolchain file to define compilers and path to ROCm |
| 8 | +#================================================================================================== |
| 9 | +if (NOT CMAKE_TOOLCHAIN_FILE) |
| 10 | + set(CMAKE_TOOLCHAIN_FILE "${CMAKE_CURRENT_SOURCE_DIR}/toolchain-linux.cmake") |
| 11 | + message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}") |
16 | 12 | endif() |
17 | 13 |
|
18 | | -# Set CMake/CPack variables |
19 | | -list( APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/llvm) |
20 | | -set(CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "Prefix install path") |
21 | | -set(CPACK_PACKAGING_INSTALL_PREFIX "${ROCM_PATH}" CACHE PATH "Path to install to when packaged.") |
22 | | -set(CMAKE_CXX_STANDARD 14) |
| 14 | +# RCCL Tests project |
| 15 | +#================================================================================================== |
| 16 | +project(rccl-tests LANGUAGES CXX) |
23 | 17 |
|
24 | | -# Get additional packages required |
25 | | -find_package(ROCM 0.7.3 CONFIG REQUIRED PATHS "${ROCM_PATH}") |
26 | | -include(ROCMSetupVersion) |
27 | | -include(ROCMCreatePackage) |
28 | | -include(ROCMInstallTargets) |
29 | | -include(ROCMCheckTargetIds) |
30 | | -include(ROCMClients) |
| 18 | +# Build options |
| 19 | +#================================================================================================== |
| 20 | +option(USE_MPI "Build RCCL-tests with MPI support." OFF) |
| 21 | +option(BUILD_LOCAL_GPU_TARGET_ONLY "Build only for GPUs detected on this machine" OFF) |
31 | 22 |
|
32 | | -# Build variables |
33 | | -option(USE_MPI "Build RCCL-tests with MPI support.") |
| 23 | +if (NOT CMAKE_BUILD_TYPE) |
| 24 | + message(WARNING "CMAKE_BUILD_TYPE is not defined. Setting to Release") |
| 25 | + set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Default build type") |
| 26 | +endif() |
34 | 27 |
|
35 | 28 | # Default GPU architectures to build |
36 | 29 | #================================================================================================== |
37 | 30 | set(DEFAULT_GPUS |
38 | | - gfx803 |
39 | | - gfx900:xnack- |
40 | | - gfx906:xnack- |
41 | | - gfx908:xnack- |
42 | | - gfx90a:xnack- |
43 | | - gfx90a:xnack+ |
44 | | - gfx940 |
45 | | - gfx941 |
| 31 | + gfx906 |
| 32 | + gfx908 |
| 33 | + gfx90a |
46 | 34 | gfx942 |
| 35 | + gfx950 |
47 | 36 | gfx1030 |
48 | 37 | gfx1100 |
49 | 38 | gfx1101 |
50 | | - gfx1102) |
| 39 | + gfx1102 |
| 40 | + gfx1200 |
| 41 | + gfx1201) |
| 42 | + |
| 43 | +# Get additional packages required |
| 44 | +include(CheckIncludeFiles) |
| 45 | +include(CheckSymbolExists) |
| 46 | +include(cmake/Dependencies.cmake) # rocm-cmake, rocm_local_targets |
| 47 | +include(cmake/CheckSymbolExistsNoWarn.cmake) |
51 | 48 |
|
52 | | -set(AMDGPU_TARGETS ${DEFAULT_GPUS} CACHE STRING "Target default GPUs if AMDGPU_TARGETS is not defined.") |
53 | | -## Determine which GPU architectures to build for |
| 49 | +# Build only for local GPU architecture |
| 50 | +if (BUILD_LOCAL_GPU_TARGET_ONLY) |
| 51 | + message(STATUS "Building only for local GPU target") |
| 52 | + if (COMMAND rocm_local_targets) |
| 53 | + rocm_local_targets(DEFAULT_GPUS) |
| 54 | + else() |
| 55 | + message(WARNING "Unable to determine local GPU targets. Falling back to default GPUs.") |
| 56 | + endif() |
| 57 | +endif() |
| 58 | + |
| 59 | +# Determine which GPU architectures to build for |
| 60 | +set(GPU_TARGETS "${DEFAULT_GPUS}" CACHE STRING "Target default GPUs if GPU_TARGETS is not defined.") |
| 61 | + |
| 62 | +# Check if clang compiler can offload to GPU_TARGETS |
54 | 63 | if (COMMAND rocm_check_target_ids) |
55 | | - message(STATUS "Checking for ROCm support for GPU targets:") |
56 | | - rocm_check_target_ids(SUPPORTED_GPUS TARGETS "${AMDGPU_TARGETS}") |
| 64 | + message(STATUS "Checking for ROCm support for GPU targets: " "${GPU_TARGETS}") |
| 65 | + rocm_check_target_ids(SUPPORTED_GPUS TARGETS ${GPU_TARGETS}) |
57 | 66 | else() |
58 | | - message(WARNING "Unable to check for supported GPU targets. Falling back to default GPUs") |
59 | | - set(SUPPORTED_GPUS ${DEFAULT_GPUS}) |
| 67 | + message(WARNING "Unable to check for supported GPU targets. Falling back to default GPUs.") |
| 68 | + set(SUPPORTED_GPUS ${DEFAULT_GPUS}) |
60 | 69 | endif() |
61 | | -set(GPU_TARGETS "${SUPPORTED_GPUS}" CACHE STRING "List of specific GPU architectures to build for.") |
| 70 | + |
| 71 | +set(GPU_TARGETS "${SUPPORTED_GPUS}") |
62 | 72 | message(STATUS "Compiling for ${GPU_TARGETS}") |
63 | 73 |
|
64 | | -find_package(RCCL HINTS CONFIG REQUIRED PATHS "${ROCM_PATH}") |
| 74 | +## NOTE: Reload rocm-cmake in order to update GPU_TARGETS |
| 75 | +include(cmake/Dependencies.cmake) # Reloading to use desired GPU_TARGETS instead of defaults |
| 76 | + |
| 77 | +# Try to establish ROCM_PATH (for find_package) |
| 78 | +#================================================================================================== |
| 79 | +if(NOT DEFINED ROCM_PATH) |
| 80 | + # Guess default location |
| 81 | + set(ROCM_PATH "/opt/rocm") |
| 82 | + message(WARNING "Unable to find ROCM_PATH: Falling back to ${ROCM_PATH}") |
| 83 | +else() |
| 84 | + message(STATUS "ROCM_PATH found: ${ROCM_PATH}") |
| 85 | +endif() |
| 86 | +set(ENV{ROCM_PATH} ${ROCM_PATH}) |
| 87 | + |
| 88 | +if("${CMAKE_CXX_COMPILER}" MATCHES ".*amdclang\\+\\+") |
| 89 | + message(STATUS "Compiling with amdclang++") |
| 90 | + set(COMPILER_EXE_NAME amdclang++) |
| 91 | + set(COMPILER_GREP_STRING "AMD clang version") |
| 92 | + set(COMPILER_AWK_CMD "awk -F\" \" '{ printf $4}'") |
| 93 | +elseif("${CMAKE_CXX_COMPILER}" MATCHES ".*clang\\+\\+") |
| 94 | + message(STATUS "Compiling with clang++") |
| 95 | + set(COMPILER_EXE_NAME clang++) |
| 96 | + set(COMPILER_GREP_STRING "AMD clang version") |
| 97 | + set(COMPILER_AWK_CMD "awk -F\" \" '{ printf $4}'") |
| 98 | +elseif("${CMAKE_CXX_COMPILER}" MATCHES ".*hipcc$") |
| 99 | + message(STATUS "Compiling with hipcc") |
| 100 | + set(COMPILER_EXE_NAME hipcc) |
| 101 | + set(COMPILER_GREP_STRING "HIP version") |
| 102 | + set(COMPILER_AWK_CMD "awk -F\" \" '{ printf $3}' | awk -F\"-\" '{ printf $1}'") |
| 103 | +else() |
| 104 | + message(FATAL_ERROR "RCCL-Tests can be built only with hipcc or amdclang++") |
| 105 | +endif() |
| 106 | + |
| 107 | +# Set CMAKE flags |
| 108 | +#================================================================================================== |
| 109 | +set(CMAKE_INSTALL_PREFIX "${ROCM_PATH}" CACHE PATH "") |
| 110 | +set(CMAKE_CXX_STANDARD 14) # We use C++14 features, this will add compile option: -std=c++14 |
| 111 | +set(CMAKE_CXX_EXTENSIONS OFF) # Without this line, it will add -std=gnu++14 instead, which has some issues. |
| 112 | +set(CPACK_PACKAGING_INSTALL_PREFIX "${ROCM_PATH}" CACHE PATH "Path to install to when packaged.") |
| 113 | +if(ROCM_PATH) |
| 114 | + #list(APPEND CMAKE_PREFIX_PATH # Temporary workaround |
| 115 | + list(PREPEND CMAKE_PREFIX_PATH # Add ROCM_PATH to CMake search paths (for finding HIP / HSA |
| 116 | + ${ROCM_PATH} |
| 117 | + ${ROCM_PATH}/hip |
| 118 | + ${ROCM_PATH}/llvm) |
| 119 | +endif() |
| 120 | + |
| 121 | +# Check for required dependencies |
| 122 | +#================================================================================================== |
| 123 | +## Check for Threads |
| 124 | +set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 125 | +find_package(Threads REQUIRED) |
| 126 | + |
| 127 | +##Adding pthread flag for linking |
| 128 | +#set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") |
| 129 | + |
| 130 | +## Check for HIP |
| 131 | +find_package(hip REQUIRED) |
| 132 | +message(STATUS "HIP compiler: ${HIP_COMPILER}") |
| 133 | +message(STATUS "HIP runtime: ${HIP_RUNTIME}") |
| 134 | +if(NOT "${HIP_COMPILER}" MATCHES "clang") |
| 135 | + message(FATAL_ERROR "RCCL requires clang-based compiler (amdclang++ or hipcc)") |
| 136 | +endif() |
| 137 | + |
| 138 | +## Check for compiler version |
| 139 | +find_program(compiler_executable ${COMPILER_EXE_NAME}) |
| 140 | +message(STATUS "${COMPILER_EXE_NAME} executable: ${compiler_executable}") |
| 141 | +execute_process( |
| 142 | + COMMAND bash "-c" "${compiler_executable} --version | grep \"${COMPILER_GREP_STRING}\" | ${COMPILER_AWK_CMD}" |
| 143 | + OUTPUT_VARIABLE compiler_version_string) |
| 144 | +message(STATUS "${COMPILER_EXE_NAME} version: ${compiler_version_string}") |
| 145 | + |
| 146 | +## Check for HIP version |
| 147 | +find_program(hipconfig_executable hipconfig) |
| 148 | +message(STATUS "hipconfig executable: ${hipconfig_executable}") |
| 149 | +execute_process( |
| 150 | + COMMAND bash "-c" "${hipconfig_executable} -v | awk -F\"-\" '{ printf $1 }'" |
| 151 | + OUTPUT_VARIABLE hip_version_string) |
| 152 | +message(STATUS "${COMPILER_EXE_NAME} HIP version: ${hip_version_string}") |
| 153 | + |
| 154 | +##Check for ROCm version |
| 155 | +set(EXPLICIT_ROCM_VERSION "" CACHE STRING "Explicit ROCM version to compile to (auto detect if empty)") |
| 156 | +if(EXPLICIT_ROCM_VERSION) |
| 157 | + set(rocm_version_string "${EXPLICIT_ROCM_VERSION}") |
| 158 | +elseif(ROCM_PATH) |
| 159 | + message(STATUS "Reading ROCM version from ${ROCM_PATH}/.info/version") |
| 160 | + file(READ "${ROCM_PATH}/.info/version" rocm_version_string) |
| 161 | +else() |
| 162 | + message(FATAL_ERROR "Could not determine ROCM version (set EXPLICIT_ROCM_VERSION or set ROCM_PATH to a valid installation)") |
| 163 | +endif() |
| 164 | +string(REGEX MATCH "([0-9]+)\\.([0-9]+)\\.([0-9]+)" rocm_version_matches ${rocm_version_string}) |
| 165 | +if (rocm_version_matches) |
| 166 | + set(ROCM_MAJOR_VERSION ${CMAKE_MATCH_1}) |
| 167 | + set(ROCM_MINOR_VERSION ${CMAKE_MATCH_2}) |
| 168 | + set(ROCM_PATCH_VERSION ${CMAKE_MATCH_3}) |
| 169 | + |
| 170 | + message(STATUS "ROCm version: ${ROCM_MAJOR_VERSION}.${ROCM_MINOR_VERSION}.${ROCM_PATCH_VERSION}") |
| 171 | + |
| 172 | + # Convert the version components to int for comparison |
| 173 | + math(EXPR ROCM_VERSION "(10000 * ${ROCM_MAJOR_VERSION}) + (100 * ${ROCM_MINOR_VERSION}) + ${ROCM_PATCH_VERSION}") |
| 174 | + add_definitions("-DROCM_VERSION=${ROCM_VERSION}") |
| 175 | +else() |
| 176 | + message(WARNING "Failed to extract ROCm version.") |
| 177 | +endif() |
| 178 | + |
| 179 | +## Check for RCCL |
| 180 | +find_package(RCCL CONFIG REQUIRED HINTS "${CMAKE_PREFIX_PATH}" PATHS "${ROCM_PATH}") |
65 | 181 | if (RCCL_FOUND) |
66 | 182 | message(STATUS "RCCL version : ${RCCL_VERSION}") |
67 | 183 | message(STATUS "RCCL include path : ${RCCL_INCLUDE_DIRS}") |
68 | 184 | message(STATUS "RCCL libraries : ${RCCL_LIBRARIES}") |
69 | 185 | endif() |
70 | 186 |
|
| 187 | +## Check for MPI (if enabled) |
71 | 188 | if (USE_MPI) |
72 | 189 | find_package(MPI REQUIRED) |
73 | 190 | if (MPI_FOUND) |
|
0 commit comments