Skip to content

Commit bdf58b1

Browse files
committed
revamp cmake MPI detection
we honor user requested MPI installations using MPI_PATH first, and check afterwards for MPICH and Open MPI in the default Ubuntu and RHEL installation directories.
1 parent 5275aa5 commit bdf58b1

File tree

2 files changed

+46
-28
lines changed

2 files changed

+46
-28
lines changed

‎CMakeLists.txt‎

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,23 @@
33
# ########################################################################
44
#Adding pthread flag for linking
55
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
6-
macro(check_mpi mpi_compiler mpi_lib_a mpi_lib_so)
7-
find_program(MPI_MPICXX ${mpi_compiler})
6+
macro(check_mpi mpi_compiler mpi_lib_a mpi_lib_so mpi_bin_dir mpi_base_lib_dir mpi_inc_dir)
7+
find_program(MPI_MPICXX ${mpi_compiler} PATHS ${mpi_bin_dir} NO_DEFAULT_PATH)
88
if (MPI_MPICXX)
99
message ("-- ${mpi_compiler} found @ ${MPI_MPICXX}")
10-
if (${CMAKE_VERSION} VERSION_LESS "3.20.0")
11-
get_filename_component(mpi.tmpdir ${MPI_MPICXX} DIRECTORY)
12-
get_filename_component(mpi_base_dir ${mpi.tmpdir} DIRECTORY)
13-
else()
14-
cmake_path(GET MPI_MPICXX PARENT_PATH mpi.tmpdir)
15-
cmake_path(GET mpi.tmpdir PARENT_PATH mpi_base_dir)
16-
endif()
17-
find_file(MPI_H mpi.h PATHS ${mpi_base_dir} PATH_SUFFIXES include include/x86_64-linux-gnu ${ARGN} {REQUIRED)
18-
if (${CMAKE_VERSION} VERSION_LESS "3.20.0")
19-
get_filename_component(mpi_inc_dir ${MPI_H} DIRECTORY)
20-
else()
21-
cmake_path(GET MPI_H PARENT_PATH mpi_inc_dir)
22-
endif()
23-
message ("-- mpi.h is in ${mpi_inc_dir}")
24-
find_file(MPI_LIB NAMES ${mpi_lib_so} ${mpi_lib_a} PATHS ${mpi_base_dir} PATH_SUFFIXES lib lib64 lib/x86_64-linux-gnu REQIRED)
10+
find_file(MPI_H mpi.h PATHS ${mpi_inc_dir} NO_DEFAULT_PATH)
11+
message ("-- mpi.h is in ${MPI_H}")
12+
find_file(MPI_LIB NAMES ${mpi_lib_so} ${mpi_lib_a} PATHS ${mpi_base_lib_dir} PATH_SUFFIXES lib lib64 lib/x86_64-linux-gnu NO_DEFAULT_PATH)
2513
message ("-- libmpi is ${MPI_LIB}")
26-
add_definitions(-DMPI_SUPPORT)
27-
include_directories(${mpi_inc_dir})
28-
link_libraries(${MPI_LIB})
14+
if (NOT MPI_H OR NOT MPI_LIB)
15+
set (MPI_MPICXX "MPI_MPICXX-NOTFOUND")
16+
set (MPI_H "MPI_H-NOTFOUND")
17+
set (MPI_LIB "MPI_LIB-NOTFOUND")
18+
else()
19+
add_definitions(-DMPI_SUPPORT)
20+
include_directories(${mpi_inc_dir})
21+
link_libraries(${MPI_LIB})
22+
endif()
2923
else()
3024
message ("-- ${mpi_compiler} not found")
3125
endif()
@@ -60,6 +54,7 @@ include(ROCMClients)
6054

6155
# Build variables
6256
option(NO_MPI "Build RCCL-tests without MPI support.")
57+
option(MPI_PATH "Use MPI in the specified directory.")
6358
## Get default GPU targets using rocm_check_target_ids
6459
rocm_check_target_ids(
6560
DEFAULT_AMDGPU_TARGETS
@@ -68,13 +63,35 @@ rocm_check_target_ids(
6863
set(AMDGPU_TARGETS "${DEFAULT_AMDGPU_TARGETS}" CACHE STRING "List of specific machine types for these tests to target.")
6964

7065
if (NOT NO_MPI)
71-
# Check for MPICH first
72-
check_mpi(mpicxx.mpich libmpich.a libmpich.so include/x86_64-linux-gnu/mpich)
66+
# CHECK for MPI Path first. User requested this directory explicitely
67+
if (MPI_PATH)
68+
set(mpi_spec_bin_dir "${MPI_PATH}/bin")
69+
set(mpi_spec_inc_dir "${MPI_PATH}/include")
70+
check_mpi(mpicxx libmpi.a libmpi.so ${mpi_spec_bin_dir} ${MPI_PATH} ${mpi_spec_inc_dir})
71+
if (NOT MPI_MPICXX)
72+
# Since the user explicitely requested this directory, abort if something went wrong.
73+
MESSAGE(FATAL_ERROR "Could not find MPI in ${MPI_PATH}")
74+
endif()
75+
endif()
76+
77+
# Check for MPICH Ubuntu installation
78+
if (NOT MPI_MPICXX)
79+
check_mpi(mpicxx.mpich libmpich.a libmpich.so /usr/bin /usr /usr/include/x86_64-linux-gnu/mpich)
80+
endif()
81+
82+
# Check for Open MPI Ubuntu installation
83+
if (NOT MPI_MPICXX)
84+
check_mpi(mpicxx.openmpi libmpi.a libmpi.so /usr/bin /usr/lib/x86_64-linux-gnu/openmpi /usr/lib/x86_64-linux-gnu/openmpi/include)
85+
endif()
86+
87+
# Check for MPICH RHEL installation
88+
if (NOT MPI_MPICXX)
89+
check_mpi(mpicxx libmpich.a libmpich.so /usr/lib64/mpich/bin /usr/lib64/mpich /usr/include/mpich-x86_64)
90+
endif()
7391

74-
# Check for MPI in general. If we find mpicxx, we don't know whether its
75-
# MPICH or another MPI implementation
92+
# Check for Open MPI RHEL installation
7693
if (NOT MPI_MPICXX)
77-
check_mpi(mpicxx libmpi.a libmpi.so)
94+
check_mpi(mpicxx libmpi.a libmpi.so /usr/lib64/openmpi/bin /usr/lib64/openmpi /usr/include/openmpi-x64_64)
7895
endif()
7996

8097
if (NOT MPI_MPICXX)
@@ -91,7 +108,7 @@ add_subdirectory(src)
91108

92109
# Create ROCm standard packages
93110
rocm_create_package(
94-
NAME rccl-separate-tests
111+
NAME rccl-tests
95112
DESCRIPTION "Tests for the ROCm Communication Collectives Library"
96113
MAINTAINER "RCCL Maintainer <rccl-maintainer@amd.com>"
97114
)

‎README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ $ make
3030
When using the cmake build procedure, please make sure that RCCL has also been built using cmake (i.e. not using the install.sh script), since cmake will check
3131
for cmake target and config files that are created during the RCCL build.
3232

33-
Using the cmake method also has the advantage that the build is automatically checking for MPI installations, i.e. it is not necessary to explicitley request
34-
MPI builds. A user can explicitely disable MPI builds by adding the -DNO_MPI=1 flag to the cmake command line.
33+
Using the cmake method also has the advantage that the build is automatically checking for MPI installations, i.e. it is not necessary to explicitly request
34+
MPI builds. A user can request to use a particular MPI library by using the MPI_PATH variable. MPI support can be explicitely disabled by adding the -DNO_MPI=1
35+
flag to the cmake command line.
3536

3637

3738
## Usage

0 commit comments

Comments
 (0)