From 49e5554636b9b651e9d772bbcfad39062896182d Mon Sep 17 00:00:00 2001 From: Aurelien Bouteiller Date: Thu, 25 Sep 2025 13:33:07 -0400 Subject: [PATCH] Modify find-pmix to create imported targets (#242) --- cmake/FindPMIx.cmake | 68 +++++++++++++++++++++++++++ cmake/find_pmix.cmake | 62 ------------------------ tests/functional_tests/CMakeLists.txt | 13 ++--- 3 files changed, 71 insertions(+), 72 deletions(-) create mode 100644 cmake/FindPMIx.cmake delete mode 100644 cmake/find_pmix.cmake diff --git a/cmake/FindPMIx.cmake b/cmake/FindPMIx.cmake new file mode 100644 index 0000000000..2fcac1da96 --- /dev/null +++ b/cmake/FindPMIx.cmake @@ -0,0 +1,68 @@ +############################################################################### +# Copyright (c) Advanced Micro Devices, Inc. All rights reserved. +# +# SPDX-License-Identifier: MIT +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. +############################################################################### + +# Find pmix installation. +# Different scenarios need to be covered: +# - pmix at user-provided location (i.e., in PMIX_ROOT) +# - pmix installed as part of Open MPI, i.e., in the MPI installation directories +# - pmix deployed with linux distros, Slurm, etc. + +find_package(PkgConfig QUIET) +if (PkgConfig_FOUND) + # Figure out and prepend the install dir for MPI + string(REGEX REPLACE "/include$" "" mpi_dir "${MPI_CXX_HEADER_DIR}") + foreach (mpiroot "${MPI_ROOT}" "$ENV{MPI_ROOT}" "${mpi_dir}") + if (mpiroot) + set(ENV{PKG_CONFIG_PATH} "${mpiroot}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") + endif() + endforeach() + # prepend PMIX_ROOT + foreach (pmixroot "${PMIX_ROOT}" "$ENV{PMIX_ROOT}" "${PMIx_ROOT}" "$ENV{PMIx_ROOT}") + if (pmixroot) + set(ENV{PKG_CONFIG_PATH} "${pmixroot}/lib/pkgconfig:$ENV{PKG_CONFIG_PATH}") + endif() + endforeach() + pkg_check_modules(PC_PMIX QUIET pmix) +endif() + +find_path(PMIX_INCLUDE_DIR pmix.h + HINTS ${PC_PMIX_INCLUDE_DIRS} ${MPI_CXX_HEADER_DIR} ${MPI_ROOT} $ENV{MPI_ROOT} + PATH_SUFFIXES include) +if (PMIX_INCLUDE_DIR) + string(REGEX REPLACE "/include$" "" pmix_dir ${PMIX_INCLUDE_DIR}) + find_library(PMIX_LIBRARY pmix PATHS ${pmix_dir} PATH_SUFFIXES lib lib64 NO_DEFAULT_PATH) +endif() + +find_package_handle_standard_args(PMIx DEFAULT_MSG + PMIX_LIBRARY PMIX_INCLUDE_DIR) +mark_as_advanced(PMIX_LIBRARY PMIX_INCLUDE_DIR) + +if (PMIx_FOUND) +add_library(PMIx::pmix UNKNOWN IMPORTED) +set_target_properties(PMIx::pmix PROPERTIES + IMPORTED_LOCATION "${PMIX_LIBRARY}" + INTERFACE_COMPILE_OPTIONS "${PC_PMIX_CFLAGS_OTHER}" + INTERFACE_INCLUDE_DIRECTORIES "${PMIX_INCLUDE_DIR}" +) +endif() diff --git a/cmake/find_pmix.cmake b/cmake/find_pmix.cmake deleted file mode 100644 index 1d1bfec942..0000000000 --- a/cmake/find_pmix.cmake +++ /dev/null @@ -1,62 +0,0 @@ -############################################################################### -# Copyright (c) Advanced Micro Devices, Inc. All rights reserved. -# -# SPDX-License-Identifier: MIT -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to -# deal in the Software without restriction, including without limitation the -# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -# sell copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -# IN THE SOFTWARE. -############################################################################### - -# Find pmix installation. -# Two different scenarios need to be covered: -# - pmix installed as part of Open MPI, i.e. it will be in the MPI installation directories -# - pmix deployed with linux distros -# - later: handle pmix deployed with slurm. - -macro(check_pmix) - set(prev_CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES}) - find_package(PMIx QUIET) - if (PMIx_FOUND) - message("-- Found pmix at ${PMIx_CONFIG} ${PMIx_INCLUDE_DIRS}") - else() - if(NOT PMIX_HEADER OR NOT PMIX_LIBRARY) - message("-- Cound not find pmix using find_package") - - list(APPEND CMAKE_REQUIRED_INCLUDES "${MPI_CXX_HEADER_DIR}") #prefer Open MPI internal PMIx if any - find_path(PMIX_HEADER pmix.h PATHS ${CMAKE_REQUIRED_INCLUDES}) - if (PMIX_HEADER) - message("-- Found pmix.h at ${PMIX_HEADER}") - get_filename_component(pmix_lib_dir ${PMIX_HEADER} DIRECTORY) - find_library(PMIX_LIBRARY pmix PATHS ${pmix_lib_dir} PATH_SUFFIXES lib lib64 NO_DEFAULT_PATH) - endif() - if(PMIX_HEADER AND PMIX_LIBRARY) - message("-- Found libpmix at ${PMIX_LIBRARY}") - elseif(NOT PMIX_HEADER) - message("-- Cound not find pmix.h") - elseif(NOT PMIX_LIBRARY) - message("-- Could not find libpmix.so") - endif() - endif() - endif() - set(CMAKE_REQUIRED_INCLUDES ${prev_CMAKE_REQUIRED_INCLUDES}) - if (PMIX_HEADER AND PMIX_LIBRARY) - set(PMIX_INCLUDE_DIRECTORIES ${PMIX_HEADER}) - set(PMIX_LIBRARIES ${PMIX_LIBRARY}) - set(PMIx_FOUND TRUE) - endif() -endmacro() diff --git a/tests/functional_tests/CMakeLists.txt b/tests/functional_tests/CMakeLists.txt index f0ac6e5788..7352299187 100644 --- a/tests/functional_tests/CMakeLists.txt +++ b/tests/functional_tests/CMakeLists.txt @@ -71,9 +71,6 @@ target_sources( ############################################################################### # ROCSHMEM ############################################################################### -include(${CMAKE_SOURCE_DIR}/cmake/find_pmix.cmake) -check_pmix() - if (BUILD_TESTS_ONLY) find_package(MPI REQUIRED) find_package(hip REQUIRED PATHS /opt/rocm) @@ -87,21 +84,17 @@ if (BUILD_TESTS_ONLY) ) endif() +find_package(PMIx) + target_compile_definitions( ${PROJECT_NAME} PRIVATE $<$:HAVE_PMIX=1> ) -target_include_directories( - ${PROJECT_NAME} - PRIVATE - ${PMIX_INCLUDE_DIRECTORIES} -) - target_link_libraries( ${PROJECT_NAME} PRIVATE roc::rocshmem - ${PMIX_LIBRARIES} + PMIx::pmix )