Skip to content

Commit

Permalink
build: Support static PMIx/PRRTE
Browse files Browse the repository at this point in the history
Update the libevent, hwloc, pmix, and prrte configure checks to use
OAC_CHECK_PACKAGE for external builds and to better pull in the
static library dependencies from the hwloc and pmix.  This solves
the missing libz problem for building applications against a
static OMPI/PMIx build.

Signed-off-by: Brian Barrett <bbarrett@amazon.com>
  • Loading branch information
bwbarrett committed Mar 27, 2022
1 parent 14545a3 commit 3c6f88b
Show file tree
Hide file tree
Showing 6 changed files with 393 additions and 353 deletions.
48 changes: 27 additions & 21 deletions config/ompi_setup_prrte.m4
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ dnl Copyright (c) 2006-2007 Los Alamos National Security, LLC. All rights
dnl reserved.
dnl Copyright (c) 2009 Oak Ridge National Labs. All rights reserved.
dnl Copyright (c) 2019-2020 Intel, Inc. All rights reserved.
dnl Copyright (c) 2020-2021 Amazon.com, Inc. or its affiliates.
dnl All Rights reserved.
dnl Copyright (c) 2020-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
dnl Copyright (c) 2021 Nanook Consulting. All rights reserved.
dnl Copyright (c) 2021 IBM Corporation. All rights reserved.
dnl $COPYRIGHT$
Expand All @@ -39,7 +38,7 @@ dnl
dnl A Makefile conditional OMPI_WANT_PRRTE will be defined based on the
dnl results of the build.
AC_DEFUN([OMPI_SETUP_PRRTE],[
OPAL_VAR_SCOPE_PUSH([prrte_setup_internal_happy prrte_setup_external_happy prrte_setup_success_var])
OPAL_VAR_SCOPE_PUSH([prrte_setup_internal_happy prrte_setup_external_happy])
opal_show_subtitle "Configuring PRRTE"
Expand Down Expand Up @@ -118,7 +117,7 @@ dnl _OMPI_SETUP_PRRTE_INTERNAL([action-if-success], [action-if-not-success])
dnl
dnl Attempt to configure the built-in PRRTE.
AC_DEFUN([_OMPI_SETUP_PRRTE_INTERNAL], [
OPAL_VAR_SCOPE_PUSH([internal_prrte_args internal_prrte_extra_libs internal_prrte_happy deprecated_prefix_by_default print_prrte_warning internal_prrte_CPPFLAGS])
OPAL_VAR_SCOPE_PUSH([internal_prrte_args internal_prrte_happy deprecated_prefix_by_default print_prrte_warning internal_prrte_CPPFLAGS opal_prrte_CPPFLAGS_save])
# This is really a PRTE option that should not be in Open MPI, but
# there is not a great way to support the orterun/mpirun checks
Expand Down Expand Up @@ -164,18 +163,21 @@ AC_DEFUN([_OMPI_SETUP_PRRTE_INTERNAL], [
AS_IF([test "$opal_libevent_mode" = "internal"],
[internal_prrte_args="$internal_prrte_args --with-libevent --disable-libevent-lib-checks"
internal_prrte_args="$internal_prrte_args --with-libevent-extra-libs=\"$opal_libevent_LIBS\""
internal_prrte_CPPFLAGS="$internal_prrte_CPPFLAGS $opal_libevent_CPPFLAGS"])
internal_prrte_args="$internal_prrte_args --with-libevent-extra-libs=\"$opal_libevent_BUILD_LIBS\""
internal_prrte_CPPFLAGS="$internal_prrte_CPPFLAGS $opal_libevent_BUILD_CPPFLAGS"])
AS_IF([test "$opal_hwloc_mode" = "internal"],
[internal_prrte_args="$internal_prrte_args --disable-hwloc-lib-checks"
internal_prrte_args="$internal_prrte_args --with-hwloc-extra-libs=\"$opal_hwloc_LIBS\""
internal_prrte_CPPFLAGS="$internal_prrte_CPPFLAGS $opal_hwloc_CPPFLAGS"])
internal_prrte_args="$internal_prrte_args --with-hwloc-extra-libs=\"$opal_hwloc_BUILD_LIBS\""
internal_prrte_CPPFLAGS="$internal_prrte_CPPFLAGS $opal_hwloc_BUILD_CPPFLAGS"])
AS_IF([test "$opal_pmix_mode" = "internal"],
[internal_prrte_args="$internal_prrte_args --disable-pmix-lib-checks"
internal_prrte_args="$internal_prrte_args --with-pmix-extra-libs=\"$opal_pmix_LIBS\""
internal_prrte_CPPFLAGS="$internal_prrte_CPPFLAGS $opal_pmix_CPPFLAGS"])
internal_prrte_args="$internal_prrte_args --with-pmix-extra-libs=\"$opal_pmix_BUILD_LIBS\""
internal_prrte_CPPFLAGS="$internal_prrte_CPPFLAGS $opal_pmix_BUILD_CPPFLAGS"])
opal_prrte_CPPFLAGS_save="${CPPFLAGS}"
OPAL_FLAGS_APPEND_UNIQ([CPPFLAGS], [${opal_pmix_CPPFLAGS}])
AC_MSG_CHECKING([if PMIx version is 4.0.0 or greater])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <pmix_version.h>]],
Expand All @@ -194,6 +196,8 @@ AC_DEFUN([_OMPI_SETUP_PRRTE_INTERNAL], [
AC_MSG_WARN([--without-prrte option.])
AC_MSG_ERROR([Cannot continue])])
CPPFLAGS="${opal_prrte_CPPFLAGS_save}"
AS_IF([test "$with_ft" != "no"],
[internal_prrte_args="--enable-prte-ft $internal_prrte_args"],
[])
Expand Down Expand Up @@ -250,23 +254,25 @@ AC_DEFUN([_OMPI_SETUP_PRRTE_EXTERNAL], [
opal_prrte_CPPFLAGS_save=$CPPFLAGS
_OPAL_CHECK_PACKAGE_HEADER([opal_prrte], [prte.h], [$with_prrte],
[setup_prrte_external_happy=yes],
[setup_prrte_external_happy=no])
AS_IF([test -n "${with_prrte}" -a "${with_prrte}" != "yes" -a "${with_prrte}" != "no"],
[OPAL_FLAGS_APPEND_UNIQ([CPPFLAGS], ["-I${with_prrte}/include"])])
CPPFLAGS="$opal_prrte_CPPFLAGS_save $opal_prrte_CPPFLAGS"
AC_CHECK_HEADER([prte.h], [setup_prrte_external_happy=yes],
[setup_prrte_external_happy=no])
AC_MSG_CHECKING([if external PRRTE version is 2.0.0 or greater])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <prte_version.h>]],
[[
AS_IF([test "${setup_prrte_external_happy}" = "yes"],
[AC_CACHE_CHECK([if external PRRTE version is 2.0.0 or greater],
[ompi_setup_prrte_cv_version_happy],
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <prte_version.h>
]], [[
#if PRTE_NUMERIC_VERSION < 0x00020000
#error "prrte API version is less than 2.0.0"
#endif
]])],
[AC_MSG_RESULT([yes])
setup_prrte_external_happy=yes],
[AC_MSG_RESULT([no])
setup_prrte_external_happy=no])
[ompi_setup_prrte_cv_version_happy="yes"],
[ompi_setup_prrte_cv_version_happy="no"])])
AS_IF([test "${ompi_setup_prrte_cv_version_happy}" = "no"],
[setup_prrte_external_happy="no"])])
CPPFLAGS="$opal_prrte_CPPFLAGS_save"
Expand Down
187 changes: 96 additions & 91 deletions config/opal_config_hwloc.m4
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ dnl
dnl Copyright (c) 2009-2017 Cisco Systems, Inc. All rights reserved
dnl Copyright (c) 2014-2018 Research Organization for Information Science
dnl and Technology (RIST). All rights reserved.
dnl Copyright (c) 2020-2021 Amazon.com, Inc. or its affiliates. All Rights
dnl reserved.
dnl Copyright (c) 2020-2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
dnl Copyright (c) 2020 Intel, Inc. All rights reserved.
dnl $COPYRIGHT$
dnl
Expand All @@ -20,42 +19,37 @@ dnl configure, abort.
dnl
dnl This macro will change the environment in the following way:
dnl
dnl * opal_hwloc_header [legacy] - will be set if building
dnl internally, to the header file that should be included for
dnl embedded builds. This is used by PRRTE, but should not
dnl be used by new code.
dnl * opal_hwloc_mode - either external or internal. If internal,
dnl --with-hwloc should be ignored by other packages
dnl * opal_hwloc_CPPFLAGS - the C Preprocessor flags necessary to
dnl run the preprocessor on a file which relies on Hwloc
dnl headers. This will be folded into the global CPPFLAGS,
dnl so most people should never need this.
dnl * opal_hwloc_LDFLAGS - the linker flags necessary to run the
dnl linker on a file which relies on Hwloc libraries. This
dnl will be folded into the global CPPFLAGS, so most people
dnl should never need this.
dnl * opal_hwloc_LIBS - the libraries necessary to link source which
dnl uses Hwloc. Cannot be added to LIBS yet, because then
dnl other execution tests later in configure (there are sadly
dnl some) would fail if the path in LDFLAGS was not added to
dnl LD_LIBRARY_PATH.
dnl * opal_hwloc_WRAPPER_LDFLAGS - the linker flags necessary to
dnl add to the wrapper compilers in order to link an opal
dnl application when opal is built as a static library.
dnl * CPPFLAGS, LDFLAGS, LIBS - Updated to build against hwloc.
dnl Note that the values may be updated right before
dnl config.status.
dnl
dnl OPAL_WRAPPER_FLAGS_ADD will be called to add the correct LDFLAGS,
dnl STATIC_LDFLAGS, LIBS, and STATIC_LIBS for hwloc.
dnl
dnl The following environment variables will only be set if
dnl opal_hwloc_mode is "internal":
dnl
dnl * opal_hwloc_BUILD_CPPFLAGS - the C Preprocessor flags
dnl necessary to run the preprocessor on a file which relies
dnl on hwloc headers. This will be folded into the global
dnl CPPFLAGS (see note above).
dnl * opal_hwloc_BUILD_LIBS - the libraries necessary to link
dnl source which uses hwloc. Cannot be added to LIBS yet,
dnl because then other execution tests later in configure
dnl (there are sadly some) would fail if the path in LDFLAGS
dnl was not added to LD_LIBRARY_PATH.
dnl * opal_hwloc_WRAPPER_LIBS - the linker flags necessary to
dnl add to the wrapper compilers in order to link an opal
dnl application when opal is built as a static library.
dnl * CPPFLAGS, LDFLAGS - Updated opal_hwloc_CPPFLAGS and
dnl opal_hwloc_LDFLAGS.
AC_DEFUN([OPAL_CONFIG_HWLOC], [
OPAL_VAR_SCOPE_PUSH([external_hwloc_happy internal_hwloc_happy pkg_config_file pkg_config_happy pkg_config_ldflags pkg_config_libs])
OPAL_VAR_SCOPE_PUSH([external_hwloc_happy internal_hwloc_happy opal_hwloc_STATIC_LDFLAGS opal_hwloc_LIBS opal_hwloc_STATIC_LIBS])
opal_show_subtitle "Configuring hwloc"
OPAL_3RDPARTY_WITH([hwloc], [hwloc], [package_hwloc])
opal_hwloc_header=""
# unless internal specifically requested by the user, try to find
# an external that works.
external_hwloc_happy=0
Expand All @@ -76,79 +70,54 @@ AC_DEFUN([OPAL_CONFIG_HWLOC], [
AS_IF([test "$external_hwloc_happy" = "0" -a "$internal_hwloc_happy" = "0"],
[AC_MSG_ERROR([Could not find viable hwloc build.])])
AS_IF([test "$opal_hwloc_mode" = "internal"],
[pkg_config_file="${OMPI_TOP_BUILDDIR}/3rd-party/hwloc_directory/hwloc.pc"
PKG_CONFIG_PATH="${OMPI_TOP_BUILDDIR}/3rd-party/hwloc_directory:${PKG_CONFIG_PATH}"],
[test -n "$with_hwloc"],
[pkg_config_file="${with_hwloc}/lib/pkgconfig/hwloc.pc"
PKG_CONFIG_PATH="${with_hwloc}/lib/pkgconfig:${PKG_CONFIG_PATH}"],
[pkg_config_file="hwloc"])
pkg_config_happy=1
OPAL_GET_LDFLAGS_FROM_PC([$pkg_config_file], [pkg_config_ldflags], [pkg_config_happy=0])
OPAL_GET_LIBS_FROM_PC([$pkg_config_file], [pkg_config_libs], [pkg_config_happy=0])
AS_IF([test $pkg_config_happy -ne 0],
[opal_hwloc_WRAPPER_LDFLAGS="$pkg_config_ldflags"
opal_hwloc_WRAPPER_LIBS="$pkg_config_libs"],
[# guess that what we have from compiling OMPI is good enough
AS_IF([test -z "$opal_hwloc_WRAPPER_LDFLAGS"],
[opal_hwloc_WRAPPER_LDFLAGS="$opal_hwloc_LDFLAGS"])
AS_IF([test -z "$opal_hwloc_WRAPPER_LIBS"],
[opal_hwloc_WRAPPER_LIBS="$opal_hwloc_LIBS"])])
OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [$opal_hwloc_WRAPPER_LDFLAGS])
OPAL_WRAPPER_FLAGS_ADD([LIBS], [$opal_hwloc_WRAPPER_LIBS])
# this will work even if there is no hwloc package included,
# because hwloc_tarball and hwloc_directory will evaluate to an
# empty string. These are relative to the 3rd-party/ directory.
dnl this will work even if there is no hwloc package included,
dnl because hwloc_tarball and hwloc_directory will evaluate to an
dnl empty string. These are relative to the 3rd-party/ directory.
OPAL_3RDPARTY_EXTRA_DIST="$OPAL_3RDPARTY_EXTRA_DIST hwloc_tarball"
OPAL_3RDPARTY_DISTCLEAN_DIRS="$OPAL_3RDPARTY_DISTCLEAN_DIRS hwloc_directory"
AC_SUBST(opal_hwloc_CPPFLAGS)
AC_SUBST(opal_hwloc_LIBS)
AC_SUBST(opal_hwloc_LDFLAGS)
OPAL_WRAPPER_FLAGS_ADD([LDFLAGS], [${opal_hwloc_LDFLAGS}])
OPAL_WRAPPER_FLAGS_ADD([STATIC_LDFLAGS], [${opal_hwloc_STATIC_LDFLAGS}])
OPAL_WRAPPER_FLAGS_ADD([LIBS], [${opal_hwloc_LIBS}])
OPAL_WRAPPER_FLAGS_ADD([STATIC_LIBS], [${opal_hwloc_STATIC_LIBS}])
OPAL_WRAPPER_FLAGS_ADD([PC_MODULES], [${opal_hwloc_PC_MODULES}])
AC_CONFIG_COMMANDS_PRE([OPAL_CONFIG_HWLOC_INTERNAL_LIBS_HANDLER])
OPAL_SUMMARY_ADD([[Miscellaneous]], [[hwloc]], [hwloc], [$opal_hwloc_mode])
OPAL_VAR_SCOPE_POP
])


dnl _OPAL_CONFIG_HWLOC_EXTERNAL(action-if-happy, action-if-not-happy)
dnl
dnl only safe to call from OPAL_CONFIG_HWLOC, assumes variables from
dnl there are set.
AC_DEFUN([_OPAL_CONFIG_HWLOC_EXTERNAL], [
OPAL_VAR_SCOPE_PUSH([opal_hwloc_CPPFLAGS_save opal_hwloc_LDFLAGS_save opal_hwloc_LIBS_save opal_hwloc_external_support])
OAC_CHECK_PACKAGE([hwloc],
[opal_hwloc],
[hwloc.h],
[hwloc],
[hwloc_topology_init],
[opal_hwloc_external_support=yes],
[opal_hwloc_external_support=no])
# need these set for the tests below.
opal_hwloc_CPPFLAGS_save=$CPPFLAGS
opal_hwloc_LDFLAGS_save=$LDFLAGS
opal_hwloc_LIBS_save=$LIBS
AS_IF([test ! -z "$with_hwloc_libdir"],
[OPAL_CHECK_WITHDIR([hwloc-libdir], [$with_hwloc_libdir],
[libhwloc.*])])
OPAL_CHECK_PACKAGE([opal_hwloc],
[hwloc.h],
[hwloc],
[hwloc_topology_init],
[],
[$with_hwloc],
[$with_hwloc_libdir],
[opal_hwloc_external_support=yes],
[opal_hwloc_external_support=no])
# need these set for the tests below. If things fail, will undo at the end.
CPPFLAGS="$opal_hwloc_CPPFLAGS_save $opal_hwloc_CPPFLAGS"
LDFLAGS="$opal_hwloc_LDFLAGS_save $opal_hwloc_LDFLAGS"
LIBS="$opal_hwloc_LIBS_save $opal_hwloc_LIBS"
OPAL_FLAGS_APPEND_UNIQ([CPPFLAGS], [$opal_hwloc_CPPFLAGS])
OPAL_FLAGS_APPEND_UNIQ([LDFLAGS], [$opal_hwloc_LDFLAGS])
OPAL_FLAGS_APPEND_UNIQ([LIBS], [$opal_hwloc_LIBS])
AS_IF([test "$opal_hwloc_external_support" = "yes"],
[AC_MSG_CHECKING([if external hwloc version is 1.11.0 or greater])
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <hwloc.h>]],
[[
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <hwloc.h>
]], [[
#if HWLOC_API_VERSION < 0x00010500
#error "hwloc API version is less than 0x00011100"
#endif
Expand All @@ -159,16 +128,21 @@ AC_DEFUN([_OPAL_CONFIG_HWLOC_EXTERNAL], [
opal_hwloc_external_support="no"])])
AS_IF([test "$opal_hwloc_external_support" = "yes"],
[AC_CHECK_DECLS([HWLOC_OBJ_OSDEV_COPROC], [], [], [#include <hwloc.h>])
[AC_CHECK_DECLS([HWLOC_OBJ_OSDEV_COPROC], [], [], [#include <hwloc.h>
])
AC_CHECK_FUNCS([hwloc_topology_dup])])
CPPFLAGS="$opal_hwloc_CPPFLAGS_save"
LDFLAGS="$opal_hwloc_LDFLAGS_save"
LIBS="$opal_hwloc_LIBS_save"
AS_IF([test "$opal_hwloc_external_support" = "yes"],
[$1],
[CPPFLAGS="$opal_hwloc_CPPFLAGS_save"
$2])
[dnl Do not add hwloc libs to LIBS until late, because
dnl it will screw up other tests (like the pthread tests)
opal_hwloc_BUILD_LIBS="${opal_hwloc_LIBS}"
$1],
[$2])
OPAL_VAR_SCOPE_POP
])
Expand All @@ -180,7 +154,7 @@ dnl external hwloc is not going to be used. Assumes that if
dnl this function is called, that success means the internal package
dnl will be used.
AC_DEFUN([_OPAL_CONFIG_HWLOC_INTERNAL], [
OPAL_VAR_SCOPE_PUSH([subconfig_happy internal_hwloc_location extra_configure_args found_enable_plugins hwloc_config_arg])
OPAL_VAR_SCOPE_PUSH([subconfig_happy internal_hwloc_location extra_configure_args found_enable_plugins hwloc_config_arg pkg_config_file pkg_config_happy])
extra_configure_args=
Expand Down Expand Up @@ -216,20 +190,42 @@ AC_DEFUN([_OPAL_CONFIG_HWLOC_INTERNAL], [
[subconfig_happy=1], [subconfig_happy=0])
OPAL_SUBDIR_ENV_RESTORE([opal_hwloc_configure])
AS_IF([test "$subconfig_happy" = "1"],
AS_IF([test ${subconfig_happy} -eq 1],
[internal_hwloc_location="3rd-party/hwloc_directory"
# note: because we only ship/commit a tarball (and not the source
# directory), the source is always expanded in the builddir, so we
# only need to add a -I to the builddir.
dnl We do not consider it an error if pkg-config doesn't work / exist / etc.
pkg_config_file="${OMPI_TOP_BUILDDIR}/3rd-party/hwloc_directory/hwloc.pc"
pkg_config_happy=0
OAC_CHECK_PACKAGE_PARSE_PKGCONFIG([hwloc_internal], [opal_hwloc], [${pkg_config_file}], [pkg_config_happy=1])
dnl Don't pull LDFLAGS, because we don't have a good way to avoid
dnl a -L to our install directory, which can cause some weirdness
dnl if there's an old OMPI install there. And it makes filtering
dnl redundant flags easier.
opal_hwloc_LDFLAGS=
dnl with no pkg-config data, guess. assume that -L${libdir} is already added to LDFLAGS
AS_IF([test $pkg_config_happy -eq 0],
[opal_hwloc_STATIC_LDFLAGS=
opal_hwloc_LIBS="-lhwloc"
opal_hwloc_STATIC_LIBS=
opal_hwloc_PC_MODULES=])
# note: because we only ship/commit a tarball (and not the
# source directory), the source is always expanded in the
# builddir, so we only need to add a -I to the builddir.
# Overwrite the OAC_CHECK_PACKAGE_PARSE PKGCONFIG results,
# because it's the install dir location, not the build
# location.
opal_hwloc_CPPFLAGS="-I$OMPI_TOP_BUILDDIR/$internal_hwloc_location/include -I$OMPI_TOP_SRCDIR/$internal_hwloc_location/include"
CPPFLAGS="$CPPFLAGS $opal_hwloc_CPPFLAGS"
opal_hwloc_BUILD_CPPFLAGS="${opal_hwloc_CPPFLAGS}"
# No need to update LDFLAGS, because they will install into
# our tree and in the mean time are referenced by their .la
# files.
opal_hwloc_LIBS="$OMPI_TOP_BUILDDIR/$internal_hwloc_location/hwloc/libhwloc.la"
opal_hwloc_WRAPPER_LIBS="-lhwloc"
opal_hwloc_header="$OMPI_TOP_BUILDDIR/$internal_hwloc_location/include/hwloc.h"
opal_hwloc_BUILD_LIBS="$OMPI_TOP_BUILDDIR/$internal_hwloc_location/hwloc/libhwloc.la"
opal_hwloc_WRAPPER_LIBS="${opal_hwloc_LIBS}"
# no need to add to DIST_SUBDIRS, because we only ship the
# tarball. This is relative to the 3rd-party/ directory.
Expand All @@ -239,3 +235,12 @@ AC_DEFUN([_OPAL_CONFIG_HWLOC_INTERNAL], [
OPAL_VAR_SCOPE_POP
])


dnl We need to delay adding .la files to LIBS until the very end of
dnl configure, to avoid pulling it into other configure tests.
AC_DEFUN([OPAL_CONFIG_HWLOC_INTERNAL_LIBS_HANDLER], [
OPAL_FLAGS_APPEND_UNIQ([CPPFLAGS], [${opal_hwloc_CPPFLAGS}])
OPAL_FLAGS_APPEND_UNIQ([LDFLAGS], [$opal_hwloc_LDFLAGS])
OPAL_FLAGS_APPEND_MOVE([LIBS], [${opal_hwloc_BUILD_LIBS}])
])
Loading

0 comments on commit 3c6f88b

Please sign in to comment.