Skip to content

Commit b542a9c

Browse files
committed
build/ofi: Update checks to use cache file
Update the ofi checks to use OAC_CHECK_PACKAGE and cache checks, rather than a big if statement. This required a bit of trickery to get the cache to work with the version check macro, but as an added bonus, the print for version checking now is in the form <major>.<minor> instead of <major>,<minor>. Signed-off-by: Brian Barrett <bbarrett@amazon.com>
1 parent 3b8e99a commit b542a9c

File tree

8 files changed

+145
-157
lines changed

8 files changed

+145
-157
lines changed

config/opal_check_ofi.m4

Lines changed: 63 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dnl -*- shell-script -*-
1+
dnl -*- autoconf -*-
22
dnl
33
dnl Copyright (c) 2015-2020 Cisco Systems, Inc. All rights reserved.
44
dnl Copyright (c) 2016-2017 Los Alamos National Security, LLC. All rights
@@ -24,42 +24,55 @@ dnl $3: action if OFI API version is < $1
2424
AC_DEFUN([OPAL_CHECK_OFI_VERSION_GE],[
2525
OPAL_VAR_SCOPE_PUSH([opal_ofi_ver_ge_save_CPPFLAGS opal_ofi_ver_ge_happy])
2626
27-
AC_MSG_CHECKING([if OFI API version number is >= $1])
28-
opal_ofi_ver_ge_save_CPPFLAGS=$CPPFLAGS
29-
CPPFLAGS=$opal_ofi_CPPFLAGS
27+
AS_LITERAL_WORD_IF([$1], [], [m4_fatal([OPAL_CHECK_OFI_VERSION_GE called with non-literal first argument])])dnl
28+
AS_VAR_PUSHDEF([version_cache_var], [opal_ofi_ver_ge_cv_$1])dnl
29+
m4_pushdef([version_pretty_print], [m4_translit([$1], [,], [.])])dnl
3030
31-
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <rdma/fabric.h>]],
32-
[[
31+
AC_CACHE_CHECK([if OFI API version number is >= version_pretty_print],
32+
[version_cache_var],
33+
[opal_ofi_ver_ge_save_CPPFLAGS=$CPPFLAGS
34+
CPPFLAGS=$opal_ofi_CPPFLAGS
35+
36+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
37+
[[#include <rdma/fabric.h>
38+
]], [[
3339
#if !defined(FI_MAJOR_VERSION)
3440
#error "we cannot check the version -- sad panda"
3541
#elif FI_VERSION_LT(FI_VERSION(FI_MAJOR_VERSION, FI_MINOR_VERSION), FI_VERSION($1))
3642
#error "version is too low -- nopes"
3743
#endif
3844
]])],
39-
[opal_ofi_ver_ge_happy=1],
40-
[opal_ofi_ver_ge_happy=0])
45+
[version_cache_var=yes],
46+
[version_cache_var=no])])
4147
42-
AS_IF([test $opal_ofi_ver_ge_happy -eq 1],
43-
[AC_MSG_RESULT([yes])
44-
$2],
45-
[AC_MSG_RESULT([no])
46-
$3])
48+
AS_IF([test "${version_cache_var}" = "yes"],
49+
[$2],
50+
[$3])
4751
4852
CPPFLAGS=$opal_ofi_ver_ge_save_CPPFLAGS
4953
54+
m4_popdef([version_pretty_print])
55+
AS_VAR_POPDEF([version_cache_var])
5056
OPAL_VAR_SCOPE_POP
5157
])dnl
5258

