Skip to content

Commit 82348d8

Browse files
authored
[enhancement] Vendoring OpenMPI as an MPI implementation within TheRock (#2599)
## Motivation Issue: #1284 ## Technical Details Added OpenMPI as an MPI implementation within TheRock ## Test Plan Run the build locally using OpenMPI as an MPI implementation ## Test Result Build successful ## Submission Checklist - [x] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
1 parent 4aa048f commit 82348d8

File tree

8 files changed

+169
-2
lines changed

8 files changed

+169
-2
lines changed

BUILD_TOPOLOGY.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,12 @@ type = "target-neutral"
423423
artifact_deps = ["amd-llvm"]
424424
feature_group = "CORE"
425425

426+
[artifacts.openmpi]
427+
artifact_group = "third-party-libs"
428+
type = "target-neutral"
429+
artifact_deps = []
430+
feature_group = "CORE"
431+
426432
# --- Base Infrastructure ---
427433

428434
[artifacts.base]
@@ -618,7 +624,7 @@ disable_platforms = ["windows"]
618624
[artifacts.rccl]
619625
artifact_group = "comm-libs"
620626
type = "target-specific"
621-
artifact_deps = ["core-runtime", "core-hip", "hipify", "rocprofiler-sdk", "core-amdsmi"]
627+
artifact_deps = ["core-runtime", "core-hip", "hipify", "rocprofiler-sdk", "core-amdsmi", "openmpi"]
622628
disable_platforms = ["windows"]
623629

624630
[artifacts.rocshmem]

CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ if(THEROCK_KPACK_SPLIT_ARTIFACTS AND NOT THEROCK_KPACK_DIR)
119119
endif()
120120

121121
option(THEROCK_BUNDLE_SYSDEPS "Builds bundled system deps for portable builds into lib/rocm_sysdeps" ON)
122-
option(THEROCK_ENABLE_MPI "Enables building components with Message Passing Interface (MPI) support" OFF)
122+
# TODO: Set default to true for Linux branch after necessary changes land
123+
cmake_dependent_option(THEROCK_ENABLE_MPI
124+
"Enables building components with Message Passing Interface (MPI) support"
125+
OFF "NOT WIN32" OFF)
123126
option(THEROCK_ENABLE_LLVM_TESTS "Enables building LLVM LIT tests" OFF)
124127

125128
set(THEROCK_SANITIZER "" CACHE STRING "Enable project wide sanitizer build ('ASAN' for host+device, 'HOST_ASAN' for host-only)")

comm-libs/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ if(THEROCK_ENABLE_RCCL)
6464
list(APPEND _rccl_subproject_names rccl)
6565

6666
if(THEROCK_BUILD_TESTING)
67+
68+
set(_rccl_tests_optional_deps)
69+
if(THEROCK_ENABLE_MPI)
70+
set(_rccl_tests_optional_deps "therock-openmpi")
71+
endif()
72+
6773
therock_cmake_subproject_declare(rccl-tests
6874
EXTERNAL_SOURCE_DIR "${THEROCK_ROCM_SYSTEMS_SOURCE_DIR}/projects/rccl-tests"
6975
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/rccl-tests"
@@ -82,6 +88,7 @@ if(THEROCK_ENABLE_RCCL)
8288
hip-clr
8389
hipify
8490
rccl
91+
${_rccl_tests_optional_deps}
8592
)
8693
therock_cmake_subproject_glob_c_sources(rccl-tests
8794
SUBDIRS

profiler/CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ if(THEROCK_ENABLE_ROCPROFV3)
240240
string(REPLACE ";" "\\;" _ROCPROFSYS_GFX_TARGETS_ESCAPED "${THEROCK_DIST_AMDGPU_TARGETS}")
241241
endif()
242242

243+
set(_rocprofiler_systems_optional_deps)
244+
if(THEROCK_ENABLE_MPI)
245+
set(_rocprofiler_systems_optional_deps therock-openmpi)
246+
endif()
247+
243248
therock_cmake_subproject_declare(rocprofiler-systems
244249
USE_DIST_AMDGPU_TARGETS
245250
EXTERNAL_SOURCE_DIR "${THEROCK_ROCM_SYSTEMS_SOURCE_DIR}/projects/rocprofiler-systems"
@@ -255,6 +260,7 @@ if(THEROCK_ENABLE_ROCPROFV3)
255260
-DROCPROFSYS_BUILD_FOR_THEROCK=ON
256261
-DROCPROFSYS_GFX_TARGETS="${_ROCPROFSYS_GFX_TARGETS_ESCAPED}"
257262
-DROCPROFSYS_BUILD_SPDLOG=OFF
263+
"-DROCPROFSYS_USE_MPI=${THEROCK_ENABLE_MPI}"
258264
INSTALL_RPATH_DIRS
259265
"lib"
260266
"lib/rocprofiler-systems"
@@ -272,6 +278,7 @@ if(THEROCK_ENABLE_ROCPROFV3)
272278
rocprofiler-sdk
273279
${THEROCK_BUNDLED_LIBDRM}
274280
${THEROCK_BUNDLED_SQLITE3}
281+
${_rocprofiler_systems_optional_deps}
275282
)
276283
therock_cmake_subproject_glob_c_sources(rocprofiler-systems
277284
SUBDIRS .

third-party/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ if(THEROCK_ENABLE_HOST_SUITE_SPARSE)
4040
add_subdirectory(SuiteSparse)
4141
endif()
4242

43+
# OpenMPI implementation of MPI
44+
if(THEROCK_ENABLE_MPI)
45+
add_subdirectory(openmpi)
46+
endif()
47+
4348
# gRPC: Static library for RDC (built on-demand when depended upon)
4449
# See: docs/rfcs/RFC0007-rdc-therock-integration.md
4550
add_subdirectory(grpc)

third-party/openmpi/CMakeLists.txt

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
2+
set(_source_dir "${CMAKE_CURRENT_BINARY_DIR}/source")
3+
set(_download_stamp "${_source_dir}/download.stamp")
4+
5+
therock_subproject_fetch(therock-openmpi-sources
6+
SOURCE_DIR "${_source_dir}"
7+
# Originally mirrored from: "https://download.open-mpi.org/release/open-mpi/v5.0/openmpi-5.0.9.tar.bz2"
8+
URL "https://rocm-third-party-deps.s3.us-east-2.amazonaws.com/openmpi-5.0.9.tar.bz2"
9+
URL_HASH "SHA256=dfb72762531170847af3e4a0f21d77d7b23cf36f67ce7ce9033659273677d80b"
10+
TOUCH "${_download_stamp}"
11+
)
12+
13+
therock_cmake_subproject_declare(therock-openmpi
14+
FPRINT_SOURCE_DIR "${_source_dir}"
15+
FPRINT_FILE_GLOBS "${CMAKE_CURRENT_LIST_DIR}/*"
16+
USE_DIST_AMDGPU_TARGETS
17+
BACKGROUND_BUILD
18+
NO_MERGE_COMPILE_COMMANDS
19+
EXCLUDE_FROM_ALL
20+
OUTPUT_ON_FAILURE
21+
EXTERNAL_SOURCE_DIR
22+
.
23+
CMAKE_ARGS
24+
"-DSOURCE_DIR=${_source_dir}"
25+
BINARY_DIR
26+
build
27+
EXTRA_DEPENDS
28+
"${_download_stamp}"
29+
)
30+
31+
therock_cmake_subproject_provide_package(therock-openmpi MPI lib/cmake/openmpi)
32+
33+
therock_cmake_subproject_activate(therock-openmpi)
34+
35+
therock_provide_artifact(openmpi
36+
TARGET_NEUTRAL
37+
DESCRIPTOR artifact-openmpi.toml
38+
COMPONENTS
39+
dev
40+
lib
41+
run
42+
SUBPROJECT_DEPS
43+
therock-openmpi
44+
)
45+
return()
46+
endif()
47+
48+
include(CMakePackageConfigHelpers)
49+
50+
cmake_minimum_required(VERSION 3.25)
51+
project(OpenMPI_BUILD VERSION 5.0.9)
52+
53+
set(MPI_STAGE_DIR "${CMAKE_CURRENT_BINARY_DIR}/install")
54+
55+
include(ProcessorCount)
56+
ProcessorCount(PAR_JOBS)
57+
if(NOT PAR_JOBS OR PAR_JOBS EQUAL 0)
58+
set(PAR_JOBS 1)
59+
endif()
60+
61+
add_custom_target(
62+
build ALL
63+
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
64+
# release 5.0.9 uses autoconf 1.16.5, while the manylinux image uses 1.16.1, so we regenerate the autotools files due to incompatibility issues
65+
COMMAND
66+
${CMAKE_COMMAND} -E chdir "${SOURCE_DIR}" perl autogen.pl --force
67+
COMMAND
68+
"${SOURCE_DIR}/configure" --prefix=${CMAKE_INSTALL_PREFIX} --disable-silent-rules --enable-mpi-fortran=no
69+
COMMAND
70+
make -j ${PAR_JOBS}
71+
COMMAND
72+
make install DESTDIR="${MPI_STAGE_DIR}"
73+
VERBATIM
74+
)
75+
76+
install(DIRECTORY "${MPI_STAGE_DIR}${CMAKE_INSTALL_PREFIX}/"
77+
USE_SOURCE_PERMISSIONS
78+
DESTINATION .
79+
)
80+
81+
configure_package_config_file(
82+
"${CMAKE_CURRENT_SOURCE_DIR}/mpi-config.cmake.in"
83+
"${CMAKE_CURRENT_BINARY_DIR}/mpi-config.cmake"
84+
INSTALL_DESTINATION lib/cmake/openmpi
85+
NO_CHECK_REQUIRED_COMPONENTS_MACRO
86+
)
87+
88+
write_basic_package_version_file(
89+
"${CMAKE_CURRENT_BINARY_DIR}/mpi-version-config.cmake"
90+
VERSION "${PROJECT_VERSION}"
91+
COMPATIBILITY SameMajorVersion
92+
)
93+
94+
install(FILES
95+
"${CMAKE_CURRENT_BINARY_DIR}/mpi-config.cmake"
96+
"${CMAKE_CURRENT_BINARY_DIR}/mpi-version-config.cmake"
97+
DESTINATION lib/cmake/openmpi
98+
)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# openmpi
2+
[components.dev."third-party/openmpi/build/stage"]
3+
[components.run."third-party/openmpi/build/stage"]
4+
[components.lib."third-party/openmpi/build/stage"]
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
@PACKAGE_INIT@
2+
3+
set_and_check(MPI_ROOT "${PACKAGE_PREFIX_DIR}")
4+
5+
set_and_check(MPI_C_HEADER_DIR "${MPI_ROOT}/include")
6+
set_and_check(MPI_CXX_HEADER_DIR "${MPI_ROOT}/include")
7+
8+
set_and_check(MPI_C_INCLUDE_DIRS "${MPI_C_HEADER_DIR}")
9+
set_and_check(MPI_CXX_INCLUDE_DIRS "${MPI_CXX_HEADER_DIR}")
10+
11+
set_and_check(MPI_C_LIBRARIES "${MPI_ROOT}/lib/libmpi.so")
12+
set_and_check(MPI_CXX_LIBRARIES "${MPI_ROOT}/lib/libmpi.so")
13+
14+
set_and_check(MPIEXEC_EXECUTABLE "${MPI_ROOT}/bin/mpiexec")
15+
set_and_check(MPI_C_COMPILER "${MPI_ROOT}/bin/mpicc")
16+
set_and_check(MPI_CXX_COMPILER "${MPI_ROOT}/bin/mpicxx")
17+
18+
if(NOT TARGET MPI::MPI_C)
19+
add_library(MPI::MPI_C INTERFACE IMPORTED)
20+
set_target_properties(MPI::MPI_C PROPERTIES
21+
INTERFACE_INCLUDE_DIRECTORIES "${MPI_C_INCLUDE_DIRS}"
22+
INTERFACE_LINK_LIBRARIES "${MPI_C_LIBRARIES}"
23+
)
24+
endif()
25+
26+
if(NOT TARGET MPI::MPI_CXX)
27+
add_library(MPI::MPI_CXX INTERFACE IMPORTED)
28+
set_target_properties(MPI::MPI_CXX PROPERTIES
29+
INTERFACE_INCLUDE_DIRECTORIES "${MPI_CXX_INCLUDE_DIRS}"
30+
INTERFACE_LINK_LIBRARIES "${MPI_CXX_LIBRARIES}"
31+
)
32+
endif()
33+
34+
set(MPI_FOUND TRUE)
35+
set(MPI_C_FOUND TRUE)
36+
set(MPI_CXX_FOUND TRUE)
37+
set(MPI_Fortran_FOUND FALSE)

0 commit comments

Comments
 (0)