53-
dnl
54-
dnl _OPAL_CHECK_OFI
59+
60+
dnl OPAL_CHECK_OFI(prefix, [action if found], [action if not found])
5561
dnl --------------------------------------------------------
5662
dnl Do the real work of checking for OFI libfabric.
5763
dnl Upon return:
5864
dnl
59-
dnl - opal_ofi_happy: will be "yes" or "no"
60-
dnl - opal_ofi_{CPPFLAGS|LDFLAGS|LIBS} will be loaded (if relevant)
65+
dnl opal_ofi_{CPPFLAGS, LDFLAGS, LIBS} and prefix_{CPPFLAGS, LDFLAGS,
66+
dnl LIBS} will be set as needed.
6167
dnl
62-
AC_DEFUN([_OPAL_CHECK_OFI],[
68+
dnl This macro intentionally leaks opal_ofi_happy = yes/no as well as
69+
dnl evaluating the action if found / action if not found
70+
dnl
71+
AC_DEFUN([OPAL_CHECK_OFI],[
72+
OPAL_VAR_SCOPE_PUSH([opal_check_ofi_save_CPPFLAGS opal_check_ofi_save_LDFLAGS opal_check_ofi_save_LIBS opal_check_fi_info_pci])
73+
74+
m4_ifblank([$1], [m4_fatal([First argument must be set for call to OPAL_CHECK_OFI])])
75+
6376
# Add --with options
6477
AC_ARG_WITH([libfabric],
6578
[AS_HELP_STRING([--with-libfabric=DIR],
@@ -71,58 +84,32 @@ AC_DEFUN([_OPAL_CHECK_OFI],[
7184
AC_ARG_WITH([ofi],
7285
[AS_HELP_STRING([--with-ofi=DIR],
7386
[Specify location of OFI libfabric installation, adding DIR/include to the default search location for libfabric headers, and DIR/lib or DIR/lib64 to the default search location for libfabric libraries. Error if libfabric support cannot be found.])])
74-
7587
AC_ARG_WITH([ofi-libdir],
7688
[AS_HELP_STRING([--with-ofi-libdir=DIR],
7789
[Search for OFI libfabric libraries in DIR])])
7890
79-
if test "$with_ofi" = ""; then
80-
with_ofi=$with_libfabric
81-
fi
82-
83-
if test "$with_ofi_libdir" = ""; then
84-
with_ofi_libdir=$with_libfabric_libdir
85-
fi
91+
AS_IF([test -z "${with_ofi}"], [with_ofi=${with_libfabric}])
92+
AS_IF([test -z "${with_ofi_libdir}"], [with_ofi_libdir=${with_libfabric_libdir}])
8693
87-
# Sanity check the --with values
88-
OPAL_CHECK_WITHDIR([ofi], [$with_ofi],
89-
[include/rdma/fabric.h])
90-
OPAL_CHECK_WITHDIR([ofi-libdir], [$with_ofi_libdir],
91-
[libfabric.*])
94+
opal_check_ofi_save_CPPFLAGS=${CPPFLAGS}
95+
opal_check_ofi_save_LDFLAGS=${LDFLAGS}
96+
opal_check_ofi_save_LIBS=${LIBS}
9297
93-
OPAL_VAR_SCOPE_PUSH([opal_check_ofi_save_CPPFLAGS opal_check_ofi_save_LDFLAGS opal_check_ofi_save_LIBS opal_check_fi_info_pci])
94-
opal_check_ofi_save_CPPFLAGS=$CPPFLAGS
95-
opal_check_ofi_save_LDFLAGS=$LDFLAGS
96-
opal_check_ofi_save_LIBS=$LIBS
9798
opal_check_fi_info_pci=0
9899
99-
opal_ofi_happy=yes
100-
AS_IF([test "$with_ofi" = "no"],
101-
[opal_ofi_happy=no])
102-
103-
AS_IF([test $opal_ofi_happy = yes],
104-
[AC_MSG_CHECKING([looking for OFI libfabric in])
105-
AS_IF([test "$with_ofi" != "yes"],
106-
[opal_ofi_dir=$with_ofi
107-
AC_MSG_RESULT([($opal_ofi_dir)])],
108-
[AC_MSG_RESULT([(default search paths)])])
109-
AS_IF([test ! -z "$with_ofi_libdir" && \
110-
test "$with_ofi_libdir" != "yes"],
111-
[opal_ofi_libdir=$with_ofi_libdir])
112-
])
100+
dnl OMPI has used ofi everywhere for some time, but the pkg-config
101+
dnl module name is libfabric. Easier to set the pkg-config module
102+
dnl name explicitly than change everything in OMPI.
103+
m4_define([ofi_pkgconfig_module], [libfabric])
104+
OAC_CHECK_PACKAGE([ofi],
105+
[$1],
106+
[rdma/fabric.h],
107+
[fabric],
108+
[fi_getinfo],
109+
[opal_ofi_happy=yes],
110+
[opal_ofi_happy=no])
113111
114-
AS_IF([test $opal_ofi_happy = yes],
115-
[OPAL_CHECK_PACKAGE([opal_ofi],
116-
[rdma/fabric.h],
117-
[fabric],
118-
[fi_getinfo],
119-
[],
120-
[$opal_ofi_dir],
121-
[$opal_ofi_libdir],
122-
[],
123-
[opal_ofi_happy=no])])
124-
125-
CPPFLAGS="$CPPFLAGS $opal_ofi_CPPFLAGS"
112+
OPAL_FLAGS_APPEND_UNIQ([CPPFLAGS], [${$1_CPPFLAGS}])
126113
127114
AS_IF([test $opal_ofi_happy = yes],
128115
[AC_CHECK_HEADERS([rdma/fi_ext.h])
@@ -133,7 +120,7 @@ AC_DEFUN([_OPAL_CHECK_OFI],[
133120
[[#include <rdma/fabric.h>]])
134121
135122
AC_DEFINE_UNQUOTED([OPAL_OFI_PCI_DATA_AVAILABLE],
136-
[$opal_check_fi_info_pci],
123+
[${opal_check_fi_info_pci}],
137124
[check if pci data is available in ofi])
138125
139126
AC_CHECK_DECLS([FI_OPT_FI_HMEM_P2P],
@@ -147,51 +134,28 @@ AC_DEFUN([_OPAL_CHECK_OFI],[
147134
])
148135
149136
OPAL_FLAGS_APPEND_UNIQ([CPPFLAGS], [${opal_pmix_CPPFLAGS}])
150-
151137
AC_CHECK_DECLS([PMIX_PACKAGE_RANK],
152138
[],
153139
[],
154140
[#include <pmix.h>])])
155141
156-
CPPFLAGS=$opal_check_ofi_save_CPPFLAGS
157-
LDFLAGS=$opal_check_ofi_save_LDFLAGS
158-
LIBS=$opal_check_ofi_save_LIBS
142+
CPPFLAGS=${opal_check_ofi_save_CPPFLAGS}
143+
LDFLAGS=${opal_check_ofi_save_LDFLAGS}
144+
LIBS=${opal_check_ofi_save_LIBS}
159145
160-
AC_SUBST([opal_ofi_CPPFLAGS])
161-
AC_SUBST([opal_ofi_LDFLAGS])
162-
AC_SUBST([opal_ofi_LIBS])
146+
dnl for backwards compatibility reasons
147+
opal_ofi_CPPFLAGS="${$1_CPPFLAGS}"
148+
opal_ofi_LDFLAGS="${$1_LDFLAGS}"
149+
opal_ofi_LIBS="${$1_LIBS}"
163150
164-
OPAL_SUMMARY_ADD([Transports], [OpenFabrics OFI Libfabric], [], [$opal_ofi_happy])
165-
166-
OPAL_VAR_SCOPE_POP
151+
OPAL_SUMMARY_ADD([Transports], [OpenFabrics OFI Libfabric], [], [${$1_SUMMARY}])
167152
168-
AS_IF([test $opal_ofi_happy = no],
169-
[AS_IF([test -n "$with_ofi" && test "$with_ofi" != "no"],
153+
AS_IF([test "${opal_ofi_happy}" = "yes"],
154+
[$2],
155+
[AS_IF([test -n "${with_ofi}" && test "${with_ofi}" != "no"],
170156
[AC_MSG_WARN([OFI libfabric support requested (via --with-ofi or --with-libfabric), but not found.])
171157
AC_MSG_ERROR([Cannot continue.])])
172-
])
173-
])dnl
174-
158+
$3])
175159
176-
dnl
177-
dnl OPAL_CHECK_OFI
178-
dnl --------------------------------------------------------
179-
dnl Check to see if OFI libfabric is available.
180-
dnl
181-
dnl This is a simple wrapper around _OPAL_CHECK_OFI that just
182-
dnl ensures to only run the checks once. We do not use AC_REQUIRE
183-
dnl because that re-orders the texts and makes ordering in stdout
184-
dnl quite confusing / difficult to grok.
185-
dnl
186-
AC_DEFUN([OPAL_CHECK_OFI],[
187-
# Check for OFI libfabric. Note that $opal_ofi_happy is used in
188-
# other configure.m4's to know if OFI/libfabric configured
189-
# successfully. We only need to run the back-end checks once, but
190-
# at least emit a "checking..." statement each subsequent time
191-
# this macro is invoked so that configure's stdout has
192-
# sensible/logical output.
193-
AS_IF([test -z "$opal_ofi_happy"],
194-
[_OPAL_CHECK_OFI],
195-
[AC_MSG_CHECKING([if OFI libfabric is available])
196-
AC_MSG_RESULT([$opal_ofi_happy])])
197-
])
160+
OPAL_VAR_SCOPE_POP
161+
])dnl

ompi/mca/mtl/ofi/Makefile.am

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# and Technology (RIST). All rights reserved.
1010
# Copyright (c) 2020 Triad National Security, LLC. All rights
1111
# reserved.
12+
# Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
1213
# $COPYRIGHT$
1314
#
1415
# Additional copyrights may follow
@@ -22,7 +23,7 @@ EXTRA_DIST = post_configure.sh \
2223
MAINTAINERCLEANFILES = \
2324
$(generated_sources)
2425

25-
AM_CPPFLAGS = $(opal_ofi_CPPFLAGS)
26+
AM_CPPFLAGS = $(mtl_ofi_CPPFLAGS)
2627

2728
dist_ompidata_DATA = help-mtl-ofi.txt
2829

@@ -77,15 +78,15 @@ mcacomponentdir = $(ompilibdir)
7778
mcacomponent_LTLIBRARIES = $(component_install)
7879
mca_mtl_ofi_la_SOURCES = $(mtl_ofi_sources)
7980
mca_mtl_ofi_la_LDFLAGS = \
80-
$(opal_ofi_LDFLAGS) \
81+
$(mtl_ofi_LDFLAGS) \
8182
-module -avoid-version
8283
mca_mtl_ofi_la_LIBADD = $(top_builddir)/ompi/lib@OMPI_LIBMPI_NAME@.la \
8384
$(OPAL_TOP_BUILDDIR)/opal/mca/common/ofi/lib@OPAL_LIB_NAME@mca_common_ofi.la \
84-
$(opal_ofi_LIBS)
85+
$(mtl_ofi_LIBS)
8586

8687
noinst_LTLIBRARIES = $(component_noinst)
8788
libmca_mtl_ofi_la_SOURCES = $(mtl_ofi_sources)
8889
libmca_mtl_ofi_la_LDFLAGS = \
89-
$(opal_ofi_LDFLAGS) \
90+
$(mtl_ofi_LDFLAGS) \
9091
-module -avoid-version
91-
libmca_mtl_ofi_la_LIBADD = $(opal_ofi_LIBS)
92+
libmca_mtl_ofi_la_LIBADD = $(mtl_ofi_LIBS)

ompi/mca/mtl/ofi/configure.m4

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
# -*- shell-script -*-
1+
# -*- autoconf -*-
22
#
33
# Copyright (c) 2013-2014 Intel, Inc. All rights reserved
44
#
55
# Copyright (c) 2014-2020 Cisco Systems, Inc. All rights reserved
66
# Copyright (c) 2017 Los Alamos National Security, LLC. All rights
77
# reserved.
8+
# Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
89
# $COPYRIGHT$
910
#
1011
# Additional copyrights may follow
@@ -23,29 +24,40 @@ AC_DEFUN([MCA_ompi_mtl_ofi_POST_CONFIG], [
2324
# [action-if-cant-compile])
2425
# ------------------------------------------------
2526
AC_DEFUN([MCA_ompi_mtl_ofi_CONFIG],[
26-
AC_CONFIG_FILES([ompi/mca/mtl/ofi/Makefile])
27-
28-
# Check for OFI
29-
OPAL_CHECK_OFI
27+
OPAL_VAR_SCOPE_PUSH([mtl_ofi_happy])
3028
31-
# Check for CUDA
32-
OPAL_CHECK_CUDA
29+
AC_CONFIG_FILES([ompi/mca/mtl/ofi/Makefile])
3330
34-
# Check for cuda support. If so, we require a minimum libfabric version
35-
# of 1.9. FI_HMEM capabilities are only available starting from v1.9
36-
opal_ofi_happy="yes"
37-
AS_IF([test "$opal_check_cuda_happy" = "yes"],
38-
[OPAL_CHECK_OFI_VERSION_GE([1,9],
39-
[],
40-
[opal_ofi_happy=no])])
31+
OPAL_CHECK_OFI([mtl_ofi],
32+
[mtl_ofi_happy=1],
33+
[mtl_ofi_happy=0])
4134
42-
# The OFI MTL requires at least OFI libfabric v1.5.
43-
AS_IF([test "$opal_ofi_happy" = "yes"],
35+
dnl The OFI MTL requires at least OFI libfabric v1.5.
36+
AS_IF([test ${mtl_ofi_happy} -eq 1],
4437
[OPAL_CHECK_OFI_VERSION_GE([1,5],
4538
[],
46-
[opal_ofi_happy=no])])
39+
[mtl_ofi_happy=0])])
4740
48-
AS_IF([test "$opal_ofi_happy" = "yes"],
41+
AS_IF([test ${mtl_ofi_happy} -eq 1],
42+
[OPAL_CHECK_CUDA
43+
44+
dnl Check for cuda support. If so, we require a minimum libfabric version
45+
dnl of 1.9. FI_HMEM capabilities are only available starting from v1.9
46+
AS_IF([test "${opal_check_cuda_happy}" = "yes"],
47+
[OPAL_CHECK_OFI_VERSION_GE([1,9],
48+
[],
49+
[mtl_ofi_happy=0])])])
50+
51+
AS_IF([test ${mtl_ofi_happy} -eq 1],
4952
[$1],
50-
[$2])
53+
[AS_IF([test -n "${with_ofi}" -a "${with_ofi}" != "no"],
54+
[AC_MSG_WARN([OFI libfabric support requested (via --with-ofi or --with-libfabric), but not found.])
55+
AC_MSG_ERROR([Cannot continue.])])
56+
$2])
57+
58+
AC_SUBST([mtl_ofi_CPPFLAGS])
59+
AC_SUBST([mtl_ofi_LDFLAGS])
60+
AC_SUBST([mtl_ofi_LIBS])
61+
62+
OPAL_VAR_SCOPE_POP
5163
])dnl

opal/mca/btl/ofi/Makefile.am

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# Copyright (c) 2018 Intel, inc. All rights reserved
1616
# Copyright (c) 2020 Triad National Security, LLC. All rights
1717
# reserved.
18+
# Copyright (c) 2022 Amazon.com, Inc. or its affiliates. All Rights reserved.
1819
# $COPYRIGHT$
1920
#
2021
# Additional copyrights may follow
@@ -24,7 +25,7 @@
2425

2526
#dist_opaldata_DATA = help-mpi-btl-ofi.txt
2627

27-
AM_CPPFLAGS = $(opal_ofi_CPPFLAGS)
28+
AM_CPPFLAGS = $(btl_ofi_CPPFLAGS)
2829
sources = \
2930
btl_ofi.h \
3031
btl_ofi_component.c \
@@ -58,12 +59,12 @@ mcacomponentdir = $(opallibdir)
5859
mcacomponent_LTLIBRARIES = $(component)
5960
mca_btl_ofi_la_SOURCES = $(component_sources)
6061
mca_btl_ofi_la_LDFLAGS = -module -avoid-version \
61-
$(opal_ofi_LDFLAGS)
62+
$(btl_ofi_LDFLAGS)
6263
mca_btl_ofi_la_LIBADD = $(top_builddir)/opal/lib@OPAL_LIB_NAME@.la \
6364
$(OPAL_TOP_BUILDDIR)/opal/mca/common/ofi/lib@OPAL_LIB_NAME@mca_common_ofi.la \
64-
$(opal_ofi_LIBS)
65+
$(btl_ofi_LIBS)
6566

6667
noinst_LTLIBRARIES = $(lib)
6768
libmca_btl_ofi_la_SOURCES = $(lib_sources)
68-
libmca_btl_ofi_la_LDFLAGS = -module -avoid-version $(opal_ofi_LDFLAGS)
69-
libmca_btl_ofi_la_LIBS = $(opal_ofi_LIBS)
69+
libmca_btl_ofi_la_LDFLAGS = -module -avoid-version $(btl_ofi_LDFLAGS)
70+
libmca_btl_ofi_la_LIBS = $(btl_ofi_LIBS)

0 commit comments

Comments
 (0